U
    
W[á  ã                   @   sÔ   d Z ddlmZmZ ddlmZ G dd„ deƒZdd„ Zde_	d	d
„ Z
dd„ Zdd„ Zdd„ Zddd„Zeƒ Zdd„ Zdd„ Zdd„ ZdadadadazddlZW n ek
rº   dZY n
X edƒ ddddgZdS )zT
A module to provide some very basic threading primitives, such as
synchronization.
é    )ÚdivisionÚabsolute_import©Úwrapsc                   @   s   e Zd ZdZdd„ ZdS )Ú	DummyLockzF
    Hack to allow locks to be unpickled on an unthreaded system.
    c                 C   s   t dfS ©N© ©Úunpickle_lock©Úselfr   r   ú;/usr/lib/python3/dist-packages/twisted/python/threadable.pyÚ
__reduce__   s    zDummyLock.__reduce__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   C   s   t d k	rtƒ S tƒ S d S ©N)ÚthreadingmoduleÚXLockr   r   r   r   r   r
      s    r
   Tc                 C   s>   d| j kr0t ¡  d| j kr(tƒ | j d< t ¡  | j ¡  d S )NÚ_threadable_lock)Ú__dict__Ú_synchLockCreatorÚacquirer   Úreleaser   r   r   r   r   Ú	_synchPre!   s    

r   c                 C   s   | j  ¡  d S r   )r   r   r   r   r   r   Ú
_synchPost+   s    r   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                    s,   t | ƒ zˆ | f|ž|ŽW ¢S t| ƒ X d S r   )r   r   )r   ÚargsÚkwargs©Úfunctionr   r   Úsync1   s    z_sync.<locals>.syncr   )Úklassr    r!   r   r   r   Ú_sync0   s    r#   c                  G   s>   t dk	r:| D ],}|jD ] }t||j| ƒ}t|||ƒ qqdS )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   Zsynchronizedr#   r   Úsetattr)Zklassesr"   Z
methodNamer!   r   r   r   Úsynchronize<   s
    
r%   é   c                 C   sL   | r:t sHtdk	r0da G dd„ dtjtƒatƒ aqHtdƒ‚nt rHtdƒ‚n dS )zbInitialize threading.

    Don't bother calling this.  If it needs to happen, it will happen.
    NTc                   @   s   e Zd Zdd„ ZdS )r   c                 S   s   t dfS r   r	   r   r   r   r   r   Y   s    zXLock.__reduce__N)r   r   r   r   r   r   r   r   r   X   s   r   z:Cannot initialize threading, platform lacks thread supportzCannot uninitialize threads)Úthreadedr   Z_RLockÚobjectr   r   ÚRuntimeError)Zwith_threadsr   r   r   ÚinitL   s    

r*   c                   C   s   t d krtS t  ¡ jS r   )r   Ú_dummyIDZcurrentThreadZidentr   r   r   r   ÚgetThreadIDh   s    r,   c                   C   s
   t tƒ kS )zHAre we in the thread responsible for I/O requests (the event loop)?
    )ÚioThreadr,   r   r   r   r   ÚisInIOThreado   s    r.   c                   C   s
   t ƒ adS )z=Mark the current thread as responsible for I/O requests.
    N)r,   r-   r   r   r   r   ÚregisterAsIOThreadv   s    r/   NFr   )r&   )r   Z
__future__r   r   Ú	functoolsr   r(   r   r
   Z__safe_for_unpickling__r   r   r#   r%   r*   r+   r,   r.   r/   r-   r'   r   r   Z	threadingr   ÚImportErrorÚ__all__r   r   r   r   Ú<module>   s0   



