ó
O'—^c           @@ s2  d  Z  d d l m Z m Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z m Z d d l m Z d d l m Z d d l m Z m Z y d d	 l m Z Wn e k
 rÕ d Z n Xd d
 l m Z m Z m Z d d l m Z m Z y d d l Z Wn d Z n Xy# d d l  m! Z! e" e# e! f Z$ Wn e k
 rje" e# f Z$ n Xd d d d d d d d d d d d d d d g Z% i  d d d d d „ Z& d e' f d  „  ƒ  YZ( d! „  Z) d e* f d" „  ƒ  YZ+ d# „  Z, e re rd$ „  Z n  d% „  Z e Z- e j. dA k r6d) „  Z/ n	 d* „  Z/ d+ „  Z0 d, d d, e1 d- „ Z2 d, d d, d. d/ „ Z3 g  i  d d d& d& d0 d d1 „ Z4 e5 d d2 „ Z6 d e7 f d3 „  ƒ  YZ8 d4 d5 d6 „ Z9 dB i  d4 d7 „ Z: e	 d8 „  ƒ Z; d9 „  Z< d: „  Z= d; e7 f d< „  ƒ  YZ> d= d> „ Z? d? „  Z@ d@ „  ZA d S(C   s/   
kombu.utils
===========

Internal utilities.

i    (   t   absolute_importt   print_functionN(   t   contextmanager(   t   countt   repeat(   t   wraps(   t   sleep(   t   UUIDt   uuid4(   t   _uuid_generate_random(   t   itemst   reraiset   string_ti   (   t   default_encodet	   safe_repr(   t   UnsupportedOperationt   EqualityDictt   sayt   uuidt   kwdictt
   maybe_listt   fxranget
   fxrangemaxt   retry_over_timet   emergency_dump_statet   cached_propertyt
   reprkwargst   reprcallt   nestedt   filenot   maybe_filenot   .c         K@ s8  | d k r t j } n  t |  t ƒ s+ |  S| j |  ƒ p= |  }  d |  k rR d n | } |  j | ƒ \ } } }	 | s’ d | r… | n |	 }	 } n  yv y | | d | | }
 Wn? t k
 rï } t t t d j	 |  | ƒ ƒ t
 j ƒ  d ƒ n X|	 rt |
 |	 ƒ S|
 SWn) t t f k
 r3| d k r4‚  q4n X| S(   s¸  Get symbol by qualified name.

    The name should be the full dot-separated path to the class::

        modulename.ClassName

    Example::

        celery.concurrency.processes.TaskPool
                                    ^- class name

    or using ':' to separate module and symbol::

        celery.concurrency.processes:TaskPool

    If `aliases` is provided, a dict containing short name/long name
    mappings, the name is looked up in the aliases first.

    Examples:

        >>> symbol_by_name('celery.concurrency.processes.TaskPool')
        <class 'celery.concurrency.processes.TaskPool'>

        >>> symbol_by_name('default', {
        ...     'default': 'celery.concurrency.processes.TaskPool'})
        <class 'celery.concurrency.processes.TaskPool'>

        # Does not try to look up non-string names.
        >>> from celery.concurrency.processes import TaskPool
        >>> symbol_by_name(TaskPool) is TaskPool
        True

    t   :t   packages   Couldn't import {0!r}: {1}i   N(   t   Nonet	   importlibt   import_modulet
   isinstanceR   t   gett
   rpartitiont
   ValueErrorR   t   formatt   syst   exc_infot   getattrt   ImportErrort   AttributeError(   t   namet   aliasest   impR!   t   sept   defaultt   kwargst   module_namet   _t   cls_namet   modulet   exc(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   symbol_by_name0   s*    #
t	   HashedSeqc           B@ s&   e  Z d  Z d Z d „  Z d „  Z RS(   sO   type used for hash() to make sure the hash is not generated
    multiple times.t	   hashvaluec         G@ s   | |  (t  | ƒ |  _ d  S(   N(   t   hashR<   (   t   selft   seq(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   __init__q   s    c         C@ s   |  j  S(   N(   R<   (   R>   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   __hash__u   s    (   t   __name__t
   __module__t   __doc__t	   __slots__R@   RA   (    (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR;   l   s   	c         C@ s-   y |  j  ƒ  SWn t k
 r( t |  ƒ SXd  S(   N(   t
   __eqhash__R.   R=   (   t   o(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   eqhashy   s    c           B@ s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C@ s5   t  | ƒ } | |  k r% |  j | ƒ St j |  | ƒ S(   N(   RH   t   __missing__t   dictt   __getitem__(   R>   t   keyt   h(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyRK   ‚   s    c         C@ s   t  j |  t | ƒ | ƒ S(   N(   RJ   t   __setitem__RH   (   R>   RL   t   value(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyRN   ˆ   s    c         C@ s   t  j |  t | ƒ ƒ S(   N(   RJ   t   __delitem__RH   (   R>   RL   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyRP   ‹   s    (   RB   RC   RK   RN   RP   (    (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   €   s   		c         O@ s)   t  t |  ƒ j | | Ž  d t j ƒd  S(   Nt   file(   t   printt   strR)   R*   t   stderr(   t   mt   fargst   fkwargs(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR      s    c          C@ s)   t  j d ƒ }  t |  ƒ t d |  j ƒ S(   Ni   t   bytes(   t   ctypest   create_string_bufferR	   R   t   raw(   t   buffer(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   ”   s    
c           C@ s   t  t ƒ  ƒ S(   sŠ   Generate a unique id, having - hopefully - a very small chance of
    collision.

    For now this is provided by :func:`uuid.uuid4`.
    (   RS   R   (    (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   ›   s    i   i   i   c         C@ s   |  S(   N(    (   R4   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   §   s    c         C@ s   t  d „  t |  ƒ Dƒ ƒ S(   s    Make sure keyword arguments are not in Unicode.

        This should be fixed in newer Python versions,
        see: http://bugs.python.org/issue4978.

        c         s@ s*   |  ]  \ } } | j  d  ƒ | f Vq d S(   s   utf-8N(   t   encode(   t   .0RL   RO   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pys	   <genexpr>±   s   (   RJ   R
   (   R4   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   ª   s    	c         C@ s*   |  d  k r g  St |  d ƒ r# |  S|  g S(   Nt   __iter__(   R"   t   hasattr(   t   v(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   µ   s
    g      ð?c         c@ sM   |  d } x< | s  | | k r2 | V| | 7} q | s< Pn  | | Vq Wd  S(   Ng      ð?(    (   t   startt   stopt   stept
   repeatlastt   cur(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   ½   s    
g      Y@c         c@ sa   d |  d } } xI | | k r$ Pn  | V| rE t  | | | ƒ } n
 | | 7} | | 7} q Wd  S(   Ni    g      ð?(   t   min(   Rb   Rc   Rd   t   maxt   sum_Rf   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   É   s    
i   c
         C@ s  d }
 t  | | | | d t ƒ} xä t ƒ  D]Ù }
 y |  | | Ž  SWq, | k
 r} | rm |
 | k rm ‚  n  |	 r} |	 ƒ  n  t | r˜ | | | |
 ƒ n	 t | ƒ ƒ } | rx4 t t | ƒ ƒ D]  } |	 rÖ |	 ƒ  n  t d ƒ qÀ Wt t t | ƒ | ƒ ƒ qq, Xq, Wd S(   sg  Retry the function over and over until max retries is exceeded.

    For each retry we sleep a for a while before we try again, this interval
    is increased for every retry until the max seconds is reached.

    :param fun: The function to try
    :param catch: Exceptions to catch, can be either tuple or a single
        exception class.
    :keyword args: Positional arguments passed on to the function.
    :keyword kwargs: Keyword arguments passed on to the function.
    :keyword errback: Callback for when an exception in ``catch`` is raised.
        The callback must take two arguments: ``exc`` and ``interval``, where
        ``exc`` is the exception instance, and ``interval`` is the time in
        seconds to sleep next..
    :keyword max_retries: Maximum number of retries before we give up.
        If this is not set, we will retry forever.
    :keyword interval_start: How long (in seconds) we start sleeping between
        retries.
    :keyword interval_step: By how much the interval is increased for each
        retry.
    :keyword interval_max: Maximum number of seconds to sleep between retries.

    i    Re   g      ð?N(	   R   t   TrueR   t   floatt   nextt   ranget   intR   t   abs(   t   funt   catcht   argsR4   t   errbackt   max_retriest   interval_startt   interval_stept   interval_maxt   callbackt   retriest   interval_rangeR9   t   ttsR6   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   Ö   s(    

c   	      C@ sÜ   d d l  m } d d l m } | d  k rD d d  l } | j } n  | ƒ  } t d | ƒ | | d ƒ } zW y | |  | d d ƒWn9 t k
 r¾ } t d | ƒ | j	 t
 | |  ƒ ƒ ƒ n XWd  | j ƒ  | j ƒ  X| S(   Ni    (   t   pformat(   t   mktemps&   EMERGENCY DUMP STATE TO FILE -> {0} <-t   wt   protocols0   Cannot pickle state: {0!r}. Fallback to pformat.(   t   pprintR|   t   tempfileR}   R"   t   picklet   dumpR   t	   Exceptiont   writeR   t   flusht   close(	   t   statet	   open_fileRƒ   R|   R}   R‚   t   persistt   fhR9   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR     s"    	!
c           B@ sS   e  Z d  Z d d d d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 RS(   s‚  Property descriptor that caches the return value
    of the get function.

    *Examples*

    .. code-block:: python

        @cached_property
        def connection(self):
            return Connection()

        @connection.setter  # Prepares stored value
        def connection(self, value):
            if value is None:
                raise TypeError('Connection must be a connection')
            return value

        @connection.deleter
        def connection(self, value):
            # Additional action to do at del(self.attr)
            if value is not None:
                print('Connection {0!r} deleted'.format(value)

    c         C@ sI   | |  _  | |  _ | |  _ | p' | j |  _ | j |  _ | j |  _ d  S(   N(   t   _cached_property__gett   _cached_property__sett   _cached_property__delRD   RB   RC   (   R>   t   fgett   fsett   fdelt   doc(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR@   7  s    			c         C@ sX   | d  k r |  Sy | j |  j SWn/ t k
 rS |  j | ƒ } | j |  j <| SXd  S(   N(   R"   t   __dict__RB   t   KeyErrorRŒ   (   R>   t   objt   typeRO   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   __get__?  s    c         C@ sH   | d  k r |  S|  j d  k	 r4 |  j | | ƒ } n  | | j |  j <d  S(   N(   R"   R   R“   RB   (   R>   R•   RO   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   __set__H  s
    c         C@ sc   | d  k r |  Sy | j j |  j ƒ } Wn t k
 r< n# X|  j d  k	 r_ |  j | | ƒ n  d  S(   N(   R"   R“   t   popRB   R”   RŽ   (   R>   R•   RO   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt
   __delete__O  s    c         C@ s   |  j  |  j | |  j ƒ S(   N(   t	   __class__RŒ   RŽ   (   R>   R   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   setterZ  s    c         C@ s   |  j  |  j |  j | ƒ S(   N(   R›   RŒ   R   (   R>   R‘   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   deleter]  s    N(
   RB   RC   RD   R"   R@   R—   R˜   Rš   Rœ   R   (    (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR     s   				s   , s   {0}={1}c         @ s#   | j  ‡  f d †  t |  ƒ Dƒ ƒ S(   Nc         3@ s-   |  ]# \ } } ˆ  j  | t | ƒ ƒ Vq d  S(   N(   R)   t
   _safe_repr(   R^   t   kRa   (   t   fmt(    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pys	   <genexpr>b  s    (   t   joinR
   (   R4   R2   R    (    (   R    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   a  s    c         C@ sI   d j  |  | j t t | p d ƒ ƒ | r6 | r6 | p9 d t | | ƒ ƒ S(   Ns   {0}({1}{2}{3})t    (    (   R)   R¡   t   mapRž   R   (   R/   Rr   R4   R2   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   e  s    c          g@ sû   g  } g  } d } zÞ zc yI x= |  D]5 } | j } | j } | j | ƒ  ƒ | j | ƒ q" W| VWn t j ƒ  } n XWd xE | rÂ | j ƒ  } y | | Œ  r¨ d } n  Wq~ t j ƒ  } q~ Xq~ W| d k rî t | d | d | d ƒ n  XWd ~ Xd S(   sK   Combine multiple context managers into a single nested
    context manager.Ni    i   i   (   NNN(   NNN(   NNN(   R"   t   __exit__t	   __enter__t   appendR*   R+   R™   R   (   t   managerst   exitst   varsR9   t   mgrt   exitt   enter(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   m  s0     				$c         c@ sC   t  |  ƒ }  t j } x' t d  ƒ D] } | |  ƒ |  d Vq" Wd  S(   Ni    (   t   listt   randomt   shuffleR   R"   (   t   itR¯   R6   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   shufflecycle  s
    	
c         C@ sC   y d d l  m } Wn t k
 r. t g  ƒ SXd „  | |  ƒ Dƒ S(   Ni    (   t   iter_entry_pointsc         s@ s!   |  ] } | | j  ƒ  f Vq d  S(   N(   t   load(   R^   t   ep(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pys	   <genexpr>  s    (   t   pkg_resourcesR²   R-   t   iter(   t	   namespaceR²   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   entrypoints˜  s
    t   ChannelPromisec           B@ s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C@ s   | |  _  d  S(   N(   t   __contract__(   R>   t   contract(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR@   ¢  s    c         C@ s7   y |  j  SWn% t k
 r2 |  j ƒ  } |  _  | SXd  S(   N(   t	   __value__R.   Rº   (   R>   RO   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   __call__¥  s
    c         C@ s<   y t  |  j ƒ SWn$ t k
 r7 d j t |  j ƒ ƒ SXd  S(   Ns   <promise: 0x{0:x}>(   t   reprR¼   R.   R)   t   idRº   (   R>   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   __repr__¬  s    (   RB   RC   R@   R½   RÀ   (    (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR¹      s   		R¢   c         @ s   d j  ‡  f d †  |  Dƒ ƒ S(   NR¢   c         3@ sI   |  ]? } | j  ƒ  s! | ˆ  k r' | n | d  k r9 d n d | Vq d S(   s    s   \000s   \N(   t   isalnum(   R^   t   c(   t   white(    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pys	   <genexpr>µ  s   (   R¡   (   t   pRÃ   (    (   RÃ   s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   escape_regex³  s    c         C@ s    t  |  t j ƒ r |  S|  j ƒ  S(   N(   R%   t   numberst   IntegralR   (   t   f(    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   º  s    c         C@ s&   y t  |  ƒ SWn t k
 r! n Xd S(   s3   Get object fileno, or :const:`None` if not defined.N(   R   t   FILENO_ERRORS(   RÈ   (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyR   À  s    (   i   i   i   (    (B   RD   t
   __future__R    R   R#   RÆ   R®   R*   t
   contextlibR   t	   itertoolsR   R   t	   functoolsR   t   timeR   R   R   R   R	   R-   R"   t
   kombu.fiveR
   R   R   t   encodingR   R   Rž   RY   t   ioR   R.   R(   RÉ   t   __all__R:   R­   R;   RH   RJ   R   R   t   gen_unique_idt   version_infoR   R   t   FalseR   R   R   t   openR   t   objectR   R   R   R   R±   R¸   R¹   RÅ   R   R   (    (    (    s6   /tmp/pip-unpacked-wheel-UAnTfW/kombu/utils/__init__.pyt   <module>   sv   

		;							/D#			