eftddlZddlZddlZddlZGddeejjZGddeZ dS)Nc8eZdZdZdZdZejZdZ dZ dS) DictStacka A stack of dictionaries that behaves as a view on those dictionaries, giving preference to the last. >>> stack = DictStack([dict(a=1, c=2), dict(b=2, a=2)]) >>> stack['a'] 2 >>> stack['b'] 2 >>> stack['c'] 2 >>> len(stack) 3 >>> stack.push(dict(a=3)) >>> stack['a'] 3 >>> set(stack.keys()) == set(['a', 'b', 'c']) True >>> set(stack.items()) == set([('a', 3), ('b', 2), ('c', 2)]) True >>> dict(**stack) == dict(stack) == dict(a=3, c=2, b=2) True >>> d = stack.pop() >>> stack['a'] 2 >>> d = stack.pop() >>> stack['a'] 1 >>> stack.get('b', None) >>> 'c' in stack True ct|}tttjd|DS)Nc3>K|]}|VdSN)keys).0cs /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/setuptools/_distutils/_collections.py z%DictStack.__iter__..,s*5N5N1affhh5N5N5N5N5N5N)list__iter__iterset itertoolschain from_iterable)selfdictss r rzDictStack.__iter__*sH d##C 555N5N5N5N5NNNOOPPPr cttt|D]}||vr ||cSt |r)reversedtuplerrKeyError)rkeyscopes r __getitem__zDictStack.__getitem__.sWeDMM$$7$78899 " "Ee||Sz!!!smmr cLtjj||Sr) collectionsabcMapping __contains__)rothers r r"zDictStack.__contains__6s&33D%@@@r cTttt|Sr)lenrr)rs r __len__zDictStack.__len__9s4T ##$$$r N) __name__ __module__ __qualname____doc__rrrappendpushr"r&r r rrsjBQQQ ;DAAA%%%%%r rceZdZdZiejfdZedZdZ ddZ dZ dZ e d d iZGd d eZed ZedZdS)RangeMapaa A dictionary-like object that uses the keys as bounds for a range. Inclusion of the value for that range is determined by the key_match_comparator, which defaults to less-than-or-equal. A value is returned for a key if it is the first key that matches in the sorted list of keys. One may supply keyword parameters to be passed to the sort function used to sort keys (i.e. key, reverse) as sort_params. Let's create a map that maps 1-3 -> 'a', 4-6 -> 'b' >>> r = RangeMap({3: 'a', 6: 'b'}) # boy, that was easy >>> r[1], r[2], r[3], r[4], r[5], r[6] ('a', 'a', 'a', 'b', 'b', 'b') Even float values should work so long as the comparison operator supports it. >>> r[4.5] 'b' But you'll notice that the way rangemap is defined, it must be open-ended on one side. >>> r[0] 'a' >>> r[-1] 'a' One can close the open-end of the RangeMap by using undefined_value >>> r = RangeMap({0: RangeMap.undefined_value, 3: 'a', 6: 'b'}) >>> r[0] Traceback (most recent call last): ... KeyError: 0 One can get the first or last elements in the range by using RangeMap.Item >>> last_item = RangeMap.Item(-1) >>> r[last_item] 'b' .last_item is a shortcut for Item(-1) >>> r[RangeMap.last_item] 'b' Sometimes it's useful to find the bounds for a RangeMap >>> r.bounds() (0, 6) RangeMap supports .get(key, default) >>> r.get(0, 'not found') 'not found' >>> r.get(7, 'not found') 'not found' One often wishes to define the ranges by their left-most values, which requires use of sort params and a key_match_comparator. >>> r = RangeMap({1: 'a', 4: 'b'}, ... sort_params=dict(reverse=True), ... key_match_comparator=operator.ge) >>> r[1], r[2], r[3], r[4], r[5], r[6] ('a', 'a', 'a', 'b', 'b', 'b') That wasn't nearly as easy as before, so an alternate constructor is provided: >>> r = RangeMap.left({1: 'a', 4: 'b', 7: RangeMap.undefined_value}) >>> r[1], r[2], r[3], r[4], r[5], r[6] ('a', 'a', 'a', 'b', 'b', 'b') cXt||||_||_dSr)dict__init__ sort_paramsmatch)rsourcer3key_match_comparators r r2zRangeMap.__init__s) dF###&) r cN||tdtjS)NT)reverse)r3r6)r1operatorge)clsr5s r leftz RangeMap.lefts/s T 2 2 2    r cVt|fi|j}t|tjr|||}nN|||}t||}|tj urt||Sr) sortedrr3 isinstancer/Itemr_find_first_match_r1undefined_valuer)ritem sorted_keysresultrs r rzRangeMap.__getitem__sTYY[[==D,<== dHM * * $%%k$&788FF))+t<rr3r/ first_item last_item)rrDs r boundszRangeMap.boundss=TYY[[==D,<== H/0+h>P2QRRr RangeValueUndefinedr-ceZdZdZdS) RangeMap.Itemz RangeMap ItemN)r'r(r)r*r-r r r@rUsr r@rr)r'r(r)r*r9ler2 classmethodr<rrHrArRtyperBintr@rPrQr-r r r/r/>sNN`,.HK****   [       SSS :dd0"b99;;OsaJRIIIr r/) rrJrr9rr r!rr1r/r-r r r[s2%2%2%2%2%ko-2%2%2%lDDDDDtDDDDDr