📄 _plist.cpython-39.pyc

Size: 9,331 bytes
Path: //usr/lib64/python3.9/site-packages/pyrsistent/__pycache__/_plist.cpython-39.pyc
Modified: 2022-02-11 23:38:07
a

`�]_e �@s�ddlmZmZddlmZddlmZGdd�de�ZGdd�de�Z	Gdd	�d	e	�Z
e�e
�e�e
�Gd
d�de	�Ze�e�e�e�e�Z
ddd�Zdd�ZdS)�)�Sequence�Hashable)�Integral)�reducec@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�
_PListBuilderzc
    Helper class to allow construction of a list without
    having to reverse it in the end.
    )�_head�_tailcCst|_t|_dS�N)�_EMPTY_PLISTrr��self�r
�7/usr/lib64/python3.9/site-packages/pyrsistent/_plist.py�__init__
sz_PListBuilder.__init__cCs6|js||�|_|j|_n||�|j_|jj|_|jSr	)rr�rest)r�elem�constructorr
r
r�_appends


z_PListBuilder._appendcCs|�|dd��S)NcSs
t|t�Sr	)�PListr
)�er
r
r�<lambda>�z+_PListBuilder.append_elem.<locals>.<lambda>�r�rrr
r
r�append_elemsz_PListBuilder.append_elemcCs|�|dd��S)NcSs|Sr	r
)�lr
r
rrrz,_PListBuilder.append_plist.<locals>.<lambda>r)r�plr
r
r�append_plistsz_PListBuilder.append_plistcCs|jSr	)rrr
r
r�build!sz_PListBuilder.buildN)
�__name__�
__module__�__qualname__�__doc__�	__slots__rrrrrr
r
r
rrs
rc@s�eZdZdZejZejZdd�Zdd�Zdd�Z	e	Z
dd	�Zd
d�Zdd
�Z
e
Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�
_PListBase)�__weakref__cCstt|�ffSr	)�plist�listrr
r
r�
__reduce__.sz_PListBase.__reduce__cCstdd�|D��S)a
        Return the length of the list, computed by traversing it.

        This is obviously O(n) but with the current implementation
        where a list is also a node the overhead of storing the length
        in every node would be quite significant.
        css|]
}dVqdS)�Nr
)�.0�_r
r
r�	<genexpr>:rz%_PListBase.__len__.<locals>.<genexpr>)�sumrr
r
r�__len__2sz_PListBase.__len__cCsd�t|��S)Nz
plist({0}))�formatr'rr
r
r�__repr__<sz_PListBase.__repr__cCs
t||�S)z
        Return a new list with elem inserted as new head.

        >>> plist([1, 2]).cons(3)
        plist([3, 1, 2])
        )rrr
r
r�cons@sz_PListBase.conscCs|}|D]}|�|�}q|S)a 
        Return a new list with all elements of iterable repeatedly cons:ed to the current list.
        NB! The elements will be inserted in the reverse order of the iterable.
        Runs in O(len(iterable)).

        >>> plist([1, 2]).mcons([3, 4])
        plist([4, 3, 1, 2])
        �r1)r�iterable�headrr
r
r�mconsIs	z_PListBase.mconscCs&t�}|}|r"|�|j�}|j}q
|S)a
        Return a reversed version of list. Runs in O(n) where n is the length of the list.

        >>> plist([1, 2, 3]).reverse()
        plist([3, 2, 1])

        Also supports the standard reversed function.

        >>> reversed(plist([1, 2, 3]))
        plist([3, 2, 1])
        )r&r1�firstr)r�resultr4r
r
r�reverseXsz_PListBase.reversecCsNt�}|}d}|r6||kr6|�|j�|j}|d7}q|sB|tfS|��|fS)z�
        Spilt the list at position specified by index. Returns a tuple containing the
        list up until index and the list after the index. Runs in O(index).

        >>> plist([1, 2, 3, 4]).split(2)
        (plist([1, 2]), plist([3, 4]))
        rr))rrr6rr
r)r�indexZlb�
right_list�ir
r
r�splitms
z_PListBase.splitccs|}|r|jV|j}qdSr	�r6r)rZlir
r
r�__iter__�sz_PListBase.__iter__cCst|t�stSt|�t|�kSr	)�
isinstancer$�NotImplemented�tuple)r�otherr
r
r�__lt__�s
z_PListBase.__lt__cCsHt|t�stS|}|}|r<|r<|j|jks.dS|j}|j}q|oF|S)z�
        Traverses the lists, checking equality of elements.

        This is an O(n) operation, but preserves the standard semantics of list equality.
        F)r?r$r@r6r)rrBZ	self_headZ
other_headr
r
r�__eq__�s
z_PListBase.__eq__c
Cs�t|t�rN|jdur>|jdur>|jdus2|jdkr>|�|j�Stt|�|�St|t�sjt	dt
|�j��|dkr~|t|�7}z|�|�j
WSty�}ztd�|�WYd}~n
d}~00dS)Nr)z-'%s' object cannot be interpreted as an indexr�PList index out of range)r?�slice�start�stop�step�_dropr&rAr�	TypeError�typer�lenr6�AttributeError�
IndexError)rr9rr
r
r�__getitem__�s
(
z_PListBase.__getitem__cCs0|dkrtd��|}|dkr,|j}|d8}q|S)NrrEr))rOr)r�countr4r
r
rrJ�s
z_PListBase._dropcCstt|��Sr	)�hashrArr
r
r�__hash__�sz_PListBase.__hash__cCsJt�}|}|r8|j|kr$|�|j�S|�|j�|j}q
td�|���dS)a

        Return new list with first element equal to elem removed. O(k) where k is the position
        of the element that is removed.

        Raises ValueError if no matching element is found.

        >>> plist([1, 2, 1]).remove(1)
        plist([2, 1])
        z{0} not found in PListN)rr6rrr�
ValueErrorr/)rrZbuilderr4r
r
r�remove�s
z_PListBase.removeN)rr r!r#rrQr9r(r.r0�__str__r1r5r8�__reversed__r<r>rCrDrPrJrSrUr
r
r
rr$%s&
	r$cs0eZdZdZdZ�fdd�Zdd�ZeZ�ZS)ra�
    Classical Lisp style singly linked list. Adding elements to the head using cons is O(1).
    Element access is O(k) where k is the position of the element in the list. Taking the
    length of the list is O(n).

    Fully supports the Sequence and Hashable protocols including indexing and slicing but
    if you need fast random access go for the PVector instead.

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

    Some examples:

    >>> x = plist([1, 2])
    >>> y = x.cons(3)
    >>> x
    plist([1, 2])
    >>> y
    plist([3, 1, 2])
    >>> y.first
    3
    >>> y.rest == x
    True
    >>> y[:2]
    plist([3, 1])
    r=cs tt|��|�}||_||_|Sr	)�superr�__new__r6r)�clsr6r�instance��	__class__r
rrY�sz
PList.__new__cCsdS)NTr
rr
r
r�__bool__szPList.__bool__)	rr r!r"r#rYr^�__nonzero__�
__classcell__r
r
r\rr�s
rc@s4eZdZdZdd�ZeZedd��Zedd��ZdS)	�_EmptyPListr
cCsdS)NFr
rr
r
rr^
sz_EmptyPList.__bool__cCstd��dS)NzEmpty PList has no first)rNrr
r
rr6sz_EmptyPList.firstcCs|Sr	r
rr
r
rrsz_EmptyPList.restN)	rr r!r#r^r_�propertyr6rr
r
r
rra
s
rar
FcCs$|st|�}|��tdd�|t�S)a 
    Creates a new persistent list containing all elements of iterable.
    Optional parameter reverse specifies if the elements should be inserted in
    reverse order or not.

    >>> plist([1, 2, 3])
    plist([1, 2, 3])
    >>> plist([1, 2, 3], reverse=True)
    plist([3, 2, 1])
    cSs
|�|�Sr	r2)rrr
r
rr/rzplist.<locals>.<lambda>)r'r8rr
)r3r8r
r
rr& sr&cGst|�S)zj
    Creates a new persistent list containing all arguments.

    >>> l(1, 2, 3)
    plist([1, 2, 3])
    )r&)�elementsr
r
rr2srN)r
F)�collections.abcrrZnumbersr�	functoolsr�objectrr$r�registerrar
r&rr
r
r
r�<module>s:(