Find registered Metadata object.

def _get_metadata_model(name=None):
    """Find registered Metadata object."""
    if name is not None:
        try:
            return registry[name]
        except KeyError:
            if len(registry) == 1:
                valid_names = 'Try using the name "%s" or simply leaving it '\
                              'out altogether.' % list(registry)[0]
            else:
                valid_names = "Valid names are " + ", ".join(
                    '"%s"' % k for k in list(registry))
            raise Exception(
                "Metadata definition with name \"%s\" does not exist.\n%s" % (
                    name, valid_names))
    else:
        assert len(registry) == 1, \
            "You must have exactly one Metadata class, if using " \
            "get_metadata() without a 'name' parameter."
        return list(registry.values())[0]