
    <|hh                     X    d Z d Z e       Zd Zd Z	 	 	 	 	 	 d	dZ G d de      Zd Zy)
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 ]  }	  |||      }|r|d   c S |c S  y# t        $ r ||d   u r Y /w xY w)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           P/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/monkey/api.pyget_originalr   
   s    $ &(37
XI)S![

 3	3"3
3F
 !'6!92F23  	im# $	s   	AA('A(c                 p    ddl m} t        | |t              }|t        ur
 || ||       t	        | ||       y Nr   )_save)r   r   getattr_NONEsetattr)moduleattrnewitemr   olditems        r   
patch_itemr   1   s3    fdE*GefdG$FD'"    c                 p    ddl m} t        | |t              }|t        u ry  || ||       t	        | |       y r   )r   r   r   r   delattr)r   r   r   r   s       r   remove_itemr"   :   s4    fdE*G%	&$ FDr   Nc                    ddl m} ddlm}	 ddlm}
 |	 |j                  }| |	|      	 |rt        |d| ||       |r% |
|j                  | j                  || |      |       t        |d	t        j                        }t        | |||      } ||       |rt        |d
| ||       |r# |
|j                  | j                  ||              y# t        $ r} |	|      |d}~ww xY w# |j                  $ r Y yw xY w)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!00E = //	}fmUIV#11-2H2H-2?H !11H
 $M=%WGW=%yQ 	,,]-C-C]-:<	

 Q  	7 /Q6	7  s(   C 8C' 	C$	CC$'C98C9c                   4    e Zd Z ee      Zd Zd Zd Zd Zy)r3   c                 D    || _         || _        || _        |xs i | _        y N)r6   r7   r8   patch_kwargs)selfr6   r7   r8   rE   s        r   __init__z_GeventDoPatchRequest.__init__   s(    
 +*
(.Br   c                     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__   s;    NN##JJ
 	
r   c           	      |    | j                   D ]-  }t        | j                  |t        | j                  |             / y rD   )r8   r   r6   r   r7   )rF   r   s     r   r4   z)_GeventDoPatchRequest.default_patch_items   s6    JJ 	TDt))49K9KT1RS	Tr   c                 n    t        |t              r|f|z   }| j                  }|D ]  }t        ||        y rD   )r   r	   r6   r"   )rF   r6   r8   items       r   r"   z!_GeventDoPatchRequest.remove_item   s=    mS)"$u,E ..M 	-Dt,	-r   N)	r1   
__module____qualname__staticmethodr   rG   rL   r4   r"    r   r   r3   r3      s!    -L/
T-r   r3   c                 r    fd}d|z   dz   }	 t        | |      } ||||       y # t        $ r d }Y w xY w)Nc                 $    ddl m}  ||        y )Nr   )_queue_warning)r,   rV   )messagerV   r9   s     r   warnz __call_module_hook.<locals>.warn   s    )w	*r   _gevent__monkey_patchc                       y rD   rS   )argss    r   <lambda>z$__call_module_hook.<locals>.<lambda>   s    r   )r   r.   )gevent_modulenamer   r8   r9   rX   	func_namefuncs       `   r   r/   r/      sN    + T!O3I"}i0
 		  "!"s   ' 66)NNNTTT)	__doc__r   objectr   r   r"   rA   r3   r/   rS   r   r   <module>rd      sP   #3J 	# 6:#*.)-!Pd!-F !-Fr   