mò
@©UFc           @   ss   d  d d g Z  d k Z d k Z d „  Z e d „ Z d „  Z d d „ Z e	 d j o d k
 Z
 e
 i ƒ  n d S(	   t	   decoratort   update_wrappert   getinfoNc         C   sø   t  i |  ƒ p t  i |  ƒ p t ‚ t  i |  ƒ \ } } } } t
 | ƒ } | o | i | ƒ n | o | i | ƒ n t  i | | | | d d „  ƒd d !} t d |  i d | d | d |  i d	 |  i d
 |  i d |  i d |  i d |  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   formatvaluec         C   s   d S(   Nt    (    (   t   value(    (    tf   /var/ftp/pub/linux.dell.com/srv/www/vhosts/linux.dell.com/html/repo/scripts/repo-mgmt/lib/decorator.pyt   <lambda>,   s    i   iÿÿÿÿt   namet   argnamest	   signaturet   defaultst   doct   modulet   dictt   globalst   closureN(   t   inspectt   ismethodt   funct
   isfunctiont   AssertionErrort
   getargspect   regargst   varargst	   varkwargsR   t   listR	   t   appendt   formatargspecR
   R   t   __name__t   func_defaultst   __doc__t
   __module__t   __dict__t   func_globalst   func_closure(   R   R	   R
   R   R   R   R   (    (    R   R   
   s     'c         C   sÈ   t  | t ƒ o
 | } n t | ƒ } d | d j p
 t d ‚ | o& d | } t | t d |  ƒ ƒ }  n y | d |  _
 Wn n X| 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)R   R   R   R   R   N(   t
   isinstancet   wrappedR   t   infodictR   R   t   createt   srct   evalt   wrapperR   R   R    R!   t   updateR   (   R+   R&   R(   R)   R'   (    (    R   R   2   s"     

c         C   sp   t  | ƒ } | d } d | j p
 d | j p
 t d ‚ d | } t | t d | d |  ƒ ƒ } t
 | | ƒ S(   NR	   t   _call_t   _func_s2   You cannot use _call_ or _func_ as argument names!s3   lambda %(signature)s: _call_(_func_, %(signature)s)(   R   R   R'   R	   R   R)   R*   R   t   callert   dec_funcR   (   R/   R   R)   R0   R'   R	   (    (    R   t
   _decoratorO   s    
%
c            s5   | d j o t ‡  d †  ˆ  ƒ Sn t ˆ  | ƒ Sd S(   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)``.
    c            s   t  ˆ  |  ƒ S(   N(   R1   R/   t   f(   R2   (   R/   (    R   R   w   s    N(   R   t   NoneR   R/   R1   (   R/   R   (    (   R/   R   R    X   s     t   __main__(   t   __all__R   t   sysR   t   FalseR   R1   R3   R    R   t   doctestt   testmod(   R5   R   R1   R   R6   R   R8   R    (    (    R   t   ?   s   	(		#