%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/pyrsistent/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/pyrsistent/__pycache__/_pmap.cpython-312.pyc

�

n�9e�J��>�ddlmZmZddlmZddlmZmZddlm	Z	ddl
mZed�Zedd�	�Z
Gd
�d�ZGd�d
e�ZGd�de�ZGd�deee
f�Zej$e�ej$e�d�Zeid�Zidfd�Zd�Zy)�)�Mapping�Hashable)�chain)�Generic�TypeVar)�pvector��	transform�KT�VT_coT)�	covariantc�(�eZdZdZd�Zd�Zd�Zd�Zy)�PMapViewa�View type for the persistent map/dict type `PMap`.

    Provides an equivalent of Python's built-in `dict_values` and `dict_items`
    types that result from expreessions such as `{}.values()` and
    `{}.items()`. The equivalent for `{}.keys()` is absent because the keys are
    instead represented by a `PSet` object, which can be created in `O(1)` time.

    The `PMapView` class is overloaded by the `PMapValues` and `PMapItems`
    classes which handle the specific case of values and items, respectively

    Parameters
    ----------
    m : mapping
        The mapping/dict-like object of which a view is to be created. This
        should generally be a `PMap` object.
    c��t|t�s't|t�rt|�}nt	d��t
j
|d|�y)Nz"PViewMap requires a Mapping object�_map)�
isinstance�PMapr�pmap�	TypeError�object�__setattr__)�self�ms  �2/usr/lib/python3/dist-packages/pyrsistent/_pmap.py�__init__zPMapView.__init__s=���!�T�"��!�W�%���G��� D�E�E����4���+�c�,�t|j�S�N)�lenr�rs r�__len__zPMapView.__len__&s���4�9�9�~�rc�0�tt|��d���)Nz
 is immutable)r�type)r�k�vs   rrzPMapView.__setattr__)s���T�$�Z�9�:�:rc��td���Nz"Persistent maps are not reversible�rr s r�__reversed__zPMapView.__reversed__,����<�=�=rN)�__name__�
__module__�__qualname__�__doc__rr!rr)�rrrr
s���",��;�>rrc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�
PMapValuesaView type for the values of the persistent map/dict type `PMap`.

    Provides an equivalent of Python's built-in `dict_values` type that result
    from expreessions such as `{}.values()`. See also `PMapView`.

    Parameters
    ----------
    m : mapping
        The mapping/dict-like object of which a view is to be created. This
        should generally be a `PMap` object.
    c�6�|jj�Sr�r�
itervaluesr s r�__iter__zPMapValues.__iter__;s���y�y�#�#�%�%rc�:�||jj�vSrr3)r�args  r�__contains__zPMapValues.__contains__>s���d�i�i�*�*�,�,�,rc�2�dtt|���d�S�Nzpmap_values(�)��list�iterr s r�__str__zPMapValues.__str__B����d�4��:�.�/�q�1�1rc�2�dtt|���d�Sr:r<r s r�__repr__zPMapValues.__repr__Er@rc��||uryy�NTFr/�r�xs  r�__eq__zPMapValues.__eq__Hs��
��9�T�rN�	r+r,r-r.r5r8r?rBrGr/rrr1r1/s ��
�&�-�2�2�rr1c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�	PMapItemsa|View type for the items of the persistent map/dict type `PMap`.

    Provides an equivalent of Python's built-in `dict_items` type that result
    from expreessions such as `{}.items()`. See also `PMapView`.

    Parameters
    ----------
    m : mapping
        The mapping/dict-like object of which a view is to be created. This
        should generally be a `PMap` object.
    c�6�|jj�Sr)r�	iteritemsr s rr5zPMapItems.__iter__Zs���y�y�"�"�$�$rc�n�|\}}||jvxr|j||k(S#t$rYywxYw)NF)�	Exceptionr)rr7r$r%s    rr8zPMapItems.__contains__]s:���U�a���D�I�I�~�3�$�)�)�A�,�!�"3�3���&��&�s�(�	4�4c�2�dtt|���d�S�Nzpmap_items(r;r<r s rr?zPMapItems.__str__c����T�$�t�*�-�.�a�0�0rc�2�dtt|���d�SrPr<r s rrBzPMapItems.__repr__frQrc�j�||uryt|t|��sy|j|jk(SrD)rr#rrEs  rrGzPMapItems.__eq__is.����9�T��A�t�D�z�*�5��Y�Y�!�&�&�(�(rNrHr/rrrJrJNs ��
�%�4�1�1�)rrJc�N��eZdZdZdZ�fd�Zed��Zed��Zd�Z	ed��Z
d�ZejZ
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zej4Zd�ZeZeZeZd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&e&Z'd�Z(d�Z)d �Z*Gd!�d"e+�Z,d#�Z-�xZ.S)$ra�
    Persistent map/dict. Tries to follow the same naming conventions as the built in dict where feasible.

    Do not instantiate directly, instead use the factory functions :py:func:`m` or :py:func:`pmap` to
    create an instance.

    Was originally written as a very close copy of the Clojure equivalent but was later rewritten to closer
    re-assemble the python dict. This means that a sparse vector (a PVector) of buckets is used. The keys are
    hashed and the elements inserted at position hash % len(bucket_vector). Whenever the map size exceeds 2/3 of
    the containing vectors size the map is reallocated to a vector of double the size. This is done to avoid
    excessive hash collisions.

    This structure corresponds most closely to the built in dict type and is intended as a replacement. Where the
    semantics are the same (more or less) the same function names have been used but for some cases it is not possible,
    for example assignments and deletion of values.

    PMap implements the Mapping protocol and is Hashable. It also supports dot-notation for
    element access.

    Random access and insert is log32(n) where n is the size of the map.

    The following are examples of some common operations on persistent maps

    >>> m1 = m(a=1, b=3)
    >>> m2 = m1.set('c', 3)
    >>> m3 = m2.remove('a')
    >>> m1 == {'a': 1, 'b': 3}
    True
    >>> m2 == {'a': 1, 'b': 3, 'c': 3}
    True
    >>> m3 == {'b': 3, 'c': 3}
    True
    >>> m3['c']
    3
    >>> m3.c
    3
    )�_size�_buckets�__weakref__�_cached_hashc�J��tt|�|�}||_||_|Sr)�superr�__new__rUrV)�cls�size�bucketsr�	__class__s    �rr[zPMap.__new__�s'����T�3�'��,����
���
��rc�B�t|�t|�z}||}||fSr)�hashr)r^�key�index�buckets    r�_get_bucketzPMap._get_bucket�s'���S�	�C��L�(�������f�}�rc�t�tj||�\}}|r|D]\}}||k(s�|cSt|��r)rre�KeyError)r^rb�_rdr$r%s      r�_getitemz
PMap._getitem�sF���$�$�W�c�2�	��6���
���1���8��H�
��s�m�rc�B�tj|j|�Sr)rrirV�rrbs  r�__getitem__zPMap.__getitem__�s���}�}�T�]�]�C�0�0rc�^�tj||�\}}|r|D]\}}||k(s�yyyrD)rre)r^rbrhrdr$s     r�	_containszPMap._contains�s@���$�$�W�c�2�	��6���
 ���1���8��
 ��rc�:�|j|j|�Sr)rnrVrks  rr8zPMap.__contains__�s���~�~�d�m�m�S�1�1rc�"�|j�Sr)�iterkeysr s rr5z
PMap.__iter__�����}�}��rc��td��r'r(r s rr)zPMap.__reversed__�r*rc��	||S#t$r4}tdjt|�j|��|�d}~wwxYw)Nz{0} has no attribute '{1}')rg�AttributeError�formatr#r+)rrb�es   r�__getattr__zPMap.__getattr__�sK��	���9����	� �,�3�3�D��J�4G�4G��M���
��	�s��	A�/?�Ac#�DK�|j�D]	\}}|���y�wr�rL)rr$rhs   rrqz
PMap.iterkeys��%�����N�N�$�	�D�A�q��G�	��� c#�DK�|j�D]	\}}|���y�wrrz)rrhr%s   rr4zPMap.itervalues�r{r|c#�TK�|jD]}|s�|D]\}}||f���
�y�wr)rV)rrdr$r%s    rrLzPMap.iteritems�s8�����m�m�	�F��"��D�A�q��Q�$�J��	�s�(�(c��t|�Sr)r1r s r�valueszPMap.values�s
���$��rc��ddlm}||�S)N�)�PSet)�_psetr�)rr�s  r�keysz	PMap.keys�s����D�z�rc��t|�Sr)rJr s r�itemsz
PMap.items�s�����rc��|jSr�rUr s rr!zPMap.__len__�s���z�z�rc�H�djtt|���S)Nz	pmap({0}))rv�str�dictr s rrBz
PMap.__repr__�s���!�!�#�d�4�j�/�2�2rc�D�||uryt|t�stSt|�t|�k7ryt|t�rt|d�r&t|d�r|j|jk7ry|j|jk(ryt|j��t|j��k(St|t�rt|j��|k(St|j��t|j��k(S)NTFrX)rr�NotImplementedrr�hasattrrXrVr�rLr��r�others  rrGzPMap.__eq__�s����5�=���%��)�!�!��t�9��E�
�"���e�T�"���n�-�'�%��2P��)�)�U�-?�-?�?���}�}����.������(�)�T�%�/�/�2C�-D�D�D�
��t�
$�����(�)�U�2�2��D�N�N�$�%��e�k�k�m�)<�<�<rc��td��)NzPMaps are not orderabler(r�s  r�__lt__zPMap.__lt__s���1�2�2rc�"�|j�Sr)rBr s rr?zPMap.__str__
rrrc��t|d�s'tt|j���|_|jS)NrX)r�ra�	frozensetrLrXr s r�__hash__z
PMap.__hash__s1���t�^�,� $�Y�t�~�~�/?�%@� A�D��� � � rc�^�|j�j||�j�S)a4
        Return a new PMap with key and val inserted.

        >>> m1 = m(a=1, b=2)
        >>> m2 = m1.set('a', 3)
        >>> m3 = m1.set('c' ,4)
        >>> m1 == {'a': 1, 'b': 2}
        True
        >>> m2 == {'a': 3, 'b': 2}
        True
        >>> m3 == {'a': 1, 'b': 2, 'c': 4}
        True
        )�evolver�set�
persistent�rrb�vals   rr�zPMap.sets&���|�|�~�!�!�#�s�+�6�6�8�8rc�\�|j�j|�j�S)z�
        Return a new PMap without the element specified by key. Raises KeyError if the element
        is not present.

        >>> m1 = m(a=1, b=2)
        >>> m1.remove('a')
        pmap({'b': 2})
        )r��remover�rks  rr�zPMap.remove%s$���|�|�~�$�$�S�)�4�4�6�6rc�H�	|j|�S#t$r|cYSwxYw)a
        Return a new PMap without the element specified by key. Returns reference to itself
        if element is not present.

        >>> m1 = m(a=1, b=2)
        >>> m1.discard('a')
        pmap({'b': 2})
        >>> m1 is m1.discard('c')
        True
        )r�rgrks  r�discardzPMap.discard0s*��	��;�;�s�#�#���	��K�	�s��!�!c�*�|jd�g|���S)a,
        Return a new PMap with the items in Mappings inserted. If the same key is present in multiple
        maps the rightmost (last) value is inserted.

        >>> m1 = m(a=1, b=2)
        >>> m1.update(m(a=2, c=3), {'a': 17, 'd': 35}) == {'a': 17, 'b': 2, 'c': 3, 'd': 35}
        True
        c��|Srr/)�l�rs  r�<lambda>zPMap.update.<locals>.<lambda>Is��Q�r)�update_with)r�mapss  r�updatezPMap.update@s�� �t����6��6�6rc	���|j�}|D]<}|j�D]'\}}|j|||vr||||�n|��)�>|j�S)a%
        Return a new PMap with the items in Mappings maps inserted. If the same key is present in multiple
        maps the values will be merged using merge_fn going from left to right.

        >>> from operator import add
        >>> m1 = m(a=1, b=2)
        >>> m1.update_with(add, m(a=2)) == {'a': 3, 'b': 2}
        True

        The reverse behaviour of the regular merge. Keep the leftmost element instead of the rightmost.

        >>> m1 = m(a=1)
        >>> m1.update_with(lambda l, r: l, m(a=2), {'a':3})
        pmap({'a': 1})
        )r�r�r�r�)r�	update_fnr�r��maprb�values       rr�zPMap.update_withKsn�� �,�,�.���	^�C�!�i�i�k�
^�
��U����C�3�'�>��7�3�<��!?�W\�]�
^�	^��!�!�#�#rc�$�|j|�Sr)r�r�s  r�__add__zPMap.__add__bs���{�{�5�!�!rc�&�tt|�ffSr)rr�r s r�
__reduce__zPMap.__reduce__gs���d�4�j�]�"�"rc��t||�S)a�
        Transform arbitrarily complex combinations of PVectors and PMaps. A transformation
        consists of two parts. One match expression that specifies which elements to transform
        and one transformation function that performs the actual transformation.

        >>> from pyrsistent import freeze, ny
        >>> news_paper = freeze({'articles': [{'author': 'Sara', 'content': 'A short article'},
        ...                                   {'author': 'Steve', 'content': 'A slightly longer article'}],
        ...                      'weather': {'temperature': '11C', 'wind': '5m/s'}})
        >>> short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:25] + '...' if len(c) > 25 else c)
        >>> very_short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:15] + '...' if len(c) > 15 else c)
        >>> very_short_news.articles[0].content
        'A short article'
        >>> very_short_news.articles[1].content
        'A slightly long...'

        When nothing has been transformed the original data structure is kept

        >>> short_news is news_paper
        True
        >>> very_short_news is news_paper
        False
        >>> very_short_news.articles[0] is news_paper.articles[0]
        True
        r	)r�transformationss  rr
zPMap.transformks��4���/�/rc��|Srr/r s r�copyz	PMap.copy�s���rc�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�
PMap._Evolver)�_buckets_evolverrU�_original_pmapc�r�||_|jj�|_|j|_yr)r�rVr�r�rU)r�
original_pmaps  rrzPMap._Evolver.__init__�s.��"/�D��$1�$:�$:�$B�$B�$D�D�!�&�,�,�D�Jrc�B�tj|j|�Sr)rrir�rks  rrlzPMap._Evolver.__getitem__�s���=�=��!6�!6��<�<rc�(�|j||�yr)r�r�s   r�__setitem__zPMap._Evolver.__setitem__�s���H�H�S�#�rc��||f}tj|j|�\}}t|j�d|jzk}|r�|D]@\}}||k(s�||ur.|D�	�
cgc]\}	}
|	|k(s|	|
fn|	|f��}}	}
||j|<|cS|r"|j�|j
||�S|g}|j|�||j|<|xjdz
c_|S|r"|j�|j
||�S|g|j|<|xjdz
c_|Scc}
}	w)Ngq=
ףp�?r�)rrer�rrU�_reallocater��extend)rrbr��kvrcrd�reallocation_requiredr$r%�k2�v2�
new_buckets            rr�zPMap._Evolver.set�sS���s��B� �,�,�T�-B�-B�C�H�M�E�6�$'��(=�(=�$>���
�
�AR�$R�!��"�$�D�A�q��C�x��C�<�ag�)h�W]�WY�[]�2��7�2�r�(�"�c��*R�)h�J�)h�;E�D�1�1�%�8�#��$�)��$�$�&��8�8�C��-�-� �T�
��!�!�&�)�/9��%�%�e�,��
�
�a��
��K�)��$�$�&��8�8�C��-�-�02�t��%�%�e�,��
�
�a��
��K��/*is�&D=c��dt|j�z}|dgz}|jj�}tjd�|D��D]7\}}t|�|z}||r||j
||f��0||fg||<�9t�j�|_|jj|�y)N�c3�&K�|]	}|s�|���y�wrr/)�.0rFs  r�	<genexpr>z,PMap._Evolver._reallocate.<locals>.<genexpr>�s����+D�!�!�A�+D�s��)
rr�r�r�
from_iterablera�appendrr�r�)r�new_size�new_listr^r$r%rcs       rr�zPMap._Evolver._reallocate�s����3�t�4�4�5�5�H��4�&�(�H��+�+�6�6�8�G��+�+�+D�w�+D�D�
/���1��Q��(�*���E�?��U�O�*�*�A�q�6�2�()�1�v�h�H�U�O�
/�%,�I�$5�$5�$7�D�!��!�!�(�(��2rc�6�|jj�Sr)r��is_dirtyr s rr�zPMap._Evolver.is_dirty�s���(�(�1�1�3�3rc��|j�r3t|j|jj	��|_|j
Sr)r�rrUr�r�r�r s rr�zPMap._Evolver.persistent�s9���}�}��&*�4�:�:�t�7L�7L�7W�7W�7Y�&Z��#��&�&�&rc��|jSrr�r s rr!zPMap._Evolver.__len__�s���:�:�rc�B�tj|j|�Sr)rrnr�rks  rr8zPMap._Evolver.__contains__�s���>�>�$�"7�"7��=�=rc�&�|j|�yr)r�rks  r�__delitem__zPMap._Evolver.__delitem__�s���K�K��rc�P�tj|j|�\}}|rb|D��cgc]\}}||k(r�||f��}}}t|�t|�z
}|dkDr*|r|nd|j|<|xj|zc_|Stdj
|���cc}}w)Nrz{0})rrer�rrUrgrv)rrbrcrdr$r%r��	size_diffs        rr�zPMap._Evolver.remove�s��� �,�,�T�-B�-B�C�H�M�E�6��39�L��!�Q�!�s�(�q�!�f�L�
�L���K�#�j�/�9�	��q�=�AK�:�QU�D�)�)�%�0��J�J�)�+�J��K��5�<�<��,�-�-��Ms
�
B"�B"N)r+r,r-�	__slots__rrlr�r�r�r�r�r!r8r�r�r/rr�_Evolverr��s?��C�	�	-�
	=�	� 	�D	3� 	4�	'�	�	>�	�	.rr�c�$�|j|�S)a-
        Create a new evolver for this pmap. For a discussion on evolvers in general see the
        documentation for the pvector evolver.

        Create the evolver and perform various mutating updates to it:

        >>> m1 = m(a=1, b=2)
        >>> e = m1.evolver()
        >>> e['c'] = 3
        >>> len(e)
        3
        >>> del e['a']

        The underlying pmap remains the same:

        >>> m1 == {'a': 1, 'b': 2}
        True

        The changes are kept in the evolver. An updated pmap can be created using the
        persistent() function on the evolver.

        >>> m2 = e.persistent()
        >>> m2 == {'b': 2, 'c': 3}
        True

        The new pmap will share data with the original pmap in the same way that would have
        been done if only using operations on the pmap.
        )r�r s rr�zPMap.evolver�s��:�}�}�T�"�"r)/r+r,r-r.r�r[�staticmethodrerirlrnr8r�getr5r)rxrqr4rLr�r�r�r!rBrG�__ne__r��__le__�__gt__�__ge__r?r�r�r�r�r�r�r��__or__r�r
r�rr�r��
__classcell__)r_s@rrrns���$�JE�I������
����1��	��	�2��+�+�C��>����� ����3�=�$�^�^�F�3��F�
�F�
�F��!�
9� 	7�� 	7�$�."��F�#�0�8�^.�6�^.�@#rrc��|r|}n	dt|�zxsd}|dgz}t|t�st	|�}|j�D]8\}}t
|�}||z}||}|r|j||f��1||fg||<�:tt|�t�j|��S#t$rd}Y��wxYw)Nr��)rrNrrr�r�rar�rrr�)	�initial�pre_sizer]r^r$r%�hrcrds	         r�_turbo_mappingr�
s������	��s�7�|�#�(�q�D��d�V�m�G��g�w�'��w�-���
�
��&���1���G���D���������M�M�1�a�&�!� �!�f�X�G�E�N�&���G��g�i�.�.�w�7�8�8��/�	��D�	�s�B1�1B?�>B?c�4�|s|dk(rtSt||�S)a�
    Create new persistent map, inserts all elements in initial into the newly created map.
    The optional argument pre_size may be used to specify an initial size of the underlying bucket vector. This
    may have a positive performance impact in the cases where you know beforehand that a large number of elements
    will be inserted into the map eventually since it will reduce the number of reallocations required.

    >>> pmap({'a': 13, 'b': 14}) == {'a': 13, 'b': 14}
    True
    r)�_EMPTY_PMAPr�)r�r�s  rrr0s ���x�1�}����'�8�,�,rc��t|�S)z�
    Creates a new persistent map. Inserts all key value arguments into the newly created map.

    >>> m(a=13, b=14) == {'a': 13, 'b': 14}
    True
    )r)�kwargss rrr@s����<�rN)�collections.abcrr�	itertoolsr�typingrr�pyrsistent._pvectorr�pyrsistent._transformationsr
rrrr1rJr�registerr�r�rrr/rr�<module>r�s���-��#�'�1��T�]����4�(��#>�#>�J���>)��)�@Y#�7�2�u�9��Y#�v����������$��9�@�R��#���a�
-� r

Zerion Mini Shell 1.0