mò @©UFc@ssdddgZdkZdkZd„Zed„Zd„Zdd„Ze djodk Z e i ƒndS( t decoratortupdate_wrappertgetinfoNcCsøti|ƒpti|ƒpt‚ti|ƒ\}}}}t |ƒ}|o|i |ƒn|o|i |ƒnti ||||dd„ƒdd!}td|id|d|d|id |id |id |id |id |iƒ S(so Returns an info dictionary containing: - name (the name of the function : str) - argnames (the names of the arguments : list) - defaults (the values of the default arguments : tuple) - signature (the signature : str) - doc (the docstring : str) - module (the module name : str) - dict (the function __dict__ : str) >>> def f(self, x=1, y=2, *args, **kw): pass >>> info = getinfo(f) >>> info["name"] 'f' >>> info["argnames"] ['self', 'x', 'y', 'args', 'kw'] >>> info["defaults"] (1, 2) >>> info["signature"] 'self, x, y, *args, **kw' t formatvaluecCsdS(Nt((tvalue((tf/var/ftp/pub/linux.dell.com/srv/www/vhosts/linux.dell.com/html/repo/scripts/repo-mgmt/lib/decorator.pyt,siiÿÿÿÿtnametargnamest signaturetdefaultstdoctmoduletdicttglobalstclosureN(tinspecttismethodtfunct isfunctiontAssertionErrort getargspectregargstvarargst varkwargsR tlistR tappendt formatargspecR Rt__name__t func_defaultst__doc__t __module__t__dict__t func_globalst func_closure(RR R RR RR((RR s' cCsÈt|tƒo |}n t|ƒ}d|djp td‚|o&d|}t|td|ƒƒ}ny|d|_ WnnX|d|_ |d|_ |i i|dƒ|d |_|S( sF An improvement over functools.update_wrapper. By default it works the same, but if the 'create' flag is set, generates a copy of the wrapper with the right signature and update the copy, not the original. Moreovoer, 'wrapped' can be a dictionary with keys 'name', 'doc', 'module', 'dict', 'defaults'. t _wrapper_R s("_wrapper_" is a reserved argument name!s.lambda %(signature)s: _wrapper_(%(signature)s)RR R RR N(t isinstancetwrappedRtinfodictRRtcreatetsrctevaltwrapperRRR R!tupdateR(R+R&R(R)R'((RR2s"      cCspt|ƒ}|d}d|jp d|j p td‚d|}t|td|d|ƒƒ}t ||ƒS(NR t_call_t_func_s2You cannot use _call_ or _func_ as argument names!s3lambda %(signature)s: _call_(_func_, %(signature)s)( RRR'R RR)R*Rtcallertdec_funcR(R/RR)R0R'R ((Rt _decoratorOs   % cs5|djot‡d†ˆƒSntˆ|ƒSdS(sö General purpose decorator factory: takes a caller function as input and returns a decorator with the same attributes. A caller function is any function like this:: def caller(func, *args, **kw): # do something return func(*args, **kw) Here is an example of usage: >>> @decorator ... def chatty(f, *args, **kw): ... print "Calling %r" % f.__name__ ... return f(*args, **kw) >>> chatty.__name__ 'chatty' >>> @chatty ... def f(): pass ... >>> f() Calling 'f' For sake of convenience, the decorator factory can also be called with two arguments. In this casem ``decorator(caller, func)`` is just a shortcut for ``decorator(caller)(func)``. cs tˆ|ƒS(N(R1R/tf(R2(R/(RRwsN(RtNoneRR/R1(R/R((R/RRXs t__main__( t__all__RtsysRtFalseRR1R3RRtdoctestttestmod(R5RR1RR6RR8R((Rt?s (  #