o [d@sdZgdZddlZddlZddlmZddlmZ ddlm Z ddl m ZddlmZdd lmZdd lmZdd lmZzdd lmZWn eyOYnwejezdd lmZWn eygYnwGdddej Z!Gdddej"Z#Gdddej$Z%Gddde&Z'Gddde(Z)zddlm)Z)Wn eyYnwzddlm*Z*Wn eyddZ*YnwddddddZ+d d!Z,zdd"lm,Z,Wn eyYnwGd#d$d$e(Z-Gd%d&d&ej.Z/Gd'd(d(ej.Z0Gd)d*d*ejZ1Gd+d,d,ej2Z3dS)-a?This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers, dict, list, set, and tuple. * namedtuple factory function for creating tuple subclasses with named fields * deque list-like container with fast appends and pops on either end * ChainMap dict-like class for creating a single view of multiple mappings * Counter dict subclass for counting hashable objects * OrderedDict dict subclass that remembers the order entries were added * defaultdict dict subclass that calls a factory function to supply missing values * UserDict wrapper around dictionary objects for easier dict subclassing * UserList wrapper around list objects for easier list subclassing * UserString wrapper around string objects for easier string subclassing ) ChainMapCounter OrderedDictUserDictUserList UserString defaultdictdeque namedtupleN)chain)repeat)starmap) iskeyword)eq) itemgetter)recursive_repr)proxy)r)rc@eZdZddZdS)_OrderedDictKeysViewccst|jEdHdSNreversed_mappingselfr+/usr/lib/python3.10/collections/__init__.py __reversed__<sz!_OrderedDictKeysView.__reversed__N__name__ __module__ __qualname__rrrrrr: rc@r)_OrderedDictItemsViewccs&t|jD] }||j|fVqdSrrrkeyrrrrAsz"_OrderedDictItemsView.__reversed__Nrrrrrr#?r"r#c@r)_OrderedDictValuesViewccs"t|jD]}|j|VqdSrrr$rrrrGsz#_OrderedDictValuesView.__reversed__Nrrrrrr&Er"r&c@seZdZdZdS)_Link)prevnextr% __weakref__N)rr r! __slots__rrrrr'Ksr'c@seZdZdZd1ddZejeefddZej fddZ d d Z d d Z d dZ d2ddZ d2ddZddZejjZZddZddZddZejjZeZefddZd3dd Zed!d"Zd#d$Zd%d&Ze d3d'd(Z!d)d*Z"d+d,Z#d-d.Z$d/d0Z%dS)4rz)Dictionary that remembers insertion orderrcKs^z|jWnty#t|_t|j|_}||_|_i|_Ynw|j|fi|dS)zInitialize an ordered dictionary. The signature is the same as regular dictionaries. Keyword argument order is preserved. N) _OrderedDict__rootAttributeErrorr'_OrderedDict__hardroot_proxyr(r)_OrderedDict__map_OrderedDict__update)rotherkwdsrootrrr__init__]s    zOrderedDict.__init__c CsZ||vr%||j|<}|j}|j}||||_|_|_||_|||_||||dS)z!od.__setitem__(i, y) <==> od[i]=yN)r0r,r(r)r%) rr%value dict_setitemrLinklinkr4lastrrr __setitem__js zOrderedDict.__setitem__cCs>||||j|}|j}|j}||_||_d|_d|_dS)z od.__delitem__(y) <==> del od[y]N)r0popr(r))rr% dict_delitemr9 link_prev link_nextrrr __delitem__xs   zOrderedDict.__delitem__cc4|j}|j}||ur|jV|j}||us dSdS)zod.__iter__() <==> iter(od)N)r,r)r%rr4currrrr__iter__zOrderedDict.__iter__ccrA)z#od.__reversed__() <==> reversed(od)N)r,r(r%rBrrrrrEzOrderedDict.__reversed__cCs*|j}||_|_|jt|dS)z.od.clear() -> None. Remove all items from od.N)r,r(r)r0cleardict)rr4rrrrFs  zOrderedDict.clearTcCsj|std|j}|r|j}|j}||_||_n |j}|j}||_||_|j}|j|=t||}||fS)zRemove and return a (key, value) pair from the dictionary. Pairs are returned in LIFO order if last is true or FIFO order if false. zdictionary is empty)KeyErrorr,r(r)r%r0rGr<)rr:r4r9r>r?r%r6rrrpopitems  zOrderedDict.popitemc Csv|j|}|j}|j}|j}||_||_|j}|r*|j}||_||_||_||_dS|j}||_||_||_||_dS)zMove an existing element to the end (or beginning if last is false). Raise KeyError if the element does not exist. N)r0r(r)r,) rr%r:r9r>r? soft_linkr4firstrrr move_to_ends$   zOrderedDict.move_to_endcCsVtj}t|d}||j}|||jd7}|||j|7}|||j|7}|S)N)_sys getsizeoflen__dict__r0r.r,)rsizeofnsizerrr __sizeof__s  zOrderedDict.__sizeof__cCt|S)z:D.keys() -> a set-like object providing a view on D's keys)rrrrrkeyszOrderedDict.keyscCrW)z a set-like object providing a view on D's items)r#rrrritemsrYzOrderedDict.itemscCrW)z6D.values() -> an object providing a view on D's values)r&rrrrvaluesrYzOrderedDict.valuescCs0||vr ||}||=|S||jurt||S)zod.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised. )_OrderedDict__markerrH)rr%defaultresultrrrr<s zOrderedDict.popNcCs||vr||S|||<|S)zInsert key with a value of default if key is not in the dictionary. Return the value for key if key is in the dictionary, else default. rrr%r]rrr setdefaultszOrderedDict.setdefaultcCs*|s d|jjfSd|jjt|fS)zod.__repr__() <==> repr(od)z%s()z%s(%r)) __class__rlistrZrrrr__repr__szOrderedDict.__repr__cCsDt|}ttD]}||dq |jd|pddt|fS)z%Return state information for picklingNr)varscopyrr<raiterrZ)r inst_dictkrrr __reduce__s zOrderedDict.__reduce__cC ||S)z!od.copy() -> a shallow copy of odrarrrrre zOrderedDict.copycC|}|D]}|||<q|S)zYCreate a new ordered dictionary with keys from iterable and values set to value. r)clsiterabler6rr%rrrfromkeyss zOrderedDict.fromkeyscCs2t|trt||ottt||St||S)zod.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. ) isinstancerrG__eq__allmap_eqrr2rrrrrs  zOrderedDict.__eq__cCs|||Sr)updatervrrr__ior__%s zOrderedDict.__ior__cCs&t|tstS||}|||SrrqrGNotImplementedrarwrr2newrrr__or__)   zOrderedDict.__or__cCs&t|tstS||}|||Srryr{rrr__ror__0r~zOrderedDict.__ror__)r)Tr)&rr r!__doc__r5rGr;r/r'r@rDrrFrIrLrV_collections_abcMutableMappingrwr1rXrZr[__ne__objectr\r<r`_recursive_reprrcrire classmethodrprrrxr}rrrrrrNs<             r)r) _tuplegettercCstt||dS)N)doc)property _itemgetter)indexrrrrFsrF)renamedefaultsmodulec sttr ddttttt|}|rFt}t D]!\}}| r9t |s9| ds9||vr@d||<| |q$|gD]"}t|turWtd| sbtd|t |rmtd|qKt}D] }| dr|std|||vrtd|| |qsi}|d urt|}t|tkrtd tttttt|}tttjtd } d kr| d7} d d ddDdtjtttttf\id|d} d| d| d} t| | } d| _d|d | d| _|d ur|| _tfdd} d|d| j_fdd}d|d|_fd d!}fd"d#}fd$d%}| | j||||fD] }|d&|j|_qW|d | dd'|| | ||||d( }t D]\}}td)|}t||||<q|t|tf|}|d urz t d j!"d*d+}Wn t#tfyYnw|d ur||_$|S),aCReturns a new subclass of tuple with named fields. >>> Point = namedtuple('Point', ['x', 'y']) >>> Point.__doc__ # docstring for the new class 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p[0] + p[1] # indexable like a plain tuple 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessible by name 33 >>> d = p._asdict() # convert to a dictionary >>> d['x'] 11 >>> Point(**d) # convert from a dictionary Point(x=11, y=22) >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields Point(x=100, y=22) , _z*Type names and field names must be stringsz6Type names and field names must be valid identifiers: z0Type names and field names cannot be a keyword: z-Field names cannot start with an underscore: z"Encountered duplicate field name: Nz(Got more default values than field names, rM(css|]}|dVqdS)z=%rNr).0namerrr sznamedtuple..) namedtuple_) _tuple_new __builtins__rz lambda _cls, z: _tuple_new(_cls, (z))__new__zCreate new instance of cs2||}|krtddt||S)Nz Expected z arguments, got ) TypeErrorrQ)rnror^)_len num_fields tuple_newrr_makes  znamedtuple.._makez Make a new z# object from a sequence or iterablecs.||j|}|rtdt||S)NzGot unexpected field names: )rr< ValueErrorrb)rr3r^)_map field_namesrr_replacesznamedtuple.._replacez Return a new z2 object replacing specified fields with new valuescs|jj|S)z/Return a nicely formatted representation string)rarr)repr_fmtrrrcznamedtuple..__repr__cs|j|S)z9Return a new dict which maps field names to their values.)_fieldsr)_dict_ziprr_asdictrznamedtuple.._asdictcs|S)z7Return self as a plain tuple. Used by copy and pickle.rr)_tuplerr__getnewargs__rYz"namedtuple..__getnewargs__.r) rr+r_field_defaultsrrrrcrr__match_args__zAlias for field number r__main__)%rqstrreplacesplitrbrtrOinternset enumerate isidentifier _iskeyword startswithaddtyperrtuplerQrGrzipjoinrevalrr __defaults__r__func__r!r _getframe f_globalsgetr-r )typenamerrrrseenrrfield_defaultsarg_list namespacecoderrrrcrrmethodclass_namespacerr^r) rrrrrrrrrrr Hs             r cCs&|j}|D] }||dd||<qdS)z!Tally elements from the iterable.r rMN)r)mappingro mapping_getelemrrr_count_elementssr)rcseZdZdZd=fdd ZddZddZd=d d Zd d Ze d=d dZ d=fdd Z d=ddZ ddZ ddZfddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!Z"S)>raDict subclass for counting hashable items. Sometimes called a bag or multiset. Elements are stored as dictionary keys and their counts are stored as dictionary values. >>> c = Counter('abcdeabcdabcaba') # count elements from a string >>> c.most_common(3) # three most common elements [('a', 5), ('b', 4), ('c', 3)] >>> sorted(c) # list all unique elements ['a', 'b', 'c', 'd', 'e'] >>> ''.join(sorted(c.elements())) # list elements with repetitions 'aaaaabbbbcccdde' >>> sum(c.values()) # total of all counts 15 >>> c['a'] # count of letter 'a' 5 >>> for elem in 'shazam': # update counts from an iterable ... c[elem] += 1 # by adding 1 to each element's count >>> c['a'] # now there are seven 'a' 7 >>> del c['b'] # remove all 'b' >>> c['b'] # now there are zero 'b' 0 >>> d = Counter('simsalabim') # make another counter >>> c.update(d) # add in the second counter >>> c['a'] # now there are nine 'a' 9 >>> c.clear() # empty the counter >>> c Counter() Note: If a count is set to zero or reduced to zero, it will remain in the counter until the entry is deleted or the counter is cleared: >>> c = Counter('aaabbc') >>> c['b'] -= 2 # reduce the count of 'b' by two >>> c.most_common() # 'b' is still in, but its count is zero [('a', 3), ('c', 1), ('b', 0)] Nc s t|j|fi|dS)a Create a new, empty Counter object. And if given, count elements from an input iterable. Or, initialize the count from another mapping of elements to their counts. >>> c = Counter() # a new, empty counter >>> c = Counter('gallahad') # a new counter from an iterable >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping >>> c = Counter(a=4, b=2) # a new counter from keyword args N)superr5rw)rror3rkrrr55s zCounter.__init__cCsdS)z1The count of elements not in the Counter is zero.r rr$rrr __missing__CszCounter.__missing__cCs t|S)zSum of the counts)sumr[rrrrtotalHs z Counter.totalcCs>|durt|tdddSddl}|j||tddS)zList the n most common elements and their counts from the most common to the least. If n is None, then list all element counts. >>> Counter('abracadabra').most_common(3) [('a', 5), ('b', 2), ('r', 2)] NrMT)r%reverser r%)sortedrZrheapqnlargest)rrTrrrr most_commonLs zCounter.most_commoncCsttt|S)aIterator over elements repeating each as many times as its count. >>> c = Counter('ABCABC') >>> sorted(c.elements()) ['A', 'A', 'B', 'B', 'C', 'C'] # Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1}) >>> product = 1 >>> for factor in prime_factors.elements(): # loop over factors ... product *= factor # and multiply them >>> product 1836 Note, if an element's count has been set to zero or is a negative number, elements() will ignore it. )_chain from_iterable_starmap_repeatrZrrrrelements\szCounter.elementscCstd)Nz@Counter.fromkeys() is undefined. Use Counter(iterable) instead.)NotImplementedError)rnrovrrrrpts zCounter.fromkeysc sr|dur.t|tjr)|r"|j}|D] \}}|||d||<qn t|nt|||r7||dSdS)aLike dict.update() but add counts instead of replacing them. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.update('witch') # add elements from another iterable >>> d = Counter('watch') >>> c.update(d) # add elements from another counter >>> c['h'] # four 'h' in which, witch, and watch 4 Nr )rqrMappingrrZrrwrrror3self_getrcountrkrrrws  zCounter.updatecKsr|dur.|j}t|tjr |D] \}}||d|||<qn|D] }||dd||<q"|r7||dSdS)aLike dict.update() but subtracts counts instead of replacing them. Counts can be reduced below zero. Both the inputs and outputs are allowed to contain zero and negative counts. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.subtract('witch') # subtract elements from another iterable >>> c.subtract(Counter('watch')) # subtract elements from another counter >>> c['h'] # 2 in which, minus 1 in witch, minus 1 in watch 0 >>> c['w'] # 1 in which, minus 1 in witch, minus 1 in watch -1 Nr rM)rrqrrrZsubtractrrrrrs zCounter.subtractcCrj)zReturn a shallow copy.rkrrrrrerlz Counter.copycCs|jt|ffSr)rarGrrrrrizCounter.__reduce__cs||vr t|dSdS)zGLike dict.__delitem__() but does not raise KeyError for missing values.N)rr@)rrrkrrr@szCounter.__delitem__c*ttstStfddfDS)z=True if all counts agree. Missing counts are treated as zero.c3s*|]}|D] }||kVqqdSrrrcer2rrrr(z!Counter.__eq__..rqrrzrsrvrrrrr zCounter.__eq__cCst|tstS||k S)z@True if any counts disagree. Missing counts are treated as zero.rqrrzrvrrrrs  zCounter.__ne__cr)z:True if all counts in self are a subset of those in other.c3s*|]}|D] }||kVqqdSrrrrrrrrz!Counter.__le__..rrvrrr__le__rzCounter.__le__cCst|tstS||ko||kS)zATrue if all counts in self are a proper subset of those in other.rrvrrr__lt__ zCounter.__lt__cr)z.rrvrrr__ge__rzCounter.__ge__cCst|tstS||ko||kS)zCTrue if all counts in self are a proper superset of those in other.rrvrrr__gt__rzCounter.__gt__cCsR|s |jjdSzt|}Wn tyt|}Ynw|jjd|dS)Nz()rr)rarrGrr)rdrrrrcs  zCounter.__repr__cCspt|tstSt}|D]\}}|||}|dkr |||<q|D]\}}||vr5|dkr5|||<q%|S)zAdd counts from two counters. >>> Counter('abbb') + Counter('bcc') Counter({'b': 4, 'c': 2, 'a': 1}) r rqrrzrZrr2r^rrnewcountrrr__add__s  zCounter.__add__cCstt|tstSt}|D]\}}|||}|dkr |||<q|D]\}}||vr7|dkr7d|||<q%|S)z Subtract count, but keep only results with positive counts. >>> Counter('abbbc') - Counter('bccd') Counter({'b': 2, 'a': 1}) r rrrrr__sub__-s   zCounter.__sub__cCs|t|tstSt}|D]\}}||}||kr|n|}|dkr&|||<q|D]\}}||vr;|dkr;|||<q+|S)zUnion is the maximum of value in either of the input counters. >>> Counter('abbb') | Counter('bcc') Counter({'b': 3, 'c': 2, 'a': 1}) r rrr2r^rr other_countrrrrr}@s zCounter.__or__cCsRt|tstSt}|D]\}}||}||kr|n|}|dkr&|||<q|S)z Intersection is the minimum of corresponding counts. >>> Counter('abbb') & Counter('bcc') Counter({'b': 1}) r rrrrr__and__Ts zCounter.__and__cCs,t}|D] \}}|dkr|||<q|S)zEAdds an empty counter, effectively stripping negative and zero countsr rrZrr^rrrrr__pos__es zCounter.__pos__cCs0t}|D]\}}|dkrd|||<q|S)z{Subtracts from an empty counter. Strips positive and zero counts, and flips the sign on negative counts. r rrrrr__neg__ms  zCounter.__neg__cCs&dd|D}|D]}||=q |S)z?Internal method to strip elements with a negative or zero countcSsg|] \}}|dks|qS)r r)rrrrrr zsz*Counter._keep_positive..)rZ)r nonpositiverrrr_keep_positivexszCounter._keep_positivecCs*|D] \}}|||7<q|S)zInplace add from another counter, keeping only positive counts. >>> c = Counter('abbb') >>> c += Counter('bcc') >>> c Counter({'b': 4, 'c': 2, 'a': 1}) rZrrr2rrrrr__iadd__ zCounter.__iadd__cCs*|D] \}}|||8<q|S)zInplace subtract counter, but keep only results with positive counts. >>> c = Counter('abbbc') >>> c -= Counter('bccd') >>> c Counter({'b': 2, 'a': 1}) rrrrr__isub__r zCounter.__isub__cCs2|D]\}}||}||kr|||<q|S)zInplace union is the maximum of value from either counter. >>> c = Counter('abbb') >>> c |= Counter('bcc') >>> c Counter({'b': 3, 'c': 2, 'a': 1}) r)rr2rrrrrrrx  zCounter.__ior__cCs2|D]\}}||}||kr|||<q|S)zInplace intersection is the minimum of corresponding counts. >>> c = Counter('abbb') >>> c &= Counter('bcc') >>> c Counter({'b': 1}) r)rr2rrrrrr__iand__r zCounter.__iand__r)#rr r!rr5rrrrrrprwrrerir@rrrrrrrrcrrr}rrrrr r rxr  __classcell__rrrkrrs@2   " -   rc@seZdZdZddZddZddZd-d d Zd d Zd dZ ddZ ddZ e ddZ eddZddZeZd-ddZeddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZdS).ra A ChainMap groups multiple dicts (or other mappings) together to create a single, updateable view. The underlying mappings are stored in a list. That list is public and can be accessed or updated using the *maps* attribute. There is no other state. Lookups search the underlying mappings successively until a key is found. In contrast, writes, updates, and deletions only operate on the first mapping. cGst|pig|_dS)zInitialize a ChainMap by setting *maps* to the given mappings. If no mappings are provided, a single empty dictionary is used. N)rbmaps)rrrrrr5szChainMap.__init__cCst|r)rHr$rrrrszChainMap.__missing__c Cs6|jD]}z||WStyYqw||Sr)rrHr)rr%rrrr __getitem__s   zChainMap.__getitem__NcCs||vr||S|Srrr_rrrrz ChainMap.getcCsttj|jSr)rQrunionrrrrr__len__zChainMap.__len__cCs,i}t|jD] }|t|qt|Sr)rrrwrGrprf)rrrrrrrDszChainMap.__iter__cstfdd|jDS)Nc3s|]}|vVqdSrr)rmrrrrsz(ChainMap.__contains__..anyrr$rrr __contains__szChainMap.__contains__cC t|jSrrrrrr__bool__ zChainMap.__bool__cCs"|jjddtt|jdS)Nrrr)rarrrtreprrrrrrrcs"zChainMap.__repr__cGs|tj|g|RS)z?Create a ChainMap with a single dict created from the iterable.)rGrp)rnroargsrrrrpszChainMap.fromkeyscCs&|j|jdg|jddRS)zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r rMN)rarrerrrrres&z ChainMap.copycKs0|dur|}n|r|||j|g|jRS)zNew ChainMap with a new map followed by all previous maps. If no map is provided, an empty dict is used. Keyword arguments update the map or new empty dict. N)rwrar)rrkwargsrrr new_childs  zChainMap.new_childcCs|j|jddS)zNew ChainMap from maps[1:].rMN)rarrrrrparentsszChainMap.parentscCs||jd|<dSNr )r)rr%r6rrrr; rzChainMap.__setitem__cCs0z |jd|=WdStytd|w)Nr $Key not found in the first mapping: )rrHr$rrrr@s  zChainMap.__delitem__cCs(z|jdWStytdw)zPRemove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.r z#No keys found in the first mapping.)rrIrHrrrrrIs  zChainMap.popitemcGs8z |jdj|g|RWStytd|w)zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r r")rr<rH)rr%rrrrr<s  z ChainMap.popcCs|jddS)z'Clear maps[0], leaving maps[1:] intact.r N)rrFrrrrrF$szChainMap.clearcCs|jd||Sr!)rrwrvrrrrx(szChainMap.__ior__cCs,t|tjstS|}|jd||Sr!)rqrrrzrerrw)rr2rrrrr},s zChainMap.__or__cCs<t|tjstSt|}t|jD]}||q||Sr) rqrrrzrGrrrwra)rr2rchildrrrr3s   zChainMap.__ror__r)rr r!rr5rrrrrDrrrrcrrpre__copy__rrr r;r@rIr<rFrxr}rrrrrrs6       rc@seZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZedddZdS)rNcKs.i|_|dur |||r||dSdSr)datarw)rrGrrrrr5Cs  zUserDict.__init__cCrrrQr%rrrrrJrzUserDict.__len__cCs6||jvr |j|St|jdr|j||St|)Nr)r%hasattrrarrHr$rrrrMs   zUserDict.__getitem__cC||j|<dSrr%)rr%itemrrrr;TzUserDict.__setitem__cC |j|=dSrr)r$rrrr@W zUserDict.__delitem__cCrr)rfr%rrrrrDZrzUserDict.__iter__cC ||jvSrr)r$rrrr^rzUserDict.__contains__cCrrrr%rrrrrcbrzUserDict.__repr__cCs:t|tr||j|jBSt|tr||j|BStSrrqrrar%rGrzrvrrrr}e  zUserDict.__or__cCs:t|tr||j|jBSt|tr|||jBStSrr0rvrrrrlr1zUserDict.__ror__cCs0t|tr|j|jO_|S|j|O_|Sr)rqrr%rvrrrrxss zUserDict.__ior__cCs4|j|j}|j|j|jd|jd<|SNr%)rarrRrwrerinstrrrr$zszUserDict.__copy__cCsX|jtur t|jSddl}|j}z i|_||}W||_n||_w|||Sr!)rarr%rerw)rrer%rrrrres   z UserDict.copycCrmrr)rnror6rr%rrrrps zUserDict.fromkeysr)rr r!r5rrr;r@rDrrcr}rrxr$rerrprrrrr@s   rc@seZdZdZd@ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$ZeZd%d&Zd'd(Zd)d*Zd+d,ZdAd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"dS)BrzAA more or less complete user-defined wrapper around list objects.NcCsjg|_|dur3t|t|jkr||jdd<dSt|tr,|jdd|jdd<dSt||_dSdSr)r%rrqrrb)rinitlistrrrr5s zUserList.__init__cCrrr/rrrrrcrzUserList.__repr__cCs|j||kSrr%_UserList__castrvrrrrrzUserList.__lt__cCs|j||kSrr6rvrrrrrzUserList.__le__cCs|j||kSrr6rvrrrrrrzUserList.__eq__cCs|j||kSrr6rvrrrrrzUserList.__gt__cCs|j||kSrr6rvrrrrrzUserList.__ge__cCst|tr|jS|Sr)rqrr%rvrrr__castrzUserList.__castcCr.rr)rr*rrrrrzUserList.__contains__cCrrr&rrrrrrzUserList.__len__cCs$t|tr ||j|S|j|Sr)rqslicerar%rirrrrs  zUserList.__getitem__cCr(rr)rr<r*rrrr;r+zUserList.__setitem__cCr,rr)r;rrrr@r-zUserList.__delitem__cCsPt|tr||j|jSt|t|jr||j|S||jt|Srrqrrar%rrbrvrrrr zUserList.__add__cCsPt|tr||j|jSt|t|jr|||jS|t||jSrr>rvrrr__radd__r?zUserList.__radd__cCsVt|tr|j|j7_|St|t|jr |j|7_|S|jt|7_|Sr)rqrr%rrbrvrrrr s zUserList.__iadd__cC||j|Srrar%rrTrrr__mul__rzUserList.__mul__cCs|j|9_|Srr)rCrrr__imul__szUserList.__imul__cCs8|j|j}|j|j|jddd|jd<|Sr2)rarrRrwr3rrrr$szUserList.__copy__cC|j|dSr)r%appendr9rrrrGrzUserList.appendcCs|j||dSr)r%insertr=rrrrHrzUserList.insertcC |j|Sr)r%r<r;rrrr<r-z UserList.popcCrFr)r%remover9rrrrKrzUserList.removecC|jdSr)r%rFrrrrrFr+zUserList.clearcCrjrrkrrrrrerz UserList.copycCrJr)r%rr9rrrrr-zUserList.countcGs|jj|g|RSrr%r)rr*rrrrr rzUserList.indexcCrLr)r%rrrrrrr+zUserList.reversecOs|jj|i|dSr)r%sortrrr3rrrrNsz UserList.sortcCs,t|tr|j|jdS|j|dSr)rqrr%extendrvrrrrPs zUserList.extendrrI)#rr r!rr5rcrrrrrrr7rrrr;r@rr@r rD__rmul__rEr$rGrHr<rKrFrerrrrNrPrrrrrsB     rc@sxeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZeZd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1ejfd2d3Zd4d5Zd6d7Z dd:d;Z!d1ejfddudvZ?ddwdxZ@ddydzZAdd{d|ZBdd~dZCd1ejfddZDdddZEddZFddZGddZHddZIddZJdgS)rcCs@t|tr ||_dSt|tr|jdd|_dSt||_dSr)rqrr%rrseqrrrr5!s   zUserString.__init__cCrr)rr%rrrr__str__)rzUserString.__str__cCrrr/rrrrrc,rzUserString.__repr__cCrr)intr%rrrr__int__/rzUserString.__int__cCrr)floatr%rrrr __float__2rzUserString.__float__cCrr)complexr%rrrr __complex__5rzUserString.__complex__cCrr)hashr%rrrr__hash__8rzUserString.__hash__cCs|jddfSrr)rrrrr;rzUserString.__getnewargs__cCs t|tr |j|jkS|j|kSrrqrr%rstringrrrrr>   zUserString.__eq__cCs t|tr |j|jkS|j|kSrr^r_rrrrCrazUserString.__lt__cCs t|tr |j|jkS|j|kSrr^r_rrrrHrazUserString.__le__cCs t|tr |j|jkS|j|kSrr^r_rrrrMrazUserString.__gt__cCs t|tr |j|jkS|j|kSrr^r_rrrrRrazUserString.__ge__cCst|tr|j}||jvSrr^)rcharrrrrWs  zUserString.__contains__cCrrr&rrrrr\rzUserString.__len__cCs||j|SrrB)rrrrrr_rzUserString.__getitem__cCsJt|tr||j|jSt|tr||j|S||jt|Sr)rqrrar%rrvrrrrbs  zUserString.__add__cCs.t|tr |||jS|t||jSr)rqrrar%rvrrrr@is zUserString.__radd__cCrArrBrCrrrrDnrzUserString.__mul__cCs||j|SrrBrrrrr__mod__srzUserString.__mod__cCs|t||Sr)rar)rtemplaterrr__rmod__vrzUserString.__rmod__cC||jSr)rar% capitalizerrrrrhzrzUserString.capitalizecCrgr)rar%casefoldrrrrri}rzUserString.casefoldcG||jj|g|RSr)rar%centerrwidthrrrrrkzUserString.centerr cC t|tr|j}|j|||Sr)rqrr%rrsubstartendrrrr zUserString.countcC"t|tr|j}||j|Sr)rqrr%ra removeprefix)rprefixrrrrv zUserString.removeprefixcCrur)rqrr%ra removesuffix)rsuffixrrrryrxzUserString.removesuffixutf-8strictcCs.|durdn|}|durdn|}|j||S)Nr{r|)r%encode)rencodingerrorsrrrr}szUserString.encodecC|j|||Sr)r%endswith)rrzrrrsrrrrrzUserString.endswithcC||j|Sr)rar% expandtabs)rtabsizerrrrrzUserString.expandtabscCror)rqrr%findrprrrrrtzUserString.findcOs|jj|i|Sr)r%formatrOrrrrrzUserString.formatcCrJr)r% format_map)rrrrrrr-zUserString.format_mapcCrrrMrprrrrrzUserString.indexcC |jSr)r%isalpharrrrrrzUserString.isalphacCrr)r%isalnumrrrrrrzUserString.isalnumcCrr)r%isasciirrrrrrzUserString.isasciicCrr)r% isdecimalrrrrrrzUserString.isdecimalcCrr)r%isdigitrrrrrrzUserString.isdigitcCrr)r%rrrrrrrzUserString.isidentifiercCrr)r%islowerrrrrrrzUserString.islowercCrr)r% isnumericrrrrrrzUserString.isnumericcCrr)r% isprintablerrrrrrzUserString.isprintablecCrr)r%isspacerrrrrrzUserString.isspacecCrr)r%istitlerrrrrrzUserString.istitlecCrr)r%isupperrrrrrrzUserString.isuppercCrJr)r%rrSrrrrr-zUserString.joincGrjr)rar%ljustrlrrrrrnzUserString.ljustcCrgr)rar%lowerrrrrrrzUserString.lowerNcCrr)rar%lstriprcharsrrrrrzUserString.lstripcCrJr)r% partitionrseprrrrr-zUserString.partitionrIcCs6t|tr|j}t|tr|j}||j|||Sr)rqrr%rar)roldr|maxsplitrrrrs  zUserString.replacecCror)rqrr%rfindrprrrrrtzUserString.rfindcCrr)r%rindexrprrrrrzUserString.rindexcGrjr)rar%rjustrlrrrrrnzUserString.rjustcCrJr)r% rpartitionrrrrrr-zUserString.rpartitioncCrr)rar%rstriprrrrrrzUserString.rstripcC|j||Sr)r%rrrrrrrrr+zUserString.splitcCrr)r%rsplitrrrrrr+zUserString.rsplitFcCrJr)r% splitlines)rkeependsrrrrr-zUserString.splitlinescCrr)r%r)rrwrrrsrrrrrzUserString.startswithcCrr)rar%striprrrrrrzUserString.stripcCrgr)rar%swapcaserrrrrrzUserString.swapcasecCrgr)rar%titlerrrrr rzUserString.titlecGs||jj|Sr)rar% translatercrrrr rzUserString.translatecCrgr)rar%upperrrrrrrzUserString.uppercCrr)rar%zfill)rrmrrrrrzUserString.zfill)r{r|)rrrQ)NrI)F)Krr r!r5rUrcrWrYr[r]rrrrrrrrrrrr@rDrRrdrfrhrirkrOmaxsizerrvryr}rrrrrrrrrrrrrrrrrrrrrrr maketransrrrrrrrrrrrrrrrrrrrrrrs          r)4r__all__rsysrO itertoolsr rr rr rkeywordrroperatorrrurrreprlibrr_weakrefrr/ _collectionsr ImportErrorMutableSequenceregisterrKeysViewr ItemsViewr# ValuesViewr&rr'rGrrr rrrrrrSequencerrrrrsr            k    0 =Z