Your IP : 18.218.209.109
��Yfq�+@s�dZddddddddd d
dgZydd
lmZWnek
rUYnXddlmZddlmZddl m
Z
ddlmZyddl
mZWn%ek
r�Gdd�d�ZYnXdXZdYZeedd�Zeedd�Zedd�Zedd �Zed!d"�Zed#d$�Zed%d&�Zed'd(�Zed)d*�Zed+d,�Zed-d.�Zed/d0�Zed1d2�Zed3d4�Zd5d6efd7efd8efgd7d8efd5efd6efgd6d5efd8efd7efgd8d7efd6efd5efgiZ d9d�Z!d:d�Z"ydd;lm"Z"Wnek
r�YnXd<d �Z#ydd=lm#Z#Wnek
r�YnXGd>d
�d
e$�Z%ed?d@dAdBdCg�Z&GdDdE�dEe'�Z(e$�fe)e*e+e,dF�he-e.e,e/dGdH�Z0dIdJdKd�Z1dLdM�Z2yddNlm2Z2Wnek
ryYnXdOdP�Z3dFdQdR�Z4dSdT�Z5dUdV�Z6dWd�Z7dFS)ZzEfunctools.py - Tools for working with functions and callable objects
�update_wrapper�wraps�WRAPPER_ASSIGNMENTS�WRAPPER_UPDATES�total_ordering�
cmp_to_key� lru_cache�reduce�partial�
partialmethod�singledispatch�)r)�get_cache_token)�
namedtuple)�MappingProxyType)�WeakKeyDictionary)�RLockc@s.eZdZdZdd�Zdd�ZdS)rz/Dummy reentrant lock for builds without threadscCsdS)N�)�selfrr�./opt/alt/python35/lib64/python3.5/functools.py� __enter__szRLock.__enter__cCsdS)Nr)r�exctype�excinst�exctbrrr�__exit__szRLock.__exit__N)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrrrrr�__annotations__�__dict__c
Cs�xF|D]>}yt||�}Wntk
r4YqXt|||�qWx0|D](}t||�jt||i��qPW||_|S)aUpdate a wrapper function to look like the wrapped function
wrapper is the function to be updated
wrapped is the original function
assigned is a tuple naming the attributes assigned directly
from the wrapped function to the wrapper function (defaults to
functools.WRAPPER_ASSIGNMENTS)
updated is a tuple naming the attributes of the wrapper that
are updated with the corresponding attribute from the wrapped
function (defaults to functools.WRAPPER_UPDATES)
)�getattr�AttributeError�setattr�update�__wrapped__)�wrapper�wrapped�assigned�updated�attr�valuerrrr+s
& cCsttd|d|d|�S)a�Decorator factory to apply update_wrapper() to a wrapper function
Returns a decorator that invokes update_wrapper() with the decorated
function as the wrapper argument and the arguments to wraps() as the
remaining arguments. Default arguments are as for update_wrapper().
This is a convenience function to simplify applying partial() to
update_wrapper().
r&r'r()r r)r&r'r(rrrrIscCs0|j|�}||kr|S|o/||kS)zIReturn a > b. Computed by @total_ordering from (not a < b) and (a != b).)�__lt__)r�other�NotImplemented� op_resultrrr�_gt_from_ltasr/cCs|j|�}|p||kS)zEReturn a <= b. Computed by @total_ordering from (a < b) or (a == b).)r+)rr,r-r.rrr�_le_from_lthsr0cCs$|j|�}||kr|S|S)z=Return a >= b. Computed by @total_ordering from (not a < b).)r+)rr,r-r.rrr�_ge_from_ltmsr1cCs0|j|�}||kr|S|p/||kS)zJReturn a >= b. Computed by @total_ordering from (not a <= b) or (a == b).)�__le__)rr,r-r.rrr�_ge_from_letsr3cCs/|j|�}||kr|S|o.||kS)zFReturn a < b. Computed by @total_ordering from (a <= b) and (a != b).)r2)rr,r-r.rrr�_lt_from_le{sr4cCs$|j|�}||kr|S|S)z=Return a > b. Computed by @total_ordering from (not a <= b).)r2)rr,r-r.rrr�_gt_from_le�sr5cCs0|j|�}||kr|S|o/||kS)zIReturn a < b. Computed by @total_ordering from (not a > b) and (a != b).)�__gt__)rr,r-r.rrr�_lt_from_gt�sr7cCs|j|�}|p||kS)zEReturn a >= b. Computed by @total_ordering from (a > b) or (a == b).)r6)rr,r-r.rrr�_ge_from_gt�sr8cCs$|j|�}||kr|S|S)z=Return a <= b. Computed by @total_ordering from (not a > b).)r6)rr,r-r.rrr�_le_from_gt�sr9cCs0|j|�}||kr|S|p/||kS)zJReturn a <= b. Computed by @total_ordering from (not a >= b) or (a == b).)�__ge__)rr,r-r.rrr�_le_from_ge�sr;cCs/|j|�}||kr|S|o.||kS)zFReturn a > b. Computed by @total_ordering from (a >= b) and (a != b).)r:)rr,r-r.rrr�_gt_from_ge�sr<cCs$|j|�}||kr|S|S)z=Return a < b. Computed by @total_ordering from (not a >= b).)r:)rr,r-r.rrr�_lt_from_ge�sr=r+r6r2r:cs{�fdd�tD�}|s+td��t|�}x=t|D]1\}}||krB||_t�||�qBW�S)z6Class decorator that fills in missing ordering methodscs:g|]0}t�|d�tt|d�k r|�qS)N)r �object)�.0�op)�clsrr�
<listcomp>�s z"total_ordering.<locals>.<listcomp>z6must define at least one ordering operation: < > <= >=)�_convert�
ValueError�maxrr")rA�roots�root�opname�opfuncr)rArr�s cs G�fdd�dt�}|S)z,Convert a cmp= function into a key= functioncs�eZdZdgZdd�Z�fdd�Z�fdd�Z�fdd �Z�fd
d�Z�fdd
�Z dZ
dS)zcmp_to_key.<locals>.K�objcSs
||_dS)N)rJ)rrJrrr�__init__�szcmp_to_key.<locals>.K.__init__cs�|j|j�dkS)Nr)rJ)rr,)�mycmprrr+�szcmp_to_key.<locals>.K.__lt__cs�|j|j�dkS)Nr)rJ)rr,)rLrrr6�szcmp_to_key.<locals>.K.__gt__cs�|j|j�dkS)Nr)rJ)rr,)rLrr�__eq__�szcmp_to_key.<locals>.K.__eq__cs�|j|j�dkS)Nr)rJ)rr,)rLrrr2�szcmp_to_key.<locals>.K.__le__cs�|j|j�dkS)Nr)rJ)rr,)rLrrr:�szcmp_to_key.<locals>.K.__ge__N)rrr� __slots__rKr+r6rMr2r:�__hash__r)rLrr�K�s rP)r>)rLrPr)rLrr�s)rcs�t�d�rJ�j���jj�}|j��|�~�j����fdd�}�|_�|_�|_|S)zSNew function with partial application of the given arguments
and keywords.
�funccs*�j�}|j|���||�S)N)�copyr#)ZfargsZ fkeywordsZnewkeywords)�argsrQ�keywordsrr�newfunc�s
zpartial.<locals>.newfunc)�hasattrrSrTrRr#rQ)rQrSrTZtmpkwrUr)rSrQrTrr �s
)r c@sXeZdZdZdd�Zdd�Zdd�Zdd �Zed
d��Z dS)
r
z�Method descriptor with partial application of the given arguments
and keywords.
Supports wrapping existing descriptors and handles non-descriptor
callables as instance methods.
cOs�t|�r2t|d�r2tdj|���t|t�r�|j|_|j||_|jj �|_|jj
|�n||_||_||_dS)N�__get__z${!r} is not callable or a descriptor)�callablerV� TypeError�format�
isinstancer
rQrSrTrRr#)rrQrSrTrrrrKs zpartialmethod.__init__cCs}djtt|j��}djdd�|jj�D��}d}|jd|jjd|jj d|j
d|d |�S)
Nz, css'|]\}}dj||�VqdS)z{}={!r}N)rZ)r?�k�vrrr� <genexpr>)sz)partialmethod.__repr__.<locals>.<genexpr>z*{module}.{cls}({func}, {args}, {keywords})�modulerArQrSrT)�join�map�reprrSrT�itemsrZ� __class__rrrQ)rrSrT�
format_stringrrr�__repr__'s zpartialmethod.__repr__cs+�fdd�}�j|_�|_|S)NcsR�jj�}|j|�|^}}|f�jt|�}�j||�S)N)rTrRr#rS�tuplerQ)rSrT�
call_keywords�cls_or_self�rest� call_args)rrr�_method3s
z3partialmethod._make_unbound_method.<locals>._method)�__isabstractmethod__�_partialmethod)rrlr)rr�_make_unbound_method2s z"partialmethod._make_unbound_methodcCs�t|jdd�}d}|dk r�|||�}||jk r�t||j|j�}y|j|_Wntk
r�YnX|dkr�|j�j||�}|S)NrW) r rQr rSrT�__self__r!rorW)rrJrA�get�result�new_funcrrrrW=s
zpartialmethod.__get__cCst|jdd�S)NrmF)r rQ)rrrrrmPsz"partialmethod.__isabstractmethod__N)
rrrrrKrfrorW�propertyrmrrrrr
s� CacheInfo�hits�misses�maxsize�currsizec@s7eZdZdZdZedd�Zdd�ZdS)�
_HashedSeqz� This class guarantees that hash() will be called no more than once
per element. This is important because the lru_cache() will hash
the key multiple times on a cache miss.
� hashvaluecCs#||dd�<||�|_dS)N)r{)r�tup�hashrrrrKdsz_HashedSeq.__init__cCs|jS)N)r{)rrrrrOhsz_HashedSeq.__hash__N)rrrrrNr}rKrOrrrrrz[srzNc s�|} |rC||j��}
| |7} x|
D]}| |7} q/W|r�| |�fdd�|D��7} |r�| |�fdd�|
D��7} n0|| �dkr��| d�|kr�| dSt| �S)a�Make a cache key from optionally typed positional and keyword arguments
The key is constructed in a way that is flat as possible rather than
as a nested structure that would take more memory.
If there is only a single argument and its data type is known to cache
its hash value, then that argument is returned without a wrapper. This
saves space and improves lookup speed.
c3s|]}�|�VqdS)Nr)r?r])�typerrr^�sz_make_key.<locals>.<genexpr>c3s!|]\}}�|�VqdS)Nr)r?r\r])r~rrr^�s�r)rcrz)rS�kwds�typed�kwd_mark� fasttypes�sortedrgr~�len�key�sorted_items�itemr)r~r� _make_keyks
#&(r��FcsA�dk r(t�t�r(td����fdd�}|S)a�Least-recently-used cache decorator.
If *maxsize* is set to None, the LRU features are disabled and the cache
can grow without bound.
If *typed* is True, arguments of different types will be cached separately.
For example, f(3.0) and f(3) will be treated as distinct calls with
distinct results.
Arguments to the cached function must be hashable.
View the cache statistics named tuple (hits, misses, maxsize, currsize)
with f.cache_info(). Clear the cache and statistics with f.cache_clear().
Access the underlying function with f.__wrapped__.
See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
Nz)Expected maxsize to be an integer or Nonecs"t|��t�}t||�S)N)�_lru_cache_wrapper�
_CacheInfor)�
user_functionr%)rxr�rr�decorating_function�sz&lru_cache.<locals>.decorating_function)r[�intrY)rxr�r�r)rxr�rr�scsYt��t�
d\����i�d��d��j�t�� g�
�
�
ddg�
dd�<�dkr���fdd�}nr�dkr�����
����fdd�}n<��������� �
���
��fd d�}���� ��fd
d�}���� ��
fdd
�}||_||_|S)Nrr��Fcs�||�}�d7�|S)Nrr)rSr�rr)rwr�rrr%�s
z#_lru_cache_wrapper.<locals>.wrappercsb�||��}�|��}|�k r;�d7�|S�||�}|�|<�d7�|S)Nrr)rSr�r�rr)�cache� cache_getrv�make_keyrw�sentinelr�r�rrr%�s
cs�� ||�
�}����|�}|dk r�|\}}}}||�<||�<��}||�<��<||�<�|�<�d7�|SWdQRX�||�}���|�kr�n��r%�} || �<|| �<| ����}
��}d��<��<�|
=| �|<nH��}|�||g}||�<��<�|<�j��
k��d7�WdQRX|S)Nr)�__len__)rSr�r��linkZ link_prevZ link_nextZ_keyrrZlastZoldrootZoldkeyZ oldresult)�KEY�NEXT�PREV�RESULTr�r��fullrv�lockr�rxrwrGr�r�rrr%�sB
cs+�������j��SWdQRXdS)zReport cache statisticsN)r�r)r�r�rvr�rxrwrr�
cache_info
sz&_lru_cache_wrapper.<locals>.cache_infocsH��;�j���ddg�dd�<d��d�WdQRXdS)z$Clear the cache and cache statisticsNrF)�clearr)r�r�rvr�rwrGrr�cache_clears
z'_lru_cache_wrapper.<locals>.cache_clear)rrr�r�)r>r�rqrr�r�)r�rxr�r�r%r�r�r)r�r�r�r�r�r�r�r�rvr�r�rxrwrGr�r�r�rr��s(
*<9!! r�)r�cCs�g}x�dd�|D�}|s&|SxG|D]?}|d}x,|D]#}||dd�krDd}PqDWPq-W|dkr�td��|j|�x%|D]}|d|kr�|d=q�Wq WdS)z�Merges MROs in *sequences* to a single MRO using the C3 algorithm.
Adapted from http://www.python.org/download/releases/2.3/mro/.
cSsg|]}|r|�qSrr)r?�srrrrB1s z_c3_merge.<locals>.<listcomp>rrNzInconsistent hierarchy)�RuntimeError�append)� sequencesrr�s1� candidate�s2�seqrrr� _c3_merge)s$
r�c
s�xLtt|j��D]/\}�t�d�rt|j�|}PqWd}�rat��ng�t|jd|��}g}t|j|d��}xM�D]E�t|��r�t�fdd�|jD��r�|j��q�Wx|D]��j ��q�W�fdd�|D�}�fdd�|D�}�fd d�|D�} t
|gg||| |g|g|g�S)
a�Computes the method resolution order using extended C3 linearization.
If no *abcs* are given, the algorithm works exactly like the built-in C3
linearization used for method resolution.
If given, *abcs* is a list of abstract base classes that should be inserted
into the resulting MRO. Unrelated ABCs are ignored and don't end up in the
result. The algorithm inserts ABCs where their functionality is introduced,
i.e. issubclass(cls, abc) returns True for the class itself but returns
False for all its direct base classes. Implicit ABCs for a given class
(either registered or inferred from the presence of a special method like
__len__) are inserted directly after the last ABC explicitly listed in the
MRO of said class. If two implicit ABCs end up next to each other in the
resulting MRO, their ordering depends on the order of types in *abcs*.
�__abstractmethods__rNc3s|]}t|��VqdS)N)�
issubclass)r?�b)�baserrr^asz_c3_mro.<locals>.<genexpr>cs"g|]}t|d���qS)�abcs)�_c3_mro)r?r�)r�rrrBhs z_c3_mro.<locals>.<listcomp>cs"g|]}t|d���qS)r�)r�)r?r�)r�rrrBis cs"g|]}t|d���qS)r�)r�)r?r�)r�rrrBjs )� enumerate�reversed� __bases__rVr��listr��anyr��remover�)
rAr��i�boundary�explicit_bases�abstract_bases�other_bases�explicit_c3_mros�abstract_c3_mros�
other_c3_mrosr)r�r�rr�Ds("
r�cs]t�j����fdd���fdd��D���fdd���fdd��D��t���g}x��D]�}g}xR|j�D]D}|�kr�t�|�r�|j�fdd�|jD��q�W|s�|j|�q�|jd td
d�x8|D]0}x'|D]}||kr"|j|�q"WqWq�Wt�d|�S)
z�Calculates the method resolution order for a given class *cls*.
Includes relevant abstract base classes (with their respective bases) from
the *types* iterable. Uses a modified C3 linearization algorithm.
cs(|�ko't|d�o't�|�S)N�__mro__)rVr�)�typ)�basesrArr�
is_relatedzsz _compose_mro.<locals>.is_relatedcs"g|]}�|�r|�qSrr)r?�n)r�rrrB}s z _compose_mro.<locals>.<listcomp>cs4x-�D]%}||kr||jkrdSqWdS)NTF)r�)r�r,)�typesrr�is_strict_base�s
z$_compose_mro.<locals>.is_strict_basecs"g|]}�|�s|�qSrr)r?r�)r�rrrB�s cs"g|]}|�kr|�qSrr)r?r�)�type_setrrrB�s r��reverseTr�)�setr��__subclasses__r�r��sortr�r�)rAr��mror��found�sub�subclsr)r�rAr�r�r�r�r�_compose_mroqs*
'
r�cCs�t||j��}d}x|D]w}|dk r�||kr�||jkr�||jkr�t||�r�tdj||���P||kr"|}q"W|j|�S)a^Returns the best matching implementation from *registry* for type *cls*.
Where there is no registered implementation for a specific type, its method
resolution order is used to find a more generic implementation.
Note: if *registry* does not contain an implementation for the base
*object* type, this function may return None.
NzAmbiguous dispatch: {} or {})r��keysr�r�r�rZrq)rA�registryr��match�trrr�
_find_impl�s
r�cs�i�t��d����fdd��d����fdd���fdd�}|�t<�|_�|_t��|_�j|_t||�|S)alSingle-dispatch generic function decorator.
Transforms a function into a generic function, which can have different
behaviours depending upon the type of its first argument. The decorated
function acts as the default implementation, and additional
implementations can be registered using the register() attribute of the
generic function.
Ncs��dk r1t�}�|kr1�j�|�y�|}WnNtk
r�y�|}Wn!tk
r�t|��}YnX|�|<YnX|S)z�generic_func.dispatch(cls) -> <function implementation>
Runs the dispatch algorithm to return the best available implementation
for the given *cls* registered on *generic_func*.
N)r
r��KeyErrorr�)rA�
current_token�impl)�cache_token�dispatch_cacher�rr�dispatch�s
z singledispatch.<locals>.dispatchcs[|dkr��fdd�S|��<�dkrMt�d�rMt���j�|S)z�generic_func.register(cls, func) -> func
Registers a new implementation for the given *cls* on a *generic_func*.
Ncs
��|�S)Nr)�f)rA�registerrr�<lambda>�sz2singledispatch.<locals>.register.<locals>.<lambda>r�)rVr
r�)rArQ)r�r�r�r�)rArr��s
z singledispatch.<locals>.registercs�|dj�||�S)Nr)rd)rS�kw)r�rrr%�szsingledispatch.<locals>.wrapper) rr>r�r�rr�r��_clear_cacher)rQr%r)r�r�r�r�r�rr�s
)rrrrr)r)8r�__all__�
_functoolsr�ImportError�abcr
�collectionsrr�r�weakrefr�_threadrrrrrr-r/r0r1r3r4r5r7r8r9r;r<r=rCrrr r>r
r�r�rzr��str� frozensetr~r�rgr�r�rr�r�r�r�r�rrrrr�<module>s�
N %s
-)
?>