'Internal method used to decorate parse actions that take fewer than 3 arguments,
so that all parse actions can be called as f(s,l,t).'

def _normalizeParseActionArgs(f):

    STAR_ARGS = 4
    try:
        restore = None
        if isinstance(f, type):
            restore = f
            f = f.__init__
        if (f.func_code.co_flags & STAR_ARGS):
            return f
        numargs = f.func_code.co_argcount
        if hasattr(f, 'im_self'):
            numargs -= 1
        if restore:
            f = restore
    except AttributeError:
        try:
            if (f.__call__.im_func.func_code.co_flags & STAR_ARGS):
                return f
            numargs = f.__call__.im_func.func_code.co_argcount
            if hasattr(f.__call__, 'im_self'):
                numargs -= 1
        except AttributeError:
            if (f.__call__.func_code.co_flags & STAR_ARGS):
                return f
            numargs = f.__call__.func_code.co_argcount
            if hasattr(f.__call__, 'im_self'):
                numargs -= 1
    if (numargs == 3):
        return f
    else:
        if (numargs == 2):
            def tmp(s, l, t):
                return f(l, t)
        elif (numargs == 1):
            def tmp(s, l, t):
                return f(t)
        else:
            def tmp(s, l, t):
                return f()
        try:
            tmp.__name__ = f.__name__
        except AttributeError:
            pass
        try:
            tmp.__doc__ = f.__doc__
        except AttributeError:
            pass
        try:
            tmp.__dict__.update(f.__dict__)
        except AttributeError:
            pass
        return tmp
