ó
*} Uc        	   @   s>  d  Z  d d d d d d d d d	 g	 Z d
 d l m Z m Z d
 d l m Z m Z d d l m	 Z
 d
 d l m Z d
 d l Z y d
 d l m Z Wn! e k
 r¶ d d l m Z n Xd e f d „  ƒ  YZ d e f d „  ƒ  YZ d" Z d# Z e e d „ Z e e d „ Z d „  Z d „  Z e d d ƒ Z d  d! „ Z  d S($   sE   functools.py - Tools for working with functions and callable objects
t   update_wrappert   wrapst   WRAPPER_ASSIGNMENTSt   WRAPPER_UPDATESt   total_orderingt
   cmp_to_keyt	   lru_cachet   reducet   partialiÿÿÿÿ(   R   R   (   t   MutableMappingt
   namedtuplei   (   t   recursive_repr(   t   proxyN(   t   allocate_lockt   _Linkc           B   s   e  Z d Z RS(   t   prevt   nextt   keyt   __weakref__(   R   R   R   R   (   t   __name__t
   __module__t	   __slots__(    (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR      s   t   OrderedDictc           B   s  e  Z d  Z d „  Z e j e e d „ Z e j d „ Z d „  Z	 d „  Z
 d „  Z e d „ Z e d „ Z d	 „  Z e j Z Z e j Z e j Z e j Z e j Z e ƒ  Z e d
 „ Z d d „ Z e ƒ  d „  ƒ Z d „  Z d „  Z e  d d „ ƒ Z! d „  Z" RS(   s)   Dictionary that remembers insertion orderc         O   s™   t  | ƒ d k r+ t d t  | ƒ ƒ ‚ n  y |  j WnL t k
 r„ t ƒ  |  _ t |  j ƒ |  _ } | | _ | _ i  |  _	 n X|  j
 | | Ž  d S(   sÅ   Initialize an ordered dictionary.  The signature is the same as
        regular dictionaries, but keyword arguments are not recommended because
        their insertion order is arbitrary.

        i   s$   expected at most 1 arguments, got %dN(   t   lent	   TypeErrort   _OrderedDict__roott   AttributeErrorR   t   _OrderedDict__hardroott   _proxyR   R   t   _OrderedDict__mapt   _OrderedDict__update(   t   selft   argst   kwdst   root(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   __init__.   s    c   	      C   s~   | |  k rj | ƒ  |  j  | <} |  j } | j } | | | | _ | _ | _ | | _ | | ƒ | _ n  | |  | | ƒ d S(   s!   od.__setitem__(i, y) <==> od[i]=yN(   R   R   R   R   R   (	   R   R   t   valuet   dict_setitemR   t   Linkt   linkR"   t   last(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   __setitem__?   s    			c         C   sG   | |  | ƒ |  j  j | ƒ } | j } | j } | | _ | | _ d S(   s    od.__delitem__(y) <==> del od[y]N(   R   t   popR   R   (   R   R   t   dict_delitemR'   t	   link_prevt	   link_next(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   __delitem__M   s    			c         c   s:   |  j  } | j } x! | | k	 r5 | j V| j } q Wd S(   s   od.__iter__() <==> iter(od)N(   R   R   R   (   R   R"   t   curr(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   __iter__X   s
    		c         c   s:   |  j  } | j } x! | | k	 r5 | j V| j } q Wd S(   s#   od.__reversed__() <==> reversed(od)N(   R   R   R   (   R   R"   R/   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   __reversed__a   s
    		c         C   s7   |  j  } | | _ | _ |  j j ƒ  t j |  ƒ d S(   s.   od.clear() -> None.  Remove all items from od.N(   R   R   R   R   t   cleart   dict(   R   R"   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR2   j   s    	c         C   sž   |  s t  d ƒ ‚ n  |  j } | rK | j } | j } | | _ | | _ n$ | j } | j } | | _ | | _ | j } |  j | =t j |  | ƒ } | | f S(   s™   od.popitem() -> (k, v), return and remove a (key, value) pair.
        Pairs are returned in LIFO order if last is true or FIFO order if false.

        s   dictionary is empty(   t   KeyErrorR   R   R   R   R   R3   R*   (   R   R(   R"   R'   R,   R-   R   R$   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   popitemq   s     									
c         C   s   |  j  | } | j } | j } | | _ | | _ |  j } | rn | j } | | _ | | _ | | _ | _ n+ | j } | | _ | | _ | | _ | _ d S(   sÑ   Move an existing element to the end (or beginning if last==False).

        Raises KeyError if the element does not exist.
        When last=True, acts like a fast version of self[key]=self.pop(key).

        N(   R   R   R   R   (   R   R   R(   R'   R,   R-   R"   t   first(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   move_to_endˆ   s    											c         C   sq   t  j } t |  ƒ d } | |  j ƒ } | | |  j ƒ d 7} | | |  j ƒ | 7} | | |  j ƒ | 7} | S(   Ni   i   (   t   _syst	   getsizeofR   t   __dict__R   R   R   (   R   t   sizeoft   nt   size(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt
   __sizeof__    s    	c         C   sC   | |  k r! |  | } |  | =| S| |  j  k r? t | ƒ ‚ n  | S(   s²   od.pop(k[,d]) -> v, remove specified key and return the corresponding
        value.  If key is not found, d is returned if given, otherwise KeyError
        is raised.

        (   t   _OrderedDict__markerR4   (   R   R   t   defaultt   result(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR*   ±   s    
c         C   s"   | |  k r |  | S| |  | <| S(   sD   od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od(    (   R   R   R@   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt
   setdefault¿   s    
c         C   s7   |  s d |  j  j f Sd |  j  j t |  j ƒ  ƒ f S(   s   od.__repr__() <==> repr(od)s   %s()s   %s(%r)(   t	   __class__R   t   listt   items(   R   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   __repr__Æ   s    c         C   sˆ   g  |  D] } | |  | g ^ q } t  |  ƒ j ƒ  } x' t  t ƒ  ƒ D] } | j | d ƒ qE W| rx |  j | f | f S|  j | f f S(   s%   Return state information for picklingN(   t   varst   copyR   R*   t   NoneRC   (   R   t   kRE   t	   inst_dict(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt
   __reduce__Í   s    #c         C   s   |  j  |  ƒ S(   s!   od.copy() -> a shallow copy of od(   RC   (   R   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRH   ×   s    c         C   s(   |  ƒ  } x | D] } | | | <q W| S(   s   OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
        If not specified, the value defaults to None.

        (    (   t   clst   iterableR$   R   R   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   fromkeysÛ   s    	c         C   s`   t  | t ƒ rP t |  ƒ t | ƒ k oO t d „  t |  j ƒ  | j ƒ  ƒ Dƒ ƒ St j |  | ƒ S(   s“   od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
        while comparison to a regular mapping is order-insensitive.

        c         s   s!   |  ] \ } } | | k Vq d  S(   N(    (   t   .0t   pt   q(    (    s6   lib/python2.7/site-packages/functools32/functools32.pys	   <genexpr>í   s    (   t
   isinstanceR   R   t   allt   zipRE   R3   t   __eq__(   R   t   other(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRV   æ   s    )N(#   R   R   t   __doc__R#   R3   R)   R   R   R.   R0   R1   R2   t   TrueR5   R7   R>   R	   t   updateR   t   keyst   valuesRE   t   __ne__t   objectR?   R*   RI   RB   t   _recursive_reprRF   RL   RH   t   classmethodRO   RV   (    (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR      s0   														
	
R   R   RX   R:   c         C   sˆ   | |  _  xE | D]= } y t | | ƒ } Wn t k
 r< q Xt |  | | ƒ q Wx0 | D]( } t |  | ƒ j t | | i  ƒ ƒ qX W|  S(   s  Update a wrapper function to look like the wrapped function

       wrapper is the function to be updated
       wrapped is the original function
       assigned is a tuple naming the attributes assigned directly
       from the wrapped function to the wrapper function (defaults to
       functools.WRAPPER_ASSIGNMENTS)
       updated is a tuple naming the attributes of the wrapper that
       are updated with the corresponding attribute from the wrapped
       function (defaults to functools.WRAPPER_UPDATES)
    (   t   __wrapped__t   getattrR   t   setattrRZ   (   t   wrappert   wrappedt   assignedt   updatedt   attrR$   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR    õ   s    	&c         C   s   t  t d |  d | d | ƒS(   s‹  Decorator factory to apply update_wrapper() to a wrapper function

       Returns a decorator that invokes update_wrapper() with the decorated
       function as the wrapper argument and the arguments to wraps() as the
       remaining arguments. Default arguments are as for update_wrapper().
       This is a convenience function to simplify applying partial() to
       update_wrapper().
    Re   Rf   Rg   (   R   R    (   Re   Rf   Rg   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR     s    c         C   sK  i d d „  f d d „  f d d „  f g d 6d d „  f d d	 „  f d d
 „  f g d 6d d „  f d d „  f d d „  f g d 6d d „  f d d „  f d d „  f g d 6} t  t |  ƒ ƒ t  | ƒ @} | sã t d ƒ ‚ n  t | ƒ } xU | | D]I \ } } | | k rú | | _ t t | ƒ j | _ t |  | | ƒ qú qú W|  S(   s6   Class decorator that fills in missing ordering methodst   __gt__c         S   s   |  | k  p |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   <lambda>"  s    t   __le__c         S   s   |  | k  p |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   #  s    t   __ge__c         S   s   |  | k  S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   $  s    t   __lt__c         S   s   |  | k p |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   %  s    c         S   s   |  | k o |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   &  s    c         S   s   |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   '  s    c         S   s   |  | k p |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   (  s    c         S   s   |  | k p |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   )  s    c         S   s   |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   *  s    c         S   s   |  | k p |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   +  s    c         S   s   |  | k o |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   ,  s    c         S   s   |  | k S(   N(    (   R   RW   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyRj   -  s    s6   must define at least one ordering operation: < > <= >=(	   t   sett   dirt
   ValueErrort   maxR   Rb   t   intRX   Rc   (   RM   t   convertt   rootsR"   t   opnamet   opfunc(    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR     s.    	c            s    d t  f ‡  f d †  ƒ  Y} | S(   s,   Convert a cmp= function into a key= functiont   Kc              sz   e  Z d  g Z d „  Z ‡  f d †  Z ‡  f d †  Z ‡  f d †  Z ‡  f d †  Z ‡  f d †  Z ‡  f d †  Z	 d Z RS(	   t   objc         S   s   | |  _  d  S(   N(   Rx   (   R   Rx   (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyR#   >  s    c            s   ˆ  |  j  | j  ƒ d k  S(   Ni    (   Rx   (   R   RW   (   t   mycmp(    s6   lib/python2.7/site-packages/functools32/functools32.pyRm   @  s    c            s   ˆ  |  j  | j  ƒ d k S(   Ni    (   Rx   (   R   RW   (   Ry   (    s6   lib/python2.7/site-packages/functools32/functools32.pyRi   B  s    c            s   ˆ  |  j  | j  ƒ d k S(   Ni    (   Rx   (   R   RW   (   Ry   (    s6   lib/python2.7/site-packages/functools32/functools32.pyRV   D  s    c            s   ˆ  |  j  | j  ƒ d k S(   Ni    (   Rx   (   R   RW   (   Ry   (    s6   lib/python2.7/site-packages/functools32/functools32.pyRk   F  s    c            s   ˆ  |  j  | j  ƒ d k S(   Ni    (   Rx   (   R   RW   (   Ry   (    s6   lib/python2.7/site-packages/functools32/functools32.pyRl   H  s    c            s   ˆ  |  j  | j  ƒ d k S(   Ni    (   Rx   (   R   RW   (   Ry   (    s6   lib/python2.7/site-packages/functools32/functools32.pyR]   J  s    N(   R   R   R   R#   Rm   Ri   RV   Rk   Rl   R]   RI   t   __hash__(    (   Ry   (    s6   lib/python2.7/site-packages/functools32/functools32.pyRw   <  s   		(   R^   (   Ry   Rw   (    (   Ry   s6   lib/python2.7/site-packages/functools32/functools32.pyR   :  s    t	   CacheInfos   hits misses maxsize currsizeid   c            s   t  t t t ‡  f d † } | S(   sì  Least-recently-used cache decorator.

    If *maxsize* is set to None, the LRU features are disabled and the cache
    can grow without bound.

    Arguments to the cached function must be hashable.

    View the cache statistics named tuple (hits, misses, maxsize, currsize) with
    f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.

    See:  http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used

    c            s  d g d g ‰ ‰ t  ƒ  f ‰ t ƒ  ‰ ˆ d  k rp t ƒ  ‰ t ˆ ƒ ‡  ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ f d †  ƒ } nZ t ƒ  ‰ ˆ j ‰ ˆ j ‰ t ˆ ƒ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ f d †  ƒ } ‡ ‡ ‡ ‡ ‡ ‡ f d †  } ‡ ‡ ‡ ‡ f d †  } | | _ | | _	 | S(   Ni    c             s’   |  } | r/ | ˆ ˆ ˆ | j  ƒ  ƒ ƒ 7} n  y" ˆ | } ˆ d c d 7<| SWn ˆ  k
 rd n Xˆ |  | Ž  } | ˆ | <ˆ d c d 7<| S(   Ni    i   (   RE   (   R    R!   R   RA   (   R4   t   cachet   hitst   kwd_markt   missest   sortedt   tuplet   user_function(    s6   lib/python2.7/site-packages/functools32/functools32.pyRd   o  s    #

c       	      sÕ   |  } | r/ | ˆ ˆ ˆ
 | j  ƒ  ƒ ƒ 7} n  ˆ E y, ˆ | } ˆ | ƒ ˆ d c d 7<| SWn ˆ  k
 ru n XWd  QXˆ |  | Ž  } ˆ > | ˆ | <ˆ	 d c d 7<ˆ ˆ ƒ ˆ k rË ˆ d ƒ n  Wd  QX| S(   Ni    i   (   RE   (   R    R!   R   RA   (   R4   R|   t   cache_popitemt   cache_renewR}   R~   R   t   lockt   maxsizeR   R€   R   R‚   (    s6   lib/python2.7/site-packages/functools32/functools32.pyRd   ƒ  s$    #



c        
      s2   ˆ & t  ˆ d ˆ d ˆ ˆ ˆ  ƒ ƒ SWd QXd S(   s   Report cache statisticsi    N(   t
   _CacheInfo(    (   R|   R}   R   R…   R†   R   (    s6   lib/python2.7/site-packages/functools32/functools32.pyt
   cache_info˜  s    c              s-   ˆ ! ˆ  j  ƒ  d ˆ d <ˆ d <Wd QXd S(   s$   Clear the cache and cache statisticsi    N(   R2   (    (   R|   R}   R…   R   (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   cache_clear  s    
(
   R^   t   LockRI   R3   R   R   R5   R7   Rˆ   R‰   (   R‚   R   R€   R   R4   Rd   Rˆ   R‰   (   R†   (   R4   R|   Rƒ   R„   R}   R~   R   R…   R   R€   R   R‚   s6   lib/python2.7/site-packages/functools32/functools32.pyt   decorating_functione  s    		3			?		(   R   R€   R   R4   (   R†   R‹   (    (   R†   s6   lib/python2.7/site-packages/functools32/functools32.pyR   Q  s    A(   R   R   RX   (   R:   (!   RX   t   __all__t
   _functoolsR   R   t   collectionsR	   R
   t	   reprlib32R   R_   t   weakrefR   R   t   sysR8   t   threadR   RŠ   t   ImportErrort   _dummy_thread32R^   R   R3   R   R   R   R    R   R   R   R‡   R   (    (    (    s6   lib/python2.7/site-packages/functools32/functools32.pyt   <module>   s.   	Ô		