HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/jaraco/__pycache__/collections.cpython-310.pyc
o

;j�g�@sddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
mZddlZee
e	e
ejfZdede
fdd�ZGdd	�d	ejj�ZGd
d�de�Zdd
�ZGdd�de�Zdd�Zedfdd�ZGdd�de�ZGdd�de�ZGdd�d�ZGdd�d�Zdd�Z Gdd �d e�Z!Gd!d"�d"e"ejj#�Z$Gd#d$�d$e�Z%Gd%d&�d&ejjejj&�Z'Gd'd(�d(ee%�Z(Gd)d*�d*�Z)Gd+d,�d,ej*�Z+Gd-d.�d.�Z,Gd/d0�d0�Z-d1d2�Z.Gd3d4�d4ej/�Z0Gd5d6�d6�Z1Gd7d8�d8e�Z2dS)9�N)�	Container�Iterable�Mapping)�Callable�Union�obj�returncCs8t|tj�r	|jSt|t�st|t�st|�}|j}|S�N)�
isinstance�re�Pattern�	fullmatchrr�set�__contains__)r�r�F/opt/saltstack/salt/lib/python3.10/site-packages/jaraco/collections.py�	_dispatchs

rc@sBeZdZdZdedefdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�
ProjectionaT
    Project a set of keys over a mapping

    >>> sample = {'a': 1, 'b': 2, 'c': 3}
    >>> prj = Projection(['a', 'c', 'd'], sample)
    >>> dict(prj)
    {'a': 1, 'c': 3}

    Projection also accepts an iterable or callable or pattern.

    >>> iter_prj = Projection(iter('acd'), sample)
    >>> call_prj = Projection(lambda k: ord(k) in (97, 99, 100), sample)
    >>> pat_prj = Projection(re.compile(r'[acd]'), sample)
    >>> prj == iter_prj == call_prj == pat_prj
    True

    Keys should only appear if they were specified and exist in the space.
    Order is retained.

    >>> list(prj)
    ['a', 'c']

    Attempting to access a key not in the projection
    results in a KeyError.

    >>> prj['b']
    Traceback (most recent call last):
    ...
    KeyError: 'b'

    Use the projection to update another dict.

    >>> target = {'a': 2, 'b': 2}
    >>> target.update(prj)
    >>> target
    {'a': 1, 'b': 2, 'c': 3}

    Projection keeps a reference to the original dict, so
    modifying the original dict may modify the Projection.

    >>> del sample['a']
    >>> dict(prj)
    {'c': 3}
    �keys�spacecCst|�|_||_dSr	)r�_match�_space)�selfrrrrr�__init__M�

zProjection.__init__cCs|�|�s	t|��|j|Sr	)r�KeyErrorr�r�keyrrr�__getitem__Qs

zProjection.__getitem__cCst|j|j�Sr	)�filterrr�rrrr�_keys_resolvedV�zProjection._keys_resolvedcCs|��Sr	)r!r rrr�__iter__YszProjection.__iter__cCstt|����Sr	)�len�tupler!r rrr�__len__\�zProjection.__len__N)�__name__�
__module__�__qualname__�__doc__�
_Matchablerrrr!r#r&rrrrrs-rc� eZdZdZ�fdd�Z�ZS)�
DictFiltera
    *Deprecated*

    Takes a dict and simulates a sub-dict based on a pattern.

    >>> sample = dict(a=1, b=2, c=3, d=4, ef=5)

    Filter for only single-character keys:

    >>> filtered = DictFilter(sample, include_pattern='.$')
    >>> filtered == dict(a=1, b=2, c=3, d=4)
    True

    >>> filtered['e']
    Traceback (most recent call last):
    ...
    KeyError: 'e'

    >>> 'e' in filtered
    False

    Pattern is useful for excluding keys with a prefix.

    >>> filtered = DictFilter(sample, include_pattern=r'(?![ace])')
    >>> filtered == dict(b=2, d=4)
    True

    DictFilter keeps a reference to the original dict, so
    modifying the original dict may modify the filtered dict.

    >>> del sample['d']
    >>> dict(filtered)
    {'b': 2}
    cs*tjdtdd�t��t�|�j|�dS)Nz@DictFilter is deprecated. Pass re.Pattern to Projection instead.�)�
stacklevel)�warnings�warn�DeprecationWarning�superrr�compile�match)r�dictZinclude_pattern��	__class__rrr�s�zDictFilter.__init__�r(r)r*r+r�
__classcell__rrr8rr.`s#r.cst�fdd�|��D��S)a1
    dict_map is much like the built-in function map.  It takes a dictionary
    and applys a function to the values of that dictionary, returning a
    new dictionary with the mapped values in the original keys.

    >>> d = dict_map(lambda x:x+1, dict(a=1, b=2))
    >>> d == dict(a=2,b=3)
    True
    c3s �|]\}}|�|�fVqdSr	r)�.0r�value��functionrr�	<genexpr>�s�zdict_map.<locals>.<genexpr>)r7�items)r?Z
dictionaryrr>r�dict_map�s
rBc@s|eZdZdZiejfdd�Zedd��Zdd�Z	dd	d
�Z
dd�Zd
d�Ze
ddi��ZGdd�de�Zed�Zed�ZdS)�RangeMapaP
    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.

    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'

    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')

    cCst�||�||_||_dSr	)r7r�sort_paramsr6)r�sourcerD�key_match_comparatorrrrr�s
zRangeMap.__init__cCs||tdd�tjd�S)NT)�reverse)rDrF)r7�operator�ge)�clsrErrr�left�s�z
RangeMap.leftcCsbt|��fi|j��}t|tj�r|�||�}|S|�||�}t�||�}|tj	ur/t
|��|Sr	)�sortedrrDr
rC�Itemr�_find_first_match_r7�undefined_valuer)r�item�sorted_keys�resultrrrrr�s�
zRangeMap.__getitem__NcC�"z||WSty|YSw)z�
        Return the value for key if key is in the dictionary, else default.
        If default is not given, it defaults to None, so that this method
        never raises a KeyError.
        �r)rr�defaultrrr�gets

�zRangeMap.getcCs0t�|j|�}tt||��}|r|dSt|���Nr)�	functools�partialr6�listrr)rrrPZis_match�matchesrrrrNs
zRangeMap._find_first_match_cCs*t|��fi|j��}|tj|tjfSr	)rLrrDrC�
first_item�	last_item)rrQrrr�boundsszRangeMap.boundsZRangeValueUndefinedrc@seZdZdZdS)z
RangeMap.Itemz
RangeMap ItemN)r(r)r*r+rrrrrMsrMr���r	)r(r)r*r+rH�ler�classmethodrKrrVrNr^�typerO�intrMr\r]rrrrrC�sP

rCcC�|Sr	r)�xrrr�
__identity!�rfFcs�fdd�}t|��||d�S)a�
    Return the items of the dictionary sorted by the keys.

    >>> sample = dict(foo=20, bar=42, baz=10)
    >>> tuple(sorted_items(sample))
    (('bar', 42), ('baz', 10), ('foo', 20))

    >>> reverse_string = lambda s: ''.join(reversed(s))
    >>> tuple(sorted_items(sample, key=reverse_string))
    (('foo', 20), ('bar', 42), ('baz', 10))

    >>> tuple(sorted_items(sample, reverse=True))
    (('foo', 20), ('baz', 10), ('bar', 42))
    cs�|d�SrWr)rP�rrr�pairkey_key6�z!sorted_items.<locals>.pairkey_key)rrG)rLrA)�drrGrirrhr�sorted_items%srlcs�eZdZdZedd��Z�fdd�Z�fdd�Z�fdd	�Z�fd
d�Z	�fdd
�Z
�fdd�Z�fdd�Z�fdd�Z
dd�Z�ZS)�KeyTransformingDictz�
    A dict subclass that transforms the keys before they're used.
    Subclasses may override the default transform_key to customize behavior.
    cCrdr	rrhrrr�
transform_keyBsz!KeyTransformingDict.transform_keycs8tt|���t|i|��}|��D]}|j|�qdSr	)r4rmrr7rA�__setitem__)r�argsZkargsrkrPr8rrrFs
�zKeyTransformingDict.__init__cs |�|�}tt|��||�dSr	)rnr4rmro)rr�valr8rrroNs
zKeyTransformingDict.__setitem__c�|�|�}tt|��|�Sr	)rnr4rmrrr8rrrR�
zKeyTransformingDict.__getitem__crrr	)rnr4rmrrr8rrrVrsz KeyTransformingDict.__contains__crrr	)rnr4rm�__delitem__rr8rrrtZrszKeyTransformingDict.__delitem__c�(|�|�}tt|�j|g|�Ri|��Sr	)rnr4rmrV�rrrp�kwargsr8rrrV^�
zKeyTransformingDict.getcrur	)rnr4rm�
setdefaultrvr8rrrybrxzKeyTransformingDict.setdefaultcrur	)rnr4rm�poprvr8rrrzfrxzKeyTransformingDict.popcs4zt�fdd�|��D��WStyt���w)z�
        Given a key, return the actual key stored in self that matches.
        Raise KeyError if the key isn't found.
        c3s�|]	}|�kr|VqdSr	r)r<Ze_keyrhrrr@p��z7KeyTransformingDict.matching_key_for.<locals>.<genexpr>)�nextr�
StopIterationrrrrhr�matching_key_forjs
�z$KeyTransformingDict.matching_key_for)r(r)r*r+�staticmethodrnrrorrrtrVryrzr~r;rrr8rrm<s
rmc@seZdZdZedd��ZdS)�FoldedCaseKeyedDicta�
    A case-insensitive dictionary (keys are compared as insensitive
    if they are strings).

    >>> d = FoldedCaseKeyedDict()
    >>> d['heLlo'] = 'world'
    >>> list(d.keys()) == ['heLlo']
    True
    >>> list(d.values()) == ['world']
    True
    >>> d['hello'] == 'world'
    True
    >>> 'hello' in d
    True
    >>> 'HELLO' in d
    True
    >>> print(repr(FoldedCaseKeyedDict({'heLlo': 'world'})))
    {'heLlo': 'world'}
    >>> d = FoldedCaseKeyedDict({'heLlo': 'world'})
    >>> print(d['hello'])
    world
    >>> print(d['Hello'])
    world
    >>> list(d.keys())
    ['heLlo']
    >>> d = FoldedCaseKeyedDict({'heLlo': 'world', 'Hello': 'world'})
    >>> list(d.values())
    ['world']
    >>> key, = d.keys()
    >>> key in ['heLlo', 'Hello']
    True
    >>> del d['HELLO']
    >>> d
    {}

    get should work

    >>> d['Sumthin'] = 'else'
    >>> d.get('SUMTHIN')
    'else'
    >>> d.get('OTHER', 'thing')
    'thing'
    >>> del d['sumthin']

    setdefault should also work

    >>> d['This'] = 'that'
    >>> print(d.setdefault('this', 'other'))
    that
    >>> len(d)
    1
    >>> print(d['this'])
    that
    >>> print(d.setdefault('That', 'other'))
    other
    >>> print(d['THAT'])
    other

    Make it pop!

    >>> print(d.pop('THAT'))
    other

    To retrieve the key in its originally-supplied form, use matching_key_for

    >>> print(d.matching_key_for('this'))
    This

    >>> d.matching_key_for('missing')
    Traceback (most recent call last):
    ...
    KeyError: 'missing'
    cCstj�|�Sr	)�jaraco�textZ
FoldedCaserhrrrrn�sz!FoldedCaseKeyedDict.transform_keyN)r(r)r*r+rrnrrrrr�usJr�c@s eZdZdZdd�Zdd�ZdS)�DictAdapteraD
    Provide a getitem interface for attributes of an object.

    Let's say you want to get at the string.lowercase property in a formatted
    string. It's easy with DictAdapter.

    >>> import string
    >>> print("lowercase is %(ascii_lowercase)s" % DictAdapter(string))
    lowercase is abcdefghijklmnopqrstuvwxyz
    cC�
||_dSr	)�object)rZ
wrapped_obrrrr��
zDictAdapter.__init__cCst|j|�Sr	)�getattrr�)r�namerrrr�rjzDictAdapter.__getitem__N)r(r)r*r+rrrrrrr��sr�cr-)�ItemsAsAttributesa�
    Mix-in class to enable a mapping object to provide items as
    attributes.

    >>> C = type('C', (dict, ItemsAsAttributes), dict())
    >>> i = C()
    >>> i['foo'] = 'bar'
    >>> i.foo
    'bar'

    Natural attribute access takes precedence

    >>> i.foo = 'henry'
    >>> i.foo
    'henry'

    But as you might expect, the mapping functionality is preserved.

    >>> i['foo']
    'bar'

    A normal attribute error should be raised if an attribute is
    requested that doesn't exist.

    >>> i.missing
    Traceback (most recent call last):
    ...
    AttributeError: 'C' object has no attribute 'missing'

    It also works on dicts that customize __getitem__

    >>> missing_func = lambda self, key: 'missing item'
    >>> C = type(
    ...     'C',
    ...     (dict, ItemsAsAttributes),
    ...     dict(__missing__ = missing_func),
    ... )
    >>> i = C()
    >>> i.missing
    'missing item'
    >>> i.foo
    'missing item'
    c
s�z	ttt|�|�WSty@}z+t�}dd�}||||�}||ur*|WYd}~S|j\}|�d|jjd�}|f|_�d}~ww)NcSrSr	rT)ZcontrZmissing_resultrrr�
_safe_getitem
s

�z4ItemsAsAttributes.__getattr__.<locals>._safe_getitemr4�)	r�r4r��AttributeErrorr�rp�replacer9r()rr�eZnovalr�rR�messager8rr�__getattr__s��zItemsAsAttributes.__getattr__)r(r)r*r+r�r;rrr8rr��s,r�cCs2tdd�|��D��}t|�t|�kstd��|S)a�
    Given a dictionary, return another dictionary with keys and values
    switched. If any of the values resolve to the same key, raises
    a ValueError.

    >>> numbers = dict(a=1, b=2, c=3)
    >>> letters = invert_map(numbers)
    >>> letters[1]
    'a'
    >>> numbers['d'] = 3
    >>> invert_map(numbers)
    Traceback (most recent call last):
    ...
    ValueError: Key conflict in inverted mapping
    css�|]	\}}||fVqdSr	r)r<�k�vrrrr@.r{zinvert_map.<locals>.<genexpr>z Key conflict in inverted mapping)r7rAr$�
ValueError)�map�resrrr�
invert_mapsr�c@�eZdZdZdd�ZdS)�IdentityOverrideMapz�
    A dictionary that by default maps each key to itself, but otherwise
    acts like a normal dictionary.

    >>> d = IdentityOverrideMap()
    >>> d[42]
    42
    >>> d['speed'] = 'speedo'
    >>> print(d['speed'])
    speedo
    cCs|Sr	rrrrr�__missing__ArgzIdentityOverrideMap.__missing__N)r(r)r*r+r�rrrrr�4sr�c@sNeZdZdZdd�Zdd�ZejZdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
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
    >>> stack['a'] = 4
    >>> set(stack.keys()) == set(['a', 'b', 'c'])
    True
    >>> set(stack.items()) == set([('a', 4), ('b', 2), ('c', 2)])
    True
    >>> dict(**stack) == dict(stack) == dict(a=4, 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
    >>> del stack['c']
    >>> dict(stack)
    {'a': 1}
    cCs(t�|�}tttj�dd�|D����S)Ncss�|]}|��VqdSr	)r)r<�crrrr@m��z%DictStack.__iter__.<locals>.<genexpr>)rZr#�iterr�	itertools�chain�
from_iterable)rZdictsrrrr#krxzDictStack.__iter__cCs4ttt�|���D]}||vr||Sq	t|��r	)�reversedr%rZr#r)rrZscoperrrros
�zDictStack.__getitem__cCstjj�||�Sr	)�collections�abcrr�r�otherrrrrwr'zDictStack.__contains__cCsttt|���Sr	)r$rZr�r rrrr&zr'zDictStack.__len__cCst�|d�}|�||�S�Nr_)rZrro)rrrP�lastrrrro}szDictStack.__setitem__cCst�|d�}|�|�Sr�)rZrrt)rrr�rrrrt�s
zDictStack.__delitem__cOstj|g|�Ri|��Sr	)rZrz�rrprwrrrrz�sz
DictStack.popN)r(r)r*r+r#rrZ�append�pushrr&rortrzrrrrr�Es%r�csTeZdZdZ�fdd�Z�fdd�Zdd�Z�fdd	�Z�fd
d�Zdd
�Z	�Z
S)�BijectiveMapa�
    A Bijective Map (two-way mapping).

    Implemented as a simple dictionary of 2x the size, mapping values back
    to keys.

    Note, this implementation may be incomplete. If there's not a test for
    your use case below, it's likely to fail, so please test and send pull
    requests or patches for additional functionality needed.


    >>> m = BijectiveMap()
    >>> m['a'] = 'b'
    >>> m == {'a': 'b', 'b': 'a'}
    True
    >>> print(m['b'])
    a

    >>> m['c'] = 'd'
    >>> len(m)
    2

    Some weird things happen if you map an item to itself or overwrite a
    single key of a pair, so it's disallowed.

    >>> m['e'] = 'e'
    Traceback (most recent call last):
    ValueError: Key cannot map to itself

    >>> m['d'] = 'e'
    Traceback (most recent call last):
    ValueError: Key/Value pairs may not overlap

    >>> m['e'] = 'd'
    Traceback (most recent call last):
    ValueError: Key/Value pairs may not overlap

    >>> print(m.pop('d'))
    c

    >>> 'c' in m
    False

    >>> m = BijectiveMap(dict(a='b'))
    >>> len(m)
    1
    >>> print(m['b'])
    a

    >>> m = BijectiveMap()
    >>> m.update(a='b')
    >>> m['b']
    'a'

    >>> del m['b']
    >>> len(m)
    0
    >>> 'a' in m
    False
    cs"tt|���|j|i|��dSr	)r4r�r�updater�r8rrr�szBijectiveMap.__init__csl||krtd��||vr|||kp||vo|||k}|r"td��tt|��||�tt|��||�dS)NzKey cannot map to itselfzKey/Value pairs may not overlap)r�r4r�ro)rrPr=Zoverlapr8rrro�s
�
�zBijectiveMap.__setitem__cCs|�|�dSr	)rz)rrPrrrrt�r"zBijectiveMap.__delitem__cstt|���dS)Nr/)r4r�r&r r8rrr&��zBijectiveMap.__len__cs6||}tt|��|�tt|�j|g|�Ri|��Sr	)r4r�rtrz)rrrprwZmirrorr8rrrz�szBijectiveMap.popcOs*t|i|��}|��D]}|j|�qdSr	)r7rAro)rrprwrkrPrrrr��s�zBijectiveMap.update)r(r)r*r+rrortr&rzr�r;rrr8rr��s=r�csfeZdZdZdgZ�fdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
�ZS)�
FrozenDicta�
    An immutable mapping.

    >>> a = FrozenDict(a=1, b=2)
    >>> b = FrozenDict(a=1, b=2)
    >>> a == b
    True

    >>> a == dict(a=1, b=2)
    True
    >>> dict(a=1, b=2) == a
    True
    >>> 'a' in a
    True
    >>> type(hash(a)) is type(0)
    True
    >>> set(iter(a)) == {'a', 'b'}
    True
    >>> len(a)
    2
    >>> a['a'] == a.get('a') == 1
    True

    >>> a['c'] = 3
    Traceback (most recent call last):
    ...
    TypeError: 'FrozenDict' object does not support item assignment

    >>> a.update(y=3)
    Traceback (most recent call last):
    ...
    AttributeError: 'FrozenDict' object has no attribute 'update'

    Copies should compare equal

    >>> copy.copy(a) == a
    True

    Copies should be the same type

    >>> isinstance(copy.copy(a), FrozenDict)
    True

    FrozenDict supplies .copy(), even though
    collections.abc.Mapping doesn't demand it.

    >>> a.copy() == a
    True
    >>> a.copy() is not a
    True
    Z__datacs$tt|��|�}t|i|��|_|Sr	)r4r��__new__r7�_FrozenDict__data)rJrprwrr8rrr�$szFrozenDict.__new__cCs
||jvSr	�r�rrrrr*r�zFrozenDict.__contains__cCsttt|j�����Sr	)�hashr%rLr�rAr rrr�__hash__.szFrozenDict.__hash__cC�
t|j�Sr	)r�r�r rrrr#2r�zFrozenDict.__iter__cCr�r	)r$r�r rrrr&5r�zFrozenDict.__len__cCs
|j|Sr	r�rrrrr8r�zFrozenDict.__getitem__cOs|jj|i|��Sr	)r�rVr�rrrrV<r�zFrozenDict.getcCst|t�r|j}|j�|�Sr	)r
r�r��__eq__r�rrrr�@s
zFrozenDict.__eq__cCs
t�|�S)zReturn a shallow copy of self)�copyr rrrr�Es
zFrozenDict.copy)r(r)r*r+�	__slots__r�rr�r#r&rrVr�r�r;rrr8rr��s4r�cs:eZdZdZd	�fdd�	Zedd��Zedd��Z�ZS)
�Enumerationa�
    A convenient way to provide enumerated values

    >>> e = Enumeration('a b c')
    >>> e['a']
    0

    >>> e.a
    0

    >>> e[1]
    'b'

    >>> set(e.names) == set('abc')
    True

    >>> set(e.codes) == set(range(3))
    True

    >>> e.get('d') is None
    True

    Codes need not start with 0

    >>> e = Enumeration('a b c', range(1, 4))
    >>> e['a']
    1

    >>> e[3]
    'c'
    Ncs<t|t�r	|��}|durt��}tt|��t||��dSr	)	r
�str�splitr��countr4r�r�zip)r�names�codesr8rrrks

zEnumeration.__init__cCsdd�|D�S)Ncss�|]
}t|t�r|VqdSr	)r
r�)r<rrrrr@ts�z$Enumeration.names.<locals>.<genexpr>rr rrrr�rszEnumeration.namescs�fdd��jD�S)Nc3s�|]}�|VqdSr	r)r<r�r rrr@xr�z$Enumeration.codes.<locals>.<genexpr>)r�r rr rr�vszEnumeration.codesr	)	r(r)r*r+r�propertyr�r�r;rrr8rr�Js 
r�c@r�)�
Everythinga
    A collection "containing" every possible thing.

    >>> 'foo' in Everything()
    True

    >>> import random
    >>> random.randint(1, 999) in Everything()
    True

    >>> random.choice([None, 'foo', 42, ('a', 'b', 'c')]) in Everything()
    True
    cC�dS�NTrr�rrrr�rgzEverything.__contains__N)r(r)r*r+rrrrrr�{sr�cr-)�InstrumentedDictaD
    Instrument an existing dictionary with additional
    functionality, but always reference and mutate
    the original dictionary.

    >>> orig = {'a': 1, 'b': 2}
    >>> inst = InstrumentedDict(orig)
    >>> inst['a']
    1
    >>> inst['c'] = 3
    >>> orig['c']
    3
    >>> inst.keys() == orig.keys()
    True
    cst���||_dSr	)r4r�data)rr�r8rrr�rzInstrumentedDict.__init__r:rrr8rr��sr�c@�(eZdZdZdd�ZeZdd�ZeZdS)�Leasta
    A value that is always lesser than any other

    >>> least = Least()
    >>> 3 < least
    False
    >>> 3 > least
    True
    >>> least < 3
    True
    >>> least <= 3
    True
    >>> least > 3
    False
    >>> 'x' > least
    True
    >>> None > least
    True
    cCr�r�rr�rrr�__le__�rgzLeast.__le__cCr��NFrr�rrr�__ge__�rgzLeast.__ge__N)r(r)r*r+r��__lt__r��__gt__rrrrr���r�c@r�)�Greatesta2
    A value that is always greater than any other

    >>> greatest = Greatest()
    >>> 3 < greatest
    True
    >>> 3 > greatest
    False
    >>> greatest < 3
    False
    >>> greatest > 3
    True
    >>> greatest >= 3
    True
    >>> 'x' > greatest
    False
    >>> None > greatest
    False
    cCr�r�rr�rrrr��rgzGreatest.__ge__cCr�r�rr�rrrr��rgzGreatest.__le__N)r(r)r*r+r�r�r�r�rrrrr��r�r�cCs|dd�g}|dd�<|S)z�
    Clear items in place and return a copy of items.

    >>> items = [1, 2, 3]
    >>> popped = pop_all(items)
    >>> popped is items
    False
    >>> popped
    [1, 2, 3]
    >>> items
    []
    Nr)rArRrrr�pop_all�s
r�c�(eZdZdZ�fdd�Zdd�Z�ZS)�FreezableDefaultDicta!
    Often it is desirable to prevent the mutation of
    a default dict after its initial construction, such
    as to prevent mutation during iteration.

    >>> dd = FreezableDefaultDict(list)
    >>> dd[0].append('1')
    >>> dd.freeze()
    >>> dd[1]
    []
    >>> len(dd)
    1
    cst|dt�j�|�S)N�_frozen)r�r4r�rr8rrr�sz FreezableDefaultDict.__missing__cs�fdd��_dS)Ncs���Sr	)�default_factoryrhr rr�<lambda>	sz-FreezableDefaultDict.freeze.<locals>.<lambda>)r�r rr r�freezer�zFreezableDefaultDict.freeze)r(r)r*r+r�r�r;rrr8rr��sr�c@seZdZddd�Zdd�ZdS)�AccumulatorrcCr�r	�rq)r�initialrrrr
r�zAccumulator.__init__cCs|j|7_|jSr	r�)rrqrrr�__call__szAccumulator.__call__N)r)r(r)r*rr�rrrrr�s
r�cr�)�WeightedLookupa�
    Given parameters suitable for a dict representing keys
    and a weighted proportion, return a RangeMap representing
    spans of values proportial to the weights:

    >>> even = WeightedLookup(a=1, b=1)

    [0, 1) -> a
    [1, 2) -> b

    >>> lk = WeightedLookup(a=1, b=2)

    [0, 1) -> a
    [1, 3) -> b

    >>> lk[.5]
    'a'
    >>> lk[1.5]
    'b'

    Adds ``.random()`` to select a random weighted value:

    >>> lk.random() in ['a', 'b']
    True

    >>> choices = [lk.random() for x in range(1000)]

    Statistically speaking, choices should be .5 a:b
    >>> ratio = choices.count('a') / choices.count('b')
    >>> .4 < ratio < .6
    True
    cs>t|i|��}tt�|���}t�jt||���tj	d�dS)N)rF)
r7r�r��valuesr4rr�rrH�lt)rrprw�rawZindexesr8rrr7s zWeightedLookup.__init__cCs |��\}}t��|}||Sr	)r^�random)r�lower�upper�selectorrrrr�>szWeightedLookup.random)r(r)r*r+rr�r;rrr8rr�s!r�)3rrH�collections.abcr�r�r�rXr�r1rrr�typingrrZjaraco.textr�rr,rr�rr.rBr7rCrfrlrmr�r�r�r�r�rZ�MutableMappingr�r��Hashabler�r�r��UserDictr�r�r�r��defaultdictr�r�r�rrrr�<module>sL
A-
9PFEc]1