grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ”qcqã+@s½dZddddddddd d d g Zyd d lmZWnek rUYnXd dlmZd dlmZd dl m Z d dl m Z yd dl 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"yd d;lm"Z"Wnek r€YnXd<d „Z#yd d=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„Z2yd dNlm2Z2Wnek 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__rrrrrrrs  rrrrrÚ__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(rrrrIs cCs0|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_ltas r/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_ltms r1cCs0|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_lets r3cCs/|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{s r4cCs$|j|ƒ}||kr|S| S)z=Return a > b. Computed by @total_ordering from (not a <= b).)r2)rr,r-r.rrrÚ _gt_from_le‚s r5cCs0|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‰s r7cCs|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•s r9cCs0|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œs r;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£s r<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ªs r=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ú Ãs z"total_ordering..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‡fd d †Z dZ dS)zcmp_to_key..KÚobjcSs ||_dS)N)rJ)rrJrrrÚ__init__Öszcmp_to_key..K.__init__csˆ|j|jƒdkS)Nr )rJ)rr,)Úmycmprrr+Øszcmp_to_key..K.__lt__csˆ|j|jƒdkS)Nr )rJ)rr,)rLrrr6Úszcmp_to_key..K.__gt__csˆ|j|jƒdkS)Nr )rJ)rr,)rLrrÚ__eq__Üszcmp_to_key..K.__eq__csˆ|j|jƒdkS)Nr )rJ)rr,)rLrrr2Þszcmp_to_key..K.__le__csˆ|j|jƒdkS)Nr )rJ)rr,)rLrrr:àszcmp_to_key..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 fkeywordsZ newkeywords)ÚargsrQÚkeywordsrrÚnewfuncüs  zpartial..newfunc)ÚhasattrrSrTrRr#rQ)rQrSrTZtmpkwrUr)rSrQrTrr ðs      )r c@sXeZdZdZdd„Zdd„Zdd„Zdd „Zed d „ƒZ d S) 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__c Cs}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ú )sz)partialmethod.__repr__..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.._method)Ú__isabstractmethod__Ú_partialmethod)rrlr)rrÚ_make_unbound_method2s  z"partialmethod._make_unbound_methodc Csª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[s rzNc 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..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..decorating_function)r[ÚintrY)rxr�rŽr)rxr�rr‡s csYtƒ‰t‰ d\‰‰‰‰i‰d‰‰ d‰ˆj‰tƒ‰ g‰ ˆ ˆ ddgˆ dd…<ˆ dkr�‡ ‡fdd†}nrˆ dkr҇‡‡ ‡ ‡‡‡fdd†}n<‡‡‡‡‡‡‡‡‡ ‡ ‡ ‡ ‡ ‡‡fd d†}‡‡‡‡ ‡ ‡ fd d †}‡‡‡‡ ‡ ‡ fd d †}||_||_|S)Nr rééFcsˆ||Ž}ˆd7‰|S)Nrr)rSr€rr)rwr�rrr%¼s z#_lru_cache_wrapper..wrappercsbˆ||ˆƒ}ˆ|ˆƒ}|ˆk r;ˆd7‰|Sˆ||Ž}|ˆ|<ˆd7‰|S)Nrr)rSr€r†rr)ÚcacheÚ cache_getrvÚmake_keyrwÚsentinelr�r�rrr%Ås    c s‚ˆ ||ˆ ƒ}ˆ��ˆ|ƒ}|dk r•|\}}}}||ˆ<||ˆ<ˆ ˆ}||ˆ<ˆ ˆ<||ˆ<ˆ |ˆ<ˆd7‰|SWdQRXˆ||Ž}ˆ�Ê|ˆkrÁn¬ˆr%ˆ } || ˆ<|| ˆ<| ˆ‰ ˆ ˆ} ˆ ˆ} dˆ ˆ<ˆ ˆ<ˆ| =| ˆ|.cache_infoc sHˆ�;ˆjƒˆˆddgˆdd….cache_clear)r rr�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..r rNzInconsistent 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__r Nc3s|]}t|ˆƒVqdS)N)Ú issubclass)r?Úb)Úbaserrr^asz_c3_mro..cs"g|]}t|dˆƒ‘qS)Úabcs)Ú_c3_mro)r?r­)r®rrrBhs z_c3_mro..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..is_relatedcs"g|]}ˆ|ƒr|‘qSrr)r?Ún)rÁrrrB}s z _compose_mro..cs4x-ˆD]%}||kr||jkrdSqWdS)NTF)r¾)r¿r,)ÚtypesrrÚis_strict_base€s z$_compose_mro..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|ˆ| 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..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Úász2singledispatch..register..rª)rVr rŸ)rArQ)r×rØrÛrÐ)rArrÛÙs    z singledispatch..registercsˆ|djƒ||ŽS)Nr )rd)rSÚkw)rÙrrr%èszsingledispatch..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Ór rrrrÚs”                     N % s  - )