
    ia                         S SK JrJr  S SKrS SKrS SKrS SKJr  S SKJ	r	J
r
Jr  S SKJrJr  S SKJrJr  S SKJr   " S S	\5      rg)
    )absolute_importunicode_literalsN)SpyCall)ExistingSpyErrorIncompatibleFunctionErrorInternalKGBError)iterkeyspyver)FunctionSig
_UNSET_ARG)is_attr_defined_on_ancestorc                   l   \ rS rSrSr\R                  r\R                  r\R                  r/ SQr	/ SSS.r
0 rSSS\S4S jr\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       rS$S jrS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S r$S r%S  r&S%S! jr'S" r(S#r)g)&FunctionSpy   a  A spy infiltrating a function.

A FunctionSpy takes the place of another function. It will record any
calls made to the function for later inspection.

By default, a FunctionSpy will allow the call to go through to the
original function. This can be disabled by passing call_original=False
when initiating the spy. If disabled, the original function will never be
called.

This can also be passed a call_fake parameter pointing to another
function to call instead of the original. If passed, this will take
precedence over call_original.
)call_originalcalled_withlast_called_withraisedlast_raisedreturnedlast_returnedraised_with_messagelast_raised_with_messagereset_callsunspyFN)callscalled	last_callTc                    [         R                  " 5       U l        Ub  Ub  [        S5      e[	        US5      (       a  [        U5      e[        U5      (       a]  [	        U[        R                  5      (       a>  [	        U[        R                  5      (       d-  [	        U[        R                  5      (       d  [        SU-  5      e[        UUUS9nXl        U[        La  X`R                  La  U R                  U R                  :X  a  [        S5      e[	        X`R                   5      (       d  [        S5      eU R                  U R"                  :X  d'  [$        S   S	:X  a%  U R                  U R&                  :X  a  [        S
5      eUR(                  (       a%  U R                  U R&                  :X  a  [        S5      eUb  Ub   eUR+                  U 5      nUc   eUbJ  [        U5      (       d  [        SU-  5      e[        UUS9n	UR-                  U	5      (       d  [/        UUUU	S9eXl        X l        UR4                  U l        U R9                  U R2                  5      U l        U R=                  5       (       aE  U R                  R>                  RA                  U R                   5      U l!        U RE                  5         OU R2                  U l!        U(       a  X0l#        O U(       a  U R2                  U l#        OSU l#        U RI                  U5        U RF                  U R2                  L a*  U R9                  U RF                  U RJ                  S9U l#        gg)ad  Initialize the spy.

This will begin spying on the provided function or method, injecting
new code into the function to help record how it was called and
what it returned, and adding methods and state onto the function
for callers to access in order to get those results.

Version Added:
    7.0:
    Added support for specifying an explicit function name using
    ``func_name=``.

Version Added:
    5.0:
    Added support for specifying an instance in ``owner`` when spying
    on bound methods using decorators that return plain functions.

Args:
    agency (kgb.agency.SpyAgency):
        The spy agency that manages this spy.

    func (callable):
        The function or method to spy on.

    call_fake (callable, optional):
        The optional function to call when this function is invoked.

        This cannot be specified if ``op`` is provided.

    call_original (bool, optional):
        Whether to call the original function when the spy is
        invoked. If ``False``, no function will be called.

        This is ignored if ``call_fake`` or ``op`` are provided.

    op (kgb.spies.BaseOperation, optional):
        An operation to perform.

        This cannot be specified if ``call_fake`` is provided.

    owner (type or object, optional):
        The owner of the function or method.

        If spying on an unbound method, this **must** be set to the
        class that owns it.

        If spying on a bound method that identifies as a plain
        function (which may happen if the method is decorated and
        dynamically returns a new function on access), this should
        be the instance of the object you're spying on.

    func_name (str, optional):
        An explicit name for the function. This will be used instead
        of the function's specified name, and is usually a sign of a
        bad decorator.

        Version Added:
            7.0
Nz)op and call_fake cannot both be provided.spyzK%r cannot be spied on. It does not appear to be a valid function or method.)funcowner	func_namez@This function has no owner, but an owner was passed to spy_on().z3The owner passed does not contain the spied method.r      zEThe owner passed does not match the actual owner of the bound method.zUnable to spy on unbound slippery methods (those that return a new function on each attribute access). Please spy on an instance instead.zU%r cannot be used for call_fake. It does not appear to be a valid function or method.)r#   )r!   func_sigincompatible_funcincompatible_func_sig)code)&inspectcurrentframe
init_frame
ValueErrorhasattrr   callabler   FUNC_NAME_ATTRMETHOD_SELF_ATTRFUNC_GLOBALS_ATTR_sigr   r"   	func_typeTYPE_FUNCTIONr#   TYPE_BOUND_METHODr
   TYPE_UNBOUND_METHODis_slipperysetupis_compatible_withr   agency	orig_func	real_func
_real_func_clone_function_call_orig_func_get_owner_needs_patching__dict__get_owner_func_attr_value_patch_ownerr!   _build_proxy_func	_old_code)
selfr:   r!   	call_faker   opr"   r#   sigcall_fake_sigs
             H/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/kgb/spies.py__init__FunctionSpy.__init__<   s   ~ "..0 >i3HII4"4((k8899{;;<<{<<== >#$ % % t %$-/ 	
 
"uJJ'>~~!3!33 #$ $ unn55$ &5 6 6nn(>(>>Qx1}~~)A)AA$,- - OONNd666 ( ) ) >$$$I((( I&&  "P#,"- . . (	2;=M ))-88/ &/*7	9 9 --#33DNNC))++ 

##''7 ' *...D' !IDIDI 	t$ 99&,,TYY26.. - BDI '    c                 .    U R                   R                  $ )zThe type of function being spied on.

This will be one of :py:attr:`TYPE_FUNCTION`,
:py:attr:`TYPE_UNBOUND_METHOD`, or :py:attr:`TYPE_BOUND_METHOD`.

Type:
    int
)r2   r3   rG   s    rL   r3   FunctionSpy.func_type   s     yy"""rO   c                 .    U R                   R                  $ )z8The name of the function being spied on.

Type:
    str
)r2   r#   rQ   s    rL   r#   FunctionSpy.func_name  s     yy"""rO   c                 .    U R                   R                  $ )ztThe owner of the method, if a bound or unbound method.

This will be ``None`` if there is no owner.

Type:
    type
)r2   r"   rQ   s    rL   r"   FunctionSpy.owner  s     yyrO   c                 P     U R                   R                  $ ! [         a     gf = f)z'Whether or not the spy was ever called.F)r=   r   AttributeErrorrQ   s    rL   r   FunctionSpy.called  s)    	??))) 		    
%%c                 T     U R                   R                  $ ! [         a    / s $ f = f)zUThe list of calls made to the function.

Each is an instance of :py:class:`SpyCall`.
)r=   r   rX   rQ   s    rL   r   FunctionSpy.calls  s+    	??((( 	I	s    ''c                 P     U R                   R                  $ ! [         a     gf = f)z^The last call made to this function.

If a spy hasn't been called yet, this will be ``None``.
N)r=   r   rX   rQ   s    rL   r   FunctionSpy.last_call)  s)    	??,,, 		rZ   c                    U R                   nU R                  n[        US5      (       d   e[        R                  [        U 5      	 U?[        U R                  5       H  n[        X$5        M     U R                   H  n[        X%5        M     [        U[        R                  U R                  5        Ub&  U R                  X0R                   U R"                  5        U(       a&  U R$                  R&                  R)                  U 5        gg)aO  Remove the spy from the function, restoring the original.

The spy will, by default, be removed from the registry's
list of spies. This can be disabled by passing ``unregister=False``,
but don't do that. That's for internal use.

Args:
    unregister (bool, optional):
        Whether to unregister the spy from the associated agency.
r    N)r=   r"   r-   r   _spy_mapidr    r	   _FUNC_ATTR_DEFAULTSdelattr_PROXY_METHODSsetattrr   FUNC_CODE_ATTRrF   _set_methodr#   rC   r:   spiesremove)rG   
unregisterr<   r"   	attr_namer#   s         rL   r   FunctionSpy.unspy4  s     OO	

y%((((  D*M!$":":;II) < ,,II) - 		;55t~~FUNN!88: KK$$T* rO   c           	         U R                   U R                  :X  a   U R                  " U R                  /UQ70 UD6$ U R                   U R                  :X  ay  U(       a  [        US   U R                  5      (       dT  [        SU R                  R                  < SU R                  R                  < SU R                  R                  < S35      eU R                  " U0 UD6$ )a  Call the original function being spied on.

The function will behave as normal, and will not trigger any spied
behavior or call tracking.

Args:
    *args (tuple):
        The positional arguments to pass to the function.

    **kwargs (dict):
        The keyword arguments to pass to the function.

Returns:
    object:
    The return value of the function.

Raises:
    Exception:
        Any exceptions raised by the function.
r   zThe first argument to z(.call_original() must be an instance of .z", since this is an unbound method.)	r3   r5   r?   r"   r6   
isinstance	TypeError__name__
__module__rG   argskwargss      rL   r   FunctionSpy.call_originalV  s    * >>T333''

DTDVDD~~!9!99:d1gtzz#B#B#  //88::00::..01 1 ''888rO   c                 F   ^^ [        UU4S jU R                   5       5      $ )a@  Return whether the spy was ever called with the given arguments.

This will check each and every recorded call to see if the arguments
and keyword arguments match up. If at least one call does match, this
will return ``True``.

Not every argument and keyword argument made in the call must be
provided to this method. These can be a subset of the positional and
keyword arguments in the call, but cannot contain any arguments not
made in the call.

Args:
    *args (tuple):
        The positional arguments made in the call, or a subset of
        those arguments (starting with the first argument).

    **kwargs (dict):
        The keyword arguments made in the call, or a subset of those
        arguments.

Returns:
    bool:
    ``True`` if there's at least one call matching these arguments.
    ``False`` if no call matches.
c              3   H   >#    U  H  nUR                   " T0 TD6v   M     g 7fN)r   ).0callrt   ru   s     rL   	<genexpr>*FunctionSpy.called_with.<locals>.<genexpr>  s(      
" d-f-"   "anyr   rs   s    ``rL   r   FunctionSpy.called_withz  s#    4  



 
 	
rO   c                 T    U R                   nUSL=(       a    UR                  " U0 UD6$ )a  Return whether the spy was last called with the given arguments.

Not every argument and keyword argument made in the call must be
provided to this method. These can be a subset of the positional and
keyword arguments in the call, but cannot contain any arguments not
made in the call.

Args:
    *args (tuple):
        The positional arguments made in the call, or a subset of
        those arguments (starting with the first argument).

    **kwargs (dict):
        The keyword arguments made in the call, or a subset of those
        arguments.

Returns:
    bool:
    ``True`` if the last call's arguments match the provided arguments.
    ``False`` if they do not.
N)r   r   )rG   rt   ru   r{   s       rL   r   FunctionSpy.last_called_with  s-    , ~~4ED$4$4d$Ef$EErO   c                 B   ^ [        U4S jU R                   5       5      $ )a  Return whether the spy was ever called and returned the given value.

This will check each and every recorded call to see if any of them
returned the given value.  If at least one call did, this will return
``True``.

Args:
    value (object):
        The expected returned value from the call.

Returns:
    bool:
    ``True`` if there's at least one call that returned this value.
    ``False`` if no call returned the value.
c              3   F   >#    U  H  nUR                  T5      v   M     g 7fry   )r   )rz   r{   values     rL   r|   'FunctionSpy.returned.<locals>.<genexpr>  s$      
" MM%  "   !r   )rG   r   s    `rL   r   FunctionSpy.returned  #       



 
 	
rO   c                 R    U R                   nUSL=(       a    UR                  U5      $ )zReturn whether the spy's last call returned the given value.

Args:
    value (object):
        The expected returned value from the call.

Returns:
    bool:
    ``True`` if the last call returned this value. ``False`` if it
    did not.
N)r   r   )rG   r   r{   s      rL   r   FunctionSpy.last_returned  s&     ~~48DMM%$88rO   c                 B   ^ [        U4S jU R                   5       5      $ )a  Return whether the spy was ever called and raised this exception.

This will check each and every recorded call to see if any of them
raised an exception of a given type. If at least one call does match,
this will return ``True``.

Args:
    exception_cls (type):
        The expected type of exception raised by a call.

Returns:
    bool:
    ``True`` if there's at least one call raising the given exception
    type. ``False`` if no call matches.
c              3   F   >#    U  H  nUR                  T5      v   M     g 7fry   )r   )rz   r{   exception_clss     rL   r|   %FunctionSpy.raised.<locals>.<genexpr>  s$      
" KK&&"r   r   )rG   r   s    `rL   r   FunctionSpy.raised  r   rO   c                 R    U R                   nUSL=(       a    UR                  U5      $ )a  Return whether the spy's last call raised this exception.

Args:
    exception_cls (type):
        The expected type of exception raised by a call.

Returns:
    bool:
    ``True`` if the last call raised the given exception type.
    ``False`` if it did not.
N)r   r   )rG   r   r{   s      rL   r   FunctionSpy.last_raised  s&     ~~4>DKK$>>rO   c                 F   ^^ [        UU4S jU R                   5       5      $ )a0  Return whether the spy's calls ever raised this exception/message.

This will check each and every recorded call to see if any of them
raised an exception of a given type with the given message. If at least
one call does match, this will return ``True``.

Args:
    exception_cls (type):
        The expected type of exception raised by a call.

    message (unicode):
        The expected message from the exception.

Returns:
    bool:
    ``True`` if there's at least one call raising the given exception
    type and message. ``False`` if no call matches.
c              3   H   >#    U  H  nUR                  TT5      v   M     g 7fry   )r   )rz   r{   r   messages     rL   r|   2FunctionSpy.raised_with_message.<locals>.<genexpr>  s(      
" $$]G<<"r~   r   )rG   r   r   s    ``rL   r   FunctionSpy.raised_with_message  s#    &  



 
 	
rO   c                 R    U R                   nUSL=(       a    UR                  X5      $ )aa  Return whether the spy's last call raised this exception/message.

Args:
    exception_cls (type):
        The expected type of exception raised by a call.

    message (unicode):
        The expected message from the exception.

Returns:
    bool:
    ``True`` if the last call raised the given exception type and
    message. ``False`` if it did not.
N)r   r   )rG   r   r   r{   s       rL   r   $FunctionSpy.last_raised_with_message  s/     ~~D  A((@	BrO   c                 j    / U R                   l        SU R                   l        SU R                   l        g)z-Reset the list of calls recorded by this spy.FN)r=   r   r   r   rQ   s    rL   r   FunctionSpy.reset_calls)  s&     "!&$(!rO   c                    UnU R                   U R                  U R                  4;   a  USS nU R                  nU R                  nU R
                  n[        XU5      nUR                  R                  U5        SUl	        Xul
        Uc  SnU$  UR                  (       a?  UR                  R                  U R                  5      nUR                  (       a  U" U0 UD6nO	U" U0 UD6n Xl        U$ ! [          a  n	Xl        e Sn	A	ff = f)a  Call the original function or fake function for the spy.

This will be called automatically when calling the spied function,
recording the call and the results from the call.

Args:
    *args (tuple):
        Positional arguments passed to the function.

    **kwargs (dict):
        All dictionary arguments either passed to the function or
        default values for unspecified keyword arguments in the
        function signature.

Returns:
    object:
    The result of the function call.
   NT)r3   r5   r6   r2   r=   r!   r   r   appendr   r   
has_getterdefined_func__get__r"   r7   	Exception	exceptionreturn_value)
rG   rt   ru   record_argsrJ   r<   r!   r{   resultes
             rL   __call__FunctionSpy.__call__/  s   & >>d44"668 8%ab/KiiOO	yyt&1t$	"<F0 ->> !--55djjAF "(!8!8 "4262F
 !'  !"s   AC/ C/ /
D9D  Dc                    U R                   nXR                  :X  a  SnU R                  nOU R                  nXR                  :X  a=  U R                  R
                  nU[        L a  UR                  nSnO,UR                  nSnOXR                  :X  a  UR                  nSnW< SU R                  < SU< 3n[        U R                  5      nUS:X  a  SnOS	nS
WU[        U R                  5      U4-  $ )zReturn a string representation of the spy.

This is mainly used for debugging information. It will show some
details on the spied function and call log.

Returns:
    unicode:
    The resulting string representation.
functionclassmethodzbound methodzunbound methodrn   z of r   r{   r   z<Spy for %s %s (%d %s)>)r3   r4   r#   r"   r5   	__class__typerq   r6   lenr   )	rG   r3   func_type_strqualnamer"   	owner_cls
class_name
call_count	calls_strs	            rL   __repr__FunctionSpy.__repr__l  s     NN	***&M~~HJJE222 !JJ00	$!&J$1M!*!3!3J$2M666"^^
 0(2DNNEJH_
?II(M8,/

OY,H H 	HrO   c                     U R                   nUSL=(       aT    [        R                  " U5      (       + =(       d2    U R                  R                  =(       d    [        XR                  5      $ )af  Return whether the owner (if any) needs to be patched.

Owners need patching if they're an instance, if the function is
slippery, or if the function is defined on an ancestor of the class
and not the class itself.

See :py:meth:`_patch_owner` for what patching entails.

Returns:
    bool:
    ``True`` if the owner needs patching. ``False`` if it does not.
N)r"   r)   isclassr2   r7   r   r#   )rG   r"   s     rL   r@   %FunctionSpy._get_owner_needs_patching  sU     

T! E__U++ D&&D,UNNC	FrO   c                    U R                  U R                  5      nU R                  nU R                  U R                  :X  a\  X/n[
        S   S:  a  UR                  U5        U R                  X R                  [        R                  " XR                  5      5        OU R                  X R                  U5        Xl        g)a  Patch the owner.

This will create a new method in place of an existing one on the
owner, in order to ensure that the owner has its own unique copy
for spying purposes.

Patching the owner will avoid collisions between spies in the event
that the method being spied on is defined by a parent of the owner,
rather than the owner itself.

See :py:meth:`_get_owner_needs_patching` the conditions under which
patching will occur.
r      N)r>   r=   r"   r3   r5   r
   r   rg   r#   types
MethodType)rG   r<   r"   method_type_argss       rL   rD   FunctionSpy._patch_owner  s    & ((9	

>>T333 )1Qx1} ''.UNN"--iDF UNNI>#rO   c           	         U R                   n[        U 5      nU R                  nU R                  UUUS9nU R	                  X5      u  pgX`l        [        U[        R                  U5        U [        R                  U'   Xl        UR                  R                  [        R                  " U R                   5      5        U R"                   H*  n[%        XH5      (       a   e[        XH['        X5      5        M,     g)a  Build the proxy function used to forward calls to this spy.

This will construct a new function compatible with the signature of
the provided function, which will call this spy whenever it's called.
The bytecode of the provided function will be set to that of the
generated proxy function. See the comment within this function for
details on how this works.

Args:
    func (callable):
        The function to proxy.
)r!   rJ   spy_idN)r2   ra   r=   _compile_forwarding_call_func_build_spy_coderF   re   r   rf   r   r`   r    rA   updatecopydeepcopyrb   rd   r-   getattr)	rG   r!   rJ   r   r<   forwarding_callold_codenew_codeproxy_func_names	            rL   rE   FunctionSpy._build_proxy_func  s    | iiDOO	<< = 
 "11$H!	;55x@ (,V$
 !!$--0H0H"IJ#22Oy::::I0NO  3rO   c                    UR                   R                  n[        U5      nU(       a)  SSR                  UR                   R                  5      -  nOSnSUR	                  5       UR                  5       UUS.-  nU(       a  SUSR                  S U 5       5      S.-  nOS	U-  n0 n	 [        [        US
S5      [        5       U	5        U(       a  U	S   " 5       nOU	S   nUc   eU$ ! [         a  n
[        SUU
US.-  5      eSn
A
ff = f)a  Compile a forwarding call function for the spy.

This will build the Python code for a function that approximates the
function we're spying on, with the same function definition and
closure behavior.

Version Added:
    7.1

Args:
    func (callable):
        The function being spied on.

    sig (kgb.signature.BaseFunctionSig):
        The function signature to use for this function.

    spy_id (int):
        The ID used for the spy registration.

Returns:
    callable:
    The resulting forwarding function.
z        (%s)
z,  z    def _kgb_forwarding_call(%(params)s):
        from kgb.spies import FunctionSpy as _kgb_cls
%(use_closure_vars)s        _kgb_l = locals()
        return _kgb_cls._spy_map[%(spy_id)s](%(call_args)s)
)	call_argsparamsr   use_closure_varszadef _kgb_forwarding_call_closure(%(params)s):
%(forwarding_call)s    return _kgb_forwarding_call
c              3   ,   #    U  H
  nS U-  v   M     g7f)z%s=NoneN )rz   _vars     rL   r|   <FunctionSpy._compile_forwarding_call_func.<locals>.<genexpr>  s      ($0D "D($0s   )r   r   zif 1:
%sz<string>execzBUnable to compile a spy function for %(func)r: %(error)s

%(code)s)r(   errorr!   N_kgb_forwarding_call_closure_kgb_forwarding_call)__code__co_freevarsbooljoinformat_forward_call_argsformat_arg_specevalcompileglobalsr   r   )rG   r!   rJ   r   closure_varsuse_closureuse_closure_vars_strforwarding_call_strfunc_code_strexec_localsr   r   s               rL   r   )FunctionSpy._compile_forwarding_call_funcI  s\   0 }}00<(  !))DMM5567 ! $& L !99;--/ $8	
 	 4 (;"ii ($0( 	  %&  	
F;K) )*HIKO)*@AO***)  		" *  		s   ( C& &
D0DDc                    [        U[        R                  5      n[        U[        R                  5      nX4:w  d   e[        US5      (       a  SUR                  0n[
        S:  a  UR                  US'   [
        S:  aQ  UR                  [        R                  [        R                  -  [        R                  -  -  nUR                  U-  US'   UR                  " S0 UD6nOUR                  /n[
        S:  a  UR                  UR                  5        UUR                   UR"                  UR                  UR$                  UR&                  UR(                  UR*                  UR,                  UR                  UR.                  UR0                  UR2                  UR4                  /-  n[6        R8                  " U6 nXs:w  d   eXt:w  d   eX74$ )a  Build a CodeType to inject into the spied function.

This will create a function bytecode object that contains a mix of
attributes from the original function and the forwarding call. The
result can be injected directly into the spied function, containing
just the right data to impersonate the function and call our own
logic.

Version Added:
    7.1

Args:
    func (callable):
        The function being spied on.

    forwarding_call (callable):
        The spy forwarding call we built.

Returns:
    tuple:
    A 2-tuple containing:

    1. The spied function's code object (:py:class:`types.CodeType`).
    1. The new spy code object (:py:class:`types.CodeType`).
replaceco_name)r      co_qualnameco_flags)r   r   r   )r   r   rf   r-   r   r
   r   r   r)   CO_GENERATORCO_COROUTINECO_ASYNC_GENERATORr   co_argcountr   co_kwonlyargcount
co_nlocalsco_stacksizeco_code	co_constsco_namesco_varnamesco_filenameco_firstlineno	co_lnotabr   co_cellvarsr   CodeType)	rG   r!   r   r   	temp_codereplace_kwargsmirror_flagsr   	code_argss	            rL   r   FunctionSpy._build_spy_code  s   4 4!;!;<O[-G-GH	$$$8Y'' 8++N 080D0D}-, '00(((()../ 0 .7-?-?,-Nz* ((:>:H #../I  !<!<=$$&&""!!##""%%%%  ((##$$$$ I  ~~y1H###$$$!!rO   c                    [         R                  " U=(       d    [        U[        R                  5      [        U[        R
                  5      [        U[        R                  5      [        U[        R                  5      [        U[        R                  5      5      n[        S   S:  a2  S H,  n[        X4[        R                  " [        X5      5      5        M.     U$ )a  Clone a function, optionally providing new bytecode.

This will create a new function that contains all the state of the
original (including annotations and any default argument values).

Args:
    func (types.FunctionType):
        The function to clone.

    code (types.CodeType, optional):
        The new bytecode for the function. If not specified, the
        original function's bytecode will be used.

Returns:
    types.FunctionType:
    The new function.
r   r   )__annotations____kwdefaults__)r   FunctionTyper   r   rf   r1   r/   FUNC_DEFAULTS_ATTRFUNC_CLOSURE_ATTRr
   re   r   r   )rG   r!   r(   cloned_funcattrs        rL   r>   FunctionSpy._clone_function.  s    $ ((=GD+"<"<=D+778D+445D+889D+778: 8q= >4==9L+MN > rO   c                    [         R                  " U5      (       a  Uc  [        X5        g[        XU5        gUc   [        R                  X5        g [        R                  XU5        g! [         a+  n[        U5      S:X  a  UR                  U	  SnAg SnAgSnAff = f! [         a,  n[        U5      S:X  a  X1R                  U'    SnAg SnAgSnAff = f)a  Set a new method on an object.

This will set the method (or delete the attribute for one if setting
``None``).

If setting on a class, this will use a standard
:py:func:`setattr`/:py:func:`delattr`.

If setting on an instance, this will use a standard
:py:meth:`object.__setattr__`/:py:meth:`object.__delattr__` (in order
to avoid triggering a subclass-defined version of
:py:meth:`~object.__setattr__`/:py:meth:`~object.__delattr__`, which
might lose or override our spy).

Args:
    owner (type or object):
        The class or instance to set the method on.

    name (unicode):
        The name of the attribute to set for the method.

    method (types.MethodType):
        The method to set (or ``None`` to delete).
Nz/can't apply this __delattr__ to instance objectz/can't apply this __setattr__ to instance object)
r)   r   rc   re   object__delattr__rp   strrA   __setattr__)rG   r"   namemethodr   s        rL   rg   FunctionSpy._set_methodP  s    2 ??5!!~$V,^-""5/2""57  -q6NN
 t, O-  2q6NN ,2NN4( O2s/   A* B" *
B4BB"
C,CC)	r?   rF   rC   r=   r2   r:   r!   r+   r;   )Try   )*rq   rr   __qualname____firstlineno____doc__r   r4   r5   r6   rd   rb   r`   r   rM   propertyr3   r#   r"   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   rD   rE   r   r   r>   rg   __static_attributes__r   rO   rL   r   r      sR      --M
 $55
 &99N  H/34
dxBt 	# 	# # #         +D"9H
>F4
*9 
*? 
0B();z+HZF(!$FwPrsjn"` D/2rO   r   )
__future__r   r   r   r)   r   	kgb.callsr   
kgb.errorsr   r   r   kgb.pycompatr	   r
   kgb.signaturer   r   	kgb.utilsr   r  r   r   rO   rL   <module>r#     s7    8    * * ) 1 1o2& o2rO   