3
4^^              $   @   s  d Z ddddddddd	g	Zd
dlT d
dlZeej7 Zd
dlmZmZ d
dlm	Z
 d
dlZd
dlZd
dlmZ d
dlmZmZmZ d
dlmZ yd
dlmZ W n ek
r   Y nX ej e yd
dlm!Z! W n ek
r   Y nX G dd de"Z#G dd de$Z%G dd de&Z'G dd de(Z)G dd de*Z+yd
dlm+Z+ W n ek
rX   Y nX dZ,dZ-d Z.d!d!dd"d#dZ/d$d% Z0yd
d&lm0Z0 W n ek
r   Y nX G d'd de*Z1G d(d	 d	e2Z3G d)d de2Z4G d*d deZ5G d+d de6Z7dS ),a?  This module implements specialized container datatypes providing
alternatives to Python's general purpose built-in containers, dict,
list, set, and tuple.

* namedtuple   factory function for creating tuple subclasses with named fields
* deque        list-like container with fast appends and pops on either end
* ChainMap     dict-like class for creating a single view of multiple mappings
* Counter      dict subclass for counting hashable objects
* OrderedDict  dict subclass that remembers the order entries were added
* defaultdict  dict subclass that calls a factory function to supply missing values
* UserDict     wrapper around dictionary objects for easier dict subclassing
* UserList     wrapper around list objects for easier list subclassing
* UserString   wrapper around string objects for easier string subclassing

dequedefaultdict
namedtupleUserDictUserList
UserStringCounterOrderedDictChainMap    )*N)
itemgettereq)	iskeyword)proxy)repeatchainstarmap)recursive_repr)r   )r   c               @   s   e Zd Zdd ZdS )_OrderedDictKeysViewc             c   s   t | jE d H  d S )N)reversed_mapping)self r   */usr/lib/python3.6/collections/__init__.py__reversed__5   s    z!_OrderedDictKeysView.__reversed__N)__name__
__module____qualname__r   r   r   r   r   r   3   s   r   c               @   s   e Zd Zdd ZdS )_OrderedDictItemsViewc             c   s(   x"t | jD ]}|| j| fV  qW d S )N)r   r   )r   keyr   r   r   r   :   s    z"_OrderedDictItemsView.__reversed__N)r   r   r   r   r   r   r   r   r   8   s   r   c               @   s   e Zd Zdd ZdS )_OrderedDictValuesViewc             c   s$   xt | jD ]}| j| V  qW d S )N)r   r   )r   r   r   r   r   r   @   s    z#_OrderedDictValuesView.__reversed__N)r   r   r   r   r   r   r   r   r    >   s   r    c               @   s   e Zd ZdZdS )_Linkprevnextr   __weakref__N)r"   r#   r   r$   )r   r   r   	__slots__r   r   r   r   r!   D   s   r!   c               @   s   e Zd ZdZdd ZejeefddZej	fddZ	dd	 Z
d
d Zdd Zd*ddZd+ddZdd Zej ZZdd Zdd Zdd ZejZe ZefddZd,ddZe d d! Zd"d# Zd$d% Zed-d&d'Z d(d) Z!dS ).r   z)Dictionary that remembers insertion orderc              O   s   | st d| ^}} t| dkr0t dt|  y
|j W n> tk
rx   t |_t|j |_}| |_|_i |_	Y nX |j
| | dS )zInitialize an ordered dictionary.  The signature is the same as
        regular dictionaries.  Keyword argument order is preserved.
        z?descriptor '__init__' of 'OrderedDict' object needs an argument   z$expected at most 1 arguments, got %dN)	TypeErrorlen_OrderedDict__rootAttributeErrorr!   _OrderedDict__hardroot_proxyr"   r#   _OrderedDict__map_OrderedDict__update)argskwdsr   rootr   r   r   __init__V   s    
zOrderedDict.__init__c       	      C   sZ   || krJ|  | j |< }| j}|j}|||  |_|_|_||_|||_|| || dS )z!od.__setitem__(i, y) <==> od[i]=yN)r-   r)   r"   r#   r   )	r   r   valueZdict_setitemr   ZLinklinkr1   lastr   r   r   __setitem__i   s    
zOrderedDict.__setitem__c             C   s>   || | | j j|}|j}|j}||_||_d|_d|_dS )z od.__delitem__(y) <==> del od[y]N)r-   popr"   r#   )r   r   Zdict_delitemr4   	link_prev	link_nextr   r   r   __delitem__w   s    
zOrderedDict.__delitem__c             c   s,   | j }|j}x||k	r&|jV  |j}qW dS )zod.__iter__() <==> iter(od)N)r)   r#   r   )r   r1   currr   r   r   __iter__   s
    
zOrderedDict.__iter__c             c   s,   | j }|j}x||k	r&|jV  |j}qW dS )z#od.__reversed__() <==> reversed(od)N)r)   r"   r   )r   r1   r;   r   r   r   r      s
    
zOrderedDict.__reversed__c             C   s*   | j }| |_|_| jj  tj|  dS )z.od.clear() -> None.  Remove all items from od.N)r)   r"   r#   r-   cleardict)r   r1   r   r   r   r=      s    
zOrderedDict.clearTc             C   sj   | st d| j}|r0|j}|j}||_||_n|j}|j}||_||_|j}| j|= tj| |}||fS )zRemove and return a (key, value) pair from the dictionary.

        Pairs are returned in LIFO order if last is true or FIFO order if false.
        zdictionary is empty)KeyErrorr)   r"   r#   r   r-   r>   r7   )r   r5   r1   r4   r8   r9   r   r3   r   r   r   popitem   s     zOrderedDict.popitemc       	      C   st   | j | }|j}|j}|j}||_||_| j}|rR|j}||_||_||_||_n|j}||_||_||_||_dS )zMove an existing element to the end (or beginning if last==False).

        Raises KeyError if the element does not exist.
        When last=True, acts like a fast version of self[key]=self.pop(key).

        N)r-   r"   r#   r)   )	r   r   r5   r4   r8   r9   Z	soft_linkr1   firstr   r   r   move_to_end   s$    
zOrderedDict.move_to_endc             C   sV   t j}t| d }|| j}||| jd 7 }||| j| 7 }||| j| 7 }|S )Nr&      )_sys	getsizeofr(   __dict__r-   r+   r)   )r   Zsizeofnsizer   r   r   
__sizeof__   s    
zOrderedDict.__sizeof__c             C   s   t | S )z:D.keys() -> a set-like object providing a view on D's keys)r   )r   r   r   r   keys   s    zOrderedDict.keysc             C   s   t | S )z<D.items() -> a set-like object providing a view on D's items)r   )r   r   r   r   items   s    zOrderedDict.itemsc             C   s   t | S )z6D.values() -> an object providing a view on D's values)r    )r   r   r   r   values   s    zOrderedDict.valuesc             C   s0   || kr| | }| |= |S || j kr,t||S )zod.pop(k[,d]) -> v, remove specified key and return the corresponding
        value.  If key is not found, d is returned if given, otherwise KeyError
        is raised.

        )_OrderedDict__markerr?   )r   r   defaultresultr   r   r   r7      s    
zOrderedDict.popNc             C   s   || kr| | S || |< |S )zDod.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in odr   )r   r   rN   r   r   r   
setdefault   s    zOrderedDict.setdefaultc             C   s*   | sd| j jf S d| j jt| j f S )zod.__repr__() <==> repr(od)z%s()z%s(%r))	__class__r   listrK   )r   r   r   r   __repr__   s    zOrderedDict.__repr__c             C   sH   t | j }xt t D ]}|j|d qW | jf |p8ddt| j fS )z%Return state information for picklingN)varscopyr   r7   rQ   iterrK   )r   Z	inst_dictkr   r   r   
__reduce__  s    zOrderedDict.__reduce__c             C   s
   | j | S )z!od.copy() -> a shallow copy of od)rQ   )r   r   r   r   rU     s    zOrderedDict.copyc             C   s    |  }x|D ]}|||< qW |S )zOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
        If not specified, the value defaults to None.

        r   )clsiterabler3   r   r   r   r   r   fromkeys  s    
zOrderedDict.fromkeysc             C   s2   t |tr&tj| |o$ttt| |S tj| |S )zod.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
        while comparison to a regular mapping is order-insensitive.

        )
isinstancer   r>   __eq__allmap_eq)r   otherr   r   r   r]     s    
zOrderedDict.__eq__)T)T)N)N)"r   r   r   __doc__r2   r>   r6   r,   r!   r:   r<   r   r=   r@   rB   rI   MutableMappingupdater.   rJ   rK   rL   __ne__objectrM   r7   rP   _recursive_reprrS   rX   rU   classmethodr[   r]   r   r   r   r   r   G   s0   		

	


)r   a  from builtins import property as _property, tuple as _tuple
from operator import itemgetter as _itemgetter
from collections import OrderedDict

class {typename}(tuple):
    '{typename}({arg_list})'

    __slots__ = ()

    _fields = {field_names!r}

    def __new__(_cls, {arg_list}):
        'Create new instance of {typename}({arg_list})'
        return _tuple.__new__(_cls, ({arg_list}))

    @classmethod
    def _make(cls, iterable, new=tuple.__new__, len=len):
        'Make a new {typename} object from a sequence or iterable'
        result = new(cls, iterable)
        if len(result) != {num_fields:d}:
            raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result))
        return result

    def _replace(_self, **kwds):
        'Return a new {typename} object replacing specified fields with new values'
        result = _self._make(map(kwds.pop, {field_names!r}, _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % list(kwds))
        return result

    def __repr__(self):
        'Return a nicely formatted representation string'
        return self.__class__.__name__ + '({repr_fmt})' % self

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values.'
        return OrderedDict(zip(self._fields, self))

    def __getnewargs__(self):
        'Return self as a plain tuple.  Used by copy and pickle.'
        return tuple(self)

{field_defs}
z	{name}=%rzW    {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
F)verboserenamemodulec            C   s  t |tr|jddj }ttt|}t| } |rt }xNt|D ]B\}}|j  spt	|sp|j
dsp||kr|d| ||< |j| qDW xN| g| D ]@}t|tk	rtd|j std| t	|rtd| qW t }xJ|D ]B}|j
do| rtd| ||krtd	| |j| qW tj| t|t|tt|jd
ddd djdd |D djdd t|D d}td|  d}	t||	 |	|  }
||
_|rt|
j |dkrytjdjjdd}W n ttfk
r   Y nX |dk	r
||
_|
S )aC  Returns a new subclass of tuple with named fields.

    >>> Point = namedtuple('Point', ['x', 'y'])
    >>> Point.__doc__                   # docstring for the new class
    'Point(x, y)'
    >>> p = Point(11, y=22)             # instantiate with positional args or keywords
    >>> p[0] + p[1]                     # indexable like a plain tuple
    33
    >>> x, y = p                        # unpack like a regular tuple
    >>> x, y
    (11, 22)
    >>> p.x + p.y                       # fields also accessible by name
    33
    >>> d = p._asdict()                 # convert to a dictionary
    >>> d['x']
    11
    >>> Point(**d)                      # convert from a dictionary
    Point(x=11, y=22)
    >>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
    Point(x=100, y=22)

    , _z_%dz*Type names and field names must be stringsz8Type names and field names must be valid identifiers: %rz2Type names and field names cannot be a keyword: %rz/Field names cannot start with an underscore: %rz$Encountered duplicate field name: %r' r&   z, c             s   s   | ]}t j|d V  qdS ))nameN)_repr_templateformat).0rq   r   r   r   	<genexpr>  s   znamedtuple.<locals>.<genexpr>
c             s   s    | ]\}}t j||d V  qdS ))indexrq   N)_field_templaters   )rt   rw   rq   r   r   r   ru     s   )typenamefield_names
num_fieldsarg_listrepr_fmt
field_defsznamedtuple_%s)r   Nr   __main__)r\   strreplacesplitrR   r_   set	enumerateisidentifier
_iskeyword
startswithaddtyper'   
ValueError_class_templaters   tupler(   reprjoinr>   exec_sourceprintrD   	_getframe	f_globalsgetr*   r   )ry   rz   ri   rj   rk   seenrw   rq   class_definition	namespacerO   r   r   r   r   e  sj    










c             C   s*   | j }x|D ]}||dd | |< qW dS )z!Tally elements from the iterable.r
   r&   N)r   )mappingrZ   Zmapping_getelemr   r   r   _count_elements  s    
r   )r   c                   s   e Zd ZdZ fddZdd Zd/ddZd	d
 Zed0ddZ	 fddZ
dd Zdd Zdd Z fddZdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Z  ZS )1r   a  Dict subclass for counting hashable items.  Sometimes called a bag
    or multiset.  Elements are stored as dictionary keys and their counts
    are stored as dictionary values.

    >>> c = Counter('abcdeabcdabcaba')  # count elements from a string

    >>> c.most_common(3)                # three most common elements
    [('a', 5), ('b', 4), ('c', 3)]
    >>> sorted(c)                       # list all unique elements
    ['a', 'b', 'c', 'd', 'e']
    >>> ''.join(sorted(c.elements()))   # list elements with repetitions
    'aaaaabbbbcccdde'
    >>> sum(c.values())                 # total of all counts
    15

    >>> c['a']                          # count of letter 'a'
    5
    >>> for elem in 'shazam':           # update counts from an iterable
    ...     c[elem] += 1                # by adding 1 to each element's count
    >>> c['a']                          # now there are seven 'a'
    7
    >>> del c['b']                      # remove all 'b'
    >>> c['b']                          # now there are zero 'b'
    0

    >>> d = Counter('simsalabim')       # make another counter
    >>> c.update(d)                     # add in the second counter
    >>> c['a']                          # now there are nine 'a'
    9

    >>> c.clear()                       # empty the counter
    >>> c
    Counter()

    Note:  If a count is set to zero or reduced to zero, it will remain
    in the counter until the entry is deleted or the counter is cleared:

    >>> c = Counter('aaabbc')
    >>> c['b'] -= 2                     # reduce the count of 'b' by two
    >>> c.most_common()                 # 'b' is still in, but its count is zero
    [('a', 3), ('c', 1), ('b', 0)]

    c                 sN   | st d| ^}} t| dkr0t dt|  tt|j  |j| | dS )a	  Create a new, empty Counter object.  And if given, count elements
        from an input iterable.  Or, initialize the count from another mapping
        of elements to their counts.

        >>> c = Counter()                           # a new, empty counter
        >>> c = Counter('gallahad')                 # a new counter from an iterable
        >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
        >>> c = Counter(a=4, b=2)                   # a new counter from keyword args

        z;descriptor '__init__' of 'Counter' object needs an argumentr&   z$expected at most 1 arguments, got %dN)r'   r(   superr   r2   rd   )r/   r0   r   )rQ   r   r   r2     s    zCounter.__init__c             C   s   dS )z1The count of elements not in the Counter is zero.r
   r   )r   r   r   r   r   __missing__  s    zCounter.__missing__Nc             C   s6   |dkrt | j tdddS tj|| j tddS )zList the n most common elements and their counts from the most
        common to the least.  If n is None, then list all element counts.

        >>> Counter('abcdeabcdabcaba').most_common(3)
        [('a', 5), ('b', 4), ('c', 3)]

        Nr&   T)r   reverse)r   )sortedrK   _itemgetter_heapqnlargest)r   rG   r   r   r   most_common  s    	zCounter.most_commonc             C   s   t jtt| j S )a  Iterator over elements repeating each as many times as its count.

        >>> c = Counter('ABCABC')
        >>> sorted(c.elements())
        ['A', 'A', 'B', 'B', 'C', 'C']

        # Knuth's example for prime factors of 1836:  2**2 * 3**3 * 17**1
        >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
        >>> product = 1
        >>> for factor in prime_factors.elements():     # loop over factors
        ...     product *= factor                       # and multiply them
        >>> product
        1836

        Note, if an element's count has been set to zero or is a negative
        number, elements() will ignore it.

        )_chainfrom_iterable_starmap_repeatrK   )r   r   r   r   elements+  s    zCounter.elementsc             C   s   t dd S )Nz@Counter.fromkeys() is undefined.  Use Counter(iterable) instead.)NotImplementedError)rY   rZ   vr   r   r   r[   C  s    zCounter.fromkeysc                 s   | st d| ^}} t| dkr0t dt|  | r<| d nd}|dk	rt|tr|r|j}x8|j D ]\}}|||d ||< qfW qtt|j| n
t	|| |r|j| dS )a  Like dict.update() but add counts instead of replacing them.

        Source can be an iterable, a dictionary, or another Counter instance.

        >>> c = Counter('which')
        >>> c.update('witch')           # add elements from another iterable
        >>> d = Counter('watch')
        >>> c.update(d)                 # add elements from another counter
        >>> c['h']                      # four 'h' in which, witch, and watch
        4

        z9descriptor 'update' of 'Counter' object needs an argumentr&   z$expected at most 1 arguments, got %dr
   N)
r'   r(   r\   Mappingr   rK   r   r   rd   r   )r/   r0   r   rZ   self_getr   count)rQ   r   r   rd   J  s     

zCounter.updatec              O   s   | st d| ^}} t| dkr0t dt|  | r<| d nd}|dk	r|j}t|trxH|j D ]\}}||d| ||< qbW n x|D ]}||dd ||< qW |r|j| dS )a  Like dict.update() but subtracts counts instead of replacing them.
        Counts can be reduced below zero.  Both the inputs and outputs are
        allowed to contain zero and negative counts.

        Source can be an iterable, a dictionary, or another Counter instance.

        >>> c = Counter('which')
        >>> c.subtract('witch')             # subtract elements from another iterable
        >>> c.subtract(Counter('watch'))    # subtract elements from another counter
        >>> c['h']                          # 2 in which, minus 1 in witch, minus 1 in watch
        0
        >>> c['w']                          # 1 in which, minus 1 in witch, minus 1 in watch
        -1

        z;descriptor 'subtract' of 'Counter' object needs an argumentr&   z$expected at most 1 arguments, got %dr
   N)r'   r(   r   r\   r   rK   subtract)r/   r0   r   rZ   r   r   r   r   r   r   r   r  s    

zCounter.subtractc             C   s
   | j | S )zReturn a shallow copy.)rQ   )r   r   r   r   rU     s    zCounter.copyc             C   s   | j t| ffS )N)rQ   r>   )r   r   r   r   rX     s    zCounter.__reduce__c                s   || krt  j| dS )zGLike dict.__delitem__() but does not raise KeyError for missing values.N)r   r:   )r   r   )rQ   r   r   r:     s    zCounter.__delitem__c             C   s`   | sd| j j S y&djtdj| j }d| j j|f S  tk
rZ   dj| j jt| S X d S )Nz%s()z, z%r: %rz%s({%s})z
{0}({1!r}))	rQ   r   r   r_   __mod__r   r'   rs   r>   )r   rK   r   r   r   rS     s    zCounter.__repr__c             C   sx   t |tstS t }x0| j D ]$\}}|||  }|dkr|||< qW x,|j D ] \}}|| krP|dkrP|||< qPW |S )zAdd counts from two counters.

        >>> Counter('abbb') + Counter('bcc')
        Counter({'b': 4, 'c': 2, 'a': 1})

        r
   )r\   r   NotImplementedrK   )r   ra   rO   r   r   newcountr   r   r   __add__  s    
zCounter.__add__c             C   s|   t |tstS t }x0| j D ]$\}}|||  }|dkr|||< qW x0|j D ]$\}}|| krP|dk rPd| ||< qPW |S )z Subtract count, but keep only results with positive counts.

        >>> Counter('abbbc') - Counter('bccd')
        Counter({'b': 2, 'a': 1})

        r
   )r\   r   r   rK   )r   ra   rO   r   r   r   r   r   r   __sub__  s    
zCounter.__sub__c             C   s   t |tstS t }x<| j D ]0\}}|| }||k r:|n|}|dkr|||< qW x,|j D ] \}}|| kr\|dkr\|||< q\W |S )zUnion is the maximum of value in either of the input counters.

        >>> Counter('abbb') | Counter('bcc')
        Counter({'b': 3, 'c': 2, 'a': 1})

        r
   )r\   r   r   rK   )r   ra   rO   r   r   other_countr   r   r   r   __or__  s    
zCounter.__or__c             C   sV   t |tstS t }x<| j D ]0\}}|| }||k r:|n|}|dkr|||< qW |S )z Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        r
   )r\   r   r   rK   )r   ra   rO   r   r   r   r   r   r   r   __and__  s    
zCounter.__and__c             C   s0   t  }x$| j D ]\}}|dkr|||< qW |S )zEAdds an empty counter, effectively stripping negative and zero countsr
   )r   rK   )r   rO   r   r   r   r   r   __pos__  s
    zCounter.__pos__c             C   s4   t  }x(| j D ]\}}|dk rd| ||< qW |S )z{Subtracts from an empty counter.  Strips positive and zero counts,
        and flips the sign on negative counts.

        r
   )r   rK   )r   rO   r   r   r   r   r   __neg__  s
    zCounter.__neg__c             C   s*   dd | j  D }x|D ]
}| |= qW | S )z?Internal method to strip elements with a negative or zero countc             S   s   g | ]\}}|d ks|qS )r
   r   )rt   r   r   r   r   r   
<listcomp>  s    z*Counter._keep_positive.<locals>.<listcomp>)rK   )r   nonpositiver   r   r   r   _keep_positive  s    

zCounter._keep_positivec             C   s.   x$|j  D ]\}}| |  |7  < q
W | j S )zInplace add from another counter, keeping only positive counts.

        >>> c = Counter('abbb')
        >>> c += Counter('bcc')
        >>> c
        Counter({'b': 4, 'c': 2, 'a': 1})

        )rK   r   )r   ra   r   r   r   r   r   __iadd__  s    	zCounter.__iadd__c             C   s.   x$|j  D ]\}}| |  |8  < q
W | j S )zInplace subtract counter, but keep only results with positive counts.

        >>> c = Counter('abbbc')
        >>> c -= Counter('bccd')
        >>> c
        Counter({'b': 2, 'a': 1})

        )rK   r   )r   ra   r   r   r   r   r   __isub__%  s    	zCounter.__isub__c             C   s6   x,|j  D ] \}}| | }||kr
|| |< q
W | j S )zInplace union is the maximum of value from either counter.

        >>> c = Counter('abbb')
        >>> c |= Counter('bcc')
        >>> c
        Counter({'b': 3, 'c': 2, 'a': 1})

        )rK   r   )r   ra   r   r   r   r   r   r   __ior__2  s
    	zCounter.__ior__c             C   s6   x,| j  D ] \}}|| }||k r
|| |< q
W | j S )zInplace intersection is the minimum of corresponding counts.

        >>> c = Counter('abbb')
        >>> c &= Counter('bcc')
        >>> c
        Counter({'b': 1})

        )rK   r   )r   ra   r   r   r   r   r   r   __iand__A  s
    	zCounter.__iand__)N)N)r   r   r   rb   r2   r   r   r   rh   r[   rd   r   rU   rX   r:   rS   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   )rQ   r   r     s0   +
("c               @   s   e Zd ZdZdd Zdd Zdd Zd'd	d
Zdd Zdd Z	dd Z
dd Ze dd Zedd Zdd ZeZd(ddZedd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZdS ))r	   a   A ChainMap groups multiple dicts (or other mappings) together
    to create a single, updateable view.

    The underlying mappings are stored in a list.  That list is public and can
    be accessed or updated using the *maps* attribute.  There is no other
    state.

    Lookups search the underlying mappings successively until a key is found.
    In contrast, writes, updates, and deletions only operate on the first
    mapping.

    c             G   s   t |pi g| _dS )zInitialize a ChainMap by setting *maps* to the given mappings.
        If no mappings are provided, a single empty dictionary is used.

        N)rR   maps)r   r   r   r   r   r2   c  s    zChainMap.__init__c             C   s   t |d S )N)r?   )r   r   r   r   r   r   j  s    zChainMap.__missing__c             C   s8   x,| j D ]"}y|| S  tk
r(   Y qX qW | j|S )N)r   r?   r   )r   r   r   r   r   r   __getitem__m  s    
zChainMap.__getitem__Nc             C   s   || kr| | S |S )Nr   )r   r   rN   r   r   r   r   u  s    zChainMap.getc             C   s   t t j| j S )N)r(   r   unionr   )r   r   r   r   __len__x  s    zChainMap.__len__c             C   s   t t j| j S )N)rV   r   r   r   )r   r   r   r   r<   {  s    zChainMap.__iter__c                s   t  fdd| jD S )Nc             3   s   | ]} |kV  qd S )Nr   )rt   m)r   r   r   ru     s    z(ChainMap.__contains__.<locals>.<genexpr>)anyr   )r   r   r   )r   r   __contains__~  s    zChainMap.__contains__c             C   s
   t | jS )N)r   r   )r   r   r   r   __bool__  s    zChainMap.__bool__c             C   s   dj | djtt| jS )Nz{0.__class__.__name__}({1})z, )rs   r   r_   r   r   )r   r   r   r   rS     s    zChainMap.__repr__c             G   s   | t j|f| S )z?Create a ChainMap with a single dict created from the iterable.)r>   r[   )rY   rZ   r/   r   r   r   r[     s    zChainMap.fromkeysc             C   s$   | j | jd j f| jdd  S )zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r
   r&   N)rQ   r   rU   )r   r   r   r   rU     s    zChainMap.copyc             C   s   |dkri }| j |f| j S )zyNew ChainMap with a new map followed by all previous maps.
        If no map is provided, an empty dict is used.
        N)rQ   r   )r   r   r   r   r   	new_child  s    zChainMap.new_childc             C   s   | j | jdd  S )zNew ChainMap from maps[1:].r&   N)rQ   r   )r   r   r   r   parents  s    zChainMap.parentsc             C   s   || j d |< d S )Nr
   )r   )r   r   r3   r   r   r   r6     s    zChainMap.__setitem__c             C   s8   y| j d |= W n" tk
r2   tdj|Y nX d S )Nr
   z(Key not found in the first mapping: {!r})r   r?   rs   )r   r   r   r   r   r:     s    zChainMap.__delitem__c             C   s0   y| j d j S  tk
r*   tdY nX dS )zPRemove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.r
   z#No keys found in the first mapping.N)r   r@   r?   )r   r   r   r   r@     s    zChainMap.popitemc             G   s>   y| j d j|f| S  tk
r8   tdj|Y nX dS )zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r
   z(Key not found in the first mapping: {!r}N)r   r7   r?   rs   )r   r   r/   r   r   r   r7     s    zChainMap.popc             C   s   | j d j  dS )z'Clear maps[0], leaving maps[1:] intact.r
   N)r   r=   )r   r   r   r   r=     s    zChainMap.clear)N)N)r   r   r   rb   r2   r   r   r   r   r<   r   r   rg   rS   rh   r[   rU   __copy__r   propertyr   r6   r:   r@   r7   r=   r   r   r   r   r	   U  s(   

c               @   sb   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZedddZdS )r   c              O   s   | st d| ^}} t| dkr0t dt|  | r>| d }n0d|krj|jd}dd l}|jdtdd nd }i |_|d k	r|j| t|r|j| d S )	Nz<descriptor '__init__' of 'UserDict' object needs an argumentr&   z$expected at most 1 arguments, got %dr
   r>   z0Passing 'dict' as keyword argument is deprecatedrC   )
stacklevel)r'   r(   r7   warningswarnDeprecationWarningdatard   )r/   kwargsr   r>   r   r   r   r   r2     s$    


zUserDict.__init__c             C   s
   t | jS )N)r(   r   )r   r   r   r   r     s    zUserDict.__len__c             C   s:   || j kr| j | S t| jdr.| jj| |S t|d S )Nr   )r   hasattrrQ   r   r?   )r   r   r   r   r   r     s
    

zUserDict.__getitem__c             C   s   || j |< d S )N)r   )r   r   itemr   r   r   r6     s    zUserDict.__setitem__c             C   s   | j |= d S )N)r   )r   r   r   r   r   r:     s    zUserDict.__delitem__c             C   s
   t | jS )N)rV   r   )r   r   r   r   r<     s    zUserDict.__iter__c             C   s
   || j kS )N)r   )r   r   r   r   r   r     s    zUserDict.__contains__c             C   s
   t | jS )N)r   r   )r   r   r   r   rS     s    zUserDict.__repr__c             C   sR   | j tkrt| jj S dd l}| j}zi | _|j| }W d || _X |j|  |S )Nr
   )rQ   r   r   rU   rd   )r   rU   r   cr   r   r   rU     s    

zUserDict.copyNc             C   s    |  }x|D ]}|||< qW |S )Nr   )rY   rZ   r3   dr   r   r   r   r[     s    
zUserDict.fromkeys)N)r   r   r   r2   r   r   r6   r:   r<   r   rS   rU   rh   r[   r   r   r   r   r     s   c               @   s   e Zd ZdZd>ddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZeZd%d& Zd'd( Zd)d* Zd@d,d-Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!dS )Ar   zAA more or less complete user-defined wrapper around list objects.Nc             C   sb   g | _ |d k	r^t|t| j kr0|| j d d < n.t|trT|j d d  | j d d < n
t|| _ d S )N)r   r   r\   r   rR   )r   initlistr   r   r   r2     s    
zUserList.__init__c             C   s
   t | jS )N)r   r   )r   r   r   r   rS     s    zUserList.__repr__c             C   s   | j | j|k S )N)r   _UserList__cast)r   ra   r   r   r   __lt__  s    zUserList.__lt__c             C   s   | j | j|kS )N)r   r   )r   ra   r   r   r   __le__  s    zUserList.__le__c             C   s   | j | j|kS )N)r   r   )r   ra   r   r   r   r]     s    zUserList.__eq__c             C   s   | j | j|kS )N)r   r   )r   ra   r   r   r   __gt__  s    zUserList.__gt__c             C   s   | j | j|kS )N)r   r   )r   ra   r   r   r   __ge__  s    zUserList.__ge__c             C   s   t |tr|jS |S )N)r\   r   r   )r   ra   r   r   r   __cast  s    zUserList.__castc             C   s
   || j kS )N)r   )r   r   r   r   r   r     s    zUserList.__contains__c             C   s
   t | jS )N)r(   r   )r   r   r   r   r     s    zUserList.__len__c             C   s
   | j | S )N)r   )r   ir   r   r   r     s    zUserList.__getitem__c             C   s   || j |< d S )N)r   )r   r   r   r   r   r   r6     s    zUserList.__setitem__c             C   s   | j |= d S )N)r   )r   r   r   r   r   r:     s    zUserList.__delitem__c             C   sP   t |tr| j| j|j S t |t| jr<| j| j| S | j| jt| S )N)r\   r   rQ   r   r   rR   )r   ra   r   r   r   r     s
    
zUserList.__add__c             C   sP   t |tr| j|j| j S t |t| jr<| j|| j S | jt|| j S )N)r\   r   rQ   r   r   rR   )r   ra   r   r   r   __radd__#  s
    
zUserList.__radd__c             C   sR   t |tr|  j|j7  _n2t |t| jr<|  j|7  _n|  jt|7  _| S )N)r\   r   r   r   rR   )r   ra   r   r   r   r   )  s    
zUserList.__iadd__c             C   s   | j | j| S )N)rQ   r   )r   rG   r   r   r   __mul__1  s    zUserList.__mul__c             C   s   |  j |9  _ | S )N)r   )r   rG   r   r   r   __imul__4  s    zUserList.__imul__c             C   s   | j j| d S )N)r   append)r   r   r   r   r   r   7  s    zUserList.appendc             C   s   | j j|| d S )N)r   insert)r   r   r   r   r   r   r   8  s    zUserList.insertr&   c             C   s   | j j|S )N)r   r7   )r   r   r   r   r   r7   9  s    zUserList.popc             C   s   | j j| d S )N)r   remove)r   r   r   r   r   r   :  s    zUserList.removec             C   s   | j j  d S )N)r   r=   )r   r   r   r   r=   ;  s    zUserList.clearc             C   s
   | j | S )N)rQ   )r   r   r   r   rU   <  s    zUserList.copyc             C   s   | j j|S )N)r   r   )r   r   r   r   r   r   =  s    zUserList.countc             G   s   | j j|f| S )N)r   rw   )r   r   r/   r   r   r   rw   >  s    zUserList.indexc             C   s   | j j  d S )N)r   r   )r   r   r   r   r   ?  s    zUserList.reversec             O   s   | j j|| d S )N)r   sort)r   r/   r0   r   r   r   r   @  s    zUserList.sortc             C   s*   t |tr| jj|j n| jj| d S )N)r\   r   r   extend)r   ra   r   r   r   r   A  s    
zUserList.extend)Nr   )r   )"r   r   r   rb   r2   rS   r   r   r]   r   r   r   r   r   r   r6   r:   r   r   r   r   __rmul__r   r   r   r7   r   r=   rU   r   rw   r   r   r   r   r   r   r   r     s>   


c               @   s`  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& ZeZd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1ejfd2d3Zdd5d6Zd1ejfd7d8Z dd:d;Z!d1ejfd<d=Z"d>d? Z#d@dA Z$d1ejfdBdCZ%dDdE Z&dFdG Z'dHdI Z(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/dXdY Z0dZd[ Z1d\d] Z2d^d_ Z3dd`daZ4e5j6Z6dbdc Z7ddedfZ8d1ejfdgdhZ9d1ejfdidjZ:dkdl Z;dmdn Z<ddodpZ=ddqdrZ>ddsdtZ?ddvdwZ@d1ejfdxdyZAddzd{ZBd|d} ZCd~d ZDdd ZEdd ZFdd ZGd4S )r   c             C   s<   t |tr|| _n&t |tr.|jd d  | _n
t|| _d S )N)r\   r   r   r   )r   seqr   r   r   r2   N  s
    

zUserString.__init__c             C   s
   t | jS )N)r   r   )r   r   r   r   __str__U  s    zUserString.__str__c             C   s
   t | jS )N)r   r   )r   r   r   r   rS   V  s    zUserString.__repr__c             C   s
   t | jS )N)intr   )r   r   r   r   __int__W  s    zUserString.__int__c             C   s
   t | jS )N)floatr   )r   r   r   r   	__float__X  s    zUserString.__float__c             C   s
   t | jS )N)complexr   )r   r   r   r   __complex__Y  s    zUserString.__complex__c             C   s
   t | jS )N)hashr   )r   r   r   r   __hash__Z  s    zUserString.__hash__c             C   s   | j d d  fS )N)r   )r   r   r   r   __getnewargs__[  s    zUserString.__getnewargs__c             C   s    t |tr| j|jkS | j|kS )N)r\   r   r   )r   stringr   r   r   r]   ^  s    
zUserString.__eq__c             C   s    t |tr| j|jk S | j|k S )N)r\   r   r   )r   r   r   r   r   r   b  s    
zUserString.__lt__c             C   s    t |tr| j|jkS | j|kS )N)r\   r   r   )r   r   r   r   r   r   f  s    
zUserString.__le__c             C   s    t |tr| j|jkS | j|kS )N)r\   r   r   )r   r   r   r   r   r   j  s    
zUserString.__gt__c             C   s    t |tr| j|jkS | j|kS )N)r\   r   r   )r   r   r   r   r   r   n  s    
zUserString.__ge__c             C   s   t |tr|j}|| jkS )N)r\   r   r   )r   charr   r   r   r   s  s    
zUserString.__contains__c             C   s
   t | jS )N)r(   r   )r   r   r   r   r   x  s    zUserString.__len__c             C   s   | j | j| S )N)rQ   r   )r   rw   r   r   r   r   y  s    zUserString.__getitem__c             C   sJ   t |tr| j| j|j S t |tr6| j| j| S | j| jt| S )N)r\   r   rQ   r   r   )r   ra   r   r   r   r   z  s
    

zUserString.__add__c             C   s.   t |tr| j|| j S | jt|| j S )N)r\   r   rQ   r   )r   ra   r   r   r   r     s    
zUserString.__radd__c             C   s   | j | j| S )N)rQ   r   )r   rG   r   r   r   r     s    zUserString.__mul__c             C   s   | j | j| S )N)rQ   r   )r   r/   r   r   r   r     s    zUserString.__mod__c             C   s   | j |t S )N)rQ   r/   )r   rs   r   r   r   __rmod__  s    zUserString.__rmod__c             C   s   | j | jj S )N)rQ   r   
capitalize)r   r   r   r   r     s    zUserString.capitalizec             C   s   | j | jj S )N)rQ   r   casefold)r   r   r   r   r     s    zUserString.casefoldc             G   s   | j | jj|f| S )N)rQ   r   center)r   widthr/   r   r   r   r     s    zUserString.centerr
   c             C   s    t |tr|j}| jj|||S )N)r\   r   r   r   )r   substartendr   r   r   r     s    
zUserString.countNc             C   s>   |r.|r| j | jj||S | j | jj|S | j | jj S )N)rQ   r   encode)r   encodingerrorsr   r   r   r     s
    zUserString.encodec             C   s   | j j|||S )N)r   endswith)r   suffixr   r   r   r   r   r     s    zUserString.endswith   c             C   s   | j | jj|S )N)rQ   r   
expandtabs)r   tabsizer   r   r   r    s    zUserString.expandtabsc             C   s    t |tr|j}| jj|||S )N)r\   r   r   find)r   r   r   r   r   r   r   r    s    
zUserString.findc             O   s   | j j||S )N)r   rs   )r   r/   r0   r   r   r   rs     s    zUserString.formatc             C   s   | j j|S )N)r   
format_map)r   r   r   r   r   r    s    zUserString.format_mapc             C   s   | j j|||S )N)r   rw   )r   r   r   r   r   r   r   rw     s    zUserString.indexc             C   s
   | j j S )N)r   isalpha)r   r   r   r   r    s    zUserString.isalphac             C   s
   | j j S )N)r   isalnum)r   r   r   r   r    s    zUserString.isalnumc             C   s
   | j j S )N)r   	isdecimal)r   r   r   r   r	    s    zUserString.isdecimalc             C   s
   | j j S )N)r   isdigit)r   r   r   r   r
    s    zUserString.isdigitc             C   s
   | j j S )N)r   r   )r   r   r   r   r     s    zUserString.isidentifierc             C   s
   | j j S )N)r   islower)r   r   r   r   r    s    zUserString.islowerc             C   s
   | j j S )N)r   	isnumeric)r   r   r   r   r    s    zUserString.isnumericc             C   s
   | j j S )N)r   isprintable)r   r   r   r   r    s    zUserString.isprintablec             C   s
   | j j S )N)r   isspace)r   r   r   r   r    s    zUserString.isspacec             C   s
   | j j S )N)r   istitle)r   r   r   r   r    s    zUserString.istitlec             C   s
   | j j S )N)r   isupper)r   r   r   r   r    s    zUserString.isupperc             C   s   | j j|S )N)r   r   )r   r   r   r   r   r     s    zUserString.joinc             G   s   | j | jj|f| S )N)rQ   r   ljust)r   r   r/   r   r   r   r    s    zUserString.ljustc             C   s   | j | jj S )N)rQ   r   lower)r   r   r   r   r    s    zUserString.lowerc             C   s   | j | jj|S )N)rQ   r   lstrip)r   charsr   r   r   r    s    zUserString.lstripc             C   s   | j j|S )N)r   	partition)r   sepr   r   r   r    s    zUserString.partitionr&   c             C   s6   t |tr|j}t |tr |j}| j| jj|||S )N)r\   r   r   rQ   r   )r   oldnewmaxsplitr   r   r   r     s
    

zUserString.replacec             C   s    t |tr|j}| jj|||S )N)r\   r   r   rfind)r   r   r   r   r   r   r   r    s    
zUserString.rfindc             C   s   | j j|||S )N)r   rindex)r   r   r   r   r   r   r   r    s    zUserString.rindexc             G   s   | j | jj|f| S )N)rQ   r   rjust)r   r   r/   r   r   r   r    s    zUserString.rjustc             C   s   | j j|S )N)r   
rpartition)r   r  r   r   r   r    s    zUserString.rpartitionc             C   s   | j | jj|S )N)rQ   r   rstrip)r   r  r   r   r   r    s    zUserString.rstripc             C   s   | j j||S )N)r   r   )r   r  r  r   r   r   r     s    zUserString.splitc             C   s   | j j||S )N)r   rsplit)r   r  r  r   r   r   r    s    zUserString.rsplitFc             C   s   | j j|S )N)r   
splitlines)r   keependsr   r   r   r     s    zUserString.splitlinesc             C   s   | j j|||S )N)r   r   )r   prefixr   r   r   r   r   r     s    zUserString.startswithc             C   s   | j | jj|S )N)rQ   r   strip)r   r  r   r   r   r#    s    zUserString.stripc             C   s   | j | jj S )N)rQ   r   swapcase)r   r   r   r   r$    s    zUserString.swapcasec             C   s   | j | jj S )N)rQ   r   title)r   r   r   r   r%    s    zUserString.titlec             G   s   | j | jj| S )N)rQ   r   	translate)r   r/   r   r   r   r&    s    zUserString.translatec             C   s   | j | jj S )N)rQ   r   upper)r   r   r   r   r'    s    zUserString.upperc             C   s   | j | jj|S )N)rQ   r   zfill)r   r   r   r   r   r(    s    zUserString.zfill)NN)r  )Nr   )r   )Nr   )Nr   r   )Nr   )F)N)Hr   r   r   r2   r   rS   r   r   r   r   r   r]   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   maxsizer   r   r   r  r  rs   r  rw   r  r  r	  r
  r   r  r  r  r  r  r  r   r  r  r  r   	maketransr  r   r  r  r  r  r  r   r  r   r   r#  r$  r%  r&  r'  r(  r   r   r   r   r   M  s   








)8rb   __all___collections_abcoperatorr   r   r   r`   keywordr   r   sysrD   heapqr   _weakrefr   r,   	itertoolsr   r   r   r   r   r   reprlibr   rg   _collectionsr   ImportErrorMutableSequenceregisterr   KeysViewr   	ItemsViewr   
ValuesViewr    rf   r!   r>   r   r   rr   rx   r   r   r   rc   r	   r   r   Sequencer   r   r   r   r   <module>   s`   


 `3b   lCI