
    4jK-                         S r SSKrSSKrSSKJr  SSKJr  S rS rSS jr	 " S	 S
5      r
SS jrS rS rSS jrS rg)z=Utilities for monkey patching and wrapping object attributes.    N   FunctionWrapper)register_post_import_hookc                     [        U [        5      (       a  [        U 5        [        R                  U    n U nUR                  S5      nUS   nS nU" X$5      nUSS  H  nUnU" X$5      nM     X$U4$ )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                     [         R                  " U 5      (       aG  [         R                  " U 5       H"  nU[        U5      ;   d  M  [        U5      U   s  $    [	        X5      $ [	        X5      $ N)inspectisclassgetmrovarsgetattr)parent	attributeclss      L/root/lseg-credit/backend/venv/lib/python3.13/site-packages/wrapt/patches.pylookup_attribute&resolve_path.<locals>.lookup_attribute-   sW    ??6""~~f-S	)9Y// . v116--    r   N)
isinstancestr
__import__sysmodulessplit)targetnamer   pathr   r   originals          r   resolve_pathr!      s     &#6V$F::c?DQI.  2H!"X	#F6  x((r   c                     [        XU5        g)zj
Convenience function for applying a patch to an attribute. This maps to
the standard setattr() function.
N)setattr)r   r   replacements      r   apply_patchr%   @   s     F{+r   c                 \    Uc  0 n[        X5      u  pVnU" U/UQ70 UD6n[        XVU5        U$ )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    wrappers	            r   wrap_objectr+   I   s@     ~$0$>!Vh000G7+Nr   c                   0    \ rS rSrSrS rS rS rS rSr	g)	AttributeWrapperh   zXA descriptor that intercepts access to an instance attribute to apply
a wrapper factory.c                 4    Xl         X l        X0l        X@l        g r
   )r   r'   r(   r)   )selfr   r'   r(   r)   s        r   __init__AttributeWrapper.__init__l   s    "	r   c                     UR                   U R                     nU R                  " U/U R                  Q70 U R                  D6$ r
   )__dict__r   r'   r(   r)   )r0   instanceownervalues       r   __get__AttributeWrapper.__get__r   s7    !!$..1||E=DII===r   c                 4    X!R                   U R                  '   g r
   r4   r   )r0   r5   r7   s      r   __set__AttributeWrapper.__set__v   s    ,1$..)r   c                 2    UR                   U R                  	 g r
   r;   )r0   r5   s     r   
__delete__AttributeWrapper.__delete__y   s    dnn-r   )r(   r   r'   r)   N)
__name__
__module____qualname____firstlineno____doc__r1   r8   r<   r?   __static_attributes__ r   r   r-   r-   h   s    >2.r   r-   c                     Uc  0 nUR                  SS5      u  pV[        X5      S   n[        XbX45      n[        XvU5        U$ )aH  
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*   s	            r   wrap_object_attributerL   }   sJ      ~kk#q)OD&'*Fy4@G7+Nr   c                 (   ^  U 4S jn[        T U5      $ )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                    > US   nUc  TnOI[         R                  " U5      (       a  TR                  S U5      nOTR                  U[        U5      5      n[	        XE5      $ )Nr   r   r   r8   typer   )wrappedr5   r(   r)   target_wrappedtarget_wrapperr*   s         r   _wrapper"function_wrapper.<locals>._wrapper   sU    a$N__X&&$__T8<N$__XtH~FN~>>r   r   )r*   rT   s   ` r   function_wrapperrV      s    ? 7H--r   c                 "  ^^ [        U [        5      (       af  U R                  S5      (       aP  U SS n U [        R                  ;   a$  [        [        R                  U    T[        T45      $ UU4S jn[        X05        g[        U T[        T45      $ )a[  
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. If the `target`
is a string with a trailing ``?``, the wrapping will be deferred until the
module is imported. If the module is already imported, the wrapping will be
applied immediately. 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. Returns the
wrapped target function if the wrapping was applied immediately, or ``None``
if the wrapping was deferred.
?Nc                 ,   > [        U T[        T45        g r
   r+   r   )rK   r   r*   s    r   callback'wrap_function_wrapper.<locals>.callback   s    ozBr   r   r   endswithr   r   r+   r   r   )r   r   r*   r\   s    `` r   wrap_function_wrapperr`      sy      &#6??3#7#7S[[ s{{62D/G:VV	C 	"(3vt_wjAAr   c                    ^ ^^ UUU 4S jnU$ )a  
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 decorator returns the original 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. If the `target` is a string with a
trailing ``?``, the wrapping will be deferred until the module is imported.
If the module is already imported, the wrapping will be applied immediately.
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                 2  >^  [        T[        5      (       ak  TR                  S5      (       aU  TS S nU[        R                  ;   a'  [        [        R                  U   T[        T T45        T $ UUU 4S jn[        X!5        T $ [        TT[        T T45        T $ )NrX   rY   c                 .   > [        U T[        TT45        g r
   r[   )rK   enabledr   r*   s    r   r\   :patch_function_wrapper.<locals>._wrapper.<locals>.callback   s    FD/GW;MNr   r^   )r*   _targetr\   rd   r   r   s   `  r   rT   (patch_function_wrapper.<locals>._wrapper   s    fc""vs';';SbkG#++%KK($'7AS O &h8NFD/GW3EFr   rG   )r   r   rd   rT   s   ``` r   patch_function_wrapperrh      s    $& Or   c                    ^ ^ UU 4S jnU$ )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                 .   >^  UUU 4S jn[        T U5      $ )Nc                    >^ US   nUc  T	mOI[         R                  " U5      (       a  T	R                  S U5      mOT	R                  U[        U5      5      mUUU4S jn[	        XE5      $ )Nr   c                    > [        T	T5      u  pEn[        UT
5      n[        XEU5         U " U0 UD6[        XEU5        $ ! [        XEU5        f = fr
   )r!   r   r#   )rQ   r5   r(   r)   r   r   r    r$   r   r   rS   s           r   _executeRtransient_function_wrapper.<locals>._decorator.<locals>._wrapper.<locals>._execute  sQ    0<VT0J-H-hG;79"D3F3Fx8GFx8s	   > ArO   )
rQ   r5   r(   r)   rR   rm   rS   r   r   r*   s
         @r   rT   @transient_function_wrapper.<locals>._decorator.<locals>._wrapper  s\    !!WN!(**!(x!@!(4>!J9 #><<r   r   )r*   rT   r   r   s   ` r   
_decorator.transient_function_wrapper.<locals>._decorator  s    	=( w11r   rG   )r   r   rp   s   `` r   transient_function_wrapperrr      s    2. r   )rG   Nr
   )rE   r   r   	__wrapt__r   importerr   r!   r%   r+   r-   rL   rV   r`   rh   rr   rG   r   r   <module>ru      sJ    C  
 & /
1)h,>. .*@.0B>%P r   