B Vva=ÃØã @súdZddddddddd g Zd d lZd d lmZmZd d lm Z d d l Z d d l Zd dlmZd dlmZmZmZd dlmZyd dlmZWnek ržYnXej  e¡yd dlm!Z!Wnek rÐYnXdd„Z"Gdd„dej#ƒZ$Gdd„dej%ƒZ&Gdd„dej'ƒZ(Gdd„de)ƒZ*Gdd„de+ƒZ,yd dlm,Z,Wnek rVYnXiZ-dd d d œd!d„Z.d"d#„Z/yd d$lm/Z/Wnek rœYnXGd%d„de+ƒZ0Gd&d „d ej1ƒZ2Gd'd„dej1ƒZ3Gd(d„dejƒZ4Gd)d„dej5ƒZ6d S)*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 ÚdequeÚ defaultdictÚ namedtupleÚUserDictÚUserListÚ UserStringÚCounterÚ OrderedDictÚChainMapéN)Ú itemgetterÚeq)Ú iskeyword)Úproxy)ÚrepeatÚchainÚstarmap)Úrecursive_repr)r)rcCsR|tjkr:tt|ƒ}ddl}|jdtdd|tƒ|<|Stdt›d|›ƒ‚dS)Nr zUsing or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop workingé)Ú stacklevelzmodule z has no attribute ) Ú_collections_abcÚ__all__ÚgetattrÚwarningsÚwarnÚDeprecationWarningÚglobalsÚAttributeErrorÚ__name__)ÚnameÚobjr©r ú7/opt/alt/python37/lib/python3.7/collections/__init__.pyÚ __getattr__*s    r"c@seZdZdd„ZdS)Ú_OrderedDictKeysViewccst|jƒEdHdS)N)ÚreversedÚ_mapping)Úselfr r r!Ú __reversed__?sz!_OrderedDictKeysView.__reversed__N)rÚ __module__Ú __qualname__r'r r r r!r#=sr#c@seZdZdd„ZdS)Ú_OrderedDictItemsViewccs(x"t|jƒD]}||j|fVq WdS)N)r$r%)r&Úkeyr r r!r'Dsz"_OrderedDictItemsView.__reversed__N)rr(r)r'r r r r!r*Bsr*c@seZdZdd„ZdS)Ú_OrderedDictValuesViewccs$xt|jƒD]}|j|Vq WdS)N)r$r%)r&r+r r r!r'Jsz#_OrderedDictValuesView.__reversed__N)rr(r)r'r r r r!r,Hsr,c@seZdZdZdS)Ú_Link)ÚprevÚnextr+Ú __weakref__N)rr(r)Ú __slots__r r r r!r-Nsr-c@sèeZdZdZdd„Zejeefdd„Zej fdd„Z dd „Z d d „Z d d „Z d*dd„Z d+dd„Zdd„ZejjZZdd„Zdd„Zdd„ZejjZeƒZefdd„Zd,dd„Zeƒd d!„ƒZd"d#„Zd$d%„Ze d-d&d'„ƒZ!d(d)„Z"dS).rz)Dictionary that remembers insertion ordercOsŠ|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚y |jWn>tk rxtƒ|_t|jƒ|_}||_|_i|_ YnX|j ||ŽdS)zŒInitialize an ordered dictionary. The signature is the same as regular dictionaries. Keyword argument order is preserved. z?descriptor '__init__' of 'OrderedDict' object needs an argumentéz$expected at most 1 arguments, got %dN) Ú TypeErrorÚlenÚ_OrderedDict__rootrr-Ú_OrderedDict__hardrootÚ_proxyr.r/Ú_OrderedDict__mapÚ_OrderedDict__update)ÚargsÚkwdsr&Úrootr r r!Ú__init__`s    zOrderedDict.__init__c CsZ||krJ|ƒ|j|<}|j}|j}||||_|_|_||_||ƒ|_||||ƒdS)z!od.__setitem__(i, y) <==> od[i]=yN)r8r5r.r/r+) r&r+ÚvalueZ dict_setitemrZLinkÚlinkr<Úlastr r r!Ú __setitem__ss zOrderedDict.__setitem__cCs>|||ƒ|j |¡}|j}|j}||_||_d|_d|_dS)z od.__delitem__(y) <==> del od[y]N)r8Úpopr.r/)r&r+Z dict_delitemr?Ú link_prevÚ link_nextr r r!Ú __delitem__s  zOrderedDict.__delitem__ccs,|j}|j}x||k r&|jV|j}qWdS)zod.__iter__() <==> iter(od)N)r5r/r+)r&r<Úcurrr r r!Ú__iter__Žs  zOrderedDict.__iter__ccs,|j}|j}x||k r&|jV|j}qWdS)z#od.__reversed__() <==> reversed(od)N)r5r.r+)r&r<rFr r r!r'—s  zOrderedDict.__reversed__cCs*|j}||_|_|j ¡t |¡dS)z.od.clear() -> None. Remove all items from od.N)r5r.r/r8ÚclearÚdict)r&r<r r r!rH s  zOrderedDict.clearTcCsj|s tdƒ‚|j}|r0|j}|j}||_||_n|j}|j}||_||_|j}|j|=t ||¡}||fS)z•Remove 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)ÚKeyErrorr5r.r/r+r8rIrB)r&r@r<r?rCrDr+r>r r r!Úpopitem§s  zOrderedDict.popitemc Cst|j|}|j}|j}|j}||_||_|j}|rR|j}||_||_||_||_n|j}||_||_||_||_dS)z„Move an existing element to the end (or beginning if last is false). Raise KeyError if the element does not exist. N)r8r.r/r5) r&r+r@r?rCrDZ soft_linkr<Úfirstr r r!Ú move_to_end¾s$ zOrderedDict.move_to_endcCsVtj}t|ƒd}||jƒ}|||jƒd7}|||jƒ|7}|||jƒ|7}|S)Nr2r)Ú_sysÚ getsizeofr4Ú__dict__r8r6r5)r&ZsizeofÚnÚsizer r r!Ú __sizeof__×s  zOrderedDict.__sizeof__cCst|ƒS)z:D.keys() -> a set-like object providing a view on D's keys)r#)r&r r r!ÚkeysâszOrderedDict.keyscCst|ƒS)z a set-like object providing a view on D's items)r*)r&r r r!ÚitemsæszOrderedDict.itemscCst|ƒS)z6D.values() -> an object providing a view on D's values)r,)r&r r r!ÚvaluesêszOrderedDict.valuescCs0||kr||}||=|S||jkr,t|ƒ‚|S)z²od.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__markerrJ)r&r+ÚdefaultÚresultr r r!rBòs zOrderedDict.popNcCs||kr||S|||<|S)z™Insert 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. r )r&r+rXr r r!Ú setdefaultszOrderedDict.setdefaultcCs*|sd|jjfSd|jjt| ¡ƒfS)zod.__repr__() <==> repr(od)z%s()z%s(%r))Ú __class__rÚlistrU)r&r r r!Ú__repr__ szOrderedDict.__repr__cCsHt|ƒ ¡}xttƒƒD]}| |d¡qW|jd|p8ddt| ¡ƒfS)z%Return state information for picklingNr )ÚvarsÚcopyrrBr[ÚiterrU)r&Z inst_dictÚkr r r!Ú __reduce__s zOrderedDict.__reduce__cCs | |¡S)z!od.copy() -> a shallow copy of od)r[)r&r r r!r_szOrderedDict.copycCs |ƒ}x|D] }|||<q W|S)zYCreate a new ordered dictionary with keys from iterable and values set to value. r )ÚclsÚiterabler>r&r+r r r!Úfromkeyss  zOrderedDict.fromkeyscCs2t|tƒr&t ||¡o$ttt||ƒƒSt ||¡S)z“od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. )Ú isinstancerrIÚ__eq__ÚallÚmapÚ_eq)r&Úotherr r r!rg%s zOrderedDict.__eq__)T)T)N)N)#rr(r)Ú__doc__r=rIrAr7r-rErGr'rHrKrMrSrÚMutableMappingÚupdater9rTrUrVÚ__ne__ÚobjectrWrBrZÚ_recursive_reprr]rbr_Ú classmethodrergr r r r!rQs0          )rF)ÚrenameÚdefaultsÚmodulec sºtˆtƒrˆ dd¡ ¡‰tttˆƒƒ‰t t|ƒ¡}|rtƒ}xNt ˆƒD]B\}}|  ¡rtt |ƒst|  d¡st||kr‚d|›ˆ|<|  |¡qJWxR|gˆD]D}t|ƒtk r´tdƒ‚|  ¡sÊtd|›ƒ‚t |ƒrœtd|›ƒ‚qœWtƒ}xNˆD]F}|  d¡r|std|›ƒ‚||kr,td|›ƒ‚|  |¡qðWi}|d k rˆt|ƒ}t|ƒtˆƒkrjtd ƒ‚tttttˆƒt|ƒƒƒƒƒ}tttjˆƒƒ‰tˆƒ‰tˆƒ d d ¡d d…} dd dd„ˆDƒ¡d‰tj‰t‰d| ›d| ›d} ˆd|›dœ} t| | ƒ| d} d|›d| ›d| _|d k r6|| _t‡‡‡fdd„ƒ} d|›d| j_‡fdd „}d!|›d"|_‡fd#d$„}d%d&„}d'd(„}x.| | j||||fD]}|›d)|j›|_q¤W|›d| ›dd*ˆ||| | ||||d+œ }t }xlt ˆƒD]`\}}y||\}}Wn4t!k rBt"|ƒ}d,|›}||f||<YnXt#||d-||<qöWt|tf|ƒ}|d kr¦yt $d ¡j% &d.d/¡}Wnt'tfk r¤YnX|d k r¶||_(|S)0aCReturns 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ú'Úr2éÿÿÿÿú(z, css|]}|›dVqdS)z=%rNr )Ú.0rr r r!ú „sznamedtuple..ú)zdef __new__(_cls, z): return _tuple_new(_cls, (z))Ú namedtuple_)Ú _tuple_newrÚ__new__zCreate new instance of cs2ˆ||ƒ}ˆ|ƒˆkr.tdˆ›dt|ƒ›ƒ‚|S)Nz Expected z arguments, got )r3r4)rcrdrY)Ú_lenÚ num_fieldsÚ tuple_newr r!Ú_make“s  znamedtuple.._makez Make a new z# object from a sequence or iterablecs.| t|jˆ|ƒ¡}|r*tdt|ƒ›ƒ‚|S)NzGot unexpected field names: )r†rirBÚ ValueErrorr\)Ú_selfr;rY)Ú field_namesr r!Ú_replacesznamedtuple.._replacez Return a new z2 object replacing specified fields with new valuescs|jjˆ|S)z/Return a nicely formatted representation string)r[r)r&)Úrepr_fmtr r!r]¦sznamedtuple..__repr__cSstt|j|ƒƒS)z@Return a new OrderedDict which maps field names to their values.)rÚzipÚ_fields)r&r r r!Ú_asdictªsznamedtuple.._asdictcSst|ƒS)z7Return self as a plain tuple. Used by copy and pickle.)Útuple)r&r r r!Ú__getnewargs__®sz"namedtuple..__getnewargs__Ú.r ) rlr1rÚ_field_defaultsÚ_fields_defaultsr‚r†rŠr]rŽrzAlias for field number )ÚdocrÚ__main__))rfÚstrÚreplaceÚsplitr\rirNÚinternÚsetÚ enumerateÚ isidentifierÚ _iskeywordÚ startswithÚaddÚtyper3r‡rr4rIr$rŒÚreprÚjoinr‚ÚexecrlÚ __defaults__rrÚ__func__rr)Ú_nt_itemgettersrJÚ _itemgetterÚpropertyÚ _getframeÚ f_globalsÚgetrr()Útypenamer‰rsrtruÚseenÚindexrÚfield_defaultsÚarg_listÚsÚ namespacer‚r†rŠr]rŽrÚmethodÚclass_namespaceÚcacheÚitemgetter_objectr”rYr )rƒr‰r„r‹r…r!r<s¬              cCs*|j}x|D]}||dƒd||<q WdS)z!Tally elements from the iterable.r r2N)r«)ÚmappingrdZ mapping_getÚelemr r r!Ú_count_elementsès r¹)r¹csØeZdZdZ‡fdd„Zdd„Zd/dd„Zd d „Zed0d d „ƒZ ‡fd d„Z dd„Z dd„Z dd„Z ‡fdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Z‡ZS)1raŸDict 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)] csN|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚tt|ƒ ¡|j||Ž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 z;descriptor '__init__' of 'Counter' object needs an argumentr2z$expected at most 1 arguments, got %dN)r3r4Úsuperrr=rn)r:r;r&)r[r r!r=&s  zCounter.__init__cCsdS)z1The count of elements not in the Counter is zero.r r )r&r+r r r!Ú __missing__:szCounter.__missing__NcCs6|dkrt| ¡tdƒddStj|| ¡tdƒdS)zðList 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('abcdeabcdabcaba').most_common(3) [('a', 5), ('b', 4), ('c', 3)] Nr2T)r+Úreverse)r+)ÚsortedrUr§Ú_heapqÚnlargest)r&rQr r r!Ú most_common?s zCounter.most_commoncCst tt| ¡ƒ¡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Ú_repeatrU)r&r r r!ÚelementsLszCounter.elementscCs tdƒ‚dS)Nz@Counter.fromkeys() is undefined. Use Counter(iterable) instead.)ÚNotImplementedError)rcrdÚvr r r!redszCounter.fromkeyscs¶|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚|r<|dnd}|dk r¤t|tjƒrš|rˆ|j}x8| ¡D]\}}|||dƒ||<qhWq¤tt|ƒ  |¡n t ||ƒ|r²|  |¡dS)aÉLike 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 z9descriptor 'update' of 'Counter' object needs an argumentr2z$expected at most 1 arguments, got %dr N) r3r4rfrÚMappingr«rUrºrrnr¹)r:r;r&rdÚself_getr¸Úcount)r[r r!rnks    zCounter.updatecOs¶|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚|r<|dnd}|dk r¤|j}t|tjƒr„xH| ¡D]\}}||dƒ|||<qdWn x|D]}||dƒd||<qŠW|r²| |¡dS)a·Like 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 z;descriptor 'subtract' of 'Counter' object needs an argumentr2z$expected at most 1 arguments, got %dr N)r3r4r«rfrrÈrUÚsubtract)r:r;r&rdrÉr¸rÊr r r!rË“s   zCounter.subtractcCs | |¡S)zReturn a shallow copy.)r[)r&r r r!r_µsz Counter.copycCs|jt|ƒffS)N)r[rI)r&r r r!rb¹szCounter.__reduce__cs||krtƒ |¡dS)zGLike dict.__delitem__() but does not raise KeyError for missing values.N)rºrE)r&r¸)r[r r!rE¼szCounter.__delitem__cCs`|sd|jjSy&d tdj| ¡ƒ¡}d|jj|fStk rZd |jjt|ƒ¡SXdS)Nz%s()z, z%r: %rz%s({%s})z {0}({1!r})) r[rr¢riÚ__mod__rÀr3ÚformatrI)r&rUr r r!r]Ás zCounter.__repr__cCsxt|tƒstStƒ}x0| ¡D]$\}}|||}|dkr|||<qWx,| ¡D] \}}||krP|dkrP|||<qPW|S)zAdd counts from two counters. >>> Counter('abbb') + Counter('bcc') Counter({'b': 4, 'c': 2, 'a': 1}) r )rfrÚNotImplementedrU)r&rkrYr¸rÊÚnewcountr r r!Ú__add__Ôs    zCounter.__add__cCs|t|tƒstStƒ}x0| ¡D]$\}}|||}|dkr|||<qWx0| ¡D]$\}}||krP|dkrPd|||<qPW|S)z˜ Subtract count, but keep only results with positive counts. >>> Counter('abbbc') - Counter('bccd') Counter({'b': 2, 'a': 1}) r )rfrrÎrU)r&rkrYr¸rÊrÏr r r!Ú__sub__çs   zCounter.__sub__cCs„t|tƒstStƒ}x<| ¡D]0\}}||}||kr:|n|}|dkr|||<qWx,| ¡D] \}}||kr\|dkr\|||<q\W|S)z Union is the maximum of value in either of the input counters. >>> Counter('abbb') | Counter('bcc') Counter({'b': 3, 'c': 2, 'a': 1}) r )rfrrÎrU)r&rkrYr¸rÊÚ other_countrÏr r r!Ú__or__ús   zCounter.__or__cCsVt|tƒstStƒ}x<| ¡D]0\}}||}||kr:|n|}|dkr|||<qW|S)z‡ Intersection is the minimum of corresponding counts. >>> Counter('abbb') & Counter('bcc') Counter({'b': 1}) r )rfrrÎrU)r&rkrYr¸rÊrÒrÏr r r!Ú__and__s  zCounter.__and__cCs0tƒ}x$| ¡D]\}}|dkr|||<qW|S)zEAdds an empty counter, effectively stripping negative and zero countsr )rrU)r&rYr¸rÊr r r!Ú__pos__s  zCounter.__pos__cCs4tƒ}x(| ¡D]\}}|dkrd|||<qW|S)z{Subtracts from an empty counter. Strips positive and zero counts, and flips the sign on negative counts. r )rrU)r&rYr¸rÊr r r!Ú__neg__'s zCounter.__neg__cCs*dd„| ¡Dƒ}x|D] }||=qW|S)z?Internal method to strip elements with a negative or zero countcSsg|]\}}|dks|‘qS)r r )r}r¸rÊr r r!ú 4sz*Counter._keep_positive..)rU)r&Ú nonpositiver¸r r r!Ú_keep_positive2s  zCounter._keep_positivecCs.x$| ¡D]\}}|||7<q W| ¡S)zÂInplace add from another counter, keeping only positive counts. >>> c = Counter('abbb') >>> c += Counter('bcc') >>> c Counter({'b': 4, 'c': 2, 'a': 1}) )rUrÙ)r&rkr¸rÊr r r!Ú__iadd__9s zCounter.__iadd__cCs.x$| ¡D]\}}|||8<q W| ¡S)zÂInplace subtract counter, but keep only results with positive counts. >>> c = Counter('abbbc') >>> c -= Counter('bccd') >>> c Counter({'b': 2, 'a': 1}) )rUrÙ)r&rkr¸rÊr r r!Ú__isub__Fs zCounter.__isub__cCs6x,| ¡D] \}}||}||kr |||<q W| ¡S)z½Inplace union is the maximum of value from either counter. >>> c = Counter('abbb') >>> c |= Counter('bcc') >>> c Counter({'b': 3, 'c': 2, 'a': 1}) )rUrÙ)r&rkr¸rÒrÊr r r!Ú__ior__Ss  zCounter.__ior__cCs6x,| ¡D] \}}||}||kr |||<q W| ¡S)z¯Inplace intersection is the minimum of corresponding counts. >>> c = Counter('abbb') >>> c &= Counter('bcc') >>> c Counter({'b': 1}) )rUrÙ)r&rkr¸rÊrÒr r r!Ú__iand__bs  zCounter.__iand__)N)N)rr(r)rlr=r»rÀrÅrrrernrËr_rbrEr]rÐrÑrÓrÔrÕrÖrÙrÚrÛrÜrÝÚ __classcell__r r )r[r!rós0+    ("    c@s¶eZdZdZdd„Zdd„Zdd„Zd'd d „Zd d „Zd d„Z dd„Z dd„Z e ƒdd„ƒZ edd„ƒZdd„ZeZd(dd„Zedd„ƒZdd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZdS))r a¸ 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|ƒp ig|_dS)zInitialize a ChainMap by setting *maps* to the given mappings. If no mappings are provided, a single empty dictionary is used. N)r\Úmaps)r&rßr r r!r=„szChainMap.__init__cCs t|ƒ‚dS)N)rJ)r&r+r r r!r»‹szChainMap.__missing__c Cs8x,|jD]"}y||Stk r(YqXqW| |¡S)N)rßrJr»)r&r+r·r r r!Ú __getitem__Žs   zChainMap.__getitem__NcCs||kr||S|S)Nr )r&r+rXr r r!r«–sz ChainMap.getcCsttƒj|jŽƒS)N)r4ršÚunionrß)r&r r r!Ú__len__™szChainMap.__len__cCs*i}xt|jƒD]}| |¡qWt|ƒS)N)r$rßrnr`)r&Údr·r r r!rGœszChainMap.__iter__cst‡fdd„|jDƒƒS)Nc3s|]}ˆ|kVqdS)Nr )r}Úm)r+r r!r~£sz(ChainMap.__contains__..)Úanyrß)r&r+r )r+r!Ú __contains__¢szChainMap.__contains__cCs t|jƒS)N)rårß)r&r r r!Ú__bool__¥szChainMap.__bool__cCsd |d tt|jƒ¡¡S)Nz{0.__class__.__name__}({1})z, )rÍr¢rir¡rß)r&r r r!r]¨szChainMap.__repr__cGs|tj|f|žŽƒS)z?Create a ChainMap with a single dict created from the iterable.)rIre)rcrdr:r r r!re­szChainMap.fromkeyscCs$|j|jd ¡f|jdd…žŽS)zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r r2N)r[rßr_)r&r r r!r_²sz ChainMap.copycCs|dkr i}|j|f|jžŽS)zyNew ChainMap with a new map followed by all previous maps. If no map is provided, an empty dict is used. N)r[rß)r&rär r r!Ú new_child¸szChainMap.new_childcCs|j|jdd…ŽS)zNew ChainMap from maps[1:].r2N)r[rß)r&r r r!ÚparentsÀszChainMap.parentscCs||jd|<dS)Nr )rß)r&r+r>r r r!rAÅszChainMap.__setitem__cCs8y|jd|=Wn"tk r2td |¡ƒ‚YnXdS)Nr z(Key not found in the first mapping: {!r})rßrJrÍ)r&r+r r r!rEÈszChainMap.__delitem__cCs0y|jd ¡Stk r*tdƒ‚YnXdS)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.N)rßrKrJ)r&r r r!rKÎszChainMap.popitemcGs>y|jdj|f|žŽStk r8td |¡ƒ‚YnXdS)zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r z(Key not found in the first mapping: {!r}N)rßrBrJrÍ)r&r+r:r r r!rBÕsz ChainMap.popcCs|jd ¡dS)z'Clear maps[0], leaving maps[1:] intact.r N)rßrH)r&r r r!rHÜszChainMap.clear)N)N)rr(r)rlr=r»ràr«rârGrærçrqr]rrrer_Ú__copy__rèr¨rérArErKrBrHr r r r!r vs(     c@sjeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z e ddd„ƒZdS)rcOsœ|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚|r>|d}n0d|krj| d¡}ddl}|jdtddnd}i|_|dk r†| |¡t|ƒr˜| |¡dS) Nzrãr+r r r!re#s  zUserDict.fromkeys)N)rr(r)r=râràrArErGrær]rêr_rrrer r r r!rås c@seZdZdZd@dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„ZeZd%d&„Zd'd(„Zd)d*„Zd+d,„ZdAd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Z dd?„Z"dS)BrzAA more or less complete user-defined wrapper around list objects.NcCsbg|_|dk r^t|ƒt|jƒkr0||jdd…<n.t|tƒrT|jdd…|jdd…<n t|ƒ|_dS)N)rër rfrr\)r&Úinitlistr r r!r=2s zUserList.__init__cCs t|jƒS)N)r¡rë)r&r r r!r]<rízUserList.__repr__cCs|j| |¡kS)N)rëÚ_UserList__cast)r&rkr r r!Ú__lt__=rízUserList.__lt__cCs|j| |¡kS)N)rëró)r&rkr r r!Ú__le__>rízUserList.__le__cCs|j| |¡kS)N)rëró)r&rkr r r!rg?rízUserList.__eq__cCs|j| |¡kS)N)rëró)r&rkr r r!Ú__gt__@rízUserList.__gt__cCs|j| |¡kS)N)rëró)r&rkr r r!Ú__ge__ArízUserList.__ge__cCst|tƒr|jS|S)N)rfrrë)r&rkr r r!Ú__castBszUserList.__castcCs ||jkS)N)rë)r&rïr r r!ræDrízUserList.__contains__cCs t|jƒS)N)r4rë)r&r r r!râErízUserList.__len__cCs(t|tƒr| |j|¡S|j|SdS)N)rfÚslicer[rë)r&Úir r r!ràFs zUserList.__getitem__cCs||j|<dS)N)rë)r&rúrïr r r!rAKrízUserList.__setitem__cCs |j|=dS)N)rë)r&rúr r r!rELrízUserList.__delitem__cCsPt|tƒr| |j|j¡St|t|jƒƒr<| |j|¡S| |jt|ƒ¡S)N)rfrr[rër r\)r&rkr r r!rÐMs  zUserList.__add__cCsPt|tƒr| |j|j¡St|t|jƒƒr<| ||j¡S| t|ƒ|j¡S)N)rfrr[rër r\)r&rkr r r!Ú__radd__Ss  zUserList.__radd__cCsRt|tƒr|j|j7_n2t|t|jƒƒr<|j|7_n|jt|ƒ7_|S)N)rfrrër r\)r&rkr r r!rÚYs  zUserList.__iadd__cCs| |j|¡S)N)r[rë)r&rQr r r!Ú__mul__aszUserList.__mul__cCs|j|9_|S)N)rë)r&rQr r r!Ú__imul__dszUserList.__imul__cCs8|j |j¡}|j |j¡|jddd…|jd<|S)Nrë)r[r‚rPrn)r&rðr r r!rêgszUserList.__copy__cCs|j |¡dS)N)rëÚappend)r&rïr r r!rþmrízUserList.appendcCs|j ||¡dS)N)rëÚinsert)r&rúrïr r r!rÿnrízUserList.insertr{cCs |j |¡S)N)rërB)r&rúr r r!rBoríz UserList.popcCs|j |¡dS)N)rëÚremove)r&rïr r r!rprízUserList.removecCs|j ¡dS)N)rërH)r&r r r!rHqrízUserList.clearcCs | |¡S)N)r[)r&r r r!r_rríz UserList.copycCs |j |¡S)N)rërÊ)r&rïr r r!rÊsrízUserList.countcGs|jj|f|žŽS)N)rër®)r&rïr:r r r!r®trízUserList.indexcCs|j ¡dS)N)rër¼)r&r r r!r¼urízUserList.reversecOs|jj||ŽdS)N)rëÚsort)r&r:r;r r r!rvríz UserList.sortcCs*t|tƒr|j |j¡n |j |¡dS)N)rfrrëÚextend)r&rkr r r!rws zUserList.extend)N)r{)#rr(r)rlr=r]rôrõrgrör÷rórærâràrArErÐrûrÚrüÚ__rmul__rýrêrþrÿrBrrHr_rÊr®r¼rrr r r r!r0s@  c@sheZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZeZd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1ejfd2d3„Zdˆd5d6„Zd1ejfd7d8„Z d‰d:d;„Z!d1ejfdd?„Z#d@dA„Z$d1ejfdBdC„Z%dDdE„Z&dFdG„Z'dHdI„Z(dJdK„Z)dLdM„Z*dNdO„Z+dPdQ„Z,dRdS„Z-dTdU„Z.dVdW„Z/dXdY„Z0dZd[„Z1d\d]„Z2d^d_„Z3d`da„Z4dŠdbdc„Z5e6j7Z7ddde„Z8d‹dgdh„Z9d1ejfdidj„Z:d1ejfdkdl„Z;dmdn„Zddsdt„Z?dŽdudv„Z@ddxdy„ZAd1ejfdzd{„ZBdd|d}„ZCd~d„ZDd€d„ZEd‚dƒ„ZFd„d…„ZGd†d‡„ZHd4S)‘rcCs<t|tƒr||_n&t|tƒr.|jdd…|_n t|ƒ|_dS)N)rfr–rër)r&Úseqr r r!r=„s   zUserString.__init__cCs t|jƒS)N)r–rë)r&r r r!Ú__str__‹rízUserString.__str__cCs t|jƒS)N)r¡rë)r&r r r!r]ŒrízUserString.__repr__cCs t|jƒS)N)Úintrë)r&r r r!Ú__int__rízUserString.__int__cCs t|jƒS)N)Úfloatrë)r&r r r!Ú __float__ŽrízUserString.__float__cCs t|jƒS)N)Úcomplexrë)r&r r r!Ú __complex__rízUserString.__complex__cCs t|jƒS)N)Úhashrë)r&r r r!Ú__hash__rízUserString.__hash__cCs|jdd…fS)N)rë)r&r r r!r‘szUserString.__getnewargs__cCs t|tƒr|j|jkS|j|kS)N)rfrrë)r&Ústringr r r!rg”s  zUserString.__eq__cCs t|tƒr|j|jkS|j|kS)N)rfrrë)r&rr r r!rô˜s  zUserString.__lt__cCs t|tƒr|j|jkS|j|kS)N)rfrrë)r&rr r r!rõœs  zUserString.__le__cCs t|tƒr|j|jkS|j|kS)N)rfrrë)r&rr r r!rö s  zUserString.__gt__cCs t|tƒr|j|jkS|j|kS)N)rfrrë)r&rr r r!r÷¤s  zUserString.__ge__cCst|tƒr|j}||jkS)N)rfrrë)r&Úcharr r r!ræ©s zUserString.__contains__cCs t|jƒS)N)r4rë)r&r r r!râ®rízUserString.__len__cCs| |j|¡S)N)r[rë)r&r®r r r!rà¯rízUserString.__getitem__cCsJt|tƒr| |j|j¡St|tƒr6| |j|¡S| |jt|ƒ¡S)N)rfrr[rër–)r&rkr r r!rаs   zUserString.__add__cCs.t|tƒr| ||j¡S| t|ƒ|j¡S)N)rfr–r[rë)r&rkr r r!rû¶s zUserString.__radd__cCs| |j|¡S)N)r[rë)r&rQr r r!rüºszUserString.__mul__cCs| |j|¡S)N)r[rë)r&r:r r r!r̽szUserString.__mod__cCs| |t¡S)N)r[r:)r&rÍr r r!Ú__rmod__¿szUserString.__rmod__cCs| |j ¡¡S)N)r[rëÚ capitalize)r&r r r!rÃrízUserString.capitalizecCs| |j ¡¡S)N)r[rëÚcasefold)r&r r r!rÄszUserString.casefoldcGs| |jj|f|žŽ¡S)N)r[rëÚcenter)r&Úwidthr:r r r!rÆszUserString.centerr cCs t|tƒr|j}|j |||¡S)N)rfrrërÊ)r&ÚsubÚstartÚendr r r!rÊÈs zUserString.countNcCs>|r.|r| |j ||¡¡S| |j |¡¡S| |j ¡¡S)N)r[rëÚencode)r&ÚencodingÚerrorsr r r!rÌs zUserString.encodecCs|j |||¡S)N)rëÚendswith)r&Úsuffixrrr r r!rÒszUserString.endswithécCs| |j |¡¡S)N)r[rëÚ expandtabs)r&Útabsizer r r!rÔszUserString.expandtabscCs t|tƒr|j}|j |||¡S)N)rfrrëÚfind)r&rrrr r r!r Ös zUserString.findcOs|jj||ŽS)N)rërÍ)r&r:r;r r r!rÍÚszUserString.formatcCs |j |¡S)N)rëÚ format_map)r&r·r r r!r!ÜszUserString.format_mapcCs|j |||¡S)N)rër®)r&rrrr r r!r®ÞszUserString.indexcCs |j ¡S)N)rëÚisalpha)r&r r r!r"àrízUserString.isalphacCs |j ¡S)N)rëÚisalnum)r&r r r!r#árízUserString.isalnumcCs |j ¡S)N)rëÚisascii)r&r r r!r$ârízUserString.isasciicCs |j ¡S)N)rëÚ isdecimal)r&r r r!r%ãrízUserString.isdecimalcCs |j ¡S)N)rëÚisdigit)r&r r r!r&ärízUserString.isdigitcCs |j ¡S)N)rërœ)r&r r r!rœårízUserString.isidentifiercCs |j ¡S)N)rëÚislower)r&r r r!r'ærízUserString.islowercCs |j ¡S)N)rëÚ isnumeric)r&r r r!r(çrízUserString.isnumericcCs |j ¡S)N)rëÚ isprintable)r&r r r!r)èrízUserString.isprintablecCs |j ¡S)N)rëÚisspace)r&r r r!r*érízUserString.isspacecCs |j ¡S)N)rëÚistitle)r&r r r!r+êrízUserString.istitlecCs |j ¡S)N)rëÚisupper)r&r r r!r,ërízUserString.isuppercCs |j |¡S)N)rër¢)r&rr r r!r¢ìrízUserString.joincGs| |jj|f|žŽ¡S)N)r[rëÚljust)r&rr:r r r!r-íszUserString.ljustcCs| |j ¡¡S)N)r[rëÚlower)r&r r r!r.ïrízUserString.lowercCs| |j |¡¡S)N)r[rëÚlstrip)r&Úcharsr r r!r/ðrízUserString.lstripcCs |j |¡S)N)rëÚ partition)r&Úsepr r r!r1òszUserString.partitionr{cCs6t|tƒr|j}t|tƒr |j}| |j |||¡¡S)N)rfrrër[r—)r&ÚoldÚnewÚmaxsplitr r r!r—ôs   zUserString.replacecCs t|tƒr|j}|j |||¡S)N)rfrrëÚrfind)r&rrrr r r!r6ús zUserString.rfindcCs|j |||¡S)N)rëÚrindex)r&rrrr r r!r7þszUserString.rindexcGs| |jj|f|žŽ¡S)N)r[rëÚrjust)r&rr:r r r!r8szUserString.rjustcCs |j |¡S)N)rëÚ rpartition)r&r2r r r!r9szUserString.rpartitioncCs| |j |¡¡S)N)r[rëÚrstrip)r&r0r r r!r:szUserString.rstripcCs|j ||¡S)N)rër˜)r&r2r5r r r!r˜szUserString.splitcCs|j ||¡S)N)rëÚrsplit)r&r2r5r r r!r;szUserString.rsplitFcCs |j |¡S)N)rëÚ splitlines)r&Úkeependsr r r!r< rízUserString.splitlinescCs|j |||¡S)N)rërž)r&Úprefixrrr r r!rž szUserString.startswithcCs| |j |¡¡S)N)r[rëÚstrip)r&r0r r r!r? rízUserString.stripcCs| |j ¡¡S)N)r[rëÚswapcase)r&r r r!r@rízUserString.swapcasecCs| |j ¡¡S)N)r[rëÚtitle)r&r r r!rArízUserString.titlecGs| |jj|Ž¡S)N)r[rëÚ translate)r&r:r r r!rBszUserString.translatecCs| |j ¡¡S)N)r[rëÚupper)r&r r r!rCrízUserString.uppercCs| |j |¡¡S)N)r[rëÚzfill)r&rr r r!rDrízUserString.zfill)NN)r)N)r{)N)Nr{)Nr{)F)N)Irr(r)r=rr]rr r r rrgrôrõrör÷rærâràrÐrûrürrÌrrrrrNÚmaxsizerÊrrrr rÍr!r®r"r#r$r%r&rœr'r(r)r*r+r,r¢r-r.r/r–Ú maketransr1r—r6r7r8r9r:r˜r;r<ržr?r@rArBrCrDr r r r!rƒs†         )7rlrrÚoperatorr r§r rjÚkeywordr rÚsysrNÚheapqr¾Ú_weakrefrr7Ú itertoolsrrÄrrÁrrÃÚreprlibrrqÚ _collectionsrÚ ImportErrorÚMutableSequenceÚregisterrr"ÚKeysViewr#Ú ItemsViewr*Ú ValuesViewr,rpr-rIrr¦rr¹rrmr rrÚSequencerr r r r!Ús\      _-oKS