
P'^c           @@ s  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 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 d d	 l m Z m Z d d
 l m Z m Z m Z m Z d d d d d d d d d d d d d d g Z e j  d d k Z! d Z" d Z# d j$   Z% e j& j' d  pd Z) e d  Z* d Z+ d  Z, d! Z- e j. d"  Z/ d#   Z0 d d d d d$ d%  Z1 d d d d d&  Z2 d d d d d'  Z3 d( e4 f d)     YZ5 d*   Z6 d+   Z7 g  d,  Z8 d-   Z9 d d. d/ d0  Z: d1   Z; i e< d2 6e< d3 6e< d4 6e= d5 6e= d6 6e= d7 6e= d8 6e< d9 6d:  Z> e j? e f d d d d;  Z@ d<   ZA d=   ZB d d> d?  ZC d@   ZD dA   ZE dB   ZF dC d4 dD  ZG e eG dE dC  ZH d dF  ZI e/ dG dH  ZJ dI dJ lK mL ZL dI dK lM mN ZO mP ZQ mR ZR mS ZS dI dL lT mU ZU mV ZV d dM lW mX ZX mY ZY mZ ZZ eZ Z[ d S(N   s<   
    celery.utils
    ~~~~~~~~~~~~

    Utility functions.

i    (   t   absolute_importt   print_functionN(   t   Callable(   t   partialt   wraps(   t
   getargspec(   t   pprint(   t   Exchanget   Queue(   t   CPendingDeprecationWarningt   CDeprecationWarning(   t
   WhateverIOt   itemst   reraiset   string_tt   worker_directt   warn_deprecatedt
   deprecatedt   lpmerget   is_iterablet   isattyt   cryt   maybe_reraiset	   strtoboolt   jsonifyt   gen_task_namet   nodenamet	   nodesplitt   cached_propertyi   s   
    {description} is scheduled for deprecation in     version {deprecation} and removal in version v{removal}.     {alternative}
sc   
    {description} is deprecated and scheduled for removal in
    version {removal}. {alternative}
s   
Unknown format %{0} in string {1!r}.
Possible causes: Did you forget to escape the expand sign (use '%%{0!r}'),
or did you escape and the value was expanded twice? (%%N -> %N -> %hostname)?
t   MP_MAIN_FILEs   C.dqs   {hostname}.dqt   @t   celerys   %(\w)c         C@ s5   t  |  t  r |  St t j d |   t |  d t S(   s=  Return :class:`kombu.Queue` that is a direct route to
    a worker by hostname.

    :param hostname: The fully qualified node name of a worker
                     (e.g. ``w1@example.com``).  If passed a
                     :class:`kombu.Queue` instance it will simply return
                     that instead.
    t   hostnamet   auto_delete(   t
   isinstanceR   t   WORKER_DIRECT_QUEUE_FORMATt   formatt   WORKER_DIRECT_EXCHANGEt   True(   R    (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   J   s
    	i   c         C@ sr   i |  d 6| d 6| d 6| d 6} | d  k	 rF t t j |    } n t t j |    } t j | d | d  S(   Nt   descriptiont   deprecationt   removalt   alternativet
   stacklevel(   t   NoneR	   t   PENDING_DEPRECATION_FMTR$   R
   t   DEPRECATION_FMTt   warningst   warn(   R'   R(   R)   R*   R+   t   ctxt   w(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   Z   s    

c         @ s        f d   } | S(   s  Decorator for deprecated functions.

    A deprecation warning will be emitted when the function is called.

    :keyword deprecation: Version that marks first deprecation, if this
      argument is not set a ``PendingDeprecationWarning`` will be emitted
      instead.
    :keyword removal:  Future version when this feature will be removed.
    :keyword alternative:  Instructions for an alternative solution (if any).
    :keyword description: Description of what is being deprecated.

    c         @ s+   t           f d    } | S(   Nc          @ sN   d d l  m } t d  p% |   d  d  d   d d   |  |   S(	   Ni   (   t   qualnameR'   R(   R)   R*   R+   i   (   t   importsR3   R   (   t   argst   kwargsR3   (   R*   R(   R'   t   funR)   (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   __innerv   s    (   R   (   R7   R8   (   R*   R(   R'   R)   (   R7   s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   _innert   s    '	(    (   R(   R)   R*   R'   R9   (    (   R*   R(   R'   R)   s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   f   s    c         @ s        f d   } | S(   Nc      
   @ s+   t  |  d  d  d   d  p' |  j S(   NR(   R)   R*   R'   (   t   _deprecated_propertyt   __name__(   R7   (   R*   R(   R'   R)   (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR9      s    (    (   R(   R)   R*   R'   R9   (    (   R*   R(   R'   R)   s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   deprecated_property   s    R:   c           B@ sM   e  Z d d d d d   Z d d  Z d   Z d   Z d   Z d   Z RS(   c         K@ sa   | |  _  | |  _ | |  _ | j | j | j |  _ |  _ |  _ | |  _ |  j j d d  d  S(   NR+   i   (   t   _deprecated_property__gett   _deprecated_property__sett   _deprecated_property__delR;   t
   __module__t   __doc__t	   depreinfot
   setdefault(   t   selft   fgett   fsett   fdelt   docRB   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   __init__   s    			&	c         C@ s*   | d  k r |  St |  j   |  j |  S(   N(   R,   R   RB   R=   (   RD   t   objt   type(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   __get__   s    c         C@ sO   | d  k r |  S|  j d  k r. t d   n  t |  j   |  j | |  d  S(   Ns   cannot set attribute(   R,   R>   t   AttributeErrorR   RB   (   RD   RJ   t   value(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   __set__   s    c         C@ sL   | d  k r |  S|  j d  k r. t d   n  t |  j   |  j |  d  S(   Ns   cannot delete attribute(   R,   R?   RM   R   RB   (   RD   RJ   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt
   __delete__   s    c         C@ s   |  j  |  j | |  j |  j  S(   N(   t	   __class__R=   R?   RB   (   RD   RF   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   setter   s    c         C@ s   |  j  |  j |  j | |  j  S(   N(   RQ   R=   R>   RB   (   RD   RG   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   deleter   s    N(	   R;   R@   R,   RI   RL   RO   RP   RR   RS   (    (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR:      s   
			c         C@ sE   |  j  } g  t |  D]' \ } } | d k	 r | | |  ^ q |  S(   sk   In place left precedent dictionary merge.

    Keeps values from `L`, if the value in `R` is :const:`None`.N(   t   __setitem__R   R,   (   t   Lt   Rt   sett   kt   v(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR      s    	8c         C@ s'   y t  |   Wn t k
 r" t SXt S(   N(   t   itert	   TypeErrort   FalseR&   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR      s
    c         C@ sQ   t  |  d t |    } | j d  k	 r+ | Sg  | D] } | | j k r2 | ^ q2 S(   Nt   argspec(   t   getattrR   t   keywordsR,   R5   (   R7   t   kwlistt   St   kw(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   fun_takes_kwargs   s    c         C@ s&   y |  j    SWn t k
 r! n Xd  S(   N(   R   RM   (   t   fh(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR      s    t   =i1   c   
      C@ s  d d l  } |  d k r! t   n |  }  t t d |  } t d   | j   D  } | | } x t t j	    D] \ } } | j
 |  }	 |	 s qr n  | d j |	   | |  t j | d |  | |  | d  | |  t | j d |  | d  qr W|  j   S(	   sW   Return stacktrace of all active threads,
    taken from https://gist.github.com/737056.i    Nt   filec         s@ s   |  ] } | j  | f Vq d  S(   N(   t   ident(   t   .0t   t(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pys	   <genexpr>   s    s   {0.name}s   LOCAL VARIABLESt   streams   
(   t	   threadingR,   R   R   t   printt   dictt	   enumerateR   t   syst   _current_framest   getR$   t	   tracebackt   print_stackR   t   f_localst   getvalue(
   t   outt   sepchrt   seplenRk   t   Pt   tmapt   sept   tidt   framet   thread(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR      s$    




c          C@ sD   t  j   }  z- |  d r8 t |  d |  d |  d  n  Wd ~  Xd S(   sM   Re-raise if an exception is currently being handled, or return
    otherwise.i   i    i   N(   Ro   t   exc_infoR   (   R   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR      s
    
#t   falset   not   0t   truet   yest   1t   ont   offc         C@ sQ   t  |  t  rM y | |  j   SWqM t k
 rI t d j |     qM Xn  |  S(   sO   Convert common terms for true/false to bool
    (true/false/yes/no/on/off/1/0).s    Cannot coerce {0!r} to type bool(   R"   R   t   lowert   KeyErrorR[   R$   (   t   termt   table(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR      s    c      
   @ s  d d l  m } t t d | d | d  d |   t |  |  rX |  j d t  }  n  |  d k ss t |  |  rw |  St |  t t	 f  r g  |  D] }   |  ^ q St |  t
  r t
    f d   t |   D  St |  t j  r;|  j   } |  j r| d	  | d
 } n  | j d  r7| d  d } n  | St |  t j  rW|  j   St |  t j  r|  j   } |  j r| d  } n  | St |  t j  rt |   S| d k rt d j t |   |  |    n  | |   Sd S(   s;   Transforms object making it suitable for json serializationi    (   t   Objectt   builtin_typest   keyt	   keyfiltert   unknown_type_filtert   recursec         3@ sE   |  ]; \ } }  r!  |  n d  r |   | d | f Vq d S(   i   R   N(    (   Rh   RX   RY   (   t   _jsonifyR   (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pys	   <genexpr>  s   	i   i   s   +00:00it   Zi   s+   Unsupported type: {0!r} {1!r} (parent: {2})N(   t   kombu.abstractR   R   R   R"   t   as_dictR&   R,   t   tuplet   listRm   R   t   datetimet	   isoformatt   microsecondt   endswitht   datet   timet	   timedeltat   strt
   ValueErrorR$   RK   (   RJ   R   R   R   R   t   KombuDictTypeRY   t   r(    (   R   R   s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR     sD    		
	
c         C@ s   y t  j | } Wn t k
 r* d } n X| d k	 ra | j } t ra | j t k ra d } qa n  | d k r |  j r d j |  j | g  Sd j d   | | f D  S(   s)   Generate task name from name/module pair.t   __main__t   .c         s@ s   |  ] } | r | Vq d  S(   N(    (   Rh   t   p(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pys	   <genexpr>K  s    N(	   Ro   t   modulesR   R,   R;   R   t   __file__t   maint   join(   t   appt   namet   module_namet   module(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   9  s    
	c         C@ s   t  j |  | f  S(   s)   Create node name from name/hostname pair.(   t   NODENAME_SEPR   (   R   R    (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   N  s    t   genc         C@ s4   t  d j | t t j    g  |  p0 t j    S(   Nt    (   R   R   R   t   ost   getpidt   sockett   gethostname(   R    t   prefix(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   anon_nodenameS  s    !c         C@ s6   |  j  t d  } t |  d k r2 d | d f S| S(   s,   Split node name into tuple of name/hostname.i   i    N(   t   splitR   t   lenR,   (   R   t   parts(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   X  s    c         C@ s7   t  |  p d  \ } } t | p$ t | p3 t j    S(   NR   (   R   R   t   NODENAME_DEFAULTR   R   (   R    R   t   host(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   default_nodename`  s    c         K@ s.   t  |  \ } } t |  | d | p' t | S(   Nt   n(   R   t   host_formatR   (   t   sR   t   extraR   R   (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   node_formate  s    R   c         C@ s3   d d l  m } |   } | r/ d j |  |  S| S(   Ni   (   t   current_process_indexs   {0}{1}(   t   logR   R$   (   R   t   defaultR   t   index(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   _fmt_process_indexk  s    	t   -c         K@ si   | p t  j   } | j d  \ } } } t i | d 6| d 6| d 6t d 6t d 6|  } t |  |  S(   NR   t   hR   t   dt   it   I(   R   R   t	   partitionRm   R   t   _fmt_process_index_with_prefixt   simple_format(   R   R   R   R   t   _t   domaint   keys(    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   r  s    	s   \1c         @ s?    r;  j  d d      f d   } | j |   S S(   Nt   %c         @ sc   |  j     } y  | } Wn) t k
 rH t t j |     n Xt | t  r_ |   S| S(   N(   t   expandR   R   t   UNKNOWN_SIMPLE_FORMAT_KEYR$   R"   R   (   t   matchR   t   resolver(   R   R   R   (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   resolve  s    (   RC   t   sub(   R   R   t   patternR   R   (    (   R   R   R   s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyR   |  s
    
i   (   t
   LOG_LEVELS(   R3   t   symbol_by_namet   instantiatet   import_from_cwd(   t   chunkst   noop(   R   t   kwdictt   uuid(\   RA   t
   __future__R    R   t   numbersR   t   reR   Ro   Rr   R/   R   t   collectionsR   t	   functoolsR   R   t   inspectR   R   t   kombu.entityR   R   t   celery.exceptionsR	   R
   t   celery.fiveR   R   R   R   t   __all__t   version_infot   PY3R-   R.   t   stripR   t   environRq   R,   R   R%   R#   R   R   t   compilet	   RE_FORMATR   R   R   R<   t   objectR:   R   R   Rc   R   R   R   R\   R&   R   t   RealR   R   R   R   R   R   R   R   R   R   R   R   R   R4   R3   t   get_full_cls_nameR   t   get_cls_by_nameR   R   t
   functionalR   R   t   kombu.utilsR   R   R   t   gen_unique_id(    (    (    s7   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/__init__.pyt   <module>   s   "		)					+					
"