o bc@sdZgdZddlmZddlmZddlmZddlm Z ddl m Z dZ d Z e e fd d Ze e fd d ZefddZefddZefddZefddZefddZefddZefddZefddZefddZefd d!Zefd"d#Zefd$d%Zd&efd'efd(efgd(efd)efd&efgd)efd(efd'efgd'efd&efd)efgd*Zd+d,Zd-d.Zzdd/l mZWn e!yYnwe"Z#e#fd0d1Z$zdd2l m$Z$Wn e!yYnwGd3d4d4Z%zdd5l m%Z%Wn e!yYnwGd6d7d7e"Z&d8d9Z'ed:gd;Z(Gdd?Z0dXdBdCZ1dDdEZ2zddFl m2Z2Wn e!y;YnwdGdHZ3dIdJZ4dYdLdMZ5dNdOZ6dPdQZ7dRdSZ8GdTdUdUZ9e"Z:GdVdWdWZ;dKS)ZzEfunctools.py - Tools for working with functions and callable objects )update_wrapperwrapsWRAPPER_ASSIGNMENTSWRAPPER_UPDATEStotal_orderingcache cmp_to_key lru_cachereducepartial partialmethodsingledispatchsingledispatchmethodcached_property)get_cache_token) namedtuple)recursive_repr)RLock) GenericAlias) __module____name__ __qualname____doc____annotations__)__dict__c Csd|D]}zt||}Wn tyYqwt|||q|D]}t||t||iq||_|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) )getattrAttributeErrorsetattrupdate __wrapped__)wrapperwrappedassignedupdatedattrvaluer&j/home/lily/lilypond-2.24.1/release/binaries/dependencies/install/Python-3.10.8/lib/python3.10/functools.pyr#s rcCstt|||dS)aDecorator 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 rr(r&r&r'rAs rcC*t|||}||ur|S| o||kS)zIReturn a > b. Computed by @total_ordering from (not a < b) and (a != b).type__lt__selfotherNotImplementedZ op_resultr&r&r' _gt_from_ltYr1cC(t|||}||ur|S|p||kS)zEReturn a <= b. Computed by @total_ordering from (a < b) or (a == b).r*r-r&r&r' _le_from_lt` r4cC"t|||}||ur|S| S)z=Return a >= b. Computed by @total_ordering from (not a < b).r*r-r&r&r' _ge_from_ltgr7cC*t|||}||ur|S| p||kS)zJReturn a >= b. Computed by @total_ordering from (not a <= b) or (a == b).r+__le__r-r&r&r' _ge_from_lenr2r<cC(t|||}||ur|S|o||kS)zFReturn a < b. Computed by @total_ordering from (a <= b) and (a != b).r:r-r&r&r' _lt_from_leur5r>cCr6)z=Return a > b. Computed by @total_ordering from (not a <= b).r:r-r&r&r' _gt_from_le|r8r?cCr))zIReturn a < b. Computed by @total_ordering from (not a > b) and (a != b).r+__gt__r-r&r&r' _lt_from_gtr2rBcCr3)zEReturn a >= b. Computed by @total_ordering from (a > b) or (a == b).r@r-r&r&r' _ge_from_gtr5rCcCr6)z=Return a <= b. Computed by @total_ordering from (not a > b).r@r-r&r&r' _le_from_gtr8rDcCr9)zJReturn a <= b. Computed by @total_ordering from (not a >= b) or (a == b).r+__ge__r-r&r&r' _le_from_ger2rGcCr=)zFReturn a > b. Computed by @total_ordering from (a >= b) and (a != b).rEr-r&r&r' _gt_from_ger5rHcCr6)z=Return a < b. Computed by @total_ordering from (not a >= b).rEr-r&r&r' _lt_from_ger8rIrAr;rFr,)r,r;rArFcsVfddtD}|stdt|}t|D]\}}||vr(||_t||qS)z6Class decorator that fills in missing ordering methodscs(h|]}t|dtt|dur|qSN)robject).0opclsr&r' s(z!total_ordering..z6must define at least one ordering operation: < > <= >=)_convert ValueErrormaxrr)rOZrootsrootZopnameZopfuncr&rNr'rs rcsGfdddt}|S)z,Convert a cmp= function into a key= functioncsZeZdZdgZddZfddZfddZfdd Zfd d Zfd d Z dZ dS)zcmp_to_key..KobjcSs ||_dSrJrU)r.rUr&r&r'__init__s zcmp_to_key..K.__init__cs|j|jdkSNrrVr.r/mycmpr&r'r,zcmp_to_key..K.__lt__cs|j|jdkSrXrVrYrZr&r'rAr\zcmp_to_key..K.__gt__cs|j|jdkSrXrVrYrZr&r'__eq__r\zcmp_to_key..K.__eq__cs|j|jdkSrXrVrYrZr&r'r;r\zcmp_to_key..K.__le__cs|j|jdkSrXrVrYrZr&r'rFr\zcmp_to_key..K.__ge__N) rrr __slots__rWr,rAr]r;rF__hash__r&rZr&r'Ks     r`)rK)r[r`r&rZr'rsr)rcCsRt|}|turzt|}Wntytddw|}|D]}|||}q|S)a reduce(function, iterable[, initial]) -> value Apply a function of two arguments cumulatively to the items of a sequence or iterable, from left to right, so as to reduce the iterable to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. z0reduce() of empty iterable with no initial valueN)iter_initial_missingnext StopIteration TypeError)ZfunctionZsequenceZinitialitr%Zelementr&r&r'r s    r )r csJeZdZdZdZfddZddZeddZd d Z d d Z Z S) r zSNew function with partial application of the given arguments and keywords. )funcargskeywordsr __weakref__cs^t|stdt|dr|j|}i|j|}|j}tt||}||_||_||_|S)Nz#the first argument must be callablerg) callablerehasattrrhrirgsuperr __new__)rOrgrhrir. __class__r&r'rns  zpartial.__new__cOs*i|j|}|jg|j|Ri|SrJrirgrh)r.rhrir&r&r'__call__+szpartial.__call__cCst|j}t|jg}|dd|jD|dd|jDt|jdkr6d|dd |dS|dd |dS) Ncss|]}t|VqdSrJ)repr)rLxr&r&r' 3z#partial.__repr__..css"|] \}}|d|VqdS)=Nr&rLkvr&r&r'ru4s functoolsz functools.(, )) r+rrsrgextendrhriitemsrjoin)r.Zqualnamerhr&r&r'__repr__/s  zpartial.__repr__cCs*t||jf|j|j|jpd|jpdffSrJ)r+rgrhrirr.r&r&r' __reduce__9szpartial.__reduce__cCst|ts tdt|dkrtdt||\}}}}t|r9t|tr9|dur0t|tr9|dur=t|ts=tdt|}|durHi}n t|turRt|}|durXi}||_||_||_ ||_ dS)Nz(argument to __setstate__ must be a tuplezexpected 4 items in state, got zinvalid partial state) isinstancetuplerelenrkdictr+rrgrhri)r.statergrhkwds namespacer&r&r' __setstate__=s(     zpartial.__setstate__) rrrrr^rnrrrrrr __classcell__r&r&ror'r s   r )r c@sFeZdZdZddZddZddZd d d Zed d Z e e Z dS)r zMethod descriptor with partial application of the given arguments and keywords. Supports wrapping existing descriptors and handles non-descriptor callables as instance methods. cOsht|st|dstd|t|tr)|j|_|j||_i|j||_dS||_||_||_dS)N__get__z${!r} is not callable or a descriptor) rkrlreformatrr rgrhri)r.rgrhrir&r&r'rWcs   zpartialmethod.__init__cCsNdtt|j}ddd|jD}d}|j|jj|jj |j ||dS)Nr}css |] \}}d||VqdS)z{}={!r}N)rrxr&r&r'ruxsz)partialmethod.__repr__..z*{module}.{cls}({func}, {args}, {keywords}))modulerOrgrhri) rmaprsrhrirrrprrrg)r.rhriZ format_stringr&r&r'rvs  zpartialmethod.__repr__csfdd}j|_|_|S)Ncs,ij|}j|gj|Ri|SrJrq)Z cls_or_selfrhrirr&r'_methodsz3partialmethod._make_unbound_method.._method)__isabstractmethod__Z_partialmethod)r.rr&rr'_make_unbound_methods z"partialmethod._make_unbound_methodNcCst|jdd}d}|dur4|||}||jur4t|g|jRi|j}z|j|_Wn ty3Ynw|dur@|||}|S)Nr) rrgr rhri__self__rrr)r.rUrOgetresultZnew_funcr&r&r'rs    zpartialmethod.__get__cCt|jddSNrFrrgrr&r&r'rz"partialmethod.__isabstractmethod__rJ) rrrrrWrrrpropertyr classmethodr__class_getitem__r&r&r&r'r [s   r cCst|tr |j}t|ts|SrJ)rr rgrgr&r&r'_unwrap_partials  rZ CacheInfo)hitsmissesmaxsizeZcurrsizec@s(eZdZdZdZefddZddZdS) _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<|||_dSrJr)r.Ztuphashr&r&r'rWs z_HashedSeq.__init__cCs|jSrJrrr&r&r'r_sz_HashedSeq.__hash__N)rrrrr^rrWr_r&r&r&r'rs   rc s|}|r||7}|D]} || 7}q |r7||fdd|D7}|r3||fdd|D7}t|S||dkrI|d|vrI|dSt|S)aMake 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. c3|]}|VqdSrJr&rLrzr+r&r'rurvz_make_key..c3rrJr&rrr&r'rurvr)rvaluesr) rhrtypedZkwd_markZ fasttypesrr+rkeyitemr&rr' _make_keys  rFcs~ttr dkr dn*tr.ttr.d}t|t}fdd|_t||Sdur6tdfdd}|S) aLeast-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: https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU) rrc dSNrrr&r&rr&r' zlru_cache..Nz=Expected first argument to be an integer, a callable, or Nonecs(t|t}fdd|_t||S)Ncrrr&r&rr&r'rrz8lru_cache..decorating_function..)_lru_cache_wrapper _CacheInfocache_parametersr) user_functionr rr&r'decorating_functions z&lru_cache..decorating_function) rintrkboolrrrrre)rrrr rr&rr'rs   rcstt d\id djjt gddgdd< dkr4 fdd}n' durF fdd}n fdd} fdd } fd d }||_||_|S) N)rrrFcsd7|i|}|SNrr&)rhrr)rrr&r'r sz#_lru_cache_wrapper..wrappercsL||}|}|urd7|Sd7|i|}||<|Srr&)rhrrr)r cache_getrmake_keyrsentinelrrr&r'r 's  c s ||} C|}|dur@|\}}}}||<||< }||< <||< |<d7|WdS d7 Wdn1sNwY|i|} a|vrbnKr } || <|| <|  } } d < <| =| |<n+ }| ||g}||< <|< kWd|SWd|SWd|S1swY|Srr&) rhrrlinkZ link_prevZ link_nextZ_keyrZlastZoldrootZoldkeyZ oldresult)KEYNEXTPREVRESULTrr cache_lenfullrlockrrrrTrrr&r'r 6sX       $ $ $$cs8WdS1swYdS)zReport cache statisticsNr&r&)rrrrrrr&r' cache_infoos$z&_lru_cache_wrapper..cache_infocsRddgdd<ddWddS1s"wYdS)z$Clear the cache and cache statisticsNrF)clearr&)rrrrrrTr&r' cache_clearts "z'_lru_cache_wrapper..cache_clear)rKrr__len__rrr)rrrrr rrr&)rrrrrrrrrrrrrrrTrrrr'r s* *9 r)rcCstdd|S)z@Simple lightweight unbounded cache. Sometimes called "memoize".N)r)r)rr&r&r'rrrcCsg} dd|D}|s|S|D]}|d}|D]}||ddvr&d}nqnq|dur2td|||D] }|d|krD|d=q9q)zMerges MROs in *sequences* to a single MRO using the C3 algorithm. Adapted from https://www.python.org/download/releases/2.3/mro/. TcSsg|]}|r|qSr&r&rLsr&r&r' sz_c3_merge..rrNzInconsistent hierarchy) RuntimeErrorappend)Z sequencesrs1Z candidates2seqr&r&r' _c3_merges,  rNc stt|jD]\}tdrt|j|}nqd}r"tngt|jd|}g}t|j|d}D]t|rRtfdd|jDsR|q:|D] qUfdd|D}fdd|D}fd d|D} t |gg||| |g|g|gS) aComputes 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|VqdSrJ) issubclass)rLb)baser&r'rus  z_c3_mro..cg|]}t|dqSabcs_c3_mrorLrrr&r'rz_c3_mro..crrrrrr&r'rrcrrrrrr&r'rr) enumeratereversed __bases__rlrlistranyrremover) rOriZboundaryZexplicit_basesZabstract_basesZ other_basesZexplicit_c3_mrosZabstract_c3_mrosZ other_c3_mrosr&)rrr'rsH   rcstjfddfddDfddfddDtg}D]C}g}|D]}|vrLt|rL|fdd|jDq4|sU||q,|jtd d |D]}|D] }||vrm||qbq^q,t|d S) zCalculates 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(|vot|dot|t ot|S)N__mro__)rlrrr)typ)basesrOr&r' is_relateds  z _compose_mro..is_relatedcsg|]}|r|qSr&r&rLn)rr&r'rrz _compose_mro..cs&D]}||kr||jvrdSqdS)NTF)r)rr/)typesr&r'is_strict_bases z$_compose_mro..is_strict_basecsg|]}|s|qSr&r&r)rr&r'rrcsg|]}|vr|qSr&r&r)type_setr&r'rrT)rreverser)setr__subclasses__rrsortrr)rOrmrorZfoundsubZsubclsr&)rrOrrrrr' _compose_mros2      rcCstt||}d}|D])}|dur.||vr,||jvr,||jvr,t||s,td||n||vr4|}q ||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 {})rkeysrrrrr)rOregistryrmatchtr&r&r' _find_impls    rcsddl}ddl}i|dfddddd fdd fd d }t|d d |t<|_|_||_j |_ t |||S)akSingle-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. rNc sxdurt}|kr|z|}W|Sty;z|}Wnty3t|}Ynw||<Y|Sw)zgeneric_func.dispatch(cls) -> Runs the dispatch algorithm to return the best available implementation for the given *cls* registered on *generic_func*. N)rrKeyErrorr)rOZ current_tokenZimpl) cache_tokendispatch_cacherr&r'dispatch2s"     z singledispatch..dispatchcSst|to t|t SrJ)rr+rrNr&r&r'_is_valid_dispatch_typeIsz/singledispatch.._is_valid_dispatch_typecsr|durfddSn?|durtddtdi}|s,tdd}d d lm}tt||\}sOtd |d d|<dur_td r_t |S)zgeneric_func.register(cls, func) -> func Registers a new implementation for the given *cls* on a *generic_func*. Ncs |SrJr&)f)rOregisterr&r'rUrz2singledispatch..register..z(Invalid first argument to `register()`. z is not a class.rz(Invalid first argument to `register()`: zS. Use either `@register(some_class)` or plain `@register` on an annotated function.r)get_type_hintszInvalid annotation for z. r) rertypingr rcrarrlrr)rOrgZannr Zargname)rrrrrrNr'rLs:   z singledispatch..registercs*|s td|dj|i|S)Nz( requires at least 1 positional argumentr)rerp)rhZkw)rfuncnamer&r'r tszsingledispatch..wrapperrzsingledispatch functionrJ) rweakrefZWeakKeyDictionaryrrKrrZMappingProxyTyperrZ _clear_cacher)rgrr r r&)rrrrr rrr'r s  (   r c@s8eZdZdZddZd ddZd ddZed d ZdS) r zSingle-dispatch generic method descriptor. Supports wrapping existing descriptors and handles non-descriptor callables as instance methods. cCs4t|st|dst|dt||_||_dS)Nrz is not callable or a descriptor)rkrlrer dispatcherrgr.rgr&r&r'rWs  zsingledispatchmethod.__init__NcCs|jj||dS)zgeneric_method.register(cls, func) -> func Registers a new implementation for the given *cls* on a *generic_method*. r)r r)r.rOmethodr&r&r'rszsingledispatchmethod.registercs0fdd}j|_j|_t|j|S)Ncs(j|dj}||i|SrX)r rrpr)rhkwargsrrOrUr.r&r'rsz-singledispatchmethod.__get__.._method)rrrrg)r.rUrOrr&rr'rs  zsingledispatchmethod.__get__cCrrrrr&r&r'rrz)singledispatchmethod.__isabstractmethod__rJ) rrrrrWrrrrr&r&r&r'r s   r c@s.eZdZddZddZdddZeeZdS) rcCs ||_d|_|j|_t|_dSrJ)rgattrnamerrrrr&r&r'rWs zcached_property.__init__cCs:|jdur ||_dS||jkrtd|jd|ddS)Nz?Cannot assign the same cached_property to two different names (z and z).)rre)r.ownernamer&r&r' __set_name__s   zcached_property.__set_name__Nc Cs|dur|S|jdurtdz|j}Wnty-dt|jd|jd}t|dw||jt}|tur|jB||jt}|turn| |}z|||j<Wn!tymdt|jd|jd}t|dwWd|SWd|S1swY|S)NzGCannot use cached_property instance without calling __set_name__ on it.zNo '__dict__' attribute on z instance to cache z property.zThe '__dict__' attribute on z7 instance does not support item assignment for caching ) rrerrr+rr _NOT_FOUNDrrg)r.instancerrmsgvalr&r&r'rsL            zcached_property.__get__rJ) rrrrWrrrrrr&r&r&r'rs  r)rFrJ)r?rBrCrDrGrHrIrQrrZ _functools ImportErrorrKrbr r r rrrrrstrrr+rrrrrrrrrr r rrr&r&r&r's                       A J  .t -*f(