Question

I am using a block like this:

def served(fn) :    
    def wrapper(*args, **kwargs):
        p = xmlrpclib.ServerProxy(SERVER, allow_none=True )
        return (p.__getattr__(fn.__name__)(*args, **kwargs)) # do the function call
    return functools.update_wrapper(wrapper,fn)

@served
def remote_function(a, b):
    pass

to wrap a series of XML-RPC calls into a python module. The "served" decorator gets called on stub functions to expose operations on a remote server.

I'm creating stubs like this with the intention of being able to inspect them later for information about the function, specifically its arguments.

As listed, the code above does not transfer argument information from the original function to the wrapper. If I inspect with inspect.getargspec( remote_function ) then I get essentially an empty list, instead of args=['a','b'] that I was expecting.

I'm guessing I need to give additional direction to the functools.update_wrapper() call via the optional assigned parameter, but I'm not sure exactly what to add to that tuple to get the effect I want.

The name and the docstring are correctly transferred to the new function object, but can someone advise me on how to transfer argument definitions?

Thanks.

Était-ce utile?

La solution

Previous questions here and here suggest that the decorator module can do this.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top