grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¤ f_oã&@sÐdZddddddddd d d g Zyd d lmZWnek rUYnXd dlmZd dlmZd dl m Z d dl m Z yd dl mZWnGdd„dƒZYnXdQZdRZeedd„Zeedd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d„Zd6d„Z yd d7lm Z Wnek rÈYnXd8d „Z!yd d9lm!Z!Wnek rýYnXGd:d „d e"ƒZ#ed;d<d=d>d?gƒZ$Gd@dA„dAe%ƒZ&e"ƒfe'e(e)e*dBƒhe+e,e*e-dCdD„Z.dEdFdGd„Z/dHdI„Z0dBdJdK„Z1dLdM„Z2dNdO„Z3dPd „Z4dBS)SzEfunctools.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/python34/lib64/python3.4/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|ƒ}|tkrtS| o/||kS)zIReturn a > b. Computed by @total_ordering from (not a < b) and (a != b).)Ú__lt__ÚNotImplemented)rÚotherÚ 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.rrrÚ _le_from_lthsr0cCs$|j|ƒ}|tkrtS| S)z=Return a >= b. Computed by @total_ordering from (not a < b).)r+r,)rr-r.rrrÚ _ge_from_ltms r1cCs0|j|ƒ}|tkrtS| p/||kS)zJReturn a >= b. Computed by @total_ordering from (not a <= b) or (a == b).)Ú__le__r,)rr-r.rrrÚ _ge_from_lets r3cCs/|j|ƒ}|tkrtS|o.||kS)zFReturn a < b. Computed by @total_ordering from (a <= b) and (a != b).)r2r,)rr-r.rrrÚ _lt_from_le{s r4cCs$|j|ƒ}|tkrtS| S)z=Return a > b. Computed by @total_ordering from (not a <= b).)r2r,)rr-r.rrrÚ _gt_from_le‚s r5cCs0|j|ƒ}|tkrtS| o/||kS)zIReturn a < b. Computed by @total_ordering from (not a > b) and (a != b).)Ú__gt__r,)rr-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.rrrÚ _ge_from_gt�sr8cCs$|j|ƒ}|tkrtS| S)z=Return a <= b. Computed by @total_ordering from (not a > b).)r6r,)rr-r.rrrÚ _le_from_gt•s r9cCs0|j|ƒ}|tkrtS| p/||kS)zJReturn a <= b. Computed by @total_ordering from (not a >= b) or (a == b).)Ú__ge__r,)rr-r.rrrÚ _le_from_geœs r;cCs/|j|ƒ}|tkrtS|o.||kS)zFReturn a > b. Computed by @total_ordering from (a >= b) and (a != b).)r:r,)rr-r.rrrÚ _gt_from_ge£s r<cCs$|j|ƒ}|tkrtS| S)z=Return a < b. Computed by @total_ordering from (not a >= b).)r:r,)rr-r.rrrÚ _lt_from_geªs r=csidtfdtfdtfgd6dtfdtfdtfgd6dtfdtfdtfgd6dt fdt fdt fgd6}‡fdd†|Dƒ}|s¼t dƒ‚nt |ƒ}x@||D]4\}}||krÓ||_tˆ||ƒqÓqÓWˆS)z6Class decorator that fills in missing ordering methodsr6r2r:r+cs: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: < > <= >=)r/r0r1r3r4r5r7r8r9r;r<r=Ú ValueErrorÚmaxrr")rAÚconvertÚ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 ‡fdd†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__csˆ|j|jƒdkS)Nr )rJ)rr-)rLrrÚ__ne__ászcmp_to_key..K.__ne__N) rrrÚ __slots__rKr+r6rMr2r:rNÚ__hash__r)rLrrÚKÓs   rQ)r>)rLrQr)rLrrÑs)rcs7‡‡‡fdd†}ˆ|_ˆ|_ˆ|_|S)zSNew function with partial application of the given arguments and keywords. cs*ˆjƒ}|j|ƒˆˆ||ŽS)N)Úcopyr#)ZfargsZ fkeywordsZ newkeywords)ÚargsÚfuncÚkeywordsrrÚnewfuncõs  zpartial..newfunc)rTrSrU)rTrSrUrVr)rSrTrUrr ñ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|ƒ r5t|dƒ r5tdj|ƒƒ‚nt|tƒr…|j|_|j||_|jj ƒ|_|jj |ƒn||_||_||_dS)NÚ__get__z${!r} is not callable or a descriptor) ÚcallableÚhasattrÚ TypeErrorÚformatÚ isinstancer rTrSrUrRr#)rrTrSrUrrrrK s    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)r[)r?ÚkÚvrrrú "sz)partialmethod.__repr__..z*{module}.{cls}({func}, {args}, {keywords})ÚmodulerArTrSrU) ÚjoinÚmapÚreprrSrUÚitemsr[Ú __class__rrrT)rrSrUÚ format_stringrrrÚ__repr__ s  zpartialmethod.__repr__cs+‡fdd†}ˆj|_ˆ|_|S)NcsRˆjjƒ}|j|ƒ|^}}|fˆjt|ƒ}ˆj||ŽS)N)rUrRr#rSÚtuplerT)rSrUÚ call_keywordsÚ cls_or_selfÚrestÚ call_args)rrrÚ_method,s   z3partialmethod._make_unbound_method.._method)Ú__isabstractmethod__Ú_partialmethod)rrmr)rrÚ_make_unbound_method+s  z"partialmethod._make_unbound_methodc Cs³t|jddƒ}d}|dk rˆ|||ƒ}||jk rˆt||j|jŽ}y|j|_Wq…tk r�Yq…Xqˆn|dkr¯|jƒj||ƒ}n|S)NrW) r rTr rSrUÚ__self__r!rprW)rrJrAÚgetÚresultÚnew_funcrrrrW6s    zpartialmethod.__get__cCst|jddƒS)NrnF)r rT)rrrrrnIsz"partialmethod.__isabstractmethod__N) rrrrrKrgrprWÚpropertyrnrrrrr 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ÚhashrrrrK]sz_HashedSeq.__init__cCs|jS)N)r|)rrrrrPasz_HashedSeq.__hash__N)rrrrrOr~rKrPrrrrr{Ts r{Nc sØ|} |rF||jƒƒ} | |7} x| D]} | | 7} q/Wn|rž| |‡fdd†|Dƒƒ7} |rÎ| |‡fdd†| Dƒƒ7} qÎ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_ysz_make_key..c3s!|]\}}ˆ|ƒVqdS)Nr)r?r]r^)rrrr_{sér )rdr{) rSÚkwdsÚtypedÚkwd_markÚ fasttypesÚsortedrhrÚlenÚkeyÚ sorted_itemsÚitemr)rrÚ _make_keyds  #)(rŠé€Fcswˆdk r+tˆtƒ r+tdƒ‚ntƒ‰t‰d \‰‰‰‰‡‡‡‡‡‡‡‡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 Noner r€éécs>i‰d‰‰d‰ˆj‰tƒ‰g‰ˆˆddgˆdd…<ˆ dkrn‡‡fdd†}nrˆ dkr¤‡‡‡‡ ‡‡‡‡fdd†}n<‡‡ ‡ ‡ ‡‡‡‡‡‡ ‡ ‡‡‡‡fdd†}‡‡‡‡ ‡fdd†}‡‡‡‡‡‡fd d †}||_||_t|ˆƒS) Nr Fcsˆ||Ž}ˆd7‰|S)Nr€r)rSr�rs)rxÚ user_functionrrr%¯s z7lru_cache..decorating_function..wrappercsbˆ||ˆƒ}ˆ|ˆƒ}|ˆk r;ˆd7‰|Sˆ||Ž}|ˆ|<ˆd7‰|S)Nr€r)rSr�r‡rs)ÚcacheÚ cache_getrwÚmake_keyrxÚsentinelr‚rŽrrr%¸s    c s€ˆ ||ˆ ƒ}ˆ��ˆ|ƒ}|dk r•|\}}}}||ˆ<||ˆ<ˆ ˆ}||ˆ<ˆ ˆ<||ˆ<ˆ |ˆ<ˆd7‰|SWdQXˆ||Ž}ˆ�Ê|ˆkrÀn¬ˆr$ˆ } || ˆ<|| ˆ<| ˆ‰ ˆ ˆ} ˆ ˆ} dˆ ˆ<ˆ ˆ<ˆ| =| ˆ|.decorating_function..cache_infoc sGˆ�;ˆjƒˆˆddgˆdd….decorating_function..cache_clear)rrrr¢r¤r)rŽr%r¢r¤)r›rœr�ržr‘ryr’r‚)r�r�rŸrwr rxrGrŽrÚdecorating_function¤s"     *<7!  z&lru_cache..decorating_function)r r€rŒr�)r\ÚintrZr>rŠ)ryr‚r¥r)r›rœr�ržr‘ryr’r‚rr€s 'lcCsÎg}xÁdd„|Dƒ}|s&|SxJ|D]B}|d}x/|D]&}||dd…krDd}PqDqDWPq-W|dkrŽtdƒ‚n|j|ƒx(|D] }|d|kr¢|d=q¢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?ÚsrrrrBs z_c3_merge..r r€NzInconsistent hierarchy)Ú RuntimeErrorÚappend)Ú sequencesrsÚs1Ú candidateÚs2ÚseqrrrÚ _c3_merges$      r¯c s�xOtt|jƒƒD]2\}‰tˆdƒrt|jƒ|}PqqWd}ˆrdtˆƒng‰t|jd|…ƒ}g}t|j|d…ƒ}xPˆD]H‰t|ˆƒr©t‡fdd†|jDƒƒ r©|jˆƒq©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_Osz_c3_mro..cs"g|]}t|dˆƒ‘qS)Úabcs)Ú_c3_mro)r?r³)r´rrrBVs z_c3_mro..cs"g|]}t|dˆƒ‘qS)r´)rµ)r?r³)r´rrrBWs cs"g|]}t|dˆƒ‘qS)r´)rµ)r?r³)r´rrrBXs ) Ú enumerateÚreversedÚ __bases__rYr†Úlistr±Úanyr©Úremover¯) rAr´ÚiÚboundaryÚexplicit_basesÚabstract_basesÚ other_basesÚexplicit_c3_mrosÚabstract_c3_mrosÚ other_c3_mrosr)r´r³rrµ2s("   rµcsftˆjƒ‰‡‡fdd†‰‡fdd†ˆDƒ‰‡fdd†‰‡fdd†ˆDƒ‰tˆƒ‰g}xÙˆD]Ñ}g}xU|jƒD]G}|ˆkrštˆ|ƒrš|j‡fdd†|jDƒƒqšqšW|sþ|j|ƒq�n|jd td d ƒx;|D]3}x*|D]"}||kr(|j|ƒq(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__)rYr±)Útyp)ÚbasesrArrÚ is_relatedhsz _compose_mro..is_relatedcs"g|]}ˆ|ƒr|‘qSrr)r?Ún)rÇrrrBks z _compose_mro..cs4x-ˆD]%}||kr||jkrdSqWdS)NTF)rÄ)rÅr-)ÚtypesrrÚis_strict_basens z$_compose_mro..is_strict_basecs"g|]}ˆ|ƒs|‘qSrr)r?rÈ)rÊrrrBss 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_mro_s*  *    rÔcCs³t||jƒƒ}d}xˆ|D]€}|dk r�||kr‰||jkr‰||jkr‰t||ƒ r‰tdj||ƒƒ‚nPn||kr"|}q"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¨r[rr)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 r7tƒ}ˆ|kr7ˆjƒ|‰q7nyˆ|}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|ˆˆ<ˆdkrPtˆdƒrPtƒ‰nˆ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°)rYr r£)rArT)rÝrÞrárÖ)rArráÇs    z singledispatch..registercsˆ|djƒ||ŽS)Nr )re)rSÚkw)rßrrr%Öszsingledispatch..wrapper) rr>rárßrrÖr£Ú _clear_cacher)rTr%r)rÝrßrÞrárÖrr ¢s       )z __module__z__name__z __qualname__z__doc__z__annotations__)z__dict__)5rÚ__all__Ú _functoolsrÚ ImportErrorÚabcr Ú collectionsrrÉrÚweakrefrÚ_threadrrrrrr/r0r1r3r4r5r7r8r9r;r<r=rrr r>r r¡r¹r{r¦ÚstrÚ frozensetrr…rhr†rŠrr¯rµrÔrÙr rrrrÚsr                    N — - )