
5	Pc           @   sZ  d  d d d d g Z  d d l Td d l Z e  e j  7Z  d d l m Z m Z d d	 l m Z d d
 l m	 Z
 d d l Z d d l Z d d l m Z m Z m Z y d d l m Z Wn! e k
 r d d l m Z n Xd e f d     YZ e e d  Z d  e f d     YZ e  d k rVd d l! m" Z" m# Z# e d d e$  Z% e% d d d d  Z& e& e" e# e&   k s|t'  d e d d  f d     YZ% x/ e% d d  e% d d d  f D] Z& e& GHqWd e d d  f d     YZ% e% d  d!  j( d d"  GHe d# e% j) d$ f  Z* e* j+ GHd d l, Z, e d% d&  Z- e- e, j.     GHn  d S('   t   Countert   dequet   defaultdictt
   namedtuplet   OrderedDicti(   t   *N(   R   R   (   t
   itemgetter(   t	   iskeyword(   t   repeatt   chaint   starmap(   t	   get_identc           B   s+  e  Z d  Z d   Z d d e j d  Z d d e j d  Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z e j Z e Z e   Z e d  Z d d  Z e d  Z i  d  Z d   Z d   Z e d d   Z d   Z d   Z  d   Z! d   Z" d   Z# RS(   s)   Dictionary that remembers insertion orderc         O   s   t  |  d k r+ t d t  |    n  y |  j Wn7 t k
 ro g  |  _ } | | d g | (i  |  _ n X|  j | |   d S(   s   Initialize an ordered dictionary.  The signature is the same as
        regular dictionaries, but keyword arguments are not recommended because
        their insertion order is arbitrary.

        i   s$   expected at most 1 arguments, got %dN(   t   lent	   TypeErrort   _OrderedDict__roott   AttributeErrort   Nonet   _OrderedDict__mapt   _OrderedDict__update(   t   selft   argst   kwdst   root(    (    s!   /usr/lib/python2.7/collections.pyt   __init__%   s    i    i   c         C   s\   | |  k rH |  j  } | | } | | | g | | <| | <|  j | <n  | |  | |  d S(   s!   od.__setitem__(i, y) <==> od[i]=yN(   R   R   (   R   t   keyt   valuet   PREVt   NEXTt   dict_setitemR   t   last(    (    s!   /usr/lib/python2.7/collections.pyt   __setitem__5   s
    	
)c         C   s@   | |  |  |  j  j |  \ } } } | | | <| | | <d S(   s    od.__delitem__(y) <==> del od[y]N(   R   t   pop(   R   R   R   R   t   dict_delitemt	   link_prevt	   link_next(    (    s!   /usr/lib/python2.7/collections.pyt   __delitem__?   s    
c         c   sI   d \ } } |  j  } | | } x# | | k	 rD | | V| | } q" Wd S(   s   od.__iter__() <==> iter(od)i   i   N(   i   i   (   R   (   R   R   t   KEYR   t   curr(    (    s!   /usr/lib/python2.7/collections.pyt   __iter__H   s    	
	c         c   sI   d \ } } |  j  } | | } x# | | k	 rD | | V| | } q" Wd S(   s#   od.__reversed__() <==> reversed(od)i    i   N(   i    i   (   R   (   R   R   R$   R   R%   (    (    s!   /usr/lib/python2.7/collections.pyt   __reversed__R   s    	
	c         C   sU   x |  j  j   D]
 } | 2q W|  j } | | d g | (|  j  j   t j |   d S(   s.   od.clear() -> None.  Remove all items from od.N(   R   t
   itervaluesR   R   t   cleart   dict(   R   t   nodeR   (    (    s!   /usr/lib/python2.7/collections.pyR)   \   s    	c         C   s
   t  |   S(   s   od.keys() -> list of keys in od(   t   list(   R   (    (    s!   /usr/lib/python2.7/collections.pyt   keysg   s    c         C   s   g  |  D] } |  | ^ q S(   s#   od.values() -> list of values in od(    (   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   valuesk   s    c         C   s!   g  |  D] } | |  | f ^ q S(   s.   od.items() -> list of (key, value) pairs in od(    (   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   itemso   s    c         C   s
   t  |   S(   s0   od.iterkeys() -> an iterator over the keys in od(   t   iter(   R   (    (    s!   /usr/lib/python2.7/collections.pyt   iterkeyss   s    c         c   s   x |  D] } |  | Vq Wd S(   s2   od.itervalues -> an iterator over the values in odN(    (   R   t   k(    (    s!   /usr/lib/python2.7/collections.pyR(   w   s    c         c   s$   x |  D] } | |  | f Vq Wd S(   s=   od.iteritems -> an iterator over the (key, value) pairs in odN(    (   R   R2   (    (    s!   /usr/lib/python2.7/collections.pyt	   iteritems|   s    c         C   sC   | |  k r! |  | } |  | =| S| |  j  k r? t |   n  | S(   s   od.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.

        (   t   _OrderedDict__markert   KeyError(   R   R   t   defaultt   result(    (    s!   /usr/lib/python2.7/collections.pyR      s    
c         C   s"   | |  k r |  | S| |  | <| S(   sD   od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od(    (   R   R   R6   (    (    s!   /usr/lib/python2.7/collections.pyt
   setdefault   s    
c         C   sR   |  s t  d   n  t | r* t |   n	 t |    } |  j |  } | | f S(   s   od.popitem() -> (k, v), return and remove a (key, value) pair.
        Pairs are returned in LIFO order if last is true or FIFO order if false.

        s   dictionary is empty(   R5   t   nextt   reversedR0   R   (   R   R   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   popitem   s
    $c         C   ss   t  |   t   f } | | k r% d Sd | | <z5 |  sI d |  j j f Sd |  j j |  j   f SWd | | =Xd S(   s   od.__repr__() <==> repr(od)s   ...i   s   %s()s   %s(%r)N(   t   idt
   _get_identt	   __class__t   __name__R/   (   R   t   _repr_runningt   call_key(    (    s!   /usr/lib/python2.7/collections.pyt   __repr__   s    
c         C   s   g  |  D] } | |  | g ^ q } t  |   j   } x' t  t    D] } | j | d  qE W| rx |  j | f | f S|  j | f f S(   s%   Return state information for picklingN(   t   varst   copyR   R   R   R>   (   R   R2   R/   t	   inst_dict(    (    s!   /usr/lib/python2.7/collections.pyt
   __reduce__   s    #c         C   s   |  j  |   S(   s!   od.copy() -> a shallow copy of od(   R>   (   R   (    (    s!   /usr/lib/python2.7/collections.pyRD      s    c         C   s(   |    } x | D] } | | | <q W| S(   s   OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
        If not specified, the value defaults to None.

        (    (   t   clst   iterableR   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   fromkeys   s    	c         C   sM   t  | t  r= t |   t |  k o< |  j   | j   k St j |  |  S(   s   od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
        while comparison to a regular mapping is order-insensitive.

        (   t
   isinstanceR   R   R/   R*   t   __eq__(   R   t   other(    (    s!   /usr/lib/python2.7/collections.pyRK      s    .c         C   s   |  | k S(   s   od.__ne__(y) <==> od!=y(    (   R   RL   (    (    s!   /usr/lib/python2.7/collections.pyt   __ne__   s    c         C   s
   t  |   S(   s@   od.viewkeys() -> a set-like object providing a view on od's keys(   t   KeysView(   R   (    (    s!   /usr/lib/python2.7/collections.pyt   viewkeys   s    c         C   s
   t  |   S(   s<   od.viewvalues() -> an object providing a view on od's values(   t
   ValuesView(   R   (    (    s!   /usr/lib/python2.7/collections.pyt
   viewvalues   s    c         C   s
   t  |   S(   sB   od.viewitems() -> a set-like object providing a view on od's items(   t	   ItemsView(   R   (    (    s!   /usr/lib/python2.7/collections.pyt	   viewitems   s    N($   R?   t
   __module__t   __doc__R   R*   R   R#   R&   R'   R)   R-   R.   R/   R1   R(   R3   t   MutableMappingt   updateR   t   objectR4   R   R   R8   t   TrueR;   RB   RF   RD   t   classmethodRI   RK   RM   RO   RQ   RS   (    (    (    s!   /usr/lib/python2.7/collections.pyR      s:   	
		
	
										
	
					c         B   s/  e  | e  r* | j d d  j   } n  e e e |   } | r e |  } e   } x e	 |  D] \ } } e
 d   | D  s e |  s | s | d j   s | j d  s | | k r d | | | <n  | j |  qg We |  } n  x |  f | D]q } e
 d   | D  s6e d |   n  e |  rUe d	 |   n  | d j   re d
 |   qqWe   } xc | D][ } | j d  r| re d |   n  | | k re d |   n  | j |  qWe |  }	 e |  j d d  d d !}
 d j d   | D  } d e   } x1 e	 |  D]# \ } } | d | | | f 7} qIW| r~| GHn  e d e d d |  d e d e d e  } y | | UWn* e k
 r} e | j d |   n X| |  } y% e j d  j j d d  | _ Wn e e f k
 r*n X| S(   s>  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 accessable 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)

    t   ,t    c         s   s'   |  ] } | j    p | d  k Vq d S(   t   _N(   t   isalnum(   t   .0t   c(    (    s!   /usr/lib/python2.7/collections.pys	   <genexpr>  s    i    R]   s   _%dc         s   s'   |  ] } | j    p | d  k Vq d S(   R]   N(   R^   (   R_   R`   (    (    s!   /usr/lib/python2.7/collections.pys	   <genexpr>  s    sW   Type names and field names can only contain alphanumeric characters and underscores: %rs2   Type names and field names cannot be a keyword: %rs9   Type names and field names cannot start with a number: %rs/   Field names cannot start with an underscore: %rs$   Encountered duplicate field name: %rt   't    i   is   , c         s   s   |  ] } d  | Vq d S(   s   %s=%%rN(    (   R_   t   name(    (    s!   /usr/lib/python2.7/collections.pys	   <genexpr>&  s    s  class %(typename)s(tuple):
        '%(typename)s(%(argtxt)s)' 

        __slots__ = () 

        _fields = %(field_names)r 

        def __new__(_cls, %(argtxt)s):
            'Create new instance of %(typename)s(%(argtxt)s)'
            return _tuple.__new__(_cls, (%(argtxt)s)) 

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

        def __repr__(self):
            'Return a nicely formatted representation string'
            return '%(typename)s(%(reprtxt)s)' %% self 

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

        __dict__ = property(_asdict) 

        def _replace(_self, **kwds):
            'Return a new %(typename)s 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' %% kwds.keys())
            return result 

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

sI           %s = _property(_itemgetter(%d), doc='Alias for field number %d')
t   _itemgetterR?   s   namedtuple_%sR   t	   _propertyt   _tuples   :
t   __main__(    RJ   t
   basestringt   replacet   splitt   tuplet   mapt   strR,   t   sett	   enumeratet   allt
   _iskeywordt   isdigitt
   startswitht   addt
   ValueErrorR   t   reprt   joint   localsR*   Rd   R   t   propertyt   SyntaxErrort   messaget   _syst	   _getframet	   f_globalst   getRT   R   (   t   typenamet   field_namest   verboset   renamet   namest   seent   iRc   t
   seen_namest	   numfieldst   argtxtt   reprtxtt   templatet	   namespacet   eR7   (    (    s!   /usr/lib/python2.7/collections.pyR      s^    	#&	
%c           B   s   e  Z d  Z d d  Z d   Z d d  Z d   Z e d d   Z	 d d  Z
 d d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   s  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         K   s'   t  t |   j   |  j | |  d S(   s	  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

        N(   t   superR    R   RW   (   R   RH   R   (    (    s!   /usr/lib/python2.7/collections.pyR     s    c         C   s   d S(   s1   The count of elements not in the Counter is zero.i    (    (   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   __missing__  s    c         C   sP   | d k r. t |  j   d t d  d t St j | |  j   d t d  S(   s   List 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)]

        R   i   t   reverseN(   R   t   sortedR3   Rd   RY   t   _heapqt   nlargest(   R   t   n(    (    s!   /usr/lib/python2.7/collections.pyt   most_common  s    	"c         C   s   t  j t t |  j     S(   s  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.

        (   t   _chaint   from_iterablet   _starmapt   _repeatR3   (   R   (    (    s!   /usr/lib/python2.7/collections.pyt   elements  s    c         C   s   t  d   d  S(   Ns@   Counter.fromkeys() is undefined.  Use Counter(iterable) instead.(   t   NotImplementedError(   RG   RH   t   v(    (    s!   /usr/lib/python2.7/collections.pyRI     s    c         K   s   | d k	 r t | t  rz |  ra |  j } xJ | j   D]# \ } } | | d  | |  | <q7 Wq t t |   j |  q |  j } x( | D] } | | d  d |  | <q Wn  | r |  j |  n  d S(   s  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

        i    i   N(   R   RJ   t   MappingR   R3   R   R    RW   (   R   RH   R   t   self_gett   elemt   count(    (    s!   /usr/lib/python2.7/collections.pyRW     s    		c         K   s   | d k	 r |  j } t | t  r[ x\ | j   D]# \ } } | | d  | |  | <q1 Wq x( | D] } | | d  d |  | <qb Wn  | r |  j |  n  d S(   s  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

        i    i   N(   R   R   RJ   R   R/   t   subtract(   R   RH   R   R   R   R   (    (    s!   /usr/lib/python2.7/collections.pyR     s    	c         C   s   |  j  |   S(   s   Return a shallow copy.(   R>   (   R   (    (    s!   /usr/lib/python2.7/collections.pyRD     s    c         C   s   |  j  t |   f f S(   N(   R>   R*   (   R   (    (    s!   /usr/lib/python2.7/collections.pyRF     s    c         C   s)   | |  k r% t  t |   j |  n  d S(   sG   Like dict.__delitem__() but does not raise KeyError for missing values.N(   R   R    R#   (   R   R   (    (    s!   /usr/lib/python2.7/collections.pyR#     s    c         C   sI   |  s d |  j  j Sd j t d j |  j     } d |  j  j | f S(   Ns   %s()s   , s   %r: %rs   %s({%s})(   R>   R?   Rw   Rl   t   __mod__R   (   R   R/   (    (    s!   /usr/lib/python2.7/collections.pyRB      s    !c         C   s   t  | t  s t St   } xA |  j   D]3 \ } } | | | } | d k r) | | | <q) q) Wx? | j   D]1 \ } } | |  k rm | d k rm | | | <qm qm W| S(   s   Add counts from two counters.

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

        i    (   RJ   R    t   NotImplementedR/   (   R   RL   R7   R   R   t   newcount(    (    s!   /usr/lib/python2.7/collections.pyt   __add__/  s    	c         C   s   t  | t  s t St   } xA |  j   D]3 \ } } | | | } | d k r) | | | <q) q) WxC | j   D]5 \ } } | |  k rm | d k  rm d | | | <qm qm W| S(   s    Subtract count, but keep only results with positive counts.

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

        i    (   RJ   R    R   R/   (   R   RL   R7   R   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   __sub__B  s    	c         C   s   t  | t  s t St   } xU |  j   D]G \ } } | | } | | k  rQ | n | } | d k r) | | | <q) q) Wx? | j   D]1 \ } } | |  k r | d k r | | | <q q W| S(   s   Union is the maximum of value in either of the input counters.

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

        i    (   RJ   R    R   R/   (   R   RL   R7   R   R   t   other_countR   (    (    s!   /usr/lib/python2.7/collections.pyt   __or__U  s    	
c         C   sx   t  | t  s t St   } xU |  j   D]G \ } } | | } | | k  rQ | n | } | d k r) | | | <q) q) W| S(   s    Intersection is the minimum of corresponding counts.

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

        i    (   RJ   R    R   R/   (   R   RL   R7   R   R   R   R   (    (    s!   /usr/lib/python2.7/collections.pyt   __and__i  s    	
N(   R?   RT   RU   R   R   R   R   R   RZ   RI   RW   R   RD   RF   R#   RB   R   R   R   R   (    (    (    s!   /usr/lib/python2.7/collections.pyR    d  s"   +		#							Rg   (   t   loadst   dumpst   Points   x, yt   xi
   t   yi   s   x yc           B   s&   e  Z d Z e d     Z d   Z RS(   c         C   s   |  j  d |  j d d S(   Ni   g      ?(   R   R   (   R   (    (    s!   /usr/lib/python2.7/collections.pyt   hypot  s    c         C   s   d |  j  |  j |  j f S(   Ns$   Point: x=%6.3f  y=%6.3f  hypot=%6.3f(   R   R   R   (   R   (    (    s!   /usr/lib/python2.7/collections.pyt   __str__  s    (    (   R?   RT   t	   __slots__Ry   R   R   (    (    (    s!   /usr/lib/python2.7/collections.pyR     s   i   i   i   i   g      @c           B   s/   e  Z d  Z d Z e e j  Z e d  Z	 RS(   sH   Point class with optimized _make() and _replace() without error-checkingc         K   s   |  j  | | j d |    S(   NR   R   (   R   R   (   t   _makeR   (   R   t   _mapR   (    (    s!   /usr/lib/python2.7/collections.pyt   _replace  s    (    (
   R?   RT   RU   R   RZ   Rk   t   __new__R   Rl   R   (    (    (    s!   /usr/lib/python2.7/collections.pyR     s   i   i   id   t   Point3Dt   zt   TestResultss   failed attempted(/   t   __all__t   _abcollt   _collectionsR   R   t   operatorR   Rd   t   keywordR   Rq   t   sysR|   t   heapqR   t	   itertoolsR   R   R	   R   R
   R   t   threadR   R=   t   ImportErrort   dummy_threadR*   R   t   FalseR   R    R?   t   cPickleR   R   RY   R   t   pt   AssertionErrorR   t   _fieldsR   RU   t   doctestR   t   testmod(    (    (    s!   /usr/lib/python2.7/collections.pyt   <module>   s@   
w )	