o
    ­2úh³&  ã                   @   s|   d dl Z d dlZddlmZ dd„ Zdd„ Zdi fd	d
„ZG dd„ dƒZdi fdd„Zdd„ Z	dd„ Z
ddd„Zdd„ ZdS )é    Né   ©ÚFunctionWrapperc                 C   sn   t | tƒrt| ƒ tj|  } | }| d¡}|d }dd„ }|||ƒ}|dd… D ]	}|}|||ƒ}q(|||fS )aô  
    Resolves the dotted path supplied as `name` to an attribute on a target
    object. The `target` can be a module, class, or instance of a class. If the
    `target` argument is a string, it is assumed to be the name of a module,
    which will be imported if necessary and then used as the target object.
    Returns a tuple containing the parent object holding the attribute lookup
    resolved to, the attribute name (path prefix removed if present), and the
    original attribute value.
    Ú.r   c                 S   sJ   t  | ¡r t  | ¡D ]}|t|ƒv rt|ƒ|   S q
t| |ƒS t| |ƒS ©N)ÚinspectÚisclassÚgetmroÚvarsÚgetattr)ÚparentÚ	attributeÚcls© r   úH/var/www/html/chatgem/venv/lib/python3.10/site-packages/wrapt/patches.pyÚlookup_attribute*   s   
ÿ

z&resolve_path.<locals>.lookup_attributer   N)Ú
isinstanceÚstrÚ
__import__ÚsysÚmodulesÚsplit)ÚtargetÚnamer   Úpathr   r   Úoriginalr   r   r   Úresolve_path	   s   





r   c                 C   s   t | ||ƒ dS )zÓ
    Convenience function for applying a patch to an attribute. Currently this
    maps to the standard setattr() function, but in the future may be extended
    to support more complex patching strategies.
    N)Úsetattr)r   r   Úreplacementr   r   r   Úapply_patch=   s   r   r   c           	      C   s6   t | |ƒ\}}}||g|¢R i |¤Ž}t|||ƒ |S )aù  
    Wraps an object which is the attribute of a target object with a wrapper
    object created by the `factory` function. The `target` can be a module,
    class, or instance of a class. In the special case of `target` being a
    string, it is assumed to be the name of a module, with the module being
    imported if necessary and then used as the target object. The `name` is a
    string representing the dotted path to the attribute. The `factory` function
    should accept the original object and may accept additional positional and
    keyword arguments which will be set by unpacking input arguments using
    `*args` and `**kwargs` calling conventions. The factory function should
    return a new object that will replace the original object.
    )r   r   )	r   r   ÚfactoryÚargsÚkwargsr   r   r   Úwrapperr   r   r   Úwrap_objectG   s   r$   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚAttributeWrapperc                 C   s   || _ || _|| _|| _d S r   )r   r    r!   r"   )Úselfr   r    r!   r"   r   r   r   Ú__init__e   s   
zAttributeWrapper.__init__c                 C   s(   |j | j }| j|g| j¢R i | j¤ŽS r   )Ú__dict__r   r    r!   r"   )r&   ÚinstanceÚownerÚvaluer   r   r   Ú__get__k   s   zAttributeWrapper.__get__c                 C   s   ||j | j< d S r   ©r(   r   )r&   r)   r+   r   r   r   Ú__set__o   s   zAttributeWrapper.__set__c                 C   s   |j | j= d S r   r-   )r&   r)   r   r   r   Ú
__delete__r   s   zAttributeWrapper.__delete__N)Ú__name__Ú
__module__Ú__qualname__r'   r,   r.   r/   r   r   r   r   r%   c   s
    r%   c           	      C   s<   |  dd¡\}}t| |ƒd }t||||ƒ}t|||ƒ |S )a|  
    Wraps an object which is the attribute of a class instance with a wrapper
    object created by the `factory` function. It does this by patching the
    class, not the instance, with a descriptor that intercepts access to the
    instance attribute. The `module` can be a module, class, or instance of a
    class. In the special case of `module` being a string, it is assumed to be
    the name of a module, with the module being imported if necessary and then
    used as the target object. The `name` is a string representing the dotted
    path to the attribute. The `factory` function should accept the original
    object and may accept additional positional and keyword arguments which will
    be set by unpacking input arguments using `*args` and `**kwargs` calling
    conventions. The factory function should return a new object that will
    replace the original object.
    r   r   é   )Úrsplitr   r%   r   )	Úmoduler   r    r!   r"   r   r   r   r#   r   r   r   Úwrap_object_attributev   s
   r6   c                    s   ‡ fdd„}t ˆ |ƒS )aò  
    Creates a decorator for wrapping a function with a `wrapper` function.
    The decorator which is returned may also be applied to any other callable
    objects such as lambda functions, methods, classmethods, and staticmethods,
    or objects which implement the `__call__()` method. The `wrapper` function
    should accept the `wrapped` function, `instance`, `args`, and `kwargs`,
    arguments and return the result of calling the wrapped function or some
    other appropriate value.
    c                    sH   |d }|d u rˆ }nt  |¡rˆ  d |¡}nˆ  |t|ƒ¡}t||ƒS )Nr   ©r   r   r,   Útyper   )Úwrappedr)   r!   r"   Útarget_wrappedÚtarget_wrapper©r#   r   r   Ú_wrapperž   s   

z"function_wrapper.<locals>._wrapperr   ©r#   r=   r   r<   r   Úfunction_wrapper“   s   

r?   c                 C   s   t | |t|fƒS )aL  
    Wraps a function which is the attribute of a target object with a `wrapper`
    function. The `target` can be a module, class, or instance of a class. In
    the special case of `target` being a string, it is assumed to be the name
    of a module, with the module being imported if necessary. The `name` is a
    string representing the dotted path to the attribute. The `wrapper` function
    should accept the `wrapped` function, `instance`, `args`, and `kwargs`
    arguments, and would return the result of calling the wrapped attribute or
    some other appropriate value.
    ©r$   r   )r   r   r#   r   r   r   Úwrap_function_wrapper«   s   rA   c                    s   ‡ ‡‡fdd„}|S )a3  
    Creates a decorator which can be applied to a wrapper function, where the
    wrapper function will be used to wrap a function which is the attribute of
    a target object. The `target` can be a module, class, or instance of a class.
    In the special case of `target` being a string, it is assumed to be the name
    of a module, with the module being imported if necessary. The `name` is a
    string representing the dotted path to the attribute. The `enabled`
    argument can be a boolean or a callable that returns a boolean. When a
    callable is provided, it will be called each time the wrapper is invoked to
    determine if the wrapper function should be executed or whether the wrapped
    function should be called directly. If `enabled` is not provided, the
    wrapper is enabled by default.
    c                    s   t ˆˆt| ˆ fƒS r   r@   r<   ©Úenabledr   r   r   r   r=   É   s   z(patch_function_wrapper.<locals>._wrapperr   )r   r   rC   r=   r   rB   r   Úpatch_function_wrapperº   s   rD   c                    s   ‡ ‡fdd„}|S )a·  Creates a decorator that patches a target function with a wrapper
    function, but only for the duration of the call that the decorator was
    applied to. The `target` can be a module, class, or instance of a class.
    In the special case of `target` being a string, it is assumed to be the name
    of a module, with the module being imported if necessary. The `name` is a
    string representing the dotted path to the attribute.
    c                    s   ‡‡‡ fdd„}t ˆ |ƒS )Nc                    sX   |d }|d u rˆ‰ nt  |¡rˆ d |¡‰ nˆ |t|ƒ¡‰ ‡‡‡ fdd„}t||ƒS )Nr   c              
      sR   t ˆˆ ƒ\}}}t|ˆƒ}t|||ƒ z| |i |¤ŽW t|||ƒ S t|||ƒ w r   )r   r   r   )r9   r)   r!   r"   r   r   r   r   )r   r   r;   r   r   Ú_executeâ   s   
zRtransient_function_wrapper.<locals>._decorator.<locals>._wrapper.<locals>._executer7   )r9   r)   r!   r"   r:   rE   )r   r   r#   )r;   r   r=   Ù   s   

	z@transient_function_wrapper.<locals>._decorator.<locals>._wrapperr   r>   ©r   r   r<   r   Ú
_decoratorØ   s   
z.transient_function_wrapper.<locals>._decoratorr   )r   r   rG   r   rF   r   Útransient_function_wrapperÏ   s   	rH   r   )r   r   Ú	__wrapt__r   r   r   r$   r%   r6   r?   rA   rD   rH   r   r   r   r   Ú<module>   s    4

