๓
P'^c           @@  sฮ  d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z m Z m Z m Z d d l m Z d d	 l m Z m Z m Z m Z m Z d
 d d d d d d d d d d d d d d d g Z e e d  Z e   Z d e f d     YZ d
 e f d     YZ d d e d  Z  d e f d     YZ! d    Z" d!   Z# d"   Z$ d#   Z% d d$  Z& d%   Z' d&   Z( d'   Z) d( e e* f d)     YZ+ d d*  Z, d S(+   sX   
    celery.utils.functional
    ~~~~~~~~~~~~~~~~~~~~~~~

    Utilities for functions.

i    (   t   absolute_importN(   t   wraps(   t   islice(   t   cached_property(   t   lazyt   maybe_evaluatet   is_listt
   maybe_list(   t   OrderedDict(   t   UserDictt   UserListt   itemst   keyst   ranget   LRUCacheR   R   t   memoizet   mlazyt   noopt   firstt   firstmethodt   chunkst   padlistt   mattrgettert   uniqt   regent
   dictfilterR   R   t   pypy_version_infot   DummyContextc           B@  s   e  Z d    Z d   Z RS(   c         C@  s   |  S(   N(    (   t   self(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt	   __enter__"   s    c         G@  s   d  S(   N(    (   R   t   exc_info(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __exit__%   s    (   t   __name__t
   __module__R   R   (    (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR       s   	c           B@  sแ   e  Z d  Z d d  Z d   Z d   Z e e d  Z	 d   Z
 d   Z e d  Z e Z e d  Z e Z d	   Z e Z d
 d  Z d   Z d   Z e j d d k rฤ e Z e Z e Z n d   Z d   Z d   Z RS(   s$  LRU Cache implementation using a doubly linked list to track access.

    :keyword limit: The maximum number of keys to keep in the cache.
        When a new key is inserted and the limit has been exceeded,
        the *Least Recently Used* key will be discarded from the
        cache.

    c         C@  s(   | |  _  t j   |  _ t   |  _ d  S(   N(   t   limitt	   threadingt   RLockt   mutexR   t   data(   R   R"   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __init__3   s    	c         C@  s.   |  j   |  j j |  } |  | <Wd  QX| S(   N(   R%   R&   t   pop(   R   t   keyt   value(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __getitem__8   s    
 c         O@  s   |  j  t |  j |  j } } | j | |   | ry t |  | k ry x1 t t |  |  D] } | j d t  q\ Wn  Wd  QXd  S(   Nt   last(   R%   R&   R"   t   updatet   lenR   t   popitemt   False(   R   t   argst   kwargsR&   R"   t   _(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR-   =   s    
c         C@  s:   | s |  j  j |  S|  j  |  j  j |  SWd  QXd  S(   N(   R&   R/   R%   (   R   R,   t   _needs_lock(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR/   F   s    
c         C@  sd   |  j  U |  j rM t |  j  |  j k rM |  j j t t |  j    n  | |  j | <Wd  QXd  S(   N(   R%   R"   R.   R&   R(   t   nextt   iter(   R   R)   R*   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __setitem__L   s    
!"c         C@  s   t  |  j  S(   N(   R6   R&   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __iter__S   s    c      
   c@  s^   | r |  j  n t   @ x8 |  D]0 } y | |  j | f VWq  t k
 rO q  Xq  WWd  QXd  S(   N(   R%   R   R&   t   KeyError(   R   t
   _need_lockt   k(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   _iterate_itemsV   s    c      
   c@  sX   | r |  j  n t   : x2 |  D]* } y |  j | VWq  t k
 rI q  Xq  WWd  QXd  S(   N(   R%   R   R&   R9   (   R   R:   R;   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   _iterate_values_   s    c         C@  s   t  |  j  S(   N(   R   R&   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   _iterate_keysi   s    i   c         C@  s@   |  j  1 t |  j j |   | } t |  |  | <Wd  QX| S(   N(   R%   t   intR&   R(   t   str(   R   R)   t   deltat   newval(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   incrn   s    
c         C@  s#   t  t |    } | j d  | S(   NR%   (   t   dictt   varsR(   (   R   t   d(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __getstate__v   s    c         C@  s   | |  _  t j   |  _ d  S(   N(   t   __dict__R#   R$   R%   (   R   t   state(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   __setstate__{   s    	i    i   c         C@  s   t  |  j    S(   N(   t   listR>   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR      s    c         C@  s   t  |  j    S(   N(   RK   R=   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   values   s    c         C@  s   t  |  j    S(   N(   RK   R<   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR      s    N(   R    R!   t   __doc__t   NoneR'   R+   R-   t   Truet   IS_PYPYR/   R7   R8   R<   t	   iteritemsR=   t
   itervaluesR>   t   iterkeysRC   RG   RJ   t   syst   version_infoR   RL   R   (    (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   )   s.   											c         @  s       f d   } | S(   Nc         @  sz   t  j     d    t         f d         f d   } d   _   _ |   _    _   S(   NR"   c          @  sฒ    r  |  |  } n# |  t  f t t | j     } y    | } Wd  QXWnF t k
 r  |  |   }   j d 7_   |  | <Wd  QXn X  j d 7_ | S(   Ni   (   t   KEYWORD_MARKt   tuplet   sortedR   R9   t   missest   hits(   R1   R2   R)   R*   (   t   _Mt   cachet   funt   keyfunR%   (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR[      s    #c           @  s    j    d   _   _ d S(   s+   Clear the cache and reset cache statistics.i    N(   t   clearRZ   RY   (    (   R[   R\   (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR_   ง   s    
i    (   R#   t   LockR   RZ   RY   R_   t   original_func(   R]   R_   (   t   CacheR^   t   maxsize(   R[   R\   R]   R%   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   _memoize   s    '		(    (   Rc   R^   Rb   Rd   (    (   Rb   R^   Rc   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR      s     c           B@  s#   e  Z d  Z e Z d Z d   Z RS(   sๅ   Memoized lazy evaluation.

    The function is only evaluated once, every subsequent access
    will return the same value.

    .. attribute:: evaluated

        Set to to :const:`True` after the object has been evaluated.

    c         C@  s4   |  j  s- t t |   j   |  _ t |  _  n  |  j S(   N(   t	   evaluatedt   superR   t   evaluatet   _valueRO   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyRg   ย   s    	N(   R    R!   RM   R0   Re   RN   Rh   Rg   (    (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   ด   s   
c          O@  s   d S(   sP   No operation.

    Takes any arguments/keyword arguments and does nothing.

    N(    (   R1   R2   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   ษ   s    c         @  s   t    f d   | D d  S(   sฎ   Return the first element in `iterable` that `predicate` Gives a
    :const:`True` value for.

    If `predicate` is None it will return the first item that is not None.

    c         3@  s3   |  ]) }   r   |  n	 | d  k	 r | Vq d  S(   N(   RN   (   t   .0t   v(   t	   predicate(    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pys	   <genexpr>ฺ   s    N(   R5   RN   (   Rk   t   it(    (   Rk   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   า   s    c         @  s     f d   } | S(   sื   Return a function that with a list of instances,
    finds the first instance that gives a value for the given method.

    The list can also contain lazy instances
    (:class:`~kombu.utils.functional.lazy`.)

    c         @  s[   xT |  D]L } y" t  t |     | |   } Wn t k
 rB q X| d  k	 r | Sq Wd  S(   N(   t   getattrR   t   AttributeErrorRN   (   Rl   R1   R2   t   objt   answer(   t   method(    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   _matcher่   s    "(    (   Rq   Rr   (    (   Rq   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   ฿   s    	
c         c@  s4   x- |  D]% } | g t  t |  | d   Vq Wd S(   s  Split an iterator into chunks with `n` elements each.

    Examples

        # n == 2
        >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 2)
        >>> list(x)
        [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]

        # n == 3
        >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 3)
        >>> list(x)
        [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]

    i   N(   RK   R   (   Rl   t   nR   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   ๕   s    c         C@  s#   t  |   |  | g | t |   S(   sพ  Pad list with default elements.

    Examples:

        >>> first, last, city = padlist(['George', 'Costanza', 'NYC'], 3)
        ('George', 'Costanza', 'NYC')
        >>> first, last, city = padlist(['George', 'Costanza'], 3)
        ('George', 'Costanza', None)
        >>> first, last, city, planet = padlist(
        ...     ['George', 'Costanza', 'NYC'], 4, default='Earth',
        ... )
        ('George', 'Costanza', 'NYC', 'Earth')

    (   RK   R.   (   t	   containert   sizet   default(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   
  s    c          @  s     f d   S(   s}   Like :func:`operator.itemgetter` but return :const:`None` on missing
    attributes instead of raising :exc:`AttributeError`.c         @  s   t    f d    D  S(   Nc         3@  s'   |  ] } | t    | d   f Vq d  S(   N(   Rm   RN   (   Ri   t   attr(   Ro   (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pys	   <genexpr>  s   (   RD   (   Ro   (   t   attrs(   Ro   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   <lambda>  s   (    (   Rx   (    (   Rx   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR     s    c         @  s   t        f d   |  D S(   s7   Return all unique elements in ``it``, preserving order.c         3@  s0   |  ]& } |   k r   j  |  p' | Vq d  S(   N(   t   add(   Ri   Ro   (   t   seen(    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pys	   <genexpr>&  s    (   t   set(   Rl   (    (   R{   s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   #  s    	c         C@  s#   t  |  t t f  r |  St |   S(   sญ   Regen takes any iterable, and if the object is an
    generator it will cache the evaluated list on first access,
    so that the generator can be "consumed" multiple times.(   t
   isinstanceRK   RW   t   _regen(   Rl   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   )  s    R~   c           B@  s2   e  Z d    Z d   Z d   Z e d    Z RS(   c         C@  s   | |  _  d  S(   N(   t
   _regen__it(   R   Rl   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR'   4  s    c         C@  s   t  |  j f f S(   N(   RK   R&   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt
   __reduce__7  s    c         C@  s   |  j  j   S(   N(   R   t   __length_hint__(   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   :  s    c         C@  s   t  |  j  S(   N(   RK   R   (   R   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR&   =  s    (   R    R!   R'   R   R   R   R&   (    (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR~   2  s   			c         K@  sG   |  d k r | n | r' t |  |  n |  }  t d   t |   D  S(   s<   Remove all keys from dict ``d`` whose value is :const:`None`c         s@  s-   |  ]# \ } } | d  k	 r | | f Vq d  S(   N(   RN   (   Ri   R;   Rj   (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pys	   <genexpr>E  s    N(   RN   RD   R   (   RF   t   kw(    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyR   B  s    -(-   RM   t
   __future__R    RT   R#   t	   functoolsR   t	   itertoolsR   t   kombu.utilsR   t   kombu.utils.functionalR   R   R   R   t   kombu.utils.compatR   t   celery.fiveR	   R
   R   R   R   t   __all__t   hasattrRP   t   objectRV   R   R   RN   R   R   R   R   R   R   R   R   R   R   RK   R~   R   (    (    (    s9   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/functional.pyt   <module>   s8   "(		f%									