<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def thumbnail_size(parser, token):
 """Returns a pre-configured thumbnail size, or assigns it to a context variable. Basic tag syntax:: {% thumbnail_size [size_name] [as var_name] %} The ``size`` parameter can be any of the size names configured using the setting ``MEDIA_TREE_THUMBNAIL_SIZES``. If omitted, the default size will be returned. If the ``as var_name`` clause is present, the size will be assigned to the respective context variable instead of being returned. You can use this template tag in conjunction with :func:`thumbnail` in order to use pre-configured thumbnail sizes in your templates. For example:: {% thumbnail_size "large" as large_size %} {% thumbnail some_file large_size as large_thumb %} """

    
    args = token.split_contents()
    tag = args.pop(0)
    if len(args) >= 2 and args[-2] == 'as':
        context_name = args[-1]
        args = args[:-2]
    else:
        context_name = None

    if len(args) > 1:
        raise template.TemplateSyntaxError("Invalid syntax. Expected "
            "'{%% %s [\"size_name\"] [as context_var] %%}'" % tag)
    elif len(args) == 1:
        size_name = args[0]
    else:
        size_name = None

    return ThumbnailSizeNode(size_name=size_name, context_name=context_name)