ó
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 m	 Z	 d d l
 m Z y d d l m Z Wn' e k
 r© d e f d „  ƒ  YZ n Xd	 d
 d d d d d g Z d a e ƒ  Z e ƒ  Z e a d „  Z d „  Z d „  Z d „  Z d e j f d „  ƒ  YZ e ƒ  Z e ƒ  Z d „  Z  d „  Z! d „  Z" e j# j$ d ƒ Z% e j# j$ d ƒ r}d „  Z& n e! Z& d „  Z' d „  Z( e	 e& ƒ Z) e	 e' ƒ Z* d „  Z+ d „  Z, d S(   sÁ   
    celery._state
    ~~~~~~~~~~~~~~~

    This is an internal module containing thread state
    like the ``current_app``, and ``current_task``.

    This module shouldn't be used directly.

i    (   t   absolute_importt   print_functionN(   t   Proxy(   t
   LocalStack(   t   WeakSett   AppSetc           B@ s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C@ s   t  ƒ  |  _ d  S(   N(   t   sett   _refs(   t   self(    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   __init__   s    c         C@ s   |  j  j t j | ƒ ƒ d  S(   N(   R   t   addt   weakreft   ref(   R   t   app(    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR
      s    c         c@ ss   g  } zB x; |  j  D]0 } | ƒ  } | d  k r> | j | ƒ q | Vq WWd  x  | rm |  j  j | j ƒ  ƒ qN WXd  S(   N(   R   t   Nonet   appendt   discardt   pop(   R   t   dirtyt   apprefR   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   __iter__"   s    		(   t   __name__t
   __module__R	   R
   R   (    (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR      s   		t   set_default_appt   get_current_appt   get_current_taskt   get_current_worker_taskt   current_appt   current_taskt   connect_on_app_finalizec         C@ s   t  j |  ƒ |  S(   N(   t   _on_app_finalizersR
   (   t   callback(    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR   A   s    c         C@ s+   t  t ƒ } x | D] } | |  ƒ q Wd  S(   N(   R   R   (   R   t	   callbacksR   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   _announce_app_finalizedF   s    c         C@ s
   |  a  d  S(   N(   t   _task_join_will_block(   t   blocks(    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   _set_task_join_will_blockL   s    c           C@ s   t  S(   N(   R"   (    (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   task_join_will_blockQ   s    t   _TLSc           B@ s   e  Z d  Z RS(   N(   R   R   R   R   (    (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR&   U   s   c         C@ s
   |  a  d  S(   N(   t   default_app(   R   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR   _   s    c          C@ sf   t  d  k rY d d l m }  t |  d d t j j d ƒ p= d d g  d t d t	 ƒƒ n  t
 j pe t  S(	   Ni    (   t   Celeryt   defaultt   loadert   CELERY_LOADERt   fixupst   set_as_currentt   accept_magic_kwargs(   R'   R   t
   celery.appR(   R   t   ost   environt   gett   Falset   Truet   _tlsR   (   R(   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   _get_current_appd   s    c         C@ s   |  t  _ d  S(   N(   R5   R   (   R   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   _set_current_appq   s    t   C_STRICT_APPc          C@ sE   t  d ƒ ‚ d d  l }  t d d t j ƒ|  j d t j ƒ t ƒ  S(   Ns   USES CURRENT APPi    s   -- USES CURRENT_APPt   file(   t	   Exceptiont	   tracebackt   printt   syst   stderrt   print_stackR6   (   R;   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR   w   s
    c           C@ s   t  j S(   s   Currently executing task.(   t   _task_stackt   top(    (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR      s    c          C@ s.   x' t  t j ƒ D] }  |  j j s |  Sq Wd S(   sð   Currently executing task, that was applied by the worker.

    This is used to differentiate between the actual task
    executed by the worker and any task that was called within
    a task (using ``task.__call__`` or ``task.apply``)

    N(   t   reversedR@   t   stackt   requestt   called_directly(   t   task(    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyR   †   s    c         C@ s   t  j |  ƒ d  S(   N(   t   _appsR
   (   R   (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   _register_appš   s    c           C@ s   t  S(   N(   RG   (    (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   _get_active_appsž   s    (-   t   __doc__t
   __future__R    R   R0   R=   t	   threadingR   t   celery.localR   t   celery.utils.threadsR   R   R   t   ImportErrort   objectt   __all__R   R'   RG   R   R   R3   R"   R   R!   R$   R%   t   localR&   R5   R@   R   R6   R7   R1   R2   R8   R   R   R   R   R   RH   RI   (    (    (    s/   /tmp/pip-unpacked-wheel-gV1wwp/celery/_state.pyt   <module>   sL   																	