
    wijN!                         d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
mZmZ  e       Zd Zd Zd Zd	 Zd
 Z G d de	      Z G d d      Z G d dee      Z G d de
      Z G d dee      ZddddddZy)a  The `with_signature` decorator: override the signature (and related
introspection attributes) of a wrapped callable without mutating the wrapped
function itself. Accepts a prototype callable, a prebuilt `inspect.Signature`,
or a factory that derives a signature from the wrapped function at decoration
time.

This replaces the need for the `adapter=` argument of `wrapt.decorator`,
which is planned for deprecation.
    )
CO_VARARGSCO_VARKEYWORDS	Parameter	Signature)	signature   )BaseObjectProxyBoundFunctionWrapperCallableObjectProxyFunctionWrapperc                 P     d j                  d        fd}t        |      S )aQ  Read-only property that memoizes its derivation in a `_self_*` slot.

    `functools.cached_property` is unusable on ObjectProxy subclasses: wrapt
    overrides `__dict__` with a property returning the wrapped object's dict,
    so cached_property's `instance.__dict__[name] = value` would mutate the
    wrapped function. Storing under a `_self_*` name routes through wrapt's
    own setattr handling and lands in the proxy's real instance dict. Using
    a `@property` (data descriptor) also ensures we win over any value
    copied into the instance dict by `FunctionWrapper.__init__`.
    _self_cached__c                     t        | t              }|t        u r#| j                        }| j                  |       |S N)getattr_MISSING_derive__self_setattr__)selfvalueattrslots     d/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/wrapt/signature.pygetterz_cached.<locals>.getter%   s<    dH-HLL&E!!$.    )lstripproperty)r   r   r   s   ` @r   _cachedr      s-     4;;s+,-D Fr   c                    | j                   j                         D ci c]5  }|j                  t        j                  ur|j
                  |j                  7 }}| j                  t        j                  ur| j                  |d<   |S c c}w )Nreturn)
parametersvalues
annotationr   emptynamereturn_annotationr   )sigpanns      r   _derive_annotationsr+   /   sx     &&(<<y. 	
C 
 IOO3--HJs   :Bc                 b    t        d | j                  j                         D              }|xs d S )Nc              3      K   | ]X  }|j                   t        j                  t        j                  fv r*|j                  t        j
                  ur|j                   Z y wr   )kindr   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDdefaultr%   .0r)   s     r   	<genexpr>z#_derive_defaults.<locals>.<genexpr>;   sI      66i//1P1PQQIIY__, 	
		s   AA )tupler"   r#   )r(   defaultss     r   _derive_defaultsr7   :   s3     &&( H tr   c                     | j                   j                         D ci c]Q  }|j                  t        j                  u r3|j
                  t        j                  ur|j                  |j
                  S }}|xs d S c c}w r   )r"   r#   r.   r   KEYWORD_ONLYr1   r%   r&   )r(   r)   
kwdefaultss      r   _derive_kwdefaultsr;   D   sn     &&(66Y+++		0P 	
		J 
 s   AA;c                    g g g }}}d x}}| j                   j                         D ]  }|j                  t        j                  u r|j                  |j                         ;|j                  t        j                  u r|j                  |j                         s|j                  t        j                  u r|j                  }|j                  t        j                  u r|j                  |j                         |j                  t        j                  u s|j                  } ||z   |z   }|r|j                  |       |r|j                  |       t        |      S r   )r"   r#   r.   r   r/   appendr&   r0   VAR_POSITIONALr9   VAR_KEYWORDr5   )r(   pos_only	pos_or_kwkw_onlyvar_posvar_kwr)   namess           r   _derive_varnamesrF   M   s   #%r2iHGf^^""$ 
66Y...OOAFF#VVy666QVV$VVy///ffGVVy---NN166"VVy,,,VVF
 y 7*EWV<r   c                   x     e Zd ZdZ fdZd Z ed      Z ed      Z ed      Z	 ed      Z
 ed      Z xZS )	_SignatureCodezCode-object proxy deriving argument-related co_* attrs from a Signature.

    Non-argument bits (co_flags for coroutine/generator, co_filename, etc.)
    fall through to the wrapped function's real __code__.
    c                 2    t         |   |       || _        y r   super__init___self_signaturer   wrappedr   	__class__s      r   rL   z_SignatureCode.__init__j       !(r   c                    | j                   }|dk(  rLt        j                  t        j                  ft	        fd|j
                  j                         D              S |dk(  r*t	        d |j
                  j                         D              S |dk(  r*t	        d |j
                  j                         D              S |dk(  rt        |      S |dk(  r|j
                  j                         D ch c]  }|j                   c}| j                  j                  t        t        z   z  }t        j                  v r	|t        z  }t        j                  v r	|t        z  }|S t        |      c c}w )	Nco_argcountc              3   :   K   | ]  }|j                   v   y wr   )r.   )r3   r)   kindss     r   r4   z)_SignatureCode._derive.<locals>.<genexpr>r   s     H1qvvHs   co_posonlyargcountc              3   T   K   | ]   }|j                   t        j                  u  " y wr   )r.   r   r/   r2   s     r   r4   z)_SignatureCode._derive.<locals>.<genexpr>t   s$      89)333   &(co_kwonlyargcountc              3   T   K   | ]   }|j                   t        j                  u  " y wr   )r.   r   r9   r2   s     r   r4   z)_SignatureCode._derive.<locals>.<genexpr>x   s$      56)000rX   co_varnamesco_flags)rM   r   r/   r0   sumr"   r#   rF   r.   __wrapped__r\   r   r   r>   r?   AttributeError)r   r   r(   r)   flagsrU   s        @r   r   z_SignatureCode._deriven   sM   ""= ..	0O0OPEH0E0E0GHHH'' =@^^=R=R=T   && :=..:O:O:Q   = #C((:%(^^%:%:%<=QVV=E$$--*~2M0NNE''50#$$-'LT"" >s   .E,rS   rV   rY   r[   r\   )__name__
__module____qualname____doc__rL   r   r   rS   rV   rY   r[   r\   __classcell__rP   s   @r   rH   rH   c   sJ    )#2 -(K !56 34-(Kz"Hr   rH   c                   f    e Zd ZdZd Zed        Z ed      Z ed      Z	 ed      Z
 ed      Zy)	_SignatureMixinzEShared Signature-derived introspection attrs for wrapper + surrogate.c                     | j                   }|dk(  rt        |      S |dk(  rt        |      S |dk(  rt        |      S |dk(  r t	        | j
                  j                  |      S t        |      )N__annotations____defaults____kwdefaults____code__)rM   r+   r7   r;   rH   r^   rm   r_   )r   r   r(   s      r   r   z_SignatureMixin._derive   st    ""$$&s++>!#C((##%c**:!$"2"2";";SAAT""r   c                     | j                   S r   )rM   r   s    r   __signature__z_SignatureMixin.__signature__   s    ###r   rj   rk   rl   rm   N)ra   rb   rc   rd   r   r   rp   r   rj   rk   rl   rm    r   r   rh   rh      sJ    O
# $ $ /0O>*L-.Nz"Hr   rh   c                   "     e Zd ZdZ fdZ xZS )_SignatureFunctionSurrogatea  Function surrogate exposing Signature-derived introspection attrs.

    Used as __func__ of a bound wrapper so that inspect.signature -- which
    treats the bound wrapper as a MethodType and consults __func__ -- sees
    our override and strips self/cls correctly.
    c                 2    t         |   |       || _        y r   rJ   rN   s      r   rL   z$_SignatureFunctionSurrogate.__init__   rQ   r   )ra   rb   rc   rd   rL   re   rf   s   @r   rs   rs      s    ) )r   rs   c                   ,    e Zd Zed        Zed        Zy)_BoundSignatureFunctionWrapperc                 j    t        | j                  j                  | j                  j                        S r   )rs   r^   __func___self_parentrM   ro   s    r   rx   z'_BoundSignatureFunctionWrapper.__func__   s,    *%%t'8'8'H'H
 	
r   c                 .    | j                   j                  S r   )ry   rM   ro   s    r   rp   z,_BoundSignatureFunctionWrapper.__signature__   s      000r   N)ra   rb   rc   r   rx   rp   rq   r   r   rv   rv      s(    
 

 1 1r   rv   c                   2     e Zd ZeZ fdZed        Z xZS )_SignatureFunctionWrapperc                 4    t         |   ||       || _        y r   rJ   )r   rO   wrapperr   rP   s       r   rL   z"_SignatureFunctionWrapper.__init__   s    '*(r   c                 B    t        | j                  | j                        S r   )rs   r^   rM   ro   s    r   rx   z"_SignatureFunctionWrapper.__func__   s    *4+;+;T=Q=QRRr   )	ra   rb   rc   rv   __bound_function_wrapper__rL   r   rx   re   rf   s   @r   r|   r|      s$    !?) S Sr   r|   N)	prototyper   factoryc                   t        d fD              }|dk(  rt        d      |dkD  rt        d      fd}| |S  ||       S )a  Override the signature of a wrapped callable.

    Exactly one of `prototype`, `signature`, or `factory` must be supplied:

    - `prototype`: a callable whose signature will be used.
    - `signature`: a prebuilt `inspect.Signature` object.
    - `factory`: a callable `factory(wrapped)` invoked at decoration time
      that returns either a `Signature` or a prototype callable.

    The resulting wrapper exposes the override via `__signature__`, and
    derives `__annotations__`, `__defaults__`, `__kwdefaults__`, and the
    argument-related attributes of `__code__` from the same source. The
    wrapped function is not mutated. Calling behaviour is unchanged.
    c              3   $   K   | ]  }|d u 
 y wr   rq   )r3   xs     r   r4   z!with_signature.<locals>.<genexpr>   s     KaATMKs   r   zBwith_signature requires one of prototype=, signature=, or factory=r   zFwith_signature accepts only one of prototype=, signature=, or factory=c                     d }}n3t              }n% |       }t        |t              r|n
t        |      }t        | ||      S )Nc                      | |i |S r   rq   )rO   instanceargskwargss       r   _wrapperz4with_signature.<locals>._decorator.<locals>._wrapper   s    D+F++r   )_inspect_signature
isinstancer   r|   )rO   r   resolvedproducedr   r   r   s       r   
_decoratorz"with_signature.<locals>._decorator   s^    	,   H"))4Hw'H h	2 '1  )(HEEr   )r]   	TypeError)rO   r   r   r   	specifiedr   s    ```  r   with_signaturer      sj      KIy'+JKKIA~P
 	
 1}T
 	
F$ gr   r   )rd   inspectr   r   r   r   r   r   	__wrapt__r	   r
   r   r   objectr   r   r+   r7   r;   rF   rH   rh   rs   rv   r|   r   rq   r   r   <module>r      s    E D 3  8.,(#_ (#V# #2
)/3F 
)	1%9 	1	S 	S.t .r   