
    Ϫf                         d Z ddlmZ  G d d      Zd Zde_        d Zd Zd	 Zd
 Z	ddZ
 e       Zd Zd Zd Zdadadada	 ddlZeZ e
d       g dZy# e$ r dZY w xY w)zT
A module to provide some very basic threading primitives, such as
synchronization.
    wrapsc                       e Zd ZdZd Zy)	DummyLockzF
    Hack to allow locks to be unpickled on an unthreaded system.
    c                     t         dfS N unpickle_lockselfs    ;/usr/lib/python3/dist-packages/twisted/python/threadable.py
__reduce__zDummyLock.__reduce__   s    r""    N)__name__
__module____qualname____doc__r   r	   r   r   r   r      s    #r   r   c                  6    t         
t               S t               S N)threadingmoduleXLockr   r	   r   r   r   r      s    "w{r   Tc                     d| j                   vrMt        j                          d| j                   vrt               | j                   d<   t        j	                          | j
                  j                          y )N_threadable_lock)__dict___synchLockCreatoracquirer   releaser   r   s    r   	_synchPrer   !   sU    .!!#T]]205DMM,-!!#!!#r   c                 8    | j                   j                          y r   )r   r   r   s    r   
_synchPostr!   *   s    !!#r   c                 .    t              fd       }|S )Nc                 j    t        |        	  | g|i |t        |        S # t        |        w xY wr   )r   r!   )r   argskwargsfunctions      r   syncz_sync.<locals>.sync/   s2    $	D24262tJts   % 2r   )klassr&   r'   s    ` r   _syncr)   .   s     
8_  Kr   c                      t         ?| D ]9  }|j                  D ](  }t        ||j                  |         }t	        |||       * ; yy)a&  
    Make all methods listed in each class' synchronized attribute synchronized.

    The synchronized attribute should be a list of strings, consisting of the
    names of methods that must be synchronized. If we are running in threaded
    mode these methods will be wrapped with a lock.
    N)r   synchronizedr)   r   setattr)klassesr(   
methodNamer'   s       r   synchronizer/   :   sT     " 	1E#00 1
UENN:$>?z401	1 #r   c                     | r>t         s7t        &da  G d dt        j                        at               ayt        d      yt         rt        d      y)zbInitialize threading.

    Don't bother calling this.  If it needs to happen, it will happen.
    NTc                       e Zd Zd Zy)r   c                     t         dfS r   r
   r   s    r   r   zXLock.__reduce__V   s     -r22r   N)r   r   r   r   r	   r   r   r   r   U   s    3r   r   z:Cannot initialize threading, platform lacks thread supportzCannot uninitialize threads)threadedr   _RLockr   r   RuntimeError)with_threadss    r   initr7   I   sZ     *3O22 3 %*G!"P   <==r   c                  V    t         t        S t         j                         j                  S r   )r   _dummyIDcurrent_threadidentr	   r   r   getThreadIDr<   h   s"    ))+111r   c                  $    t         t               k(  S )zCAre we in the thread responsible for I/O requests (the event loop)?)ioThreadr<   r	   r   r   isInIOThreadr?   n   s    {}$$r   c                      t               ay)z8Mark the current thread as responsible for I/O requests.N)r<   r>   r	   r   r   registerAsIOThreadrA   s   s     }Hr   NF)r?   rA   r<   r   )   )r   	functoolsr   r   r   __safe_for_unpickling__r   r!   r)   r/   r7   objectr9   r<   r?   rA   r>   r3   r   r   	threading_threadingmoduler   ImportError__all__r	   r   r   <module>rJ      s   
 # # )- %$$	18 82%
  ( 'OJ I  Os   A A#"A#