Retrieve an object which can produce (and format) metadata.

    {% get_metadata [for my_path] [in my_language] [on my_site]
    [as my_variable] %}

    or if you have multiple metadata classes:

    {% get_metadata MyClass [for my_path] [in my_language] [on my_site]
    [as my_variable] %}

def do_get_metadata(parser, token):
    """
    Retrieve an object which can produce (and format) metadata.

    {% get_metadata [for my_path] [in my_language] [on my_site]
    [as my_variable] %}

    or if you have multiple metadata classes:

    {% get_metadata MyClass [for my_path] [in my_language] [on my_site]
    [as my_variable] %}
    """
    bits = list(token.split_contents())
    tag_name = bits[0]
    bits = bits[1:]
    metadata_name = None
    args = {'as': None, 'for': None, 'in': None, 'on': None}

    # If there are an even number of bits,
    # a metadata name has been provided.
    if len(bits) % 2:
        metadata_name = bits[0]
        bits = bits[1:]

    # Each bits are in the form "key value key value ..."
    # Valid keys are given in the 'args' dict above.
    while len(bits):
        if len(bits) < 2 or bits[0] not in args:
            raise template.TemplateSyntaxError(
                "expected format is '%r [as <variable_name>]'" % tag_name)
        key, value, bits = bits[0], bits[1], bits[2:]
        args[key] = value

    return MetadataNode(
        metadata_name,
        variable_name=args['as'],
        target=args['for'],
        site=args['on'],
        language=args['in'],
    )