
    ⨽gB                     B   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y)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                   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   || _         |r?|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=|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/                  |      | _         |j2                  j5                         | _        |r|| _        ||| _        |r|| _        |r|| _        |r|| _        |r|| _        t;        | d      sJ t;        | d      st=        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	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                 R/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/decorator.py__init__zFunctionMaker.__init__A   s;   'DIyyJ&&	||DH//DK  &*T9;L;L*M(.#*41BB#G , :AD!WWa%89: (		2 4FAsD'A+s34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/   r0   kwframecallermodules        r8   rE   zFunctionMaker.updateu   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@   stderrrE   )r/   	src_templevaldict	addsourceattrssrcmor   r5   namesnfilenamecoder0   s                 r8   makezFunctionMaker.make   sd    $t*$>rZZ_:ACGHHxx{TF"1177<>#ciio > > ? 	FA((Q DEE	F ||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.
        (rJ   NrN   c              3   &   K   | ]	  }d |z     yw)z    Nr	   ).0lines     r8   	<genexpr>z'FunctionMaker.create.<locals>.<genexpr>   s     FD&4-Fs   rM   z#async def %(name)s(%(signature)s):
returnzreturn awaitzdef %(name)s(%(signature)s):
)
r    strrY   rX   r)   
splitlinesrC   r   replacerm   )clsobjbodyrd   r   r   r   re   rf   r   restr   r0   r/   ibodycallers                   r8   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<<r:   )NNNNNNNNF)NNNT)r   r   __qualname__r   	itertoolscountr]   r   r   r   r   r   r   r9   rE   rm   classmethodr   r	   r:   r8   r   r   4   sk     %Y__&N GIHDH7HUHXH
^7;@D2Lh!&"H 2604= =r:   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       r8   fixr      s8     
4	"6	"B77BIIr:   c                 j    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                  |_        	  j                   |_        	  j"                  |_        	  j$                  |_        	  j                  |_	        	 |j&                  j)                   j&                         |S # t        $ r Y {w xY w# t        $ r Y xw xY w# t        $ r Y uw xY w# t        $ r Y rw xY w# t        $ r  j                  dk(   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   rF   r~   extrasr0   kwsyntaxr   s     r8   funzdecorate.<locals>.fun   s;     tR-b=="====s   %/-/c               ?   b   K   st        | |      \  } } g| z   i |D ]  }|  y wr   r   )r   rF   resr~   r   r0   r   r   s      r8   r   zdecorate.<locals>.fun   sC     tR-bd;ftm;; 	s   ,/c                  F    st        | |      \  } } g| z   i |S r   r   r   s     r8   r   zdecorate.<locals>.fun   s1    tR-b$7&4-7B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      s    

D
!C$	))*''dii86"	> 	> 
V	$	 		8 	8
 ==CL,,CKCOC((C,,!00"22"}}DMM* J-          "!"  Jsl   
E E .E)  E8 F $%F% 	EE	E&%E&)	E54E58	FFF"!F"%	F21F2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))rM   rL   )r   r   )r   r   r,   r   )r0   r~   s    r8   deczdecoratorx.<locals>.dec  s6    ##7t,4+<+<	 $ > 	>r:   r	   )r~   r   s   ` r8   
decoratorxr     s    > Jr:   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 )NrJ   c              3      K   | ]<  }|j                   t        ur(j                  |j                  |j                          > y wr   )defaultEMPTYrC   r   )rr   prF   s     r8   rt   z)decorator.<locals>.dec.<locals>.<genexpr>*  s8      9"#!"%!7 !ffQVVQYY7 9s   AAc                      t        |       S r   r   )r0   r~   r   r   s    r8   <lambda>z(decorator.<locals>.dec.<locals>.<lambda>.  s    vvx H r:   )lentupler   )r0   r   rF   nar   r~   
dec_paramsr   s     ` @r8   r   zdecorator.<locals>.dec(  sR    Y] 9'1"#9 9 9 <HHD&&(;;r:   )
parametersr?   r   )r   r   r   r   valueskindPOSrx   r   r   r   r   r   r#   r?   r*   rE   )r~   _funcr   r   r   r   r   s   ` `   @r8   	decoratorr     s     vr844


F
#C ^^224F#!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   r9   )r/   gr3   ks       r8   r9   zContextManager.__init__?  s     ))$1a8r:   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__r0   r   kwds)fr3   r   r/   s      r8   r~   z'ContextManager.__call__.<locals>.callerC  sG    		CDIICC "!zqz" " "s   AA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   >  s    9&r:   r   c                     t        |       S r   )_contextmanager)r0   s    r8   contextmanagerr   L  s    4  r:   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(   )r3   
vancestorsaddjvas        r8   r(   r(   S  sc    
 C:& 2b!CaJqMC ! r:   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      r8   checkzdispatch_on.<locals>.checkm  sF    Y]!34= /YEF G G 5r:   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(   rW   )
types_rastypes_ttype_rar   r   typemaps
          r8   r   z5dispatch_on.<locals>.gen_func_dec.<locals>.vancestors}  s     %L$S%789!29C9! *$'vs$; *LAub!!U+QUUW0Dub)** '**CG** :
 +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
            rJ   zAmbiguous dispatch for z: r   Nrp   )r   r   RuntimeErrortyper   r(   )	r   listsr   vasn_vasr   r   r   r   s	          r8   	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&
' Lr:   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    r8   r   z@dispatch_on.<locals>.gen_func_dec.<locals>.register.<locals>.dec  s5    nQ',,hkk6AJJ;NO!"r:   r	   )r   r   r   r   s   ` r8   registerz3dispatch_on.<locals>.gen_func_dec.<locals>.register  s     %L Jr:   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   )rr   r3   s     r8   rt   zKdispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info.<locals>.<genexpr>  s      : :s   )r   productr(   r   )r   lstancsr   r   s      r8   dispatch_infoz8dispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info  sL     %LC!))9e+<= <

5 :T ::;<Jr:   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   )rr   r5   s     r8   rt   zGdispatch_on.<locals>.gen_func_dec.<locals>._dispatch.<locals>.<genexpr>  s     =$s)=s   )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 $~"~%   %,,i.?@L& *KK'=d>b>)* $$$s   " 	..z#return _f_(%s, %%(shortsignature)s))_f_)r   r   r   r   r   r   r   )rW   r   r   rZ   r   r   r,   )r0   argsetr   r   r   r   r   r   r   r   dispatch_strs   `    @@@r8   gen_func_decz!dispatch_on.<locals>.gen_func_decs  s     ^D)../=!V+;lJKK
	+	&
			%$ ##7,FY(D
i'T	 $ ; 	;r:   dispatch_on)r)   r   ner   )r   r   r   r   s   ` @@r8   r   r   e  sQ    
 333=TYY}55L'{{ GU;n *L8Lr:   )r	   Fr   )r   rer@   r   r   r   r!   
contextlibr   r   r   r   __version__r^   rS   	ParameterPOSITIONAL_OR_KEYWORDr   emptyr   objectr   r   r   r   r   r   r   r   r(   r   r	   r:   r8   <module>r      s   <
 
 
     / L Lbjj12--Q=F Q=h:zB&- & N+!$fr:   