@register.tag
def all_products_for_category(parser, token):
    try:
        # Splitting by None == splitting by spaces.
        tag_name, arg = token.contents.split(None, 1)
    except ValueError:
        raise TemplateSyntaxError, "%r tag requires arguments" \
              % token.contents.split()[0]

    m = re.search(r'(.*?)as (\w+)$', arg)

    # First, get the varname - the easiest
    if not m:
        raise TemplateSyntaxError, "Variable name was not specified for %r tag" \
              % tag_name

    arg, var  = m.groups()

    # Now, try and determine usage case the user wants
    if not arg:
        # We're of the first case.
        return AllProductsNode(var)

    m = re.search(r'^for (.+?)$', arg.strip())

    if not m:
        raise TemplateSyntaxError, "Invalid arguments for %r tag" \
              % tag_name

    arg = m.group(1)

    if arg[0] == '"' and arg[-1] == '"':
        # We're of the third case.
        cat_var = arg[1:-1]
        return AllProductsForSlugNode(arg[1:-1], var)
    elif arg:
        # We're of the second case.
        return AllProductsForVariableSlugNode(Variable(arg), var)

    raise TemplateSyntaxError, "Invalid arguments for %r tag" \
          % tag_name
Usage:
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_store/shop/templatetags/satchmo_category.py/all_products_for_category