
    ih                     f    d Z d Z e            Zd Zd Z	 	 	 	 	 	 d
dZ G d de          Zd	 ZdS )zQ
Higher level functions that comprise parts of
the public monkey patching API.


c                     ddl m} t          | t                    r| gn| }t          |t                    r|g}d}n|}d}|D ]7}	  |||          }|r|d         n|c S # t          $ r ||d         u r Y 4w xY wdS )a  
    Retrieve the original object from a module.

    If the object has not been patched, then that object will still be
    retrieved.

    :param str|sequence mod_name: The name of the standard library module,
        e.g., ``'socket'``. Can also be a sequence of standard library
        modules giving alternate names to try, e.g., ``('thread', '_thread')``;
        the first importable module will supply all *item_name* items.
    :param str|sequence item_name: A string or sequence of strings naming the
        attribute(s) on the module ``mod_name`` to return.

    :return: The original value if a string was given for
             ``item_name`` or a sequence of original values if a
             sequence was passed.
       )_get_originalTF    N)_stater   
isinstancestrImportError)mod_name	item_namer   	mod_names
item_namesunpackmodresults           </usr/local/lib/python3.11/dist-packages/gevent/monkey/api.pyget_originalr   
   s    $ &%%%%%(377E

XI)S!! [

 3 3	3"]3
33F
 !'26!99F222	  	 	 	im## $#	3 3s   AA76A7c                     ddl m} t          | |t                    }|t          ur || ||           t	          | ||           d S Nr   )_save)r   r   getattr_NONEsetattr)moduleattrnewitemr   olditems        r   
patch_itemr   1   s\    fdE**GefdG$$$FD'"""""    c                     ddl m} t          | |t                    }|t          u rd S  || ||           t	          | |           d S r   )r   r   r   r   delattr)r   r   r   r   s       r   remove_itemr"   :   s_    fdE**G%	E&$   FDr   NTc                     ddl m} ddlm}	 ddlm}
 |4	 |j        }n# t          $ r} |	|          |d}~ww xY w| |	|          	 |rt          |d| ||           |r' |
|	                    | j
        || |          |           n# |j        $ r Y dS w xY wt          |d	t          j                  }t          | |||          } ||           |rt          |d
| ||           |r% |
|                    | j
        ||                      dS )aU  
    patch_module(target_module, source_module, items=None)

    Replace attributes in *target_module* with the attributes of the
    same name in *source_module*.

    The *source_module* can provide some attributes to customize the process:

    * ``__implements__`` is a list of attribute names to copy; if not present,
      the *items* keyword argument is mandatory. ``__implements__`` must only have
      names from the standard library module in it.
    * ``_gevent_will_monkey_patch(target_module, items, warn, **kwargs)``
    * ``_gevent_did_monkey_patch(target_module, items, warn, **kwargs)``
      These two functions in the *source_module* are called *if* they exist,
      before and after copying attributes, respectively. The "will" function
      may modify *items*. The value of *warn* is a function that should be called
      with a single string argument to issue a warning to the user. If the "will"
      function raises :exc:`gevent.events.DoNotPatch`, no patching will be done. These functions
      are called before any event subscribers or plugins.

    :keyword list items: A list of attribute names to replace. If
       not given, this will be taken from the *source_module* ``__implements__``
       attribute.
    :return: A true value if patching was done, a false value if patching was canceled.

    .. versionadded:: 1.3b1
    r   )eventsr   )_BadImplements)_notify_patchNwillF_gevent_do_monkey_patchdidT)geventr$   _errorsr%   _utilr&   __implements__AttributeError__call_module_hookGeventWillPatchModuleEvent__name__
DoNotPatchr   _GeventDoPatchRequestdefault_patch_itemsGeventDidPatchModuleEvent)target_modulesource_moduleitems	_warnings_patch_kwargs_notify_will_subscribers_notify_did_subscribers_call_hooksr$   r%   r&   edo_patchrequests                 r   patch_modulerA   D   s   B ''''''$$$$$$}	7!0EE 	7 	7 	7 .//Q6	7 = .///	 	W}fmUIVVV# 	M11-2H-2?H H      uu !1 H
 $M=%WWGHW R=%yQQQ 
 	,,]-C]-:< <	
 	
 	

 4s"    
949
>B	 	
BBc                   <    e Zd Z ee          Zd Zd Zd Zd ZdS )r3   c                 B    || _         || _        || _        |pi | _        d S N)r6   r7   r8   patch_kwargs)selfr6   r7   r8   rE   s        r   __init__z_GeventDoPatchRequest.__init__   s.    
 +*
(.Br   c                 b    d| j         j        d| j        d| j        d| j        d| j        dS )N<z target=z source=z items=z kwargs=>)	__class__r1   r6   r7   r8   rE   )rF   s    r   __repr__z_GeventDoPatchRequest.__repr__   sI     N###JJJ
 	
r   c           	      l    | j         D ]+}t          | j        |t          | j        |                     ,d S rD   )r8   r   r6   r   r7   )rF   r   s     r   r4   z)_GeventDoPatchRequest.default_patch_items   sF    J 	T 	TDt)49KT1R1RSSSS	T 	Tr   c                 t    t          |t                    r|f|z   }| j        }|D ]}t          ||           d S rD   )r   r	   r6   r"   )rF   r6   r8   items       r   r"   z!_GeventDoPatchRequest.remove_item   sU    mS)) 	/"$u,E .M 	- 	-Dt,,,,	- 	-r   N)	r1   
__module____qualname__staticmethodr   rG   rL   r4   r"    r   r   r3   r3      sb        <--L/ / /
 
 
T T T- - - - -r   r3   c                     fd}d|z   dz   }	 t          | |          }n# t          $ r d }Y nw xY w ||||           d S )Nc                 ,    ddl m}  ||            d S )Nr   )_queue_warning)r,   rV   )messagerV   r9   s     r   warnz __call_module_hook.<locals>.warn   s-    ))))))w	*****r   _gevent__monkey_patchc                      d S rD   rS   )argss    r   <lambda>z$__call_module_hook.<locals>.<lambda>   s    T r   )r   r.   )gevent_modulenamer   r8   r9   rX   	func_namefuncs       `   r   r/   r/      s    + + + + + T!O3I"}i00 " " "!!" 	Ds   ! 11)NNNTTT)	__doc__r   objectr   r   r"   rA   r3   r/   rS   r   r   <module>rd      s    #3 #3 #3J 	# # #   6:#*.)-!P P P Pd!- !- !- !- !-F !- !- !-F    r   