§
    :Fcaä#  ã                   ó&  — 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
erdndderdndddderdnddderdndddœZer
 e¦   «         n edg¦  «        ZdZd„ Z G d„ de¦  «        Zd„ d „ fd!„Z G d"„ d#e¦  «        ZdS )$é    )Úabsolute_importÚprint_functionN)ÚPY3)Ú	iteritems)Úimp_acquire_lock)Úimp_release_lock)Ú
__import__Ú_threading_localÚsocketÚselectÚ	selectorsÚ
selectors2ÚsslÚ_threadÚthreadÚ
subprocessÚosÚ	threadingÚbuiltinsÚ__builtin__ÚsignalÚtimeÚqueueÚQueueÚcontextvars)zgevent.localzgevent.socketzgevent.selectzgevent.selectorsz
gevent.sslzgevent.threadzgevent.subprocessz	gevent.oszgevent.threadingzgevent.builtinszgevent.signalzgevent.timezgevent.queuezgevent.contextvarsÚ__g_patched_module_c                  ó¢   — i } t          t          ¦  «        D ]7\  }}	 t          j        |¦  «        | |<   Œ# t          $ r |t
          v rY Œ3‚ w xY w| S )z©
    Return a map from standard library name to
    imported gevent module that provides the same API.

    Optional modules are skipped if they cannot be imported.
    )r   ÚMAPPINGÚ	importlibÚimport_moduleÚImportErrorÚOPTIONAL_STDLIB_MODULES)ÚresultÚgevent_nameÚstdlib_names      ú1/usr/lib/python3/dist-packages/gevent/_patcher.pyÚ_collect_stdlib_gevent_modulesr'   /   sx   € ð €Få$-­gÑ$6Ô$6ð ð Ñ ˆ�[ð	Ý"+Ô"9¸+Ñ"FÔ"FˆF�;ÑÐøÝð 	ð 	ð 	ØÕ5Ð5Ð5Ø�Øð	øøøð €Ms   �5µAÁ
Ac                   óH   — e Zd Zd„ fd„Zd„ Zd„ Zd„ Zd„ ZdZd„ Z	d	„ Z
d
„ ZdS )Ú_SysModulesPatcherc                 ó   — dS ©N© r,   ©Úmod_names    r&   ú<lambda>z_SysModulesPatcher.<lambda>D   s   € ¸R€ ó    c                 óV   — || _         || _        t          ¦   «         | _        i | _        d S ©N)Ú	extra_allÚ	importingr'   Ú_green_modulesÚ_t_modules_to_restore)Úselfr4   r3   s      r&   Ú__init__z_SysModulesPatcher.__init__D   s0   € à"ˆŒØ"ˆŒõ =Ñ>Ô>ˆÔð &(ˆÔ"Ð"Ð"r0   c                 ó„  — i | _         | j        D ]*}t          j                             |d ¦  «        | j         |<   Œ+t          t          t          j        ¦  «        ¦  «        D ]6\  }}|                     | j        ¦  «        r|| j         |<   t          j        |= Œ7t          | j        ¦  «        D ]\  }}|t          j        |<   Œd S r2   )	r6   r5   ÚsysÚmodulesÚgetÚlistr   Ú
startswithr4   )r7   ÚmodnameÚmodÚnames       r&   Ú_savez_SysModulesPatcher._saveQ   sÒ   € Ø%'ˆÔ"ð Ô*ð 	Qð 	QˆGÝ25´+·/²/À'È4Ñ2PÔ2PˆDÔ& wÑ/Ð/õ !¥­3¬;Ñ!7Ô!7Ñ8Ô8ð 	)ð 	)‰LˆG�SØ×!Ò! $¤.Ñ1Ô1ð )Ø69�Ô*¨7Ñ3õ ”K Ð(øõ # 4Ô#6Ñ7Ô7ð 	$ð 	$‰IˆD�#Ø #�CŒK˜ÑÐð	$ð 	$r0   c                 óT  — t          t          t          j        ¦  «        ¦  «        D ]6\  }}|                     | j        ¦  «        r|| j        |<   t          j        |= Œ7t          | j        ¦  «        D ]5\  }}|�|t          j        |<   Œ	 t          j        |= Œ&# t          $ r Y Œ2w xY wd S r2   )	r=   r   r:   r;   r>   r4   r5   r6   ÚKeyError)r7   r?   r@   s      r&   Ú_restorez_SysModulesPatcher._restoref   sÉ   € õ
 !¥­3¬;Ñ!7Ô!7Ñ8Ô8ð 	)ð 	)‰LˆG�SØ×!Ò! $¤.Ñ1Ô1ð )Ø/2�Ô# GÑ,Ý”K Ð(øõ & dÔ&@ÑAÔAð 	ð 	‰LˆG�SØˆØ'*•”˜GÑ$Ð$ðÝœ GÐ,Ð,øÝð ð ð Ø�Dðøøøð	ð 	s   Â
BÂ
B%Â$B%c                 óŽ   — 	 |                       ¦   «          t          ¦   «          d | _        d S # t          ¦   «          d | _        w xY wr2   )rE   r   r6   )r7   ÚtÚvÚtbs       r&   Ú__exit__z_SysModulesPatcher.__exit__z   sQ   € ð	.Ø�MŠM‰OŒOˆOåÑÔÐØ)-ˆDÔ&Ð&Ð&øõ ÑÔÐØ)-ˆDÔ&Ð-Ð-Ð-Ð-s	   ‚- ­Ac                 óJ   — t          ¦   «          |                      ¦   «          | S r2   )r   rB   )r7   s    r&   Ú	__enter__z_SysModulesPatcher.__enter__‚   s    € ÝÑÔÐØ�
Š
‰ŒˆØˆr0   Nc                 óâ   — | j         €g| 5  |                      | j        |¦  «        | _         | | j         _        | j         t          j        t          | j        z   <   d d d ¦  «         n# 1 swxY w Y   | S r2   )ÚmoduleÚ
import_oner4   Ú__gevent_patcher__r:   r;   Ú_PATCH_PREFIX)r7   Úafter_import_hooks     r&   Ú__call__z_SysModulesPatcher.__call__‰   s¶   € ØŒ;ÐØð Jð JØ"Ÿošo¨d¬nÐ>OÑPÔP�”ð
 26�”Ô.Ø>B¼k•”�M¨D¬NÑ:Ñ;ðJð Jð Jñ Jô Jð Jð Jð Jð Jð Jð Jøøøð Jð Jð Jð Jð ˆs   ŠAA$Á$A(Á+A(c                 ó|  — t           |z   }|t          j        v rt          j        |         S |                     | j        ¦  «        sJ ‚t          j                             |d ¦  «         t          |i i |                     d¦  «        d d…         ¦  «        }|| _        |  	                    |g¦  «          ||¦  «         |S )Nú.éÿÿÿÿ)
rQ   r:   r;   r>   r4   ÚpopÚg_importÚsplitrN   Ú_import_all)r7   Úmodule_namerR   Úpatched_namerN   s        r&   rO   z_SysModulesPatcher.import_one•   s·   € Ý$ {Ñ2ˆØ�3œ;Ð&Ð&Ý”;˜|Ô,Ð,à×%Ò% d¤nÑ5Ô5Ð5Ð5Ð5ÝŒ�Š˜ TÑ*Ô*Ð*å˜+ r¨2¨{×/@Ò/@ÀÑ/EÔ/EÀcÀrÀcÔ/JÑKÔKˆØˆŒð 	×Ò˜&˜Ñ"Ô"Ð"ØÐ˜&Ñ!Ô!Ð!Øˆr0   c                 óˆ  — |r¿|                      d¦  «        }|j        }t          t          |dd¦  «        ¦  «        |                      |¦  «        z   }|D ]h}	 t          ||¦  «         Œ# t
          $ rH |j        dz   |z   }t          |i i |¦  «        }t          |||¦  «         |                     |¦  «         Y Œew xY w|°½d S d S )Nr   Ú__all__r,   rU   )	rW   Ú__name__ÚtupleÚgetattrr3   ÚAttributeErrorrX   ÚsetattrÚappend)r7   r   rN   rA   Úmod_allÚ	attr_namer[   Ú
new_modules           r&   rZ   z_SysModulesPatcher._import_all¥   sø   € àð 	-Ø—Y’Y˜q‘\”\ˆFØ”?ˆDÝ�G F¨I°rÑ:Ô:Ñ;Ô;¸d¿nºnÈTÑ>RÔ>RÑRˆGØ$ð -ð -�	ð-Ý˜F IÑ.Ô.Ð.Ð.øÝ%ð -ð -ð -Ø"(¤/°CÑ"7¸)Ñ"C�KÝ!)¨+°r¸2¸yÑ!IÔ!I�JÝ˜F I¨zÑ:Ô:Ð:Ø—L’L Ñ,Ô,Ð,Ð,Ð,ð	-øøøð ð 	-ð 	-ð 	-ð 	-ð 	-s   ÁA)Á)AB;Â:B;)r_   Ú
__module__Ú__qualname__r8   rB   rE   rJ   rL   rN   rS   rO   rZ   r,   r0   r&   r)   r)   B   sž   € € € € € à,?Ð,?ð (ð (ð (ð (ð$ð $ð $ð*ð ð ð(.ð .ð .ðð ð ð
 €Fð
ð 
ð 
ðð ð ð -ð -ð -ð -ð -r0   r)   c                 ó   — dS r+   r,   r-   s    r&   r/   r/   ¶   s   € ¨b€ r0   c                 ó   — d S r2   r,   )rN   s    r&   r/   r/   ·   s   € °D€ r0   c                 óˆ   — t          ¦   «         5  t          | |¦  «        } ||¦  «         ddd¦  «         n# 1 swxY w Y   |S )aÄ  
    Import *module_name* with gevent monkey-patches active,
    and return an object holding the greened module as *module*.

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

    .. versionchanged:: 1.5a4
       If the module defines ``__all__``, then each of those
       attributes/modules is also imported as part of the same transaction,
       recursively. The order of ``__all__`` is respected. Anything passed in
       *extra_all* (which must be in the same namespace tree) is also imported.

    .. versionchanged:: 1.5a4
       You must now do all patching for a given module tree
       with one call to this method, or at least by using the returned
       object.
    N)Úcached_platform_architecturer)   )r[   r3   rR   Úpatchers       r&   Úimport_patchedro   µ   sŽ   € õ, 
&Ñ	'Ô	'ð #ð #õ % [°)Ñ<Ô<ˆØˆÐ!Ñ"Ô"Ð"ð	#ð #ð #ñ #ô #ð #ð #ð #ð #ð #ð #øøøð #ð #ð #ð #ð
 €Ns   �7·;¾;c                   ó*   — e Zd ZdZdZdZdZd„ Zd„ ZdS )rm   a
  
    Context manager that caches ``platform.architecture``.

    Some things that load shared libraries (like Cryptodome, via
    dnspython) invoke ``platform.architecture()`` for each one. That
    in turn wants to fork and run commands , which in turn wants to
    call ``threading._after_fork`` if the GIL has been initialized.
    All of that means that certain imports done early may wind up
    wanting to have the hub initialized potentially much earlier than
    before.

    Part of the fix is to observe when that happens and delay
    initializing parts of gevent until as late as possible (e.g., we
    delay importing and creating the resolver until the hub needs it,
    unless explicitly configured).

    The rest of the fix is to avoid the ``_after_fork`` issues by
    first caching the results of platform.architecture before doing
    patched imports.

    (See events.py for similar issues with platform, and
    test__threading_2.py for notes about threading._after_fork if the
    GIL has been initialized)
    Nc                 ó€   ‡ — dd l }|‰ _        |                     ¦   «         ‰ _        |j        ‰ _        ˆ fd„}||_        ‰ S )Nr   c                  ó4   •— | s	|s‰j         S  ‰j        | i |¤ŽS r2   )Ú_arch_resultÚ
_orig_arch)ÚargsÚkwargsr7   s     €r&   Úarchz4cached_platform_architecture.__enter__.<locals>.archö   s2   ø€ Øð ) ð )ØÔ(Ð(Ø"�4”? DÐ3¨FÐ3Ð3Ð3r0   )ÚplatformÚ	_platformÚarchitecturers   rt   )r7   rx   rw   s   `  r&   rL   z&cached_platform_architecture.__enter__ñ   sY   ø€ ØˆˆˆØ!ˆŒØ$×1Ò1Ñ3Ô3ˆÔØ"Ô/ˆŒð	4ð 	4ð 	4ð 	4ð 	4ð !%ˆÔØˆr0   c                 ó6   — | j         | j        _        d | _        d S r2   )rt   ry   rz   )r7   Ú_argss     r&   rJ   z%cached_platform_architecture.__exit__ý   s   € Ø&*¤oˆŒÔ#ØˆŒˆˆr0   )	r_   rh   ri   Ú__doc__rs   rt   ry   rL   rJ   r,   r0   r&   rm   rm   Ó   sM   € € € € € ðð ð2 €LØ€JØ€Ið
ð 
ð 
ðð ð ð ð r0   rm   )Ú
__future__r   r   r   r:   Úgevent._compatr   r   r   r   Úgevent.builtinsr	   rX   r   Ú	frozensetr"   rQ   r'   Úobjectr)   ro   rm   r,   r0   r&   ú<module>rƒ      s¸  ðð 7Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6à Ð Ð Ð Ø 
€
€
€
à Ð Ð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø +Ð +Ð +Ð +Ð +Ð +Ø +Ð +Ð +Ð +Ð +Ð +ð 3Ð 2Ð 2Ð 2Ð 2Ð 2ð 'ØØØ'*Ð<˜˜°ØØ"%Ð3�Y�Y¨8Ø%ØØ#Ø%(Ð;�z�z¨mØØØ"Ð/�G�G¨Ø'ðð €ð" *-ð ˜)˜)™+œ+˜+°)°)Øð=ñ 3ô 3Ð ð &€ðð ð ð&p-ð p-ð p-ð p-ð p-˜ñ p-ô p-ð p-ðh 1Ð0Ø%8Ð%8ðð ð ð ð<,ð ,ð ,ð ,ð , 6ñ ,ô ,ð ,ð ,ð ,r0   