U
    Q»{j«B  ã                   @   sÚ   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 d¡ZejjZejjZG dd„ deƒZd	d
„ Zddd„Zdd„ Zddd„ZG dd„ deƒZeeƒZdd„ Zdd„ Zd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                   @   sZ   e Zd ZdZe ¡ Zd Z Z Z	 Z
 ZZddd„Zdd„ Zdd	d
„Zed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                 C   sÞ  || _ |�rf|j| _| jdkr$d| _|j| _|j| _t |¡sLt	|t
jƒ�rft|ƒ}t|di ƒ| _dD ]}	t| |	t||	ƒƒ qft| jƒD ]\}
}t| d|
 |ƒ qˆt| jƒ}t| jƒ}| jrÞ| d| j ¡ | d| j ¡ n| jrî| d¡ | jD ]$}	| d|	 ¡ | d|	|	f ¡ qô| j�rB| d	| j ¡ | d	| j ¡ d
 |¡| _d
 |¡| _ |j ¡ | _|�rr|| _|d k	�r‚|| _|�rŽ|| _|�rš|| _|�r¦|| _|�r²|| _t| dƒ�sÂt‚t| dƒ�sÚtd| ƒ‚d S )Nz<lambda>Z_lambda_Ú__annotations__)ÚargsÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚkwonlydefaultszarg%dÚ*z%s=Nonez%s=%sz**ú, Ú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ÚAssertionErrorÚ	TypeError)ÚselfÚfuncr   r   r   r   r   ZfuncdictZargspecÚaÚiÚargZallargsZallshortargsr   r   úH/var/www/html/bwave/python/venv/lib/python3.8/site-packages/decorator.pyÚ__init__A   sZ    





zFunctionMaker.__init__c                 K   sš   | j |_t| ddƒ|_t| di ƒ|_| j|_| jp4d|_t| ddƒ|_	zt
 d¡}W n tk
rl   d}Y nX |j dd¡}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ÚAttributeErrorÚ	f_globalsÚgetr   Úupdate)r+   r,   ÚkwÚframeZcallermoduler   r   r0   r;   u   s    
zFunctionMaker.updateFc                 K   s  |t | ƒ }|pi }t |¡}|dkr2td| ƒ‚| d¡}t|gdd„ | j d¡D ƒ ƒ}|D ]}	|	dkr`td|	|f ƒ‚q`| 	d	¡s�|d	7 }d
t
| jƒ }
zt||
dƒ}t||ƒ W n2 tk
rê   tdtjd� t|tjd� ‚ Y nX || }|�r||d< | j|f|Ž |S )zT
        Make a new function from a given template and update the signature
        Nz not a valid function template
%sé   c                 S   s   g | ]}|  d ¡‘qS )z *)Ústrip©Ú.0r/   r   r   r0   Ú
<listcomp>’   s     z&FunctionMaker.make.<locals>.<listcomp>ú,)Ú_func_Ú_call_z%s is overridden in
%sÚ
z<decorator-gen-%d>ZsinglezError in generated code:)ÚfileZ
__source__)ÚvarsÚDEFÚsearchÚSyntaxErrorÚgroupÚsetr   ÚsplitÚ	NameErrorÚendswithÚnextÚ_compile_countÚcompileÚexecÚ	ExceptionÚprintr6   Ústderrr;   )r+   Z	src_templÚevaldictÚ	addsourceÚattrsÚsrcÚmor   ÚnamesÚnÚfilenameÚcoder,   r   r   r0   Úmakeˆ   s6    


ÿ

zFunctionMaker.makeTc                 K   s¨   t |tƒr0| ¡  dd¡\}	}
|
dd… }d}nd}	d}|}| ||	||||ƒ}d dd„ | ¡ D ƒ¡}| d¡}|rŽt|ƒrŽd	|  d
d¡}nd| }|j	|||f|Ž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.
        ú(r>   NéÿÿÿÿrF   c                 s   s   | ]}d | V  qdS )z    Nr   )rA   Úliner   r   r0   Ú	<genexpr>¾   s     z'FunctionMaker.create.<locals>.<genexpr>rE   z#async def %(name)s(%(signature)s):
Úreturnzreturn awaitzdef %(name)s(%(signature)s):
)
r   Ústrr?   rN   r$   Ú
splitlinesr:   r   Úreplacera   )ÚclsÚobjÚbodyrX   r   r   r   rY   rZ   r   Úrestr   r,   r+   ZibodyÚcallerr   r   r0   Úcreate¬   s"    	

 ÿzFunctionMaker.create)NNNNNNN)NF)NNNT)r   r   Ú__qualname__r   Ú	itertoolsÚcountrR   r	   r
   r   r   r   r   r1   r;   ra   Úclassmethodro   r   r   r   r0   r   4   s"           ÿ
4
$      ÿr   c                 C   s    |j | |Ž}| ¡  |j|jfS )zA
    Fix args and kwargs to be consistent with the signature
    )ÚbindÚapply_defaultsr	   Úkwargs)r	   rv   ÚsigÚbar   r   r0   ÚfixÈ   s    ry   r   Fc                    s~  t  ˆ¡‰tˆtjƒr$t ˆˆj¡‰tˆ ƒrB‡ ‡‡‡‡fdd„}n2tˆ ƒr`‡ ‡‡‡‡fdd„}n‡ ‡‡‡‡fdd„}ˆj	|_	ˆj
|_
ˆ|_ˆ|_ˆj|_zˆj|_W n tk
r¸   Y nX zˆj|_W n tk
rÚ   Y nX zˆj|_W n tk
rü   Y nX zˆj|_W n tk
�r    Y nX zˆj	|_	W n  tk
�rN   ˆj	dk Y nX z|j ˆj¡ W n tk
�rx   Y nX |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                  Ÿ   s.   ˆst | |ˆƒ\} }ˆ ˆfˆ|  ž|ŽI d H S ©N©ry   ©r	   r<   ©rn   Úextrasr,   Úkwsyntaxrw   r   r0   ÚfunÝ   s    zdecorate.<locals>.func                  ?   s8   ˆst | |ˆƒ\} }ˆ ˆfˆ|  ž|ŽD ]
}|V  q(d S rz   r{   )r	   r<   Úresr}   r   r0   r€   â   s    c                     s(   ˆst | |ˆƒ\} }ˆ ˆfˆ|  ž|ŽS rz   r{   r|   r}   r   r0   r€   è   s    Znoname)r   r   r   r   r   Úupdate_wrapperr,   r   r   r   r   Ú__wrapped__Ú__signature__rp   r4   r8   r5   r   r   r%   r;   )r,   rn   r~   r   r€   r   r}   r0   ÚdecorateÑ   sL    
r…   c                    s   ‡ fd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                    s   t j| dtˆ | d�| | jd�S )Nz)return _call_(_func_, %(shortsignature)s))rE   rD   )rƒ   rp   )r   ro   r'   rp   ©r,   ©rn   r   r0   Údec  s    
 üzdecoratorx.<locals>.decr   )rn   rˆ   r   r‡   r0   Ú
decoratorx  s    r‰   c                    s’   |dk	rt |ˆ dˆƒS t ˆ ¡}dd„ |j ¡ D ƒ‰d	‡ ‡‡fdd„	}|jˆd�|_ˆ j|_ˆ j|_ˆ |_	ˆ j
|_
tˆ ddƒ|_|j ˆ j¡ |S )
zG
    decorator(caller) converts a caller function into a decorator
    Nr   c                 S   s   g | ]}|j tkr|‘qS r   )ÚkindÚPOS©rA   Úpr   r   r0   rB   &  s     
 zdecorator.<locals>.<listcomp>c                    sX   t |ƒd }|t‡fdd„ˆ|d … D ƒƒ ‰ | d krF‡‡ ‡fdd„S t| ˆˆ ˆƒS d S )Nr>   c                 3   s(   | ] }|j tk	rˆ  |j|j ¡V  qd S rz   )ÚdefaultÚEMPTYr:   r   rŒ   )r<   r   r0   re   *  s   
þz)decorator.<locals>.dec.<locals>.<genexpr>c                    s   t | ˆ ˆˆƒS rz   ©r…   r†   )rn   r~   r   r   r0   Ú<lambda>.  ó    z(decorator.<locals>.dec.<locals>.<lambda>)ÚlenÚtupler…   )r,   r	   r<   Úna©rn   Z
dec_paramsr   )r~   r<   r0   rˆ   (  s    
ÿ
zdecorator.<locals>.dec)Ú
parametersr5   )N)r…   r   r   r—   Úvaluesri   r„   r   r   rƒ   rp   r   r5   r%   r;   )rn   Z_funcr   rw   rˆ   r   r–   r0   Ú	decorator  s    
	r™   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚContextManagerc                 O   s   t  | |||¡ d S rz   )r   r1   )r+   Úgr-   Úkr   r   r0   r1   ?  s    zContextManager.__init__c                    s   ‡ fdd„}t ||ƒS )Nc              
      s:   ˆ j ˆ jfˆ jžˆ jŽ� | ||ŽW  5 Q R £ S Q R X d S rz   )Ú	__class__r,   r	   Úkwds)Úfr-   rœ   ©r+   r   r0   rn   C  s    z'ContextManager.__call__.<locals>.callerr�   )r+   r,   rn   r   r    r0   Ú__call__B  s    zContextManager.__call__N)r   r   rp   r1   r¡   r   r   r   r0   rš   >  s   rš   c                 C   s   t | ƒS rz   )Ú_contextmanagerr†   r   r   r0   ÚcontextmanagerL  s    r£   c                 C   sP   d}t |ƒD ]0\}}t|| ƒr&d} q>t| |ƒr| ||< d}q|rL| | ¡ dS )z_
    Append ``a`` to the list of the virtual ancestors, unless it is already
    included.
    TFN)r!   Ú
issubclassr#   )r-   Ú
vancestorsÚaddÚjÚvar   r   r0   r#   S  s    

r#   c                     sL   ˆst dƒ‚dd ˆ¡ ‰tjdf‡fdd„	‰ ‡ ‡‡fdd„}d	ˆ |_|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                    s0   |t | ƒt ˆ ƒƒr,tdt ˆ ƒt | ƒ|f ƒ‚dS )z5Make sure one passes the expected number of argumentszExpected %d arguments, got %d%sN)r“   r*   )Ú	argumentsZwrongÚmsg)Údispatch_argsr   r0   Úcheckm  s    ÿzdispatch_on.<locals>.checkc                    sœ   t tˆƒjƒ}t ˆƒ|ks&tdˆ ƒ‚i ‰‡‡‡fdd„‰‡‡fdd„‰ ‡‡fdd„}‡ ‡fdd	„}‡ ‡‡fd
d„}tjˆdˆ t|d�|ˆˆˆˆ |ˆd�
S )z4Decorator turning a function into a generic functionzUnknown dispatch arguments %sc                     sn   ˆ | ƒ dd„ t tˆƒƒD ƒ}ˆD ]<}t| ||ƒD ]*\}}}t||ƒr2|| ¡ kr2t||ƒ q2q"dd„ |D ƒS )zU
            Get a list of sets of virtual ancestors for the given types
            c                 S   s   g | ]}g ‘qS r   r   )rA   Ú_r   r   r0   rB   ‚  s     zIdispatch_on.<locals>.gen_func_dec.<locals>.vancestors.<locals>.<listcomp>c                 S   s   g | ]}t |ƒ‘qS r   )rM   )rA   Úrar   r   r0   rB   ‡  s     )Úranger“   Úzipr¤   Úmror#   )ÚtypesZrasÚtypes_ÚtÚtype_r¯   )r­   r¬   Útypemapr   r0   r¥   }  s    z5dispatch_on.<locals>.gen_func_dec.<locals>.vancestorsc                     s�   ˆ | ƒ g }t | ˆ| Ž ƒD ]p\}}t|ƒ}|dkrDtd||f ƒ‚n4|dkrp|\}td||fi ƒ ¡ dd… }n| ¡ }| |dd… ¡ q|S )zG
            Get a list of virtual MROs, one for each type
            r>   zAmbiguous dispatch for %s: %srµ   Nrc   )r±   r“   ÚRuntimeErrorÚtyper²   r#   )r³   Úlistsrµ   ZvasZn_vasr¨   r²   )r­   r¥   r   r0   Ú	ancestors‰  s    
ÿz4dispatch_on.<locals>.gen_func_dec.<locals>.ancestorsc                     s   ˆˆ ƒ ‡‡‡ fdd„}|S )zU
            Decorator to register an implementation for the given types
            c                    s&   ˆ t | ƒjtjd| j ƒ | ˆˆ< | S )Nz in )r   r	   ÚoperatorÚltr   )rŸ   )r­   r·   r³   r   r0   rˆ   ¢  s    z@dispatch_on.<locals>.gen_func_dec.<locals>.register.<locals>.decr   )r³   rˆ   )r­   r·   )r³   r0   Úregisterœ  s    z3dispatch_on.<locals>.gen_func_dec.<locals>.registerc                     s<   ˆ| ƒ g }t jˆ | Ž Ž D ]}| tdd„ |D ƒƒ¡ q|S )zI
            An utility to introspect the dispatch algorithm
            c                 s   s   | ]}|j V  qd S rz   )r   )rA   r-   r   r   r0   re   ¯  s     zKdispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info.<locals>.<genexpr>)rq   Úproductr#   r”   )r³   ÚlstZancs)r»   r­   r   r0   Údispatch_info¨  s
    z8dispatch_on.<locals>.gen_func_dec.<locals>.dispatch_infoc                    sˆ   t dd„ | D ƒƒ}zˆ| }W n tk
r2   Y nX |||ŽS tjˆ |Ž Ž }t|ƒ |D ]$}ˆ |¡}|d k	rX|||Ž  S qXˆ||ŽS )Nc                 s   s   | ]}t |ƒV  qd S rz   )r¹   r@   r   r   r0   re   ³  s     zGdispatch_on.<locals>.gen_func_dec.<locals>._dispatch.<locals>.<genexpr>)r”   ÚKeyErrorrq   r¿   rQ   r:   )r¬   r	   r<   r³   rŸ   Úcombinationsr´   )r»   r,   r·   r   r0   Ú	_dispatch²  s    

z4dispatch_on.<locals>.gen_func_dec.<locals>._dispatchz#return _f_(%s, %%(shortsignature)s))Z_f_)r¾   rŽ   r·   r¥   r»   rÁ   rƒ   )rM   r   r	   rO   r   ro   r'   )r,   Zargsetr¾   rÁ   rÄ   ©r­   r¬   Zdispatch_str)r»   r,   r·   r¥   r0   Úgen_func_decs  s*    
      üz!dispatch_on.<locals>.gen_func_decÚdispatch_on)r)   r$   r¼   Úner   )r¬   rÆ   r   rÅ   r0   rÇ   e  s    W
rÇ   )r   F)NF)r   Úrer6   r   r¼   rq   r   Ú
contextlibr   r   r   r   Ú__version__rS   rI   Ú	ParameterÚPOSITIONAL_OR_KEYWORDr‹   Úemptyr�   Úobjectr   ry   r…   r‰   r™   rš   r¢   r£   r#   rÇ   r   r   r   r0   Ú<module>   s.   
 	
=
!