B
    H/\                 @   s   d dl mZmZ d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ dd	d
derldndddder|dnddderdnddZdZG dd deZdd ZdS )    )absolute_importprint_functionN)PY3)	iteritems)imp_acquire_lock)imp_release_lock)
__import__Z_threading_localZsocketZselectZssl_threadZthread
subprocessosZ	threadingbuiltinsZ__builtin__signalZtimeZqueueZQueue)zgevent.localzgevent.socketzgevent.selectz
gevent.sslzgevent.threadzgevent.subprocessz	gevent.oszgevent.threadingzgevent.builtinszgevent.signalzgevent.timezgevent.queueZ__g_patched_module_c               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )_SysModulesPatcherc             C   s0   i | _ || _dd ttD | _ttj| _d S )Nc             S   s   i | ]\}}t ||qS  )	importlibimport_module).0Zgevent_nameZstdlib_namer   r   .lib/python3.7/site-packages/gevent/_patcher.py
<dictcomp>.   s   z/_SysModulesPatcher.__init__.<locals>.<dictcomp>)	_saved	importingr   MAPPINGgreen_modules	frozensetsysmodulesorig_imported)selfr   r   r   r   __init__+   s
    z_SysModulesPatcher.__init__c             C   s   x"| j D ]}tj|d | j|< qW tj| jd | j| j< xNttjD ]@\}}|trH|t	td  }tj|d | j|< || j |< qHW d S )N)
r   r   r   getr   r   r   
startswith_PATCH_PREFIXlen)r   modnamemod_namemodZorig_mod_namer   r   r   _save5   s    
z_SysModulesPatcher._savec             C   s&   x t | jD ]\}}|tj|< qW d S )N)r   r   r   r   )r   namer%   r   r   r   _replaceB   s    z_SysModulesPatcher._replacec          	   C   s   xLt | jD ]>\}}|d k	r(|tj|< qytj|= W q tk
rH   Y qX qW | jddd }xXtt tjD ]F\}}|| jkrp|| jkrp|	t
sp|	|rp|tjt
| < tj|= qpW d S )N.   r   )r   r   r   r   KeyErrorr   splitlistr   r    r!   )r   r#   r%   Z
pkg_prefixr   r   r   _restoreH   s    




z_SysModulesPatcher._restorec             C   s   z|    W d t  X d S )N)r.   r   )r   tvtbr   r   r   __exit__]   s    z_SysModulesPatcher.__exit__c             C   s   t   |   |   d S )N)r   r&   r(   )r   r   r   r   	__enter__c   s    z_SysModulesPatcher.__enter__N)	__name__
__module____qualname__r   r&   r(   r.   r2   r3   r   r   r   r   r   )   s   
r   c          	   C   sh   t |  }|tjkrtj| S t| : tj| d t| i i | ddd }|tj|< W dQ R X |S )z
    Import *module_name* with gevent monkey-patches active,
    and return the greened module.

    Any sub-modules that were imported by the package are also
    saved.

    Nr)   )r!   r   r   r   pop_importr,   )Zmodule_nameZpatched_namemoduler   r   r   import_patchedi   s    	


r;   )Z
__future__r   r   r   r   Zgevent._compatr   r   r   r   Zgevent.builtinsr   r9   r   r!   objectr   r;   r   r   r   r   <module>
   s,   

@