ó
Q•\c           @  sF  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d Z	 e j
 d k r d d l m Z d „  Z n$ e j d d	 ƒ Z d
 „  Z d „  Z y e j Z Wn e k
 rÜ d „  Z n Xy d d l m Z Wn e k
 rd „  Z n Xe j d ƒ Z d e f d „  ƒ  YZ d d „ Z d d „ Z y d d l m Z Wn! e k
 r‚d d l m Z n Xd e f d „  ƒ  YZ e e j ƒ Z e  e j! ƒ Z" e" d k râe j# râd „  Z e e _ n9 e" d k rúe j# rún! e" d k rd „  Z e e _ n  e e ƒ Z$ d „  Z% d „  Z& d „  Z' d S(    sT   
Decorator module, see http://pypi.python.org/pypi/decorator
for the documentation.
iÿÿÿÿ(   t   print_functionNs   4.4.0t   3(   t   getfullargspecc         C  s   |  j  S(   N(   t   __init__(   t   cls(    (    s(   lib/python2.7/site-packages/decorator.pyt   get_init0   s    t   FullArgSpecsA   args varargs varkw defaults kwonlyargs kwonlydefaults annotationsc         C  s#   t  j t j |  ƒ g  d i  f ƒ S(   s?   A quick and dirty replacement for getfullargspec for Python 2.XN(   R   t   _maket   inspectt
   getargspect   None(   t   f(    (    s(   lib/python2.7/site-packages/decorator.pyR   7   s    c         C  s
   |  j  j S(   N(   R   t   __func__(   R   (    (    s(   lib/python2.7/site-packages/decorator.pyR   ;   s    c         C  s   t  S(   N(   t   False(   R   (    (    s(   lib/python2.7/site-packages/decorator.pyt   iscoroutinefunctionB   s    (   t   isgeneratorfunctionc         C  s   t  S(   N(   R   (   t   caller(    (    s(   lib/python2.7/site-packages/decorator.pyR   H   s    s   \s*def\s*([_\w][_\w\d]*)\s*\(t   FunctionMakerc           B  s…   e  Z d  Z e j ƒ  Z d Z Z Z Z	 Z
 Z d d d d d d d d „ Z d „  Z d e d „ Z e d d d e d „ ƒ Z RS(   s´   
    An object with the ability to create functions with a given signature.
    It has attributes name, doc, module, signature, defaults, dict and
    methods update and make.
    c         C  s   | |  _  | ró| j |  _ |  j d k r6 d |  _ n  | j |  _ | j |  _ t j | ƒ rót	 | ƒ } t
 | d i  ƒ |  _ x' d D] }	 t |  |	 t
 | |	 ƒ ƒ q… Wx1 t |  j ƒ D]  \ }
 } t |  d
 |
 | ƒ q¸ Wt |  j ƒ } t |  j ƒ } |  j r.| j d |  j ƒ | j d |  j ƒ n |  j rG| j d ƒ n  x9 |  j D]. }	 | j d |	 ƒ | j d |	 |	 f ƒ qQW|  j r·| j d |  j ƒ | j d |  j ƒ n  d j | ƒ |  _ d j | ƒ |  _  | j j ƒ  |  _ qón  | r| |  _ n  | d  k	 r| |  _ n  | r/| |  _ n  | rA| |  _ n  | rS| |  _ n  | re| |  _ n  t |  d ƒ szt ‚ t |  d ƒ sœt d | ƒ ‚ n  d  S(   Ns   <lambda>t   _lambda_t   __annotations__t   argst   varargst   varkwt   defaultst
   kwonlyargst   kwonlydefaultss   arg%dt   *s   %s=Nones   %s=%ss   **s   , t   namet	   signatures%   You are decorating a non function: %s(   R   R   R   R   R   R   (   t   shortsignaturet   __name__R   t   __doc__t   doct
   __module__t   moduleR   t
   isfunctionR   t   getattrt   annotationst   setattrt	   enumerateR   t   listR   t   appendR   R   t   joinR   t   __dict__t   copyt   dictR
   R   t   hasattrt   AssertionErrort	   TypeError(   t   selft   funcR   R   R   R    R"   t   funcdictt   argspect   at   it   argt   allargst   allshortargs(    (    s(   lib/python2.7/site-packages/decorator.pyR   ]   s\    	
			c         K  sÔ   |  j  | _ t |  d d ƒ | _ t |  d i  ƒ | _ |  j | _ |  j pN d | _	 t |  d d ƒ | _
 y t j d ƒ } Wn t k
 r• d } n X| j j d d ƒ } t |  d | ƒ | _ | j j | ƒ d S(	   s2   Update the signature of func with the data in selfR    R-   R%   i   t   ?R   R"   N(   R   R   R$   R
   R   R+   R   t   __defaults__R   t   __kwdefaults__R   t   syst	   _getframet   AttributeErrort	   f_globalst   getR!   t   update(   R1   R2   t   kwt   framet   callermodule(    (    s(   lib/python2.7/site-packages/decorator.pyRB   ‘   s    
c         J  s‹  | e  |  ƒ } | p i  } e j | ƒ } | d k rJ e d | ƒ ‚ n  | j d ƒ } e | g g  |  j j d ƒ D] } | j	 d ƒ ^ qu ƒ }	 x3 |	 D]+ }
 |
 d k r› e
 d |
 | f ƒ ‚ q› q› W| j d ƒ sæ | d 7} n  d	 e e |  j ƒ f } y e | | d
 ƒ } | | UWn: e k
 rYe d d e j ƒe | d e j ƒ‚  n X| | } | rw| | d <n  |  j | |  | S(   sB   Make a new function from a given template and update the signatures    not a valid function template
%si   t   ,s    *t   _func_t   _call_s   %s is overridden in
%ss   
s   <%s:decorator-gen-%d>t   singles   Error in generated code:t   filet
   __source__N(   RG   RH   (   t   varst   DEFt   searchR
   t   SyntaxErrort   groupt   setR   t   splitt   stript	   NameErrort   endswitht   __file__t   nextt   _compile_countt   compilet	   Exceptiont   printR=   t   stderrRB   (   R1   t	   src_templt   evaldictt	   addsourcet   attrst   srct   moR   R7   t   namest   nt   filenamet   codeR2   (    (    s(   lib/python2.7/site-packages/decorator.pyt   make¢   s6    /
c         K  sæ   t  | t ƒ r@ | j ƒ  j d d ƒ \ }	 }
 |
 d  } d } n d }	 d } | } |  | |	 | | | | ƒ } d j d „  | j ƒ  Dƒ ƒ } | j d ƒ } | rÆ t | ƒ rÆ d | j	 d d	 ƒ } n
 d
 | } | j
 | | | |  S(   sú   
        Create a function from the strings name, signature and body.
        evaldict is the evaluation dictionary. If addsource is true an
        attribute __source__ is added to the result. The attributes attrs
        are added, if any.
        t   (i   iÿÿÿÿs   
c         s  s   |  ] } d  | Vq d S(   s       N(    (   t   .0t   line(    (    s(   lib/python2.7/site-packages/decorator.pys	   <genexpr>×   s    RH   s#   async def %(name)s(%(signature)s):
t   returns   return awaits   def %(name)s(%(signature)s):
N(   t
   isinstancet   strRS   RR   R
   R*   t
   splitlinesRA   R   t   replaceRg   (   R   t   objt   bodyR^   R   R    R"   R_   R`   R   t   restR   R2   R1   t   ibodyR   (    (    s(   lib/python2.7/site-packages/decorator.pyt   createÅ   s    	
	

(    N(   R   R!   R   t	   itertoolst   countRX   R   R   R   R   R   R   R
   R   RB   R   Rg   t   classmethodt   TrueRt   (    (    (    s(   lib/python2.7/site-packages/decorator.pyR   P   s   	3	#c   
      C  s
  t  d | d |  ƒ } d } x< t | ƒ D]. \ } } d | } | | | <| | d 7} q( Wd t j k ot d k  n r• t | ƒ o t | ƒ } n t | ƒ } | rÉ t j |  d | | d	 |  ƒ}	 n t j |  d
 | | d	 |  ƒ}	 t |  d ƒ r|  j	 |	 _	 n  |	 S(   s©   
    decorate(func, caller) decorates a function using a caller.
    If the caller is a generator function, the resulting function
    will be a generator function.
    RH   RG   t    s   _e%d_s   , s   3.5s   3.6s?   for res in _call_(_func_, %s%%(shortsignature)s):
    yield rest   __wrapped__s,   return _call_(_func_, %s%%(shortsignature)s)t   __qualname__(
   R-   R'   R=   t   versionR   R   R   Rt   R.   R{   (
   R2   R   t   extrasR^   t   esR6   t   extrat   ext   generatorcallert   fun(    (    s(   lib/python2.7/site-packages/decorator.pyt   decorateá   s(    


c   
   
   C  s  | d k	 r t | |  ƒ Sd d } } t j |  ƒ r] |  j j ƒ  } d |  j |  j f } n· t j |  ƒ rö |  j d k r„ d } n	 |  j } |  j } |  j j	 } t
 |  j p± d ƒ } d j |  j j | | | !ƒ } | rê | d 7} n  |  j } n |  j j j ƒ  } |  j j } t d |  d t ƒ } t j d	 | | f d
 | | f | d | d |  j d |  ƒ}	 | r}d | |	 _ n  |	 S(   s=   decorator(caller) converts a caller function into a decoratorRy   sH   decorator(%s) converts functions/generators into factories of %s objectss   <lambda>R   s   , RF   t   _callt
   _decorate_s   %s(func, %s)sh   if func is None: return lambda func:  _decorate_(func, _call, (%s))
return _decorate_(func, _call, (%s))R    R"   Rz   N(    (    (   N(   R
   Rƒ   R   t   isclassR   t   lowerR#   R   t   __code__t   co_argcountt   lenR;   R*   t   co_varnamest	   __class__t   __call__R-   R   Rt   R!   (
   R   t   _funct   defaultargsR   R   R    t   nargst   ndefsR^   t   dec(    (    s(   lib/python2.7/site-packages/decorator.pyt	   decorator  s:    			 
(   t   _GeneratorContextManager(   t   GeneratorContextManagert   ContextManagerc           B  s   e  Z d  „  Z RS(   c         C  s(   t  j | d t d |  d | ƒ d | ƒS(   s   Context manager decorators.   with _self_: return _func_(%(shortsignature)s)t   _self_RG   Rz   (   R   Rt   R-   (   R1   R2   (    (    s(   lib/python2.7/site-packages/decorator.pyR   1  s    (   R   R!   R   (    (    (    s(   lib/python2.7/site-packages/decorator.pyR–   0  s   i   c         O  s   t  j |  | | | Ž  ƒ S(   N(   R”   R   (   R1   t   gR5   t   k(    (    s(   lib/python2.7/site-packages/decorator.pyR   ;  s    i   c         O  s   t  j |  | | | ƒ S(   N(   R”   R   (   R1   R˜   R5   R™   (    (    s(   lib/python2.7/site-packages/decorator.pyR   A  s    c         C  s
   t  |  ƒ S(   N(   t   _contextmanager(   R2   (    (    s(   lib/python2.7/site-packages/decorator.pyt   contextmanagerH  s    c         C  sx   t  } xU t | ƒ D]G \ } } t | |  ƒ r8 t } Pn  t |  | ƒ r |  | | <t } q q W| rt | j |  ƒ n  d S(   s_   
    Append ``a`` to the list of the virtual ancestors, unless it is already
    included.
    N(   Rx   R'   t
   issubclassR   R)   (   R5   t
   vancestorst   addt   jt   va(    (    s(   lib/python2.7/site-packages/decorator.pyR)   O  s    
c            sc   ˆ s t  d ƒ ‚ d d j ˆ ƒ ‰ t j d ‡ f d † ‰  ‡  ‡ ‡ f d †  } d ˆ | _ | S(   sr   
    Factory of decorators turning a function into a generic function
    dispatching on the given arguments.
    s   No dispatch args passeds   (%s,)s   , Ry   c           sG   | t  |  ƒ t  ˆ  ƒ ƒ rC t d t  ˆ  ƒ t  |  ƒ | f ƒ ‚ n  d S(   s5   Make sure one passes the expected number of argumentss   Expected %d arguments, got %d%sN(   RŠ   R0   (   t	   argumentst   wrongt   msg(   t   dispatch_args(    s(   lib/python2.7/site-packages/decorator.pyt   checki  s    c           sê   t  t ˆ ƒ j ƒ } t  ˆ ƒ | k s: t d ˆ ƒ ‚ n  i  ‰ ‡ ‡ ‡ f d †  ‰ ‡ ‡ f d †  ‰  ‡ ‡ f d †  } ‡  ‡ f d †  } ‡  ‡ ‡ f d †  } t j ˆ d ˆ t d | ƒ d	 | d
 ˆ d ˆ d ˆ d ˆ  d | d ˆ ƒS(   s4   Decorator turning a function into a generic functions   Unknown dispatch arguments %sc            s´   ˆ  |  ƒ g  t  t ˆ ƒ ƒ D] } g  ^ q } xe ˆ D]] } xT t |  | | ƒ D]@ \ } } } t | | ƒ rO | | j ƒ  k rO t | | ƒ qO qO Wq6 Wg  | D] } t | ƒ ^ qž S(   sU   
            Get a list of sets of virtual ancestors for the given types
            (   t   rangeRŠ   t   zipRœ   t   mroR)   RQ   (   t   typest   _t   rast   types_t   tt   type_t   ra(   R¥   R¤   t   typemap(    s(   lib/python2.7/site-packages/decorator.pyR   y  s    
%"!c            sÂ   ˆ  |  ƒ g  } x« t  |  ˆ |  Œ  ƒ D]” \ } } t | ƒ } | d k rc t d | | f ƒ ‚ nF | d k r | \ } t d | | f i  ƒ j ƒ  d } n | j ƒ  } | j | d  ƒ q& W| S(   sG   
            Get a list of virtual MROs, one for each type
            i   s   Ambiguous dispatch for %s: %sR­   iÿÿÿÿ(   R§   RŠ   t   RuntimeErrort   typeR¨   R)   (   R©   t   listsR­   t   vast   n_vasR    R¨   (   R¥   R   (    s(   lib/python2.7/site-packages/decorator.pyt	   ancestors…  s    
"	%c            s#   ˆ ˆ  ƒ ‡ ‡ ‡  f d †  } | S(   sU   
            Decorator to register an implementation for the given types
            c           s1   ˆ  t  |  ƒ j t j d |  j ƒ |  ˆ ˆ <|  S(   Ns    in (   R   R   t   operatort   ltR   (   R   (   R¥   R°   R©   (    s(   lib/python2.7/site-packages/decorator.pyR’   ž  s    #
(    (   R©   R’   (   R¥   R°   (   R©   s(   lib/python2.7/site-packages/decorator.pyt   register˜  s    
c            sQ   ˆ |  ƒ g  } x: t  j ˆ  |  Œ  Œ  D]# } | j t d „  | Dƒ ƒ ƒ q& W| S(   sI   
            An utility to introspect the dispatch algorithm
            c         s  s   |  ] } | j  Vq d  S(   N(   R   (   Ri   R5   (    (    s(   lib/python2.7/site-packages/decorator.pys	   <genexpr>«  s    (   Ru   t   productR)   t   tuple(   R©   t   lstt   anc(   R¶   R¥   (    s(   lib/python2.7/site-packages/decorator.pyt   dispatch_info¤  s
    
!c           sª   t  d „  |  Dƒ ƒ } y ˆ | } Wn t k
 r7 n X| | | Ž  St j ˆ  | Œ  Œ  } t | ƒ x6 | D]. } ˆ j | ƒ } | d  k	 rk | | | Ž  Sqk Wˆ | | Ž  S(   Nc         s  s   |  ] } t  | ƒ Vq d  S(   N(   R²   (   Ri   R7   (    (    s(   lib/python2.7/site-packages/decorator.pys	   <genexpr>¯  s    (   R»   t   KeyErrorRu   Rº   RW   RA   R
   (   R¤   R   RC   R©   R   t   combinationsR¬   (   R¶   R2   R°   (    s(   lib/python2.7/site-packages/decorator.pyt	   _dispatch®  s    
s#   return _f_(%s, %%(shortsignature)s)t   _f_R¹   t   defaultR°   R   R¶   R¾   Rz   (   RQ   R   R   RT   R   Rt   R-   (   R2   t   argsetR¹   R¾   RÁ   (   R¥   R¤   t   dispatch_str(   R¶   R2   R°   R   s(   lib/python2.7/site-packages/decorator.pyt   gen_func_deco  s    

t   dispatch_on(   R/   R*   R·   t   neR   (   R¤   RÆ   (    (   R¥   R¤   RÅ   s(   lib/python2.7/site-packages/decorator.pyRÇ   a  s    W(    ((   R   t
   __future__R    t   reR=   R   R·   Ru   t   collectionst   __version__R|   R   R   t
   namedtupleR   R   R?   R   t   ImportErrorRY   RM   t   objectR   Rƒ   R
   R“   t
   contextlibR”   R•   R–   R   t   initRŠ   R   t   n_argsR   Rš   R›   R)   RÇ   (    (    (    s(   lib/python2.7/site-packages/decorator.pyt   <module>!   s\   		‘"'				