
    tKgpA                     :   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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y)zv
Decorator module, see
https://github.com/micheles/decorator/blob/master/docs/documentation.md
for the documentation.
    N)_GeneratorContextManager)getfullargspeciscoroutinefunctionisgeneratorfunctionz5.1.1z\s*def\s*([_\w][_\w\d]*)\s*\(c                   z    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y)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           	         || _         |r%|j                  | _        | j                  dk(  rd| _        |j                  | _        |j
                  | _        t        j                  |      rt        |      }t        |di       | _        dD ]  }	t        | |	t        ||	              t        | j                        D ]  \  }
}t        | d|
z  |        t        | j                        }t        | j                        }| j                   r=|j#                  d| j                   z          |j#                  d| j                   z          n| j$                  r|j#                  d       | j$                  D ],  }	|j#                  d|	z         |j#                  |	d|	       . | j&                  r<|j#                  d	| j&                  z          |j#                  d	| j&                  z          d
j)                  |      | _        d
j)                  |      | _         |j,                  j/                         | _        |r|| _        ||| _        |r|| _        |r|| _        |r|| _        |r|| _        t5        | d      sJ t5        | d      st7        d|z        y )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	isroutiner   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                 M/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/decorator.py__init__zFunctionMaker.__init__@   s   'DIyyJ&&	||DH//DK  &(.#*41BB#G ,AD!WWa%89, (		2FAsD'A+s3 3tyy/#DII<<NN3#56 ''dll(:;__NN3'ANN9q=1 ''1a(89 ) ::NN4$**#45 ''tzz(9:!%7!3&*ii&=# MM..0	DI &DN$DMDH DK DItV$$$t[)CdJKK *    c                    | j                   |_        t        | dd      |_        t        | di       |_        | j
                  |_        | j                  xs d|_        t        | dd      |_	        	 t        j                  d      }|j                  j                  dd      }t        | d|      |_        |j                  j!                  |       y# t        $ r d}Y ;w xY w)	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,   r-   kwframecallermodules        r5   rB   zFunctionMaker.updatet   s     		tUD1fb1 MM"119T&t]DA	@MM!$E !??..z3?L!$,?R   	L	s   /C CCc           	         |t        |       z  }|xs i }t        j                  |      }|t        d|z        |j	                  d      }t        |g| j                  j                  d      D cg c]  }|j                  d       c}z         }	|	D ]  }
|
dv st        |
d|       |j                  d      s|dz  }dt        | j                        z  }	 t        ||d	      }t        ||       ||   }|r||d<    | j&                  |fi | |S c c}w # t        $ r8 t!        d
t"        j$                         t!        |t"        j$                          w xY w)zT
        Make a new function from a given template and update the signature
        z not a valid function template
%s   ,z *)_func__call_z is overridden in

z<decorator-gen-%d>singlezError in generated code:)file
__source__)varsDEFsearchSyntaxErrorgroupsetr   splitstrip	NameErrorendswithnext_compile_countcompileexec	Exceptionprintr=   stderrrB   )r,   	src_templevaldict	addsourceattrssrcmor   r2   namesnfilenamecoder-   s                 r5   makezFunctionMaker.make   sf    $t*$>rZZ_:ACGHHxx{TF"1177<>< 36ciio<> > ?A((Q DEE  ||D!4KC
 ($t/B/B*CC	3(3Dx 
 ~"%E,D"E"1>   	,3::>#CJJ'	s   /D
D AEc                    t        |t              r+|j                         j                  dd      \  }	}
|
dd }d}nd}	d}|} | ||	||||      }dj	                  d |j                         D              }|j                  d      }|r!t        |      rd|z   j                  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.
        (rG   NrK   c              3   &   K   | ]	  }d |z     yw)z    Nr	   ).0lines     r5   	<genexpr>z'FunctionMaker.create.<locals>.<genexpr>   s     F4ED&4-4Es   rJ   z#async def %(name)s(%(signature)s):
returnzreturn awaitzdef %(name)s(%(signature)s):
)

isinstancestrrV   rU   r&   
splitlinesr@   r   replacerj   )clsobjbodyra   r   r   r   rb   rc   r   restr   r-   r,   ibodycallers                   r5   createzFunctionMaker.create   s     c3**32JD$Sb	IDDID4y(C@		FDOO4EFFh')&1:UBKK.*D 4e;Dtyyx<e<<r7   )NNNNNNNNF)NNNT)r   r   __qualname__r   	itertoolscountrZ   r   r   r   r   r   r   r6   rB   rj   classmethodr}   r	   r7   r5   r   r   3   sk     %Y__&N GIHDH7HUHXH
^7;@D2Lh!&"H 2604= =r7   r   c                 v     |j                   | i |}|j                          |j                  |j                  fS )zA
    Fix args and kwargs to be consistent with the signature
    )bindapply_defaultsr   kwargs)r   r   sigbas       r5   fixr      s8     
4	"6	"B77BIIr7   c                     t        j                         t              r
 fd}nt              r
 fd}n	 fd} j                  |_         j
                  |_         |_        |_         j                  |_        	  j                  |_	        	  j                  |_        	  j                  |_        	  j                  |_        	 |j                  j                   j                         |S # t        $ r Y iw xY w# t        $ r Y fw xY w# t        $ r Y cw xY w# t        $ r Y `w xY w# t        $ r Y |S w xY w)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                  b   K   st        | |      \  } } g| z   i | d {   S 7 wNr   r   rC   r|   extrasr-   kwsyntaxr   s     r5   funzdecorate.<locals>.fun   s;     tR-b=="====s   %/-/c               ?   b   K   st        | |      \  } } g| z   i |D ]  }|  y wr   r   )r   rC   resr|   r   r-   r   r   s      r5   r   zdecorate.<locals>.fun   s>     tR-bd;ftm;;	 <s   ,/c                  F    st        | |      \  } } g| z   i |S r   r   r   s     r5   r   zdecorate.<locals>.fun   s1    tR-b$7&4-7B77r7   )r   r   r   r   r   r   __wrapped____signature__r   r;   rA   r<   r   r   r'   rB   )r-   r|   r   r   r   r   s   ```` @r5   decorater      sJ    

D
!C6"	> 	> 
V	$	 		8 	8 ==CL,,CKCOC((C,,!00"22DMM* J%          JsZ   C? "D 4D D, %D; ?	D
D	DD	D)(D),	D87D8;	EE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                 b    t         j                  | dt        |       | | j                        S )Nz)return _call_(_func_, %(shortsignature)s))rJ   rI   )r   r   )r   r}   r)   r   )r-   r|   s    r5   deczdecoratorx.<locals>.dec  s6    ##7t,4+<+<	 $ > 	>r7   r	   )r|   r   s   ` r5   
decoratorxr     s    > Jr7   c                     |t        | d      S t        j                         }|j                  j	                         D cg c]  }|j
                  t        u s| c}d fd	}|j                        |_         j                  |_	         j                  |_
         |_         j                  |_        t         dd      |_        |j                  j!                   j                         |S c c}w )zG
    decorator(caller) converts a caller function into a decorator
    Nr	   c                     t        |      dz   }|t        fd|d  D              z   | fdS t        |       S )NrG   c              3      K   | ]<  }|j                   t        ur(j                  |j                  |j                          > y wr   )defaultEMPTYr@   r   )ro   prC   s     r5   rq   z)decorator.<locals>.dec.<locals>.<genexpr>"  s8      9'6!!"%!7 !ffQVVQYY7'6s   AAc                      t        |       S r   r   )r-   r|   r   r   s    r5   <lambda>z(decorator.<locals>.dec.<locals>.<lambda>&  s    vvx Hr7   )lentupler   )r-   r   rC   nar   r|   
dec_paramsr   s     ` @r5   r   zdecorator.<locals>.dec   sR    Y] 9'1"#9 9 9 <HHD&&(;;r7   )
parametersr<   r   )r   r   r   r   valueskindPOSrv   r   r   r   r   r   r    r<   r'   rB   )r|   _funcr   r   r   r   r   s   ` `   @r5   	decoratorr     s     vr844


F
#C ^^224F4#!4FJ< z:C??CL..CKCO**C )94@CLL(J% Gs   C6C6c                       e Zd Zd Zd Zy)ContextManagerc                 4    t        j                  | |||       y r   )r   r6   )r,   gr0   ks       r5   r6   zContextManager.__init__7  s     ))$1a8r7   c                 &      fd}t        ||      S )Nc                      j                   j                  gj                  i j                  5   | |i |cd d d        S # 1 sw Y   y xY wr   )	__class__r-   r   kwds)fr0   r   r,   s      r5   r|   z'ContextManager.__call__.<locals>.caller;  s?    		CDIICC!zqz DCCs   AAr   )r,   r-   r|   s   `  r5   __call__zContextManager.__call__:  s    	" f%%r7   N)r   r   r   r6   r   r	   r7   r5   r   r   6  s    9&r7   r   c                     t        |       S r   )_contextmanager)r-   s    r5   contextmanagerr   D  s    4  r7   c                     d}t        |      D ])  \  }}t        ||       rd} nt        | |      s#| ||<   d}+ |r|j                  |        yy)z_
    Append ``a`` to the list of the virtual ancestors, unless it is already
    included.
    TFN)r#   
issubclassr%   )r0   
vancestorsaddjvas        r5   r%   r%   K  s^    
 C:&2b!CaJqMC ' ! r7   c                        sJ d       ddj                         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        y)z5Make sure one passes the expected number of argumentszExpected %d arguments, got %d%sN)r   r+   )	argumentswrongmsgdispatch_argss      r5   checkzdispatch_on.<locals>.checke  sF    Y]!34= /YEF G G 5r7   c                     t        t               j                        }t        	      |k  st        d
z        i 	fdfdfd}fd} fd}t        j                   d
z  t        |      | | 	
      S )
z4Decorator turning a function into a generic functionzUnknown dispatch arguments %sc                  .    |        t        t                    D cg c]  }g  }}	D ]D  }t        | ||      D ]2  \  }}}t        ||      s||j	                         vs't        ||       4 F |D cg c]  }t        |       c}S c c}w c c}w )zU
            Get a list of sets of virtual ancestors for the given types
            )ranger   zipr   mror%   rT   )
types_rastypes_ttype_rar   r   typemaps
          r5   r   z5dispatch_on.<locals>.gen_func_dec.<locals>.vancestorsu  s     %L$S%7898!28C9!$'vs$;LAub!!U+QUUW0Dub) %< " '**cCGc** :
 +s   	B8Bc                  (    |        g }t        |  |        D ]t  \  }}t        |      }|dkD  rt        d|d|      |dk(  r%|\  }t        d||fi       j	                         dd }n|j	                         }|j                  |dd        v |S )zG
            Get a list of virtual MROs, one for each type
            rG   zAmbiguous dispatch for z: r   Nrm   )r   r   RuntimeErrortyper   r%   )	r   listsr   vasn_vasr   r   r   r   s	          r5   	ancestorsz4dispatch_on.<locals>.gen_func_dec.<locals>.ancestors  s     %LEeZ%783C19&;<cBD DaZCBsQGR0446qr:C%%'CS"X& 9 Lr7   c                  (               fd}|S )zU
            Decorator to register an implementation for the given types
            c                      t        |       j                  t        j                  d| j                  z          | <   | S )Nz in )r   r   operatorltr   )r   r   r   r   s    r5   r   z@dispatch_on.<locals>.gen_func_dec.<locals>.register.<locals>.dec  s5    nQ',,hkk6AJJ;NO!"r7   r	   )r   r   r   r   s   ` r5   registerz3dispatch_on.<locals>.gen_func_dec.<locals>.register  s     %L Jr7   c                       |        g }t        j                   |   D ]#  }|j                  t        d |D                     % |S )zI
            An utility to introspect the dispatch algorithm
            c              3   4   K   | ]  }|j                     y wr   )r   )ro   r0   s     r5   rq   zKdispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info.<locals>.<genexpr>  s      9SSs   )r   productr%   r   )r   lstancr   r   s      r5   dispatch_infoz8dispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info  sG     %LC (()U*;<

5 9S 99: =Jr7   c                     t        d | D              }	 	|   } ||i |S # t        $ r Y nw xY wt        j                   |  }t	        |       |D ]  }	j                  |      }| ||i |c S   |i |S )Nc              3   2   K   | ]  }t        |        y wr   )r   )ro   r2   s     r5   rq   zGdispatch_on.<locals>.gen_func_dec.<locals>._dispatch.<locals>.<genexpr>  s     =}$s)}s   )r   KeyErrorr   r   rY   r@   )
r   r   rC   r   r   combinationsr   r   r-   r   s
          r5   	_dispatchz4dispatch_on.<locals>.gen_func_dec.<locals>._dispatch  s    =}==E&EN $~"~%   %,,i.?@L&KK'=d>b>) ' $$$s   " 	..z#return _f_(%s, %%(shortsignature)s))_f_)r   r   r   r   r   r   r   )rT   r   r   rW   r   r}   r)   )r-   argsetr   r   r   r   r   r   r   r   dispatch_strs   `    @@@r5   gen_func_decz!dispatch_on.<locals>.gen_func_deck  s     ^D)../=!V+;lJKK
	+	&
			%$ ##7,FY(D
i'T	 $ ; 	;r7   dispatch_on)r&   r   ner   )r   r   r   r   s   ` @@r5   r   r   ]  sQ    
 333=TYY}55L'{{ GU;n *L8Lr7   )r	   Fr~   )r   rer=   r   r   r   
contextlibr   r   r   r   __version__r[   rP   	ParameterPOSITIONAL_OR_KEYWORDr   emptyr   objectr   r   r   r   r   r   r   r   r%   r   r	   r7   r5   <module>r      s   <
 
 
    / L Lbjj12--Q=F Q=h3lB&- & N+!$fr7   