ó
P'—^c           @   sq  d  d l  Z  d  d l Z d  d l m Z d d l m Z d d d d d	 g Z d
 „  Z d i  d „ Z d e	 f d „  ƒ  YZ
 e r d „  Z n	 d „  Z d „  Z i  d „ Z e  j d k rÓ d  d l m Z m Z n5 d e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d  d l m Z m Z e e d „ Z e e d „ Z y d  d l m Z Wn e k
 rld „  Z n Xd S(    iÿÿÿÿN(   t   partiali   (   t   PY2t	   decoratort   wrapst   unwrapt   ContextDecoratort   contextmanagerc            s9   t  ˆ  ƒ r t ˆ  ƒ S‡  f d †  } t ˆ  ƒ | ƒ Sd S(   sÊ  
    Transforms a flat wrapper into decorator::

        @decorator
        def func(call, methods, content_type=DEFAULT):  # These are decorator params
            # Access call arg by name
            if call.request.method not in methods:
                # ...
            # Decorated functions and all the arguments are accesible as:
            print(call._func, call_args, call._kwargs)
            # Finally make a call:
            return call()
    c             s   t  ˆ  |  | ƒ S(   N(   t   make_decorator(   t   dargst   dkwargs(   t   deco(    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   decorator_fab   s    N(   t   has_single_argR   R   (   R
   R   (    (   R
   s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   
   s    
c            sB   t  ˆ ƒ ‡  ‡ ‡ f d †  ƒ } ˆ ˆ  ˆ | _ | _ | _ | S(   Nc            s(   ‡ ‡ ‡ ‡  f d †  } t  ˆ  ƒ | ƒ S(   Nc             s"   t  ˆ |  | ƒ } ˆ | ˆ  ˆ Ž S(   N(   t   Call(   t   argst   kwargst   call(   R   R
   R	   t   func(    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   wrapper%   s    (   R   (   R   R   (   R   R
   R	   (   R   s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt
   _decorator#   s    (   R   t   _funct   _argst   _kwargs(   R
   R   R	   R   (    (   R   R
   R	   s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   "   s    !	R   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s¨   
    A call object to pass as first argument to decorator.

    Call object is just a proxy for decorated function
    with call arguments saved in its attributes.
    c         C   s!   | | | |  _  |  _ |  _ d  S(   N(   R   R   R   (   t   selfR   R   R   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   __init__7   s    c         O   sK   | r$ | r$ |  j  |  j |  j Ž  S|  j  |  j | t |  j |  Ž  Sd  S(   N(   R   R   R   t   dict(   R   t   at   kw(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   __call__:   s    c         C   s]   y4 t  |  j ƒ | |  j |  j ƒ } |  j | <| SWn" t k
 rX } t | j Œ  ‚ n Xd  S(   N(   t	   arggetterR   R   R   t   __dict__t	   TypeErrort   AttributeErrorR   (   R   t   namet   rest   e(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   __getattr__@   s
    ,(   t   __name__t
   __module__t   __doc__R   R   R$   (    (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   0   s   		c         C   s6   t  j |  ƒ } t | j ƒ d k o5 | j o5 | j S(   Ni   (   t   inspectt
   getargspect   lenR   t   varargst   keywords(   R   t   spec(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   I   s    c         C   s\   t  j |  ƒ } t | j ƒ d k r( t St t | j j ƒ  ƒ ƒ } | j | j	 | j
 f k S(   Ni   (   R(   t	   signatureR*   t
   parameterst   Falset   nextt   itert   valuest   kindt   VAR_POSITIONALt   VAR_KEYWORD(   R   R-   t   arg(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   M   s
    c         C   s2   t  |  d d  ƒ p t |  ƒ }  |  j j |  j j  S(   Nt   __original__(   t   getattrt   NoneR   t   __code__t   co_varnamest   co_argcount(   R   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   get_argnamesU   s    c            sµ   ˆ | k r | ˆ St  ˆ d d  ƒ p/ t ˆ ƒ } t | ƒ } t d „  t | ƒ Dƒ ƒ ‰ | j } | rŒ t t | t | ƒ | ƒ ƒ ‰  n i  ‰  ‡  ‡ ‡ f d †  } | | ˆ <| S(   NR8   c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   iR!   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pys	   <genexpr>_   s    c            s‘   |  ˆ k r( t  d ˆ j |  f ƒ ‚ ne ˆ |  } | t | ƒ k  rL | | S|  | k r` | |  S|  ˆ  k rt ˆ  |  St  d ˆ j |  f ƒ ‚ d  S(   Ns#   %s() doesn't have argument named %ss$   %s() missing required argument: '%s'(   R   R%   R*   (   R!   R   R   t   index(   t   defaultsR   t   indexes(    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   get_argf   s    
(	   R9   R:   R   R>   R   t	   enumeratet   __defaults__t   zipR*   (   R   t   _cachet   originalt   argnamest   defaults_tupleRD   (    (   RB   R   RC   s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   Y   s    	#
i   i   (   R   R   c           B   s    e  Z d  Z d „  Z d „  Z RS(   sJ   A base class or mixin that enables context managers to work as decorators.c         C   s   |  S(   sN  Return a recreated instance of self.

            Allows an otherwise one-shot context manager like
            _GeneratorContextManager to support use as
            a decorator via implicit recreation.

            This is a private interface just for _GeneratorContextManager.
            See issue #11647 for details.
            (    (   R   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   _recreate_cm   s    
c            s"   t  ˆ  ƒ ‡  ‡ f d †  ƒ } | S(   Nc             s$   ˆ j  ƒ   ˆ  |  | Ž  SWd  QXd  S(   N(   RL   (   R   t   kwds(   R   R   (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   innerŽ   s    (   R   (   R   R   RN   (    (   R   R   s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR      s    (   R%   R&   R'   RL   R   (    (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   ~   s   	t   _GeneratorContextManagerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s%   Helper for @contextmanager decorator.c         O   sl   | | | Ž  |  _  | | | |  _ |  _ |  _ t | d d  ƒ } | d  k r_ t |  ƒ j } n  | |  _ d  S(   NR'   (   t   genR   R   RM   R9   R:   t   typeR'   (   R   R   R   RM   t   doc(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   ˜   s    c         C   s   |  j  |  j |  j |  j Ž S(   N(   t	   __class__R   R   RM   (   R   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyRL   ¦   s    c         C   s5   y t  |  j ƒ SWn t k
 r0 t d ƒ ‚ n Xd  S(   Ns   generator didn't yield(   R1   RP   t   StopIterationt   RuntimeError(   R   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt	   __enter__¬   s    c         C   sÂ   | d  k rA y t |  j ƒ Wn t k
 r1 d  SXt d ƒ ‚ n} | d  k rY | ƒ  } n  y& |  j j | | | ƒ t d ƒ ‚ Wn< t k
 r› } | | k	 St j ƒ  d | k	 r¾ ‚  q¾ n Xd  S(   Ns   generator didn't stops#   generator didn't stop after throw()i   (   R:   R1   RP   RT   RU   t   throwt   syst   exc_info(   R   RQ   t   valuet	   tracebackt   exc(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   __exit__²   s     
(   R%   R&   R'   R   RL   RV   R]   (    (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyRO   •   s
   			c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   sJ  
        A decorator helping to create context managers. Resulting functions also
        behave as decorators.

        A simple example::

            @contextmanager
            def tag(name):
                print("<%s>" % name)
                yield
                print("</%s>" % name)

            with tag("h1"):
                print "foo",
            # -> <h1> foo </h1>

        Using as decorator::

            @tag('strong')
            def shout(text):
                print(text.upper())

            shout('hooray')
            # -> <strong> HOORAY </strong>
        c             s   t  ˆ  |  | Ž S(   N(   RO   (   R   RM   (   R   (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   helperí   s    (   R   (   R   R^   (    (   R   s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   Ó   s    (   t   WRAPPER_ASSIGNMENTSt   WRAPPER_UPDATESc         C   s©   xE | D]= } y t  | | ƒ } Wn t k
 r3 q Xt |  | | ƒ q Wx0 | D]( } t  |  | ƒ j t  | | i  ƒ ƒ qO W| |  _ t  | d d  ƒ pŸ t | ƒ |  _ |  S(   NR8   (   R9   R    t   setattrt   updatet   __wrapped__R:   R   R8   (   R   t   wrappedt   assignedt   updatedt   attrRZ   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   update_wrapperø   s    &	!c         C   s   t  t d |  d | d | ƒS(   sÁ  
    An utility to pass function metadata from wrapped function to a wrapper.
    Copies all function attributes including ``__name__``, ``__module__`` and
    ``__doc__``.

    In addition adds ``__wrapped__`` attribute referring to the wrapped function
    and ``__original__`` attribute referring to innermost wrapped one.

    Mostly used to create decorators::

        def some_decorator(func):
            @wraps(func)
            def wrapper(*args, **kwargs):
                do_something(*args, **kwargs)
                return func(*args, **kwargs)
            return wrapper

    But see also :func:`@decorator<decorator>` for that.
    This is extended version of :func:`functools.wraps`.
    Rd   Re   Rf   (   R    Rh   (   Rd   Re   Rf   (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR     s    (   R   c         C   s{   |  } t  t | ƒ g ƒ } xY t |  d ƒ rv |  j }  t |  ƒ } | | k rf t d j | ƒ ƒ ‚ n  | j | ƒ q W|  S(   sÏ   
        Get the object wrapped by ``func``.

        Follows the chain of :attr:`__wrapped__` attributes returning the last
        object in the chain.

        This is a backport from python 3.4.
        Rc   s!   wrapper loop when unwrapping {!r}(   t   sett   idt   hasattrRc   t
   ValueErrort   formatt   add(   R   t   ft   memot   id_func(    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyR   0  s    		(    (   i   i   (   RX   R(   t	   functoolsR    t   compatR   t   __all__R   R   t   objectR   R   R>   R   t   version_infot
   contextlibR   R   RO   R_   R`   Rh   R   R   t   ImportError(    (    (    s2   /tmp/pip-unpacked-wheel-WgnHs6/funcy/decorators.pyt   <module>   s4   			">	#