( f )
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).
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).
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 ):
        """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)."""
        STAR_ARGS = 4

        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
            else:
                if 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__

                # not a function, must be a callable object, get info from the
                # im_func binding of its bound __call__ method
                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
                else:
                    if 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__
                # not a bound method, get info directly from __call__ method
                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
                else:
                    if hasattr(f.__call__,"__self__"):
                        numargs -= 1


        #~ print ("adding function %s with %d args" % (f.func_name,numargs))
        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: #~ numargs == 0:
                def tmp(s,l,t):
                    return f()
            try:
                tmp.__name__ = f.__name__
            except (AttributeError,TypeError):
                # no need for special handling if attribute doesnt exist
                pass
            try:
                tmp.__doc__ = f.__doc__
            except (AttributeError,TypeError):
                # no need for special handling if attribute doesnt exist
                pass
            try:
                tmp.__dict__.update(f.__dict__)
            except (AttributeError,TypeError):
                # no need for special handling if attribute doesnt exist
                pass
            return tmp
def _normalizeParseActionArgs ( f ) : STAR_ARGS = 4 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 else : if 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__ # not a function, must be a callable object, get info from the # im_func binding of its bound __call__ method 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 else : if 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__ # not a bound method, get info directly from __call__ method 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 else : if hasattr ( f . __call__ , "__self__" ) : numargs -= 1 #~ print ("adding function %s with %d args" % (f.func_name,numargs)) 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 : #~ numargs == 0: def tmp ( s , l , t ) : return f ( ) try : tmp . __name__ = f . __name__ except ( AttributeError , TypeError ) : # no need for special handling if attribute doesnt exist pass try : tmp . __doc__ = f . __doc__ except ( AttributeError , TypeError ) : # no need for special handling if attribute doesnt exist pass try : tmp . __dict__ . update ( f . __dict__ ) except ( AttributeError , TypeError ) : # no need for special handling if attribute doesnt exist pass return tmp