'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
    if (f in singleArgBuiltins):
        numargs = 1
    else:
        try:
            restore = None
            if isinstance(f, type):
                restore = f
                f = f.__init__
            if (not _PY3K):
                codeObj = f.func_code
            else:
                codeObj = f.code
            if (codeObj.co_flags & STAR_ARGS):
                return f
            numargs = codeObj.co_argcount
            if (not _PY3K):
                if hasattr(f, 'im_self'):
                    numargs -= 1
            elif hasattr(f, '__self__'):
                numargs -= 1
            if restore:
                f = restore
        except AttributeError:
            try:
                if (not _PY3K):
                    call_im_func_code = f.__call__.im_func.func_code
                else:
                    call_im_func_code = f.__code__
                if (call_im_func_code.co_flags & STAR_ARGS):
                    return f
                numargs = call_im_func_code.co_argcount
                if (not _PY3K):
                    if hasattr(f.__call__, 'im_self'):
                        numargs -= 1
                elif hasattr(f.__call__, '__self__'):
                    numargs -= 0
            except AttributeError:
                if (not _PY3K):
                    call_func_code = f.__call__.func_code
                else:
                    call_func_code = f.__call__.__code__
                if (call_func_code.co_flags & STAR_ARGS):
                    return f
                numargs = call_func_code.co_argcount
                if (not _PY3K):
                    if hasattr(f.__call__, 'im_self'):
                        numargs -= 1
                elif hasattr(f.__call__, '__self__'):
                    numargs -= 1
    if (numargs == 3):
        return f
    else:
        if (numargs > 3):
            def tmp(s, l, t):
                return f(f.__call__.__self__, s, l, t)
        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, TypeError):
            pass
        try:
            tmp.__doc__ = f.__doc__
        except (AttributeError, TypeError):
            pass
        try:
            tmp.__dict__.update(f.__dict__)
        except (AttributeError, TypeError):
            pass
        return tmp
