Helper function handling flow form tags.

def tag_builder(parser, token, cls, flow_type):
    """Helper function handling flow form tags."""
    tokens = token.split_contents()
    tokens_num = len(tokens)

    if tokens_num == 1 or (tokens_num == 3 and tokens[1] == 'for'):
        flow_name = None
        if tokens_num == 3:
            flow_name = tokens[2]
        return cls(flow_name)
    else:
        raise template.TemplateSyntaxError(
            '"sitegate_%(type)s_form" tag requires zero or two arguments. '
            'E.g. {%% sitegate_%(type)s_form %%} or '
            '{%% sitegate_%(type)s_form for ClassicSignup %%}.' % {'type': flow_type})