o
    oih                     @   sT   d Z dd Ze Zdd Zdd Z						dd	d
ZG dd deZdd ZdS )zQ
Higher level functions that comprise parts of
the public monkey patching API.


c              	   C   s   ddl m} t| tr| gn| }t|tr|g}d}n|}d}|D ]%}z|||}W n ty:   ||d u r8 Y q!w |rC|d   S |  S 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result r   P/var/www/html/pca-backend/venv/lib/python3.10/site-packages/gevent/monkey/api.pyget_original
   s"   
r   c                 C   s<   ddl m} t| |t}|tur|| || t| || d S Nr   )_save)r   r   getattr_NONEsetattr)moduleattrnewitemr   olditemr   r   r   
patch_item1   s
   r   c                 C   s>   ddl m} t| |t}|tu rd S || || t| | d S r   )r   r   r   r   delattr)r   r   r   r   r   r   r   remove_item:   s   r   NTc              
   C   s
  ddl m} ddlm}	 ddlm}
 |du r5z|j}W n ty, } z|	||d}~ww |du r5|	|z|r@t|d| || |rN|
|	| j
|| || W n |jyZ   Y dS w t|d	tj}t| |||}|| |rwt|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requestr   r   r   patch_moduleD   sT   !



r<   c                   @   s4   e Zd ZeeZdd Zdd Zdd Zdd Zd	S )
r.   c                 C   s    || _ || _|| _|pi | _d S N)r1   r2   r3   patch_kwargs)selfr1   r2   r3   r>   r   r   r   __init__   s   z_GeventDoPatchRequest.__init__c                 C   s   d| j j| j| j| j| jf S )Nz+<%s target=%r source=%r items=%r kwargs=%r>)	__class__r,   r1   r2   r3   r>   )r?   r   r   r   __repr__   s   z_GeventDoPatchRequest.__repr__c                 C   s&   | j D ]}t| j|t| j| qd S r=   )r3   r   r1   r   r2   )r?   r   r   r   r   r/      s   
z)_GeventDoPatchRequest.default_patch_itemsc                 G   s2   t |tr|f| }| j}|D ]}t|| qd S r=   )r   r   r1   r   )r?   r1   r3   itemr   r   r   r      s   

z!_GeventDoPatchRequest.remove_itemN)	r,   
__module____qualname__staticmethodr   r@   rB   r/   r   r   r   r   r   r.      s    
	r.   c                    sR    fdd}d| d }zt | |}W n ty    dd }Y nw |||| d S )Nc                    s   ddl m} ||   d S )Nr   )_queue_warning)r'   rG   )messagerG   r4   r   r   warn   s   z __call_module_hook.<locals>.warn_gevent__monkey_patchc                  W   s   d S r=   r   )argsr   r   r   <lambda>   s    z$__call_module_hook.<locals>.<lambda>)r   r)   )gevent_modulenamer   r3   r4   rJ   	func_namefuncr   rI   r   r*      s   r*   )NNNTTT)	__doc__r   objectr   r   r   r<   r.   r*   r   r   r   r   <module>   s   %	

R#