Sindbad~EG File Manager
3
5*[Z�@�@s�dZddlmZddlZddlZddlZddlZddlZddlZdZ ej
dkrdddlmZdd�Znej
d d
�Zdd�Zd
d�Zy
ejZWnek
r�dd�ZYnXej
dd�Zdd�Zejd�ZGdd�de�Zffdd�Zd*dd�ZyddlmZWn"ek
�rddlmZYnXGdd�de�Zeej�Ze ej!�Z"e"dk�rhej#�rhd d!�Zee_n,e"dk�r|ej#�r|ne"d"k�r�d#d!�Zee_ee�Z$d$d%�Z%d&d'�Z&d(d)�Z'dS)+zT
Decorator module, see http://pypi.python.org/pypi/decorator
for the documentation.
�)�print_functionNz4.2.1�3)�getfullargspeccCs|jS)N)�__init__)�cls�r�/usr/lib/python3.6/decorator.py�get_init0sr �FullArgSpecz5args varargs varkw defaults kwonlyargs kwonlydefaultscCstjtj|�gdf�S)z?A quick and dirty replacement for getfullargspec for Python 2.XN)r
�_make�inspect�
getargspec)�frrrr7srcCs|jjS)N)r�__func__)rrrrr ;scCsdS)NFr)rrrr�iscoroutinefunctionBsr�ArgSpeczargs varargs varkw defaultscCst|�}t|j|j|j|j�S)z$A replacement for inspect.getargspec)rr�args�varargs�varkw�defaults)r�specrrrr
Jsr
z\s*def\s*([_\w][_\w\d]*)\s*\(c@sZeZdZdZej�ZfZZZ Z
ZZd
dd�Z
dd�Zddd �Zeddd��ZdS)�
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.
NcCs�||_|�rf|j|_|jdkr$d|_|j|_|j|_tj|��rft |�}t
|di�|_xdD]} t|| t
|| ��q\Wx&t
|j�D]\}
}t|d
|
|�q�Wt|j�}t|j�}
|jr�|jd|j�|
jd|j�n|jr�|jd�x.|jD]$} |jd| �|
jd
| | f�q�W|j�rB|jd|j�|
jd|j�dj|�|_dj|
�|_|jj�|_|�rr||_|dk �r�||_|�r�||_|�r�||_|�r�||_|�r�||_t|d��s�t�t|d��s�td|��dS)Nz<lambda>�_lambda_�__annotations__rrrr�
kwonlyargs�kwonlydefaultszarg%d�*z%s=Nonez%s=%sz**z, �name� signaturez%You are decorating a non function: %s)rrrrrr)�shortsignature�__name__r�__doc__�doc�
__module__�moduler�
isfunctionr�getattr�annotations�setattr� enumerater�listr�appendrr�joinr�__dict__�copy�dictr�hasattr�AssertionError� TypeError)�self�funcrrrr"r$ZfuncdictZargspec�a�i�argZallargsZallshortargsrrrras\
zFunctionMaker.__init__cKs�|j|_t|dd�|_t|di�|_|j|_|jp4d|_t|dd�|_ yt
jd�}Wntk
rld}YnX|j
jdd�}t|d|�|_|jj|�dS) z2Update the signature of func with the data in selfr"Nr/r'��?r r$)rr r&r!r-r�__defaults__r�__kwdefaults__r�sys� _getframe�AttributeError� f_globals�getr#�update)r3r4�kw�frameZcallermodulerrrrA�s
zFunctionMaker.updateFc
Ks|t|�}|pi}tj|�}|dkr2td|��|jd�}t|gdd�|jjd�D��}x$|D]} | dkrbtd | |f��qbW|j d
�s�|d
7}dt
|j�f}
yt||
d�}t
||�Wn*td
tjd�t|tjd��YnX||}|�r||d<|j|f|�|S)zBMake a new function from a given template and update the signatureNz not a valid function template
%s�cSsg|]}|jd��qS)z *)�strip)�.0r7rrr�
<listcomp>�sz&FunctionMaker.make.<locals>.<listcomp>�,�_func_�_call_z%s is overridden in
%s�
z<decorator-gen-%d>ZsinglezError in generated code:)�fileZ
__source__)rIrJ)�vars�DEF�search�SyntaxError�group�setr�split� NameError�endswith�next�_compile_count�compile�exec�printr<�stderrrA)
r3Z src_templ�evaldict� addsource�attrs�src�mor�names�n�filename�coder4rrr�make�s4
zFunctionMaker.makeTcKs�t|t�r0|j�jdd�\} }
|
dd�}d}nd} d}|}||| ||||�}
djdd�|j�D��}|jd�}|r�t|�r�d|jd d
�}nd|}|
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.
�(rDNrKcss|]}d|VqdS)z Nr)rF�linerrr� <genexpr>�sz'FunctionMaker.create.<locals>.<genexpr>rJz#async def %(name)s(%(signature)s):
�returnzreturn awaitzdef %(name)s(%(signature)s):
���)
�
isinstance�strrErSr,�
splitlinesr@r�replacere)r�objZbodyr\rr"r$r]r^r�restrr4r3Zibody�callerrrr�create�s
zFunctionMaker.create)NNNNNNN)NF)NNNT)r r#�__qualname__r!� itertools�countrWrrrrrrrrAre�classmethodrrrrrrrTs
3
"rc Csnt||d�}d}x0t|�D]$\}}d|}|||<||d7}qWtj|d|||d�}t|d�rj|j|_|S)zE
decorate(func, caller) decorates a function using a caller.
)rJrI�z_e%d_z, z,return _call_(_func_, %s%%(shortsignature)s))�__wrapped__rs)r/r)rrrr0rs) r4rqZextrasr\Zesr6ZextraZexZfunrrr�decorate�s
ryc
Cs|dk rt||�Sdf}}tj|�rB|jj�}d|j|jf}n~tj|�r�|jdkr\d}n|j}|j}|jj}t |j
pzf�}dj|jj|||��}|r�|d7}|j
}n|j
jj�}|jj}t|td�}tjd ||fd
||f|||j|d�} |�rd|| _
| S)
z=decorator(caller) converts a caller function into a decoratorNrwzHdecorator(%s) converts functions/generators into factories of %s objectsz<lambda>rz, rH)�_callZ
_decorate_z%s(func, %s)zhif func is None: return lambda func: _decorate_(func, _call, (%s))
return _decorate_(func, _call, (%s)))r"r$rx)N)ryrZisclassr �lowerr%r!�__code__�co_argcount�lenr:r,�co_varnames� __class__�__call__r/rrrr#)
rqZ_funcZdefaultargsrrr"�nargsZndefsr\�decrrr� decorator�s:
r�)�_GeneratorContextManager)�GeneratorContextManagerc@seZdZdd�ZdS)�ContextManagercCstj|dt||d�|d�S)zContext manager decoratorz.with _self_: return _func_(%(shortsignature)s))Z_self_rI)rx)rrrr/)r3r4rrrr�#szContextManager.__call__N)r r#rsr�rrrrr�"sr��cOstj||||��S)N)r�r)r3�gr5�krrrr-sr�cOstj||||�S)N)r�r)r3r�r5r�rrrr3scCst|�S)N)�_contextmanager)r4rrr�contextmanager:sr�cCsRd}x:t|�D].\}}t||�r&d}Pt||�r|||<d}qW|rN|j|�dS)z_
Append ``a`` to the list of the virtual ancestors, unless it is already
included.
TFN)r)�
issubclassr+)r5�
vancestors�add�j�varrrr+As
r+csL�std��ddj���tjdf�fdd� ����fdd�}d �|_|S)
zr
Factory of decorators turning a function into a generic function
dispatching on the given arguments.
zNo dispatch args passedz(%s,)z, rwcs0|t|�t���r,tdt��t|�|f��dS)z5Make sure one passes the expected number of argumentszExpected %d arguments, got %d%sN)r~r2)Z argumentsZwrong�msg)�
dispatch_argsrr�check[szdispatch_on.<locals>.checkcs�tt��j�}t��|ks&td���i����fdd����fdd����fdd�}��fdd �}���fd
d�}tj�d�t|d
�|����|�d�
S)z4Decorator turning a function into a generic functionzUnknown dispatch arguments %scsv�|�dd�tt���D�}xH�D]@}x:t|||�D]*\}}}t||�r6||j�kr6t||�q6Wq$Wdd�|D�S)zU
Get a list of sets of virtual ancestors for the given types
cSsg|]}g�qSrr)rF�_rrrrGpszIdispatch_on.<locals>.gen_func_dec.<locals>.vancestors.<locals>.<listcomp>cSsg|]}t|��qSr)rR)rF�rarrrrGus)�ranger~�zipr��mror+)�typesZras�types_�tZtype_r�)r�r��typemaprrr�ks
z5dispatch_on.<locals>.gen_func_dec.<locals>.vancestorscs��|�g}x�t|�|��D]p\}}t|�}|dkrFtd||f��n4|dkrr|\}td||fi�j�dd�}n|j�}|j|dd��qW|S)zG
Get a list of virtual MROs, one for each type
rDzAmbiguous dispatch for %s: %sr�Nrj)r�r~�RuntimeError�typer�r+)r�Zlistsr�ZvasZn_vasr�r�)r�r�rr� ancestorswsz4dispatch_on.<locals>.gen_func_dec.<locals>.ancestorscs������fdd�}|S)zU
Decorator to register an implementation for the given types
cs&�t|�jtjd|j�|��<|S)Nz in )rr�operator�ltr )r)r�r�r�rrr��sz@dispatch_on.<locals>.gen_func_dec.<locals>.register.<locals>.decr)r�r�)r�r�)r�r�register�sz3dispatch_on.<locals>.gen_func_dec.<locals>.registercs@�|�g}x.tj�|��D]}|jtdd�|D���qW|S)zI
An utility to introspect the dispatch algorithm
css|]}|jVqdS)N)r )rFr5rrrrh�szKdispatch_on.<locals>.gen_func_dec.<locals>.dispatch_info.<locals>.<genexpr>)rt�productr+�tuple)r�ZlstZanc)r�r�rr�
dispatch_info�s
z8dispatch_on.<locals>.gen_func_dec.<locals>.dispatch_infocs�tdd�|D��}y�|}Wntk
r2YnX|||�Stj�|��}t|�x(|D] }�j|�}|dk rZ|||�SqZW�||�S)Ncss|]}t|�VqdS)N)r�)rFr7rrrrh�szGdispatch_on.<locals>.gen_func_dec.<locals>._dispatch.<locals>.<genexpr>)r��KeyErrorrtr�rVr@)r�rrBr�r�combinationsr�)r�r4r�rr� _dispatch�s
z4dispatch_on.<locals>.gen_func_dec.<locals>._dispatchz#return _f_(%s, %%(shortsignature)s))Z_f_)r��defaultr�r�r�r�rx)rRrrrTrrrr/)r4Zargsetr�r�r�)r�r��dispatch_str)r�r4r�r�r�gen_func_decas
z!dispatch_on.<locals>.gen_func_dec�dispatch_on)r1r,r��ner )r�r�r)r�r�r�rr�SsW
r�)N)(r!Z
__future__r�rer<rr�rt�collections�__version__�versionrr �
namedtupler
rr>rr
rXrN�objectrryr��
contextlibr��ImportErrorr�r�rZinitr~rZn_argsrr�r�r+r�rrrr�<module>!s\
&
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists