
    MhB                     *   d Z ddlZddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZ dZ ej        d          Zej        j        Zej        j        Z G d de          Zd	 ZddZd ZddZ G d de          Z ee          Zd Zd Zd ZdS )zv
Decorator module, see
https://github.com/micheles/decorator/blob/master/docs/documentation.md
for the documentation.
    N)_GeneratorContextManager)getfullargspeciscoroutinefunctionisgeneratorfunctionz5.2.1z\s*def\s*([_\w][_\w\d]*)\s*\(c                   ~    e Zd ZdZ ej                    ZdxZxZxZ	xZ
xZZ	 	 d
dZd ZddZe	 	 dd	            ZdS )FunctionMakerz
    An object with the ability to create functions with a given signature.
    It has attributes name, doc, module, signature, defaults, dict and
    methods update and make.
     Nc           	      P   || _         |r1|j        | _        | j        dk    rd| _        |j        | _        |j        | _        t          j        |          st          |t          j                  rt          |          }t          |di           | _        dD ]!}	t          | |	t          ||	                     "t!          | j                  D ]\  }
}t          | d|
z  |           t%          | j                  }t%          | j                  }| j        r;|                    d| j        z              |                    d| j        z              n| j        r|                    d           | j        D ]4}	|                    d|	z             |                    |	d|	           5| j        r:|                    d	| j        z              |                    d	| j        z              d
                    |          | _        d
                    |          | _         |j                                        | _        |r|| _        ||| _        |r|| _        |r|| _        |r|| _        |r|| _        t;          | d          sJ t;          | d          st=          d|z            d S )Nz<lambda>_lambda___annotations__)argsvarargsvarkwdefaults
kwonlyargskwonlydefaultszarg%d*z%s=None=z**, name	signaturez%You are decorating a non function: %s)shortsignature__name__r   __doc__doc
__module__moduleinspect	isroutine
isinstance	functoolspartialr   getattrannotationssetattr	enumerater   listr   appendr   r   joinr   __dict__copydictr   hasattr	TypeError)selffuncr   r   r   r   r   funcdictargspecaiargallargsallshortargss                 I/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/decorator.py__init__zFunctionMaker.__init__A   s   ' 	1DIyJ&&&	|DH/DK && 1*T9;L*M*M 1(..#*41BB#G#G , : :AD!WWa%8%89999'	22 4 4FAsD'A+s3333ty//#DI< (NN3#5666 ''dl(:;;;;_ (NN3''' : :ANN9q=111 ''111aa(89999: ;NN4$*#4555 ''tz(9:::!%7!3!3&*ii&=&=# M..00	 	DI &DN 	%$DM 	DH 	! DK 	! DItV$$$$$t[)) 	LCdJKKK	L 	L    c                    | j         |_        t          | dd          |_        t          | di           |_        | j        |_        | j        pd|_        t          | dd          |_	        	 t          j        d          }|j                            dd          }n# t          $ r d}Y nw xY wt          | d|          |_        |j                            |           dS )	zD
        Update the signature of func with the data in self
        r   Nr,   r$      r   ?r   )r   r   r#   r   r*   r   __defaults__r   __kwdefaults__r   sys	_getframe	f_globalsgetAttributeErrorr   update)r/   r0   kwframecallermodules        r8   rE   zFunctionMaker.updateu   s     	tUD11fb11 M"19T&t]DAA	@M!$$E !?..z3??LL  	 	 	LLL	 "$,??R     s   *B B)(B)Fc                    |t          |           z  }|pi }t                              |          }|t          d|z            |                    d          }t          |gd | j                            d          D             z             }|D ]}	|	dv rt          |	d|          |	                    d          s|dz  }d	t          | j                  z  }
	 t          ||
d
          }t          ||           nE# t          $ r8 t          dt           j                   t          |t           j                    w xY w||         }|r||d<    | j        |fi | |S )zT
        Make a new function from a given template and update the signature
        Nz not a valid function template
%s   c                 8    g | ]}|                     d           S )z *)strip.0r5   s     r8   
<listcomp>z&FunctionMaker.make.<locals>.<listcomp>   s.     > > >#ciioo > > >r:   ,)_func__call_z is overridden in

z<decorator-gen-%d>singlezError in generated code:)file
__source__)varsDEFsearchSyntaxErrorgroupsetr   split	NameErrorendswithnext_compile_countcompileexec	Exceptionprintr@   stderrrE   )r/   	src_templevaldict	addsourceattrssrcmor   namesnfilenamecoder0   s                r8   makezFunctionMaker.make   s    $t**$>rZZ__:ACGHHHxx{{TF > >"177<<> > > > ? ? 	F 	FA(((QQQ DEEE ) ||D!! 	4KC
 ($t/B*C*CC	3(33Dx     	 	 	,3:>>>>#CJ''''	 ~ 	&"%E,D""E"""s   !D   AETc                    t          |t                    r8|                                                    dd          \  }	}
|
dd         }d}nd}	d}|} | ||	||||          }d                    d |                                D                       }|                    d          }|r)t          |          rd|z                       d	d
          }nd|z   } |j	        |||fi |S )z
        Create a function from the strings name, signature and body.
        evaldict is the evaluation dictionary. If addsource is true an
        attribute __source__ is added to the result. The attributes attrs
        are added, if any.
        (rJ   NrS   c              3       K   | ]	}d |z   V  
dS )z    Nr	   )rN   lines     r8   	<genexpr>z'FunctionMaker.create.<locals>.<genexpr>   s&      FFD&4-FFFFFFr:   rR   z#async def %(name)s(%(signature)s):
returnzreturn awaitzdef %(name)s(%(signature)s):
)
r    strrL   r]   r)   
splitlinesrC   r   replacerq   )clsobjbodyrh   r   r   r   ri   rj   r   restr   r0   r/   ibodycallers                   r8   createzFunctionMaker.create   s    c3 	**322JD$SbS	IDDDIDs4y(C@@		FFDOO4E4EFFFFFh'' 	<)&11 	<:UBKK.* *DD 4e;Dtyx<<e<<<r:   )NNNNNNNNF)NNNT)r   r   __qualname__r   	itertoolscountra   r   r   r   r   r   r   r9   rE   rq   classmethodr   r	   r:   r8   r   r   4   s          %Y_&&N GIHDH7HUHXH
^7;@D2L 2L 2L 2Lh! ! !&" " " "H 2604= = = [= = =r:   r   c                 `     |j         | i |}|                                 |j        |j        fS )zA
    Fix args and kwargs to be consistent with the signature
    )bindapply_defaultsr   kwargs)r   r   sigbas       r8   fixr      s;     
4	"6	"	"B7BIr:   r	   Fc                     t          j                   t           t          j                  rt          j          j                   t                    r
 fd}n"t                    r
 fd}n	 fd} j	        |_	         j
        |_
         |_        |_         j        |_        	  j        |_        n# t          $ r Y nw xY w	  j        |_        n# t          $ r Y nw xY w	  j        |_        n# t          $ r Y nw xY w	  j        |_        n# t          $ r Y nw xY w	  j	        |_	        n# t          $ r  j	        dk     Y nw xY w	 |j                             j                   n# t          $ r Y nw xY w|S )af  
    Decorates a function/generator/coroutine using a caller.
    If kwsyntax is True calling the decorated functions with keyword
    syntax will pass the named arguments inside the ``kw`` dictionary,
    even if such argument are positional, similarly to what functools.wraps
    does. By default kwsyntax is False and the the arguments are untouched.
    c                  ^   K   st          | |          \  } } g| z   R i | d {V S Nr   r   rF   r   extrasr0   kwsyntaxr   s     r8   funzdecorate.<locals>.fun   sZ       .tR--b===="=========r:   c               ?   d   K   st          | |          \  } } g| z   R i |D ]}|V  d S r   r   )r   rF   resr   r   r0   r   r   s      r8   r   zdecorate.<locals>.fun   sf       .tR--bvd;ftm;;;;;  				 r:   c                  N    st          | |          \  } } g| z   R i |S r   r   r   s     r8   r   zdecorate.<locals>.fun   sD     .tR--b6$7&4-777B777r:   noname)r   r   r    r!   r"   update_wrapperr0   r   r   r   r   __wrapped____signature__r   r>   rD   r?   r   r   r*   rE   )r0   r   r   r   r   r   s   ```` @r8   decorater      so    
D
!
!C$	)** 9'di886"" 8	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 
V	$	$ 
8	 	 	 	 	 	 	 	 	 		8 	8 	8 	8 	8 	8 	8 	8 	8
 =CL,CKCOC(C,   !0   "2      "} " " "!!!!"DM****   Jsl   <C	 	
CCC' '
C43C48D 
DDD# #
D0/D04E EEE= =
F
	F
c                       fd}|S )z
    A version of "decorator" implemented via "exec" and not via the
    Signature object. Use this if you are want to preserve the `.__code__`
    object properties (https://github.com/micheles/decorator/issues/129).
    c                 j    t                               | dt          |           | | j                  S )Nz)return _call_(_func_, %(shortsignature)s))rR   rQ   )r   r   )r   r   r,   r   )r0   r   s    r8   deczdecoratorx.<locals>.dec  s>    ##7t,,,4+<	 $ > > 	>r:   r	   )r   r   s   ` r8   
decoratorxr     s#    > > > > > Jr:   c                     |t          | d          S t          j                   }d |j                                        D             d fd	}|                              |_         j        |_         j        |_         |_	         j
        |_
        t           dd          |_        |j                             j                   |S )zG
    decorator(caller) converts a caller function into a decorator
    Nr	   c                 .    g | ]}|j         t          u |S r	   )kindPOS)rN   ps     r8   rO   zdecorator.<locals>.<listcomp>&  s    FFF#!r:   c                     t          |          dz   }|t          fd|d          D                       z   | fdS t          |           S )NrJ   c              3   t   K   | ]2}|j         t          u                    |j        |j                   V  3d S r   )defaultEMPTYrC   r   )rN   r   rF   s     r8   rw   z)decorator.<locals>.dec.<locals>.<genexpr>*  sN       9 9"#!"%!7!7 !ffQVQY77!7!7!7!79 9r:   c                 (    t          |           S r   r   )r0   r   r   r   s    r8   <lambda>z(decorator.<locals>.dec.<locals>.<lambda>.  s    vvx H H r:   )lentupler   )r0   r   rF   nar   r   
dec_paramsr   s     ` @r8   r   zdecorator.<locals>.dec(  s    YY] 9 9 9 9'1"##9 9 9 9 9 9 <HHHHHHHD&&(;;;r:   )
parametersr?   r   )r   r   r   r   valuesr{   r   r   r   r   r   r#   r?   r*   rE   )r   _funcr   r   r   r   s   ` `  @r8   	decoratorr     s     vr8444

F
#
#CFFS^2244FFFJ< < < < < < < < z::C?CL.CKCO*C )94@@CL(((Jr:   c                       e Zd Zd Zd ZdS )ContextManagerc                 4    t          j        | |||           d S r   )r   r9   )r/   gr3   ks       r8   r9   zContextManager.__init__?  s     )$1a88888r:   c                 .      fd}t          ||          S )Nc                      j         j        gj        R i j        5   | |i |cd d d            S # 1 swxY w Y   d S r   )	__class__r0   r   kwds)fr3   r   r/   s      r8   r   z'ContextManager.__call__.<locals>.callerC  s    	CDICCCCC " "q!zqzz" " " " " " " " " " " " " " " " " "s   7;;r   )r/   r0   r   s   `  r8   __call__zContextManager.__call__B  s.    	" 	" 	" 	" 	" f%%%r:   N)r   r   r   r9   r   r	   r:   r8   r   r   >  s2        9 9 9& & & & &r:   r   c                      t          |           S r   )_contextmanager)r0   s    r8   contextmanagerr   L  s    4   r:   c                     d}t          |          D ]0\  }}t          ||           rd} nt          | |          r| ||<   d}1|r|                    |            dS dS )z_
    Append ``a`` to the list of the virtual ancestors, unless it is already
    included.
    TFN)r&   
issubclassr(   )r3   
vancestorsaddjvas        r8   r(   r(   S  s    
 C:&&  2b! 	CEa 	JqMC
 ! r:   c                        s
J d            dd                                z  t          j        df fd	 fd}dz   |_        |S )zr
    Factory of decorators turning a function into a generic function
    dispatching on the given arguments.
    zNo dispatch args passedz(%s,)r    c                      |t          |           t                              r/t          dt                    t          |           |fz            dS )z5Make sure one passes the expected number of argumentszExpected %d arguments, got %d%sN)r   r.   )	argumentswrongmsgdispatch_argss      r8   checkzdispatch_on.<locals>.checkm  sh    5Y]!3!344 	G= //YEF G G G	G 	Gr:   c                 F    t          t                     j                  }t          	          |k    st          d
z            i 	fdfdfd}fd} fd}t                               d
z  t          |          | | 	
  
        S )
z4Decorator turning a function into a generic functionzUnknown dispatch arguments %sc                  $    |            d t          t                              D             }D ]P}t          | ||          D ]<\  }}}t          ||          r&||                                vrt          ||           =Qd |D             S )zU
            Get a list of sets of virtual ancestors for the given types
            c                     g | ]}g S r	   r	   )rN   _s     r8   rO   zIdispatch_on.<locals>.gen_func_dec.<locals>.vancestors.<locals>.<listcomp>  s    999!2999r:   c                 ,    g | ]}t          |          S r	   )r\   )rN   ras     r8   rO   zIdispatch_on.<locals>.gen_func_dec.<locals>.vancestors.<locals>.<listcomp>  s    ***CGG***r:   )ranger   zipr   mror(   )	typesrastypes_ttype_r   r   r   typemaps	         r8   r   z5dispatch_on.<locals>.gen_func_dec.<locals>.vancestors}  s     E%LLL99uS%7%788999C! * *$'vs$;$; * *LAub!!U++ *QUUWW0D0Dub)))* +*c****r:   c                  z    |            g }t          |  |            D ]\  }}t          |          }|dk    rt          d|d|          |dk    r2|\  }t          d||fi                                           dd         }n|                                }|                    |dd                    |S )zG
            Get a list of virtual MROs, one for each type
            rJ   zAmbiguous dispatch for z: r   Nrt   )r   r   RuntimeErrortyper   r(   )	r   listsr   vasn_vasr   r   r   r   s	          r8   	ancestorsz4dispatch_on.<locals>.gen_func_dec.<locals>.ancestors  s     E%LLLEeZZ%788 
' 
'3C199&,;<11ccBD D DaZZCBsQGR004466qrr:CC%%''CS"X&&&&Lr:   c                  .                   fd}|S )zU
            Decorator to register an implementation for the given types
            c                 t     t          |           j        t          j        d| j        z              | <   | S )Nz in )r   r   operatorltr   )r   r   r   r   s    r8   r   z@dispatch_on.<locals>.gen_func_dec.<locals>.register.<locals>.dec  s9    nQ'',hk6AJ;NOOO!"r:   r	   )r   r   r   r   s   ` r8   registerz3dispatch_on.<locals>.gen_func_dec.<locals>.register  s=     E%LLL       Jr:   c                       |            g }t          j         |   D ].}|                    t          d |D                                  /|S )zI
            An utility to introspect the dispatch algorithm
            c              3   $   K   | ]}|j         V  d S r   )r   )rN   r3   s     r8   rw   zKdispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info.<locals>.<genexpr>  s$       : : : : : : : :r:   )r   productr(   r   )r   lstancsr   r   s      r8   dispatch_infoz8dispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info  sf     E%LLLC!)99e+<= < <

5 : :T : : :::;;;;Jr:   c                    t          d | D                       }	 	|         } ||i |S # t          $ r Y nw xY wt          j         |  }t	          |           |D ]#}	                    |          }|
 ||i |c S $ |i |S )Nc              3   4   K   | ]}t          |          V  d S r   )r   rM   s     r8   rw   zGdispatch_on.<locals>.gen_func_dec.<locals>._dispatch.<locals>.<genexpr>  s(      ==$s))======r:   )r   KeyErrorr   r   r`   rC   )
r   r   rF   r   r   combinationsr   r   r0   r   s
          r8   	_dispatchz4dispatch_on.<locals>.gen_func_dec.<locals>._dispatch  s    ==}=====E&EN q$~"~~%     %,ii.?@L& * *KK''=1d>b>>))) ! 4$$$$s   , 
99z#return _f_(%s, %%(shortsignature)s))_f_)r   r   r   r   r   r   r   )r\   r   r   r^   r   r   r,   )r0   argsetr   r   r   r   r   r   r   r   dispatch_strs   `    @@@r8   gen_func_decz!dispatch_on.<locals>.gen_func_decs  s5    ^D)).//=!!V++;lJKKK
	+ 
	+ 
	+ 
	+ 
	+ 
	+ 
	+	 	 	 	 	 	&
	 
	 
	 
	 
	 
		 	 	 	 	 		% 	% 	% 	% 	% 	% 	%$ ##7,FY(D
i'T	 $ ; ; 	;r:   dispatch_on)r)   r   ner   )r   r   r   r   s   ` @@r8   r   r   e  s    
 333333TYY}555L'{ G G G G G GU; U; U; U; U; U; U;n *L8Lr:   )r	   Fr   )r   rer@   r   r   r   r!   
contextlibr   r   r   r   __version__rb   rX   	ParameterPOSITIONAL_OR_KEYWORDr   emptyr   objectr   r   r   r   r   r   r   r   r(   r   r	   r:   r8   <module>r     s  < 
 
			 



           / / / / / / L L L L L L L L L Lbj122-Q= Q= Q= Q= Q=F Q= Q= Q=h  : : : :z     B& & & & &- & & & )N++! ! !  $f f f f fr:   