ó
P'—^c        %   @   sŠ  y d  d l  m Z m Z Wn' e k
 rC d  d l m Z m Z n Xd  d l m Z m	 Z	 m
 Z
 d  d l m Z m Z d  d l m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z m Z d d	 l  m! Z! m" Z" d d
 l# m$ Z$ m% Z% m Z& d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ g% Z' i e( e) e* j+ ƒ 6e, e) i  j- ƒ  ƒ 6e, e) i  j. ƒ  ƒ 6e, e) i  j/ ƒ  ƒ 6Z0 dZ d0 „ Z2 d1 „  Z3 e rd2 „  Z4 d3 „  Z5 n d4 „  Z4 d5 „  Z5 d6 e4 _6 d7 e5 _6 d8 „  Z7 d9 „  Z8 d: „  Z9 d; „  Z: d< „  Z; d= „  Z< d> „  Z= d? „  Z> d@ „  Z? dA „  Z@ dB „  ZA e dC „ ZB e dD „ Z e dE „ Z e dF „ ZC e dG „ ZD e dH „ ZE dI „  ZF dJ „  ZG dK „  ZH dL „  ZI dM „  ZJ dN „  ZK dZ dO „ ZL dP „  ZM dZ dQ „ ZN dR „  ZO dS „  ZP dT „  ZQ dU „  ZR dV „  ZS dW „  ZT dX „  ZU dY „  ZV dZ S([   iÿÿÿÿ(   t   allt   any(   t
   itemgettert   methodcallert
   attrgetter(   t   chaint   tee(   t   defaultdicti   (
   t
   basestringt   ranget   zipt   mapt   filtert   PY2t   Mappingt   Sett   Iterablet   Iterator(   t   EMPTY(   t   partialt   compose(   t	   make_funct	   make_pred(   t   taket   xmapR   t   emptyt	   iteritemst
   itervaluest   joint   merget	   join_witht
   merge_witht   walkt	   walk_keyst   walk_valuest   selectt   select_keyst   select_valuest   compactt   is_distinctR    R   t   nonet   onet   somet   zipdictt   flipt   projectt   omitt
   zip_valuest	   zip_dictst   wheret   pluckt
   pluck_attrt   invoket   lwheret   lpluckt   lpluck_attrt   linvoket   get_int   set_int	   update_inc         C   sš   t  |  ƒ } t |  t ƒ rR | r< |  j r< t | |  j ƒ n |  j } t t | ƒ St |  t ƒ re t St |  t ƒ r~ | ƒ  j	 S| t
 k r’ t
 | S| Sd  S(   N(   t   typet
   isinstanceR   t   default_factoryR   R   R   t   iterR   R   t   FACTORY_REPLACE(   t   collt   mappert	   coll_typet   item_factory(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyt   _factory!   s    !	
c         C   s&   t  |  t ƒ r t g  ƒ St |  ƒ ƒ  S(   s-   Creates an empty collection of the same type.(   R=   R   R?   RE   (   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   1   s    
c         C   s   t  |  d ƒ r |  j ƒ  S|  S(   NR   (   t   hasattrR   (   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   8   s    c         C   s   t  |  d ƒ r |  j ƒ  S|  S(   NR   (   RF   R   (   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   ;   s    c         C   s   t  |  d ƒ r |  j ƒ  S|  S(   Nt   items(   RF   RG   (   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   >   s    c         C   s   t  |  d ƒ r |  j ƒ  S|  S(   Nt   values(   RF   RH   (   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   A   s    s2   Yields (key, value) pairs of the given collection.s&   Yields values of the given collection.c         C   s  t  |  ƒ \ }  } t | ƒ } y t | ƒ } Wn t k
 rB d SX| j } t | t ƒ rh d j |  ƒ St | t	 ƒ r¥ | j
 ƒ  } x | D] } | j | ƒ qŠ W| St | t ƒ rÁ | j | Œ  St | t t f ƒ rã t j |  ƒ St | t ƒ r| t j |  ƒ ƒ St d | j ƒ ‚ d S(   s0   Joins several collections of same type into one.t    s   Don't know how to join %sN(   R   R?   t   nextt   StopIterationt   Nonet	   __class__R=   R   R   R   t   copyt   updateR   t   unionR   R	   R   t   from_iterableR   t	   TypeErrort   __name__(   t   collst
   colls_copyt   itt   destt   clst   resultt   d(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   H   s*    	c          G   s
   t  |  ƒ S(   s    Merges several collections of same type into one.

    Works with dicts, sets, lists, tuples, iterators and strings.
    For dicts later values take precedence.(   R   (   RT   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   d   s    c         C   sÑ   t  | ƒ } | s i  St | ƒ d k r0 | d Si  } xX | D]P } xG t | ƒ D]9 \ } } | | k r| | | j | ƒ qP | g | | <qP Wq= W|  t  k	 rÍ x- t | ƒ D] \ } } |  | ƒ | | <qª Wn  | S(   s:   Joins several dicts, combining values with given function.i   i    (   t   listt   lenR   t   append(   t   ft   dictst   listst   ct   kt   v(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   l   s    c         G   s   t  |  | ƒ S(   s;   Merges several dicts, combining values with given function.(   R   (   R^   R_   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   ƒ   s    c         C   s   t  | ƒ t |  t | ƒ ƒ ƒ S(   sc   Walks the collection transforming its elements with f.
       Same as map, but preserves coll type.(   RE   R   R   (   R^   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR    ˆ   s    c            s(   t  ˆ  ƒ ‰  ‡  f d †  } t | | ƒ S(   s2   Walks keys of the collection, mapping them with f.c            s   |  \ } } ˆ  | ƒ | f S(   N(    (   t   pairRb   Rc   (   R^   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyt   pair_f‘   s    (   R   R    (   R^   RA   Re   (    (   R^   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR!      s    c            s@   t  ˆ  ƒ ‰  ‡  f d †  } t | d ˆ  ƒt | t | ƒ ƒ ƒ S(   s4   Walks values of the collection, mapping them with f.c            s   |  \ } } | ˆ  | ƒ f S(   N(    (   Rd   Rb   Rc   (   R^   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyRe   ›   s    RB   (   R   RE   R   R   (   R^   RA   Re   (    (   R^   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR"   —   s    c         C   s   t  | ƒ t |  t | ƒ ƒ ƒ S(   s'   Same as filter but preserves coll type.(   RE   t   xfilterR   (   t   predRA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR#   £   s    c            s"   t  ˆ  ƒ ‰  t ‡  f d †  | ƒ S(   s5   Select part of the collection with keys passing pred.c            s   ˆ  |  d ƒ S(   Ni    (    (   Rd   (   Rg   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyt   <lambda>ª   RI   (   R   R#   (   Rg   RA   (    (   Rg   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR$   §   s    c            s"   t  ˆ  ƒ ‰  t ‡  f d †  | ƒ S(   s7   Select part of the collection with values passing pred.c            s   ˆ  |  d ƒ S(   Ni   (    (   Rd   (   Rg   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyRh   ¯   RI   (   R   R#   (   Rg   RA   (    (   Rg   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR%   ¬   s    c         C   s-   t  |  t ƒ r t t |  ƒ St t |  ƒ Sd S(   s)   Removes falsy values from the collection.N(   R=   R   R%   t   boolR#   (   RA   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR&   ²   s    c         C   sQ   | t  k r( t |  ƒ t t |  ƒ ƒ k St |  ƒ t t t | |  ƒ ƒ ƒ k Sd S(   s7   Checks if all elements in the collection are different.N(   R   R\   t   setR   (   RA   t   key(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR'   ¼   s    c         C   s)   | t  k r t |  ƒ St t |  | ƒ ƒ S(   s5   Checks if all items in seq pass pred (or are truthy).(   R   t   _allR   (   Rg   t   seq(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR    Ä   s    
c         C   s)   | t  k r t |  ƒ St t |  | ƒ ƒ S(   s5   Checks if any item in seq passes pred (or is truthy).(   R   t   _anyR   (   Rg   Rm   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR   Ê   s    
c         C   s   t  |  | ƒ S(   s>   "Checks if none of the items in seq pass pred (or are truthy).(   R   (   Rg   Rm   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR(   Ð   s    c         C   s;   | t  k r t t |  ƒ St t d t |  | ƒ ƒ ƒ d k S(   sB   Checks whether exactly one item in seq passes pred (or is truthy).i   i   (   R   R)   Ri   R\   R   Rf   (   Rg   Rm   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR)   Ô   s    c         C   s/   | t  k r t t |  ƒ St t |  | ƒ d ƒ S(   s=   Finds first item in seq passing pred or first that is truthy.N(   R   R*   Ri   RJ   Rf   RL   (   Rg   Rm   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR*   Û   s    c         C   s   t  t |  | ƒ ƒ S(   s:   Creates a dict with keys mapped to the corresponding vals.(   t   dictR
   (   t   keyst   vals(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR+   è   s    c         C   s   d „  } t  | |  ƒ S(   sE   Flip passed dict or collection of pairs swapping its keys and values.c         S   s   |  \ } } | | f S(   N(    (   Rd   Rb   Rc   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyt	   flip_pairî   s    (   R    (   t   mappingRr   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR,   ì   s    	c            s    t  ˆ  ƒ ‡  f d †  | Dƒ ƒ S(   s"   Leaves only given keys in mapping.c         3   s+   |  ]! } | ˆ  k r | ˆ  | f Vq d  S(   N(    (   t   .0Rb   (   Rs   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pys	   <genexpr>õ   s    (   RE   (   Rs   Rp   (    (   Rs   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR-   ó   s    c            s&   t  |  ƒ ‡  f d †  t |  ƒ Dƒ ƒ S(   s    Removes given keys from mapping.c         3   s-   |  ]# \ } } | ˆ  k r | | f Vq d  S(   N(    (   Rt   Rb   Rc   (   Rp   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pys	   <genexpr>ù   s    (   RE   R   (   Rs   Rp   (    (   Rp   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR.   ÷   s    c          '   si   t  |  ƒ d k  r! t d ƒ ‚ n  t j t t |  ƒ Œ  } x) | D]! ‰  t ‡  f d †  |  Dƒ ƒ Vq@ Wd S(   s7   Yields tuples of corresponding values of several dicts.i   s)   izip_values expects at least one argumentc         3   s   |  ] } | ˆ  Vq d  S(   N(    (   Rt   RZ   (   Rk   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pys	   <genexpr>  s    N(   R\   RR   Rj   t   intersectionR   t   tuple(   R_   Rp   (    (   Rk   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR/   û   s
    c          '   so   t  |  ƒ d k  r! t d ƒ ‚ n  t j t t |  ƒ Œ  } x/ | D]' ‰  ˆ  t ‡  f d †  |  Dƒ ƒ f Vq@ Wd S(   sX   Yields tuples like (key, val1, val2, ...)
       for each common key in all given dicts.i   s(   izip_dicts expects at least one argumentc         3   s   |  ] } | ˆ  Vq d  S(   N(    (   Rt   RZ   (   Rk   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pys	   <genexpr>
  s    N(   R\   RR   Rj   Ru   R   Rv   (   R_   Rp   (    (   Rk   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR0     s
    c         C   s>   x7 | D]/ } y |  | }  Wq t  t f k
 r5 | SXq W|  S(   s7   Returns a value at path in the given nested collection.(   t   KeyErrort
   IndexError(   RA   t   patht   defaultRk   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR9     s    	c            s   t  |  | ‡  f d †  ƒ S(   s2   Creates a copy of coll with the value set at path.c            s   ˆ  S(   N(    (   t   _(   t   value(    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyRh     RI   (   R;   (   RA   Ry   R|   (    (   R|   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR:     s    c         C   s¶   | s | |  ƒ St  |  t ƒ rS |  } t | | d | d | | ƒ | | d <| S|  j ƒ  } t | ƒ d k rw i  n | } t | j | d | ƒ | d | | ƒ | | d <| Sd S(   s4   Creates a copy of coll with a value updated at path.i    i   N(   R=   R[   R;   RN   R\   t   get(   RA   Ry   RO   Rz   RN   t   current_default(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR;     s    
)1c         K   s   t  t |  |  ƒ S(   s.   Selects mappings containing all pairs in cond.(   R[   R1   (   t   mappingst   cond(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR5   *  s    c         C   s   t  t |  | ƒ ƒ S(   s%   Lists values for key in each mapping.(   R[   R2   (   Rk   R   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR6   .  s    c         C   s   t  t |  | ƒ ƒ S(   s/   Lists values of given attribute of each object.(   R[   R3   (   t   attrt   objects(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR7   2  s    c         O   s   t  t |  | | | Ž ƒ S(   s[   Makes a list of results of the obj.name(*args, **kwargs)
       for each object in objects.(   R[   R4   (   R‚   t   namet   argst   kwargs(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR8   6  s    c            s(   | j  ƒ  ‰  ‡  f d †  } t | |  ƒ S(   s4   Iterates over mappings containing all pairs in cond.c            s   t  ‡  f d †  ˆ Dƒ ƒ S(   Nc         3   s1   |  ]' \ } } | ˆ  k o( ˆ  | | k Vq d  S(   N(    (   Rt   Rb   Rc   (   t   m(    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pys	   <genexpr>A  s    (   R    (   R†   (   RG   (   R†   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyRh   A  RI   (   RG   R   (   R   R€   t   match(    (   RG   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR1   >  s    c         C   s   t  t |  ƒ | ƒ S(   s)   Iterates over values for key in mappings.(   R   R   (   Rk   R   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR2   D  s    c         C   s   t  t |  ƒ | ƒ S(   s9   Iterates over values of given attribute of given objects.(   R   R   (   R   R‚   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR3   H  s    c         O   s   t  t | | | Ž |  ƒ S(   sR   Yields results of the obj.name(*args, **kwargs)
       for each object in objects.(   R   R   (   R‚   Rƒ   R„   R…   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyR4   L  s    N(W   t   __builtin__R    Rl   R   Rn   t   ImportErrort   builtinst   operatorR   R   R   t	   itertoolsR   R   t   collectionsR   t   compatR   R	   R
   R   R   R   R   R   R   R   t
   primitivesR   t   funcsR   R   t
   funcmakersR   R   t   seqsR   R   Rf   t   __all__Ro   R<   t   objectt   __dict__R[   Rp   RH   RG   R@   RL   RE   R   R   R   t   __doc__R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   R/   R0   R9   R:   R;   R5   R6   R7   R8   R1   R2   R3   R4   (    (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/colls.pyt   <module>   s„   F													
					
						
									