ó
G8C\c           @   s  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z e d	 k  r… d d
 l m Z n  e ƒ  Z d e
 j e
 j f d „  ƒ  YZ d e
 j e
 j f d „  ƒ  YZ d e
 j e
 j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s$   Ordered dictionary implementation.

iÿÿÿÿ(   t   count(   t   eq(   t
   SortedDict(   t   recursive_repri   (   t   abc(   t
   hexversioni   (   t   imapt   KeysViewc           B   s   e  Z d  Z d „  Z RS(   s   Read-only view of mapping keys.c         C   sR   |  j  j } t | t ƒ rC | j | } g  | D] } | | ^ q/ S| | j | S(   s   ``keys_view[index]``(   t   _mappingt   _numst
   isinstancet   slicet   _list(   t   selft   indexR	   t   numst   num(    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __getitem__    s
    (   t   __name__t
   __module__t   __doc__R   (    (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR      s   t	   ItemsViewc           B   s   e  Z d  Z d „  Z RS(   s    Read-only view of mapping items.c         C   s‘   |  j  } | j } t | t ƒ rl | j | } g  | D] } | | ^ q5 } g  | D] } | | | f ^ qR S| j | } | | } | | | f S(   s   ``items_view[index]``(   R   R	   R
   R   R   (   R   R   R   R	   R   R   t   keyst   key(    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR   ,   s    		!
(   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR   )   s   t
   ValuesViewc           B   s   e  Z d  Z d „  Z RS(   s!   Read-only view of mapping values.c         C   s…   |  j  } | j } t | t ƒ rf | j | } g  | D] } | | ^ q5 } g  | D] } | | ^ qR S| j | } | | } | | S(   s   ``items_view[index]``(   R   R	   R
   R   R   (   R   R   R   R	   R   R   R   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR   <   s    		
(   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR   9   s   t   OrderedDictc           B   sÿ   e  Z d  Z d „  Z e j d „ Z e j d „ Z d „  Z d „  Z e j	 d „ Z	 e
 d „ Z e j j Z Z d „  Z d	 „  Z d
 „  Z e d „ Z d d „ Z e ƒ  d „  ƒ Z e Z d „  Z d „  Z e d d „ ƒ Z d „  Z e j j Z d „  Z  RS(   sy  Dictionary that remembers insertion order and is numerically indexable.

    Keys are numerically indexable using dict views. For example::

        >>> ordered_dict = OrderedDict.fromkeys('abcde')
        >>> keys = ordered_dict.keys()
        >>> keys[0]
        'a'
        >>> keys[-2:]
        ['d', 'e']

    The dict views support the sequence abstract base class.

    c         O   sG   i  |  _  t ƒ  |  _ |  j j ƒ  |  _ t ƒ  |  _ |  j | | Ž  d  S(   N(   t   _keysR   R	   R   t
   _keys_viewR    t   _countt   update(   R   t   argst   kwargs(    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __init__Y   s
    	c         C   sL   | |  k r8 t  |  j ƒ } | |  j | <| |  j | <n  | |  | | ƒ d S(   s   ``ordered_dict[key] = value``N(   t   nextR   R   R	   (   R   R   t   valuet   dict_setitemR   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __setitem__`   s
    c         C   s-   | |  | ƒ |  j  j | ƒ } |  j | =d S(   s   ``del ordered_dict[key]``N(   R   t   popR	   (   R   R   t   dict_delitemR   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __delitem__h   s    c         C   s   t  |  j j ƒ  ƒ S(   s   ``iter(ordered_dict)``(   t   iterR	   t   values(   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __iter__n   s    c         c   s-   |  j  } x t | ƒ D] } | | Vq Wd S(   s   ``reversed(ordered_dict)``N(   R	   t   reversed(   R   R   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __reversed__r   s    	c         C   s(   | |  ƒ |  j  j ƒ  |  j j ƒ  d S(   s   Remove all items from mapping.N(   R   t   clearR	   (   R   t
   dict_clear(    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR-   x   s    
c         C   sE   | r d n d } |  j  | } |  j | } |  j | ƒ } | | f S(   s   Remove and return (key, value) item pair.

        Pairs are returned in LIFO order if last is True or FIFO order if
        False.

        iÿÿÿÿi    (   R   R	   R%   (   R   t   lastR   R   R   R"   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   popitem~   s
    c         C   s
   t  |  ƒ S(   s7   Return set-like and sequence-like view of mapping keys.(   R   (   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR      s    c         C   s
   t  |  ƒ S(   s8   Return set-like and sequence-like view of mapping items.(   R   (   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   items‘   s    c         C   s
   t  |  ƒ S(   s9   Return set-like and sequence-like view of mapping values.(   R   (   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR)   •   s    c         C   s@   | |  k r! |  | } |  | =| S| t  k r< t | ƒ ‚ n  | S(   s˜   Remove given key and return corresponding value.

        If key is not found, default is returned if given, otherwise raise
        KeyError.

        (   t   NONEt   KeyError(   R   R   t   defaultR"   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR%   ™   s    
c         C   s"   | |  k r |  | S| |  | <| S(   sr   Return ``mapping.get(key, default)``, also set ``mapping[key] = default`` if
        key not in mapping.

        (    (   R   R   R4   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt
   setdefault¨   s    
c         C   s    d |  j  j t |  j ƒ  ƒ f S(   s   Text representation of mapping.s   %s(%r)(   t	   __class__R   t   listR1   (   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   __repr__²   s    c         C   s   |  j  t |  j ƒ  ƒ f f S(   s#   Support for pickling serialization.(   R6   R7   R1   (   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt
   __reduce__¹   s    c         C   s   |  j  |  ƒ S(   s   Return shallow copy of mapping.(   R6   (   R   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   copy½   s    c            s   |  ‡  f d †  | Dƒ ƒ S(   sh   Return new mapping with keys from iterable.

        If not specified, value defaults to None.

        c         3   s   |  ] } | ˆ  f Vq d  S(   N(    (   t   .0R   (   R"   (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pys	   <genexpr>È   s    (    (   t   clst   iterableR"   (    (   R"   s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   fromkeysÁ   s    c         C   sG   t  | t ƒ r7 t j |  | ƒ o6 t t t |  | ƒ ƒ St j |  | ƒ S(   s)   Test self and other mapping for equality.(   R
   R   t   dictt   __eq__t   allt   mapR   (   R   t   other(    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR@   Ê   s    (c         C   sS   |  j  } |  j } x0 | j ƒ  D]" \ } } | | | k s t ‚ q W| j ƒ  d S(   s/   Check consistency of internal member variables.N(   R   R	   R1   t   AssertionErrort   _check(   R   R   R   R   R"   (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyRE   Ò   s
    		N(!   R   R   R   R    R?   R$   R'   R*   R,   R-   t   TrueR0   R   t   MutableMappingR   t   _OrderedDict__updateR   R1   R)   R2   R%   t   NoneR5   R   R8   t   __str__R9   R:   t   classmethodR>   R@   t   __ne__RE   (    (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyR   I   s.   						
			N(   R   t	   itertoolsR    t   operatorR   t   sortedcontainersR   t   sortedcontainers.sortedlistR   t   recipesR   t   sysR   R   RB   t   objectR2   R   t   SequenceR   R   R?   R   (    (    (    s<   lib/python2.7/site-packages/sortedcollections/ordereddict.pyt   <module>   s   	