Mini Shell

Direktori : /usr/lib/python3.6/site-packages/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/__pycache__/ordered_set.cpython-36.pyc

3

���Xx�@s6dZddlZed�ZdZdd�ZGdd�dej�ZdS)a]
An OrderedSet is a custom MutableSet that remembers its order, so that every
entry has an index that can be looked up.

Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger,
and released under the MIT license.

Rob Speer's changes are as follows:

    - changed the content from a doubly-linked list to a regular Python list.
      Seriously, who wants O(1) deletes but O(N) lookups by index?
    - add() returns the index of the added item
    - index() just returns the index of an item
    - added a __getstate__ and __setstate__ so it can be pickled
    - added __getitem__
�Nz2.0.1cCs"t|d�o t|t�o t|t�S)a

    Are we being asked to look up a list of things, instead of a single thing?
    We check for the `__iter__` attribute so that this can cover types that
    don't have to be known by this module, such as NumPy arrays.

    Strings, however, should be considered as atomic values to look up, not
    iterables. The same goes for tuples, since they are immutable and therefore
    valid entries.

    We don't need to check for the Python 2 `unicode` type, because it doesn't
    have an `__iter__` attribute anyway.
    �__iter__)�hasattr�
isinstance�str�tuple)�obj�r�!/usr/lib/python3.6/ordered_set.py�is_iterables
r
c@s�eZdZdZd%dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZeZdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdS)&�
OrderedSetz�
    An OrderedSet is a custom MutableSet that remembers its order, so that
    every entry has an index that can be looked up.
    NcCs g|_i|_|dk	r||O}dS)N)�items�map)�self�iterablerrr	�__init__,szOrderedSet.__init__cCs
t|j�S)N)�lenr)rrrr	�__len__2szOrderedSet.__len__csp|tkr�St|d�s t|t�rB�j|}t|t�r<t|�S|Sn*t|�r`t�fdd�|D��Std|��dS)a�
        Get the item at a given index.

        If `index` is a slice, you will get back that slice of items. If it's
        the slice [:], exactly the same object is returned. (If you want an
        independent copy of an OrderedSet, use `OrderedSet.copy()`.)

        If `index` is an iterable, you'll get the OrderedSet of items
        corresponding to those indices. This is similar to NumPy's
        "fancy indexing".
        �	__index__csg|]}�j|�qSr)r)�.0�i)rrr	�
<listcomp>Jsz*OrderedSet.__getitem__.<locals>.<listcomp>z+Don't know how to index an OrderedSet by %rN)	�	SLICE_ALLrr�slicer�listrr
�	TypeError)r�index�resultr)rr	�__getitem__5s

zOrderedSet.__getitem__cCst|�S)N)r)rrrr	�copyOszOrderedSet.copycCst|�dkrdSt|�SdS)Nr)N)rr)rrrr	�__getstate__RszOrderedSet.__getstate__cCs"|dkr|jg�n
|j|�dS)N)N)r)r�staterrr	�__setstate__^szOrderedSet.__setstate__cCs
||jkS)N)r
)r�keyrrr	�__contains__dszOrderedSet.__contains__cCs0||jkr&t|j�|j|<|jj|�|j|S)z�
        Add `key` as an item to this OrderedSet, then return its index.

        If `key` is already in the OrderedSet, return the index it already
        had.
        )r
rr�append)rr"rrr	�addgs
zOrderedSet.addcCsJd}yx|D]}|j|�}qWWn$tk
rDtdt|���YnX|S)z~
        Update the set with the given iterable sequence, then return the index
        of the last element inserted.
        Nz(Argument needs to be an iterable, got %s)r%r�
ValueError�type)rZsequenceZ
item_index�itemrrr	�updatets
zOrderedSet.updatecs$t|�r�fdd�|D�S�j|S)z�
        Get the index of a given entry, raising an IndexError if it's not
        present.

        `key` can be an iterable of entries that is not a string, in which case
        this returns a list of indices.
        csg|]}�j|��qSr)r)rZsubkey)rrr	r�sz$OrderedSet.index.<locals>.<listcomp>)r
r
)rr"r)rr	r�szOrderedSet.indexcCs,|jstd��|jd}|jd=|j|=|S)zp
        Remove and return the last element from the set.

        Raises KeyError if the set is empty.
        zSet is empty����r+)r�KeyErrorr
)r�elemrrr	�pop�s
zOrderedSet.popcCsT||krP|j|}|j|=|j|=x,|jj�D]\}}||kr.|d|j|<q.WdS)z�
        Remove an element.  Do not raise an exception if absent.

        The MutableSet mixin uses this to implement the .remove() method, which
        *does* raise an error when asked to remove a non-existent item.
        r*N)r
r)rr"r�k�vrrr	�discard�s
zOrderedSet.discardcCs|jdd�=|jj�dS)z8
        Remove all items from this OrderedSet.
        N)rr
�clear)rrrr	r2�szOrderedSet.clearcCs
t|j�S)N)�iterr)rrrr	r�szOrderedSet.__iter__cCs
t|j�S)N)�reversedr)rrrr	�__reversed__�szOrderedSet.__reversed__cCs&|sd|jjfSd|jjt|�fS)Nz%s()z%s(%r))�	__class__�__name__r)rrrr	�__repr__�szOrderedSet.__repr__cCsXt|t�r&t|�t|�ko$|j|jkSyt|�}Wntk
rFdSXt|�|kSdS)NF)rrrr�setr)r�otherZother_as_setrrr	�__eq__�s
zOrderedSet.__eq__)N)r7�
__module__�__qualname__�__doc__rrrrrr!r#r%r$r)rr.r1r2rr5r8r;rrrr	r's&

r)r>�collectionsrr�__version__r
�
MutableSetrrrrr	�<module>s