o
    ,wÖih  ã                   @   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   úN/home/ubuntu/sommelier/.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#