
    iFC                        d Z ddlm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Z	ej                  dk\  r
ddlmZ d Zn ej                  dd	      Zd
 Zd Z	 ej                  Z	 ddlmZ  ej&                  d      Z G d de      ZddZd dZ	 ddlmZ  G d de      Z eej:                        Z eej@                        Z!e!dk(  rejD                  sd Zee_        n!e!dk(  rejD                  rne!dk(  r
d Zee_         ee      Z#d Z$d Z%d Z&y# e$ r d ZY w xY w# e$ r d ZY w xY w# e$ r	 ddlmZ Y w xY w)!zT
Decorator module, see http://pypi.python.org/pypi/decorator
for the documentation.
    )print_functionNz4.4.2)   )getfullargspecc                     | j                   S N)__init__clss    G/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/decorator.pyget_initr   0   s    ||    FullArgSpeczAargs varargs varkw defaults kwonlyargs kwonlydefaults annotationsc                 ^    t         j                  t        j                  |       g di fz         S )z?A quick and dirty replacement for getfullargspec for Python 2.XN)r   _makeinspect
getargspecfs    r   r   r   7   s)      !3!3A!6"dB!GHHr   c                 .    | j                   j                  S r   )r   __func__r	   s    r   r   r   ;   s    ||$$$r   c                      yNF r   s    r   iscoroutinefunctionr   B       r   )isgeneratorfunctionc                      yr   r   )callers    r   r   r   H   r   r   z\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.
    r   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 )N<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__moduler   
isfunctionr   getattrannotationssetattr	enumerater%   listr&   appendr)   r'   joinr/   __dict__copydictr(   hasattr	TypeError)selffuncr.   r/   r(   r3   r5   funcdictargspecaiargallargsallshortargss                 r   r   zFunctionMaker.__init__]   s,   'DIyyJ&&	||DH//DK!!$'(.#*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 *r   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)	z2Update the signature of func with the data in selfr3   Nr@   r8   r   r1   ?r5   )r.   r1   r7   r2   r>   r(   __defaults__r*   __kwdefaults__r$   sys	_getframe	f_globalsgetAttributeErrorr4   update)rC   rD   kwframecallermodules        r   rU   zFunctionMaker.update   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)zBMake a new function from a given template and update the signaturez 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setr0   splitstrip	NameErrorendswithnext_compile_countcompileexec	ExceptionprintrP   stderrrU   )rC   	src_templevaldict	addsourceattrssrcmor.   rI   namesnfilenamecoderD   s                 r   makezFunctionMaker.make   sb   $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.
        (rZ   Nr^   c              3   &   K   | ]	  }d |z     yw)z    Nr   ).0lines     r   	<genexpr>z'FunctionMaker.create.<locals>.<genexpr>   s     FD&4-Fs   r]   z#async def %(name)s(%(signature)s):
returnzreturn awaitzdef %(name)s(%(signature)s):
)

isinstancestrri   rh   r=   
splitlinesrS   r   replacer}   )r
   objbodyrt   r(   r3   r5   ru   rv   r.   restr/   rD   rC   ibodyr   s                   r   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   )NNNNNNNr   )NNNT)r1   r4   __qualname__r2   	itertoolscountrm   r%   r&   r'   r(   r)   r*   r   rU   r}   classmethodr   r   r   r   r    r    P   sk     %Y__&N GIHDH7HUHXH
^7;@D2Lh!" D 2604= =r   r    c                    t        ||       }d}t        |      D ]  \  }}d|z  }|||<   ||dz   z  } dt        j                  cxk  rdk  rn nt	        |      xr t        |       }nt	        |      }|rt        j                  | d|z  ||       }	nt        j                  | d	|z  ||       }	t        | d
      r| j                  |	_	        |	S )z
    decorate(func, caller) decorates a function using a caller.
    If the caller is a generator function, the resulting function
    will be a generator function.
    )r]   r\    z_e%d_r-   z3.5z3.6z?for res in _call_(_func_, %s%%(shortsignature)s):
    yield res__wrapped__z,return _call_(_func_, %s%%(shortsignature)s)r   )
r@   r:   rP   versionr   r   r    r   rA   r   )
rD   r   extrasrt   esrH   extraexgeneratorcallerfuns
             r   decorater      s    6$/H	Bf% 5q[
b4i
 #e# . 8/77 	 .f5"" "$&'(0d # D ""@2E$ # ( t^$,,Jr   c                 2   |t        ||       S d\  }}t        j                  |       r8| j                  j	                         }d| j                  d| j                  d}nt        j
                  |       r| j                  dk(  rd}n| j                  }| j                  }| j                  j                  }t        | j                  xs d      }dj                  | j                  j                  ||z
  |       }|r|d	z  }| j                  }n:| j                  j                  j	                         }| j                  j                  }t        | t         
      }t         j#                  |d|dd|d|d||| j$                  |       }	|r
d|z   |	_
        |	S )z=decorator(caller) converts a caller function into a decorator)r   r   z
decorator(z2) converts functions/generators into factories of z objectsr"   r#   r   r-   r[   )_call
_decorate_z(func, )z?if func is None: return lambda func:  _decorate_(func, _call, (z#))
return _decorate_(func, _call, (z)))r3   r5   r   r   )r   r   isclassr1   lowerr6   r2   __code__co_argcountlenrN   r=   co_varnames	__class____call__r@   r    r   r4   )
r   _funcdefaultargsr(   r.   r3   nargsndefsrt   decs
             r   	decoratorr     sf   v&&"Kv$$&)/&//K			F	#??j(D??Dnn++F''-2.ii ; ;E%K NO3K&&((..0oo%%&X6H


,2={	Lc&"3"3	  IC
 "X-Jr   )_GeneratorContextManager)GeneratorContextManagerc                       e Zd Zd Zy)ContextManagerc                 J    t         j                  |dt        | |      |      S )zContext manager decoratorz.with _self_: return _func_(%(shortsignature)s))_self_r\   r   )r    r   r@   )rC   rD   s     r   r   zContextManager.__call__0  s,    ##BT* $ > 	>r   N)r1   r4   r   r   r   r   r   r   r   /  s    >r   r      c                 :    t        j                  |  ||i |      S r   r   r   rC   grG   ks       r   r   r   :  s    '00q!zqzBBr      c                 2    t        j                  | |||      S r   r   r   s       r   r   r   @  s    '00q!Q??r   c                     t        |       S r   )_contextmanager)rD   s    r   contextmanagerr   G  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<   )rG   
vancestorsaddjvas        r   r<   r<   N  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-   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   rB   )	argumentswrongmsgdispatch_argss      r   checkzdispatch_on.<locals>.checkh  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<   rg   )
types_rastypes_ttype_rar   r   typemaps
          r   r   z5dispatch_on.<locals>.gen_func_dec.<locals>.vancestorsx  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
            rZ   zAmbiguous dispatch for z: r   Nr   )r   r   RuntimeErrortyper   r<   )	r   listsr   vasn_vasr   r   r   r   s	          r   	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ltr1   )r   r   r   r   s    r   r   z@dispatch_on.<locals>.gen_func_dec.<locals>.register.<locals>.dec  s5    nQ',,hkk6AJJ;NO!"r   r   )r   r   r   r   s   ` r   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   )r1   )r   rG   s     r   r   zKdispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info.<locals>.<genexpr>  s      9 9s   )r   productr<   tuple)r   lstancr   r   s      r   dispatch_infoz8dispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info  sL     %LC (()U*;< ;

5 9S 99:;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   )r   rI   s     r   r   zGdispatch_on.<locals>.gen_func_dec.<locals>._dispatch.<locals>.<genexpr>  s     =$s)=s   )r   KeyErrorr   r   rl   rS   )
r   r%   rV   r   r   combinationsr   r   rD   r   s
          r   	_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   defaultr   r   r   r   r   )rg   r   r%   rj   r    r   r@   )rD   argsetr   r   r   r   r   r   r   r   dispatch_strs   `    @@@r   gen_func_decz!dispatch_on.<locals>.gen_func_decn  s     ^D)../=!V+;lJKK
	+	&
			%$ ##7,FY(D
i'T	 $ ; 	;r   dispatch_on)r=   r   ner1   )r   r   r   r   s   ` @@r   r   r   `  sQ    
 333=TYY}55L'{{ GU;n *L8Lr   )r   r   )'r2   
__future__r   rerP   r   r   r   collections__version__version_infor   r   
namedtupler   r   rT   r   ImportErrorrn   rc   objectr    r   r   
contextlibr   r   r   r   initr   r%   n_argsr&   r   r   r<   r   r   r   r   <module>r     s|  < & 	 
    t& )+(( 01KI%!55
+ bjj12M=F M=`D"NO3
>- > .778	TYY	Q;t||C&Nq[T\\q[@&NN+!$fA	    J  ONOs6   D #D! D/ DD!D,+D,/D=<D=