ó
D«ÂVc           @` sÆ   d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z m	 Z	 d d l
 m Z m Z d d l m Z m Z d d l Z d Z d „  Z d	 e f d
 „  ƒ  YZ d „  Z d „  Z d „  Z d S(   u’  
Cycler
======

Cycling through combinations of values, producing dictionaries.

You can add cyclers::

    from cycler import cycler
    cc = (cycler(color=list('rgb')) +
          cycler(linestyle=['-', '--', '-.']))
    for d in cc:
        print(d)

Results in::

    {'color': 'r', 'linestyle': '-'}
    {'color': 'g', 'linestyle': '--'}
    {'color': 'b', 'linestyle': '-.'}


You can multiply cyclers::

    from cycler import cycler
    cc = (cycler(color=list('rgb')) *
          cycler(linestyle=['-', '--', '-.']))
    for d in cc:
        print(d)

Results in::

    {'color': 'r', 'linestyle': '-'}
    {'color': 'r', 'linestyle': '--'}
    {'color': 'r', 'linestyle': '-.'}
    {'color': 'g', 'linestyle': '-'}
    {'color': 'g', 'linestyle': '--'}
    {'color': 'g', 'linestyle': '-.'}
    {'color': 'b', 'linestyle': '-'}
    {'color': 'b', 'linestyle': '--'}
    {'color': 'b', 'linestyle': '-.'}
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   productt   cycle(   t   zipt   reduce(   t   mult   addu   0.10.0c         C` s   |  d k	 r t t |  ƒ ƒ n i  } | d k	 rB t t | ƒ ƒ n i  } t | j ƒ  ƒ } t | j ƒ  ƒ } | | @r… t d ƒ ‚ n  | | BS(   u  
    Helper function to compose cycler keys

    Parameters
    ----------
    left, right : iterable of dictionaries or None
        The cyclers to be composed
    Returns
    -------
    keys : set
        The keys in the composition of the two cyclers
    u"   Can not compose overlapping cyclesN(   t   Nonet   nextt   itert   sett   keyst
   ValueError(   t   leftt   rightt   l_peekt   r_peekt   l_keyt   r_key(    (    s%   lib/python2.7/site-packages/cycler.pyt   _process_keys7   s    $$
t   Cyclerc           B` sÚ   e  Z d  Z d „  Z d d d „ Z e d „  ƒ Z d „  Z d „  Z	 e
 d „  ƒ Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z RS(   u  
    Composable cycles

    This class has compositions methods:

    ``+``
      for 'inner' products (zip)

    ``+=``
      in-place ``+``

    ``*``
      for outer products (itertools.product) and integer multiplication

    ``*=``
      in-place ``*``

    and supports basic slicing via ``[]``

    Parameters
    ----------
    left : Cycler or None
        The 'left' cycler

    right : Cycler or None
        The 'right' cycler

    op : func or None
        Function which composes the 'left' and 'right' cyclers.

    c         C` s
   t  |  ƒ S(   N(   R   (   t   self(    (    s%   lib/python2.7/site-packages/cycler.pyt   __call__m   s    c         C` sÿ   t  | t ƒ r0 t | j | j | j ƒ |  _ n= | d k	 rd g  | D] } t j | ƒ ^ qC |  _ n	 d |  _ t  | t ƒ r t | j | j | j ƒ |  _ n= | d k	 rÑ g  | D] } t j | ƒ ^ q° |  _ n	 d |  _ t |  j |  j ƒ |  _ | |  _ d S(   u\   Semi-private init

        Do not use this directly, use `cycler` function instead.
        N(	   t
   isinstanceR   t   _leftt   _rightt   _opR
   t   copyR   t   _keys(   R   R   R   t   opt   v(    (    s%   lib/python2.7/site-packages/cycler.pyt   __init__p   s    !(	!(	c         C` s   t  |  j ƒ S(   u2   
        The keys this Cycler knows about
        (   R   R   (   R   (    (    s%   lib/python2.7/site-packages/cycler.pyR   Š   s    c         C` s  | | k r d S| |  j  k r; t d | | | f ƒ ‚ n  | |  j  k rf t d | | | f ƒ ‚ n  |  j  j | ƒ |  j  j | ƒ |  j d k	 r½ | |  j j k r½ |  j j | | ƒ nR t	 |  j
 t ƒ rå |  j
 j | | ƒ n* g  |  j
 D] } i | | | 6^ qï |  _
 d S(   u  
        Change a key in this cycler to a new name.
        Modification is performed in-place.

        Does nothing if the old key is the same as the new key.
        Raises a ValueError if the new key is already a key.
        Raises a KeyError if the old key isn't a key.

        Nu-   Can't replace %s with %s, %s is already a keyu)   Can't replace %s with %s, %s is not a key(   R   R   t   KeyErrort   removeR	   R   R
   R   t
   change_keyR   R   R   (   R   t   oldt   newt   entry(    (    s%   lib/python2.7/site-packages/cycler.pyR%   ‘   s    
!c         c` sU   xN |  j  |  j |  j ƒ D]4 \ } } t ƒ  } | j | ƒ | j | ƒ | Vq Wd S(   u†   
        Compose the 'left' and 'right' components of this cycle
        with the proper operation (zip or product as of now)
        N(   R   R   R   t   dictt   update(   R   t   at   bt   out(    (    s%   lib/python2.7/site-packages/cycler.pyt   _compose´   s
    %	c         ` sA   |  d ƒ } t ‡  f d †  | Dƒ ƒ | _ t ˆ  g ƒ | _ | S(   u­  
        Class method to create 'base' Cycler objects
        that do not have a 'right' or 'op' and for which
        the 'left' object is not another Cycler.

        Parameters
        ----------
        label : str
            The property key.

        itr : iterable
            Finite length iterable of the property values.

        Returns
        -------
        cycler : Cycler
            New 'base' `Cycler`
        c         3` s   |  ] } i | ˆ  6Vq d  S(   N(    (   t   .0R!   (   t   label(    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>Ô   s    N(   R
   t   listR   R   R   (   t   clsR0   t   itrt   ret(    (   R0   s%   lib/python2.7/site-packages/cycler.pyt
   _from_iter¿   s    c         ` sQ   t  ˆ  t ƒ rA |  j ƒ  } t t ‡  f d †  t j | ƒ Dƒ ƒ St d ƒ ‚ d  S(   Nc         3` s(   |  ] \ } } t  | | ˆ  ƒ Vq d  S(   N(   t   _cycler(   R/   t   kR!   (   t   key(    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>Ü   s   u+   Can only use slices with Cycler.__getitem__(   R   t   slicet   by_keyR   R	   t   sixt	   iteritemsR   (   R   R8   t   trans(    (   R8   s%   lib/python2.7/site-packages/cycler.pyt   __getitem__Ø   s
    c         C` s0   |  j  d  k r& t d „  |  j Dƒ ƒ S|  j ƒ  S(   Nc         s` s   |  ] } t  | ƒ Vq d  S(   N(   R)   (   R/   t   l(    (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>ã   s    (   R   R
   R   R   R.   (   R   (    (    s%   lib/python2.7/site-packages/cycler.pyt   __iter__á   s    c         C` sO   t  |  ƒ t  | ƒ k r? t d j t  |  ƒ t  | ƒ ƒ ƒ ‚ n  t |  | t ƒ S(   uœ   
        Pair-wise combine two equal length cycles (zip)

        Parameters
        ----------
        other : Cycler
           The second Cycler
        u1   Can only add equal length cycles, not {0} and {1}(   t   lenR   t   formatR   R   (   R   t   other(    (    s%   lib/python2.7/site-packages/cycler.pyt   __add__ç   s    		c         ` sh   t  ˆ  t ƒ r t |  ˆ  t ƒ St  ˆ  t ƒ r` |  j ƒ  } t t ‡  f d †  t j | ƒ Dƒ ƒ St	 Sd S(   uÓ   
        Outer product of two cycles (`itertools.product`) or integer
        multiplication.

        Parameters
        ----------
        other : Cycler or int
           The second Cycler or integer
        c         3` s(   |  ] \ } } t  | | ˆ  ƒ Vq d  S(   N(   R6   (   R/   R7   R!   (   RC   (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>  s   N(
   R   R   R   t   intR:   R   R	   R;   R<   t   NotImplemented(   R   RC   R=   (    (   RC   s%   lib/python2.7/site-packages/cycler.pyt   __mul__õ   s    
c         C` s   |  | S(   N(    (   R   RC   (    (    s%   lib/python2.7/site-packages/cycler.pyt   __rmul__  s    c         C` sb   i t  t 6t t 6} |  j d  k r0 t |  j ƒ St |  j ƒ } t |  j ƒ } | |  j | | ƒ S(   N(	   t   minR   R   R   R   R
   RA   R   R   (   R   t   op_dictt   l_lent   r_len(    (    s%   lib/python2.7/site-packages/cycler.pyt   __len__  s    c         C` ss   t  | t ƒ s t d ƒ ‚ n  t j |  ƒ } t | | ƒ |  _ | |  _ t |  _ t | j | j	 | j ƒ |  _	 |  S(   u¥   
        In-place pair-wise combine two equal length cycles (zip)

        Parameters
        ----------
        other : Cycler
           The second Cycler
        u"   Cannot += with a non-Cycler object(
   R   R   t	   TypeErrorR   R   R   R   R   R   R   (   R   RC   t   old_self(    (    s%   lib/python2.7/site-packages/cycler.pyt   __iadd__  s    			c         C` ss   t  | t ƒ s t d ƒ ‚ n  t j |  ƒ } t | | ƒ |  _ | |  _ t |  _ t | j | j	 | j ƒ |  _	 |  S(   u§   
        In-place outer product of two cycles (`itertools.product`)

        Parameters
        ----------
        other : Cycler
           The second Cycler
        u"   Cannot *= with a non-Cycler object(
   R   R   RN   R   R   R   R   R   R   R   (   R   RC   RO   (    (    s%   lib/python2.7/site-packages/cycler.pyt   __imul__&  s    			c         C` sM   t  |  ƒ t  | ƒ k r t S|  j | j Ar0 t St d „  t |  | ƒ Dƒ ƒ S(   u    
        Check equality
        c         s` s!   |  ] \ } } | | k Vq d  S(   N(    (   R/   R+   R,   (    (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>B  s    (   RA   t   FalseR   t   allR   (   R   RC   (    (    s%   lib/python2.7/site-packages/cycler.pyt   __eq__9  s
    c         ` s¥   i d t  6d t 6} |  j d  k rd |  j j ƒ  ‰  t ‡  f d †  |  Dƒ ƒ } d j d ˆ  d | ƒ S| j |  j	 d ƒ } d } | j d	 |  j
 d
 | d |  j ƒ Sd  S(   Nu   +u   *c         3` s   |  ] } | ˆ  Vq d  S(   N(    (   R/   R!   (   t   lab(    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>H  s    u   cycler({lab!r}, {itr!r})RU   R3   u   ?u   ({left!r} {op} {right!r})R   R    R   (   R   R   R   R
   R   t   popR1   RB   t   getR   R   (   R   t   op_mapR3   R    t   msg(    (   RU   s%   lib/python2.7/site-packages/cycler.pyt   __repr__D  s    c         C` s¦   d } t  |  j d t ƒ} x$ | D] } | d j d | ƒ 7} q" WxS t |  ƒ D]E } | d 7} x( | D]  } | d j d | | ƒ 7} qf W| d 7} qO W| d 7} | S(	   Nu   <table>R8   u   <th>{key!r}</th>u   <tr>u   <td>{val!r}</td>t   valu   </tr>u   </table>(   t   sortedR   t   reprRB   R   (   R   t   outputt   sorted_keysR8   t   dR7   (    (    s%   lib/python2.7/site-packages/cycler.pyt   _repr_html_O  s    

c         C` sZ   |  j  } t d „  | Dƒ ƒ } x4 |  D], } x# | D] } | | j | | ƒ q3 Wq& W| S(   uÓ  Values by key

        This returns the transposed values of the cycler.  Iterating
        over a `Cycler` yields dicts with a single value for each key,
        this method returns a `dict` of `list` which are the values
        for the given key.

        The returned value can be used to create an equivalent `Cycler`
        using only `+`.

        Returns
        -------
        transpose : dict
            dict of lists of the values for each key.
        c         s` s   |  ] } | t  ƒ  f Vq d  S(   N(   R1   (   R/   R7   (    (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>s  s    (   R   R)   t   append(   R   R   R-   R`   R7   (    (    s%   lib/python2.7/site-packages/cycler.pyR:   ]  s    	c         C` s,   |  j  ƒ  } t t d „  t j | ƒ Dƒ ƒ S(   uÊ   Simplify the Cycler

        Returned as a composition using only sums (no multiplications)

        Returns
        -------
        simple : Cycler
            An equivalent cycler using only summationc         s` s$   |  ] \ } } t  | | ƒ Vq d  S(   N(   R6   (   R/   R7   R!   (    (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>  s    (   R:   R   R	   R;   R<   (   R   R=   (    (    s%   lib/python2.7/site-packages/cycler.pyt   simplify}  s    c         C` s   t  |  | ƒ S(   uF  Concatenate this cycler and an other.

        The keys must match exactly.

        This returns a single Cycler which is equivalent to
        `itertools.chain(self, other)`

        Examples
        --------

        >>> num = cycler('a', range(3))
        >>> let = cycler('a', 'abc')
        >>> num.concat(let)
        cycler('a', [0, 1, 2, 'a', 'b', 'c'])

        Parameters
        ----------
        other : `Cycler`
            The `Cycler` to concatenate to this one.

        Returns
        -------
        ret : `Cycler`
            The concatenated `Cycler`
        (   t   concat(   R   RC   (    (    s%   lib/python2.7/site-packages/cycler.pyRd     s    N(   t   __name__t
   __module__t   __doc__R   R
   R"   t   propertyR   R%   R.   t   classmethodR5   R>   R@   RD   RG   RH   RM   RP   RQ   RT   RZ   Ra   R:   t
   _transposeRc   Rd   (    (    (    s%   lib/python2.7/site-packages/cycler.pyR   M   s,   		#															c         ` sš   |  j  | j  k r_ d j d d d g ƒ j d |  j  | j  @d |  j  | j  Aƒ } t | ƒ ‚ n  |  j ƒ  ‰  | j ƒ  ‰ t t ‡  ‡ f d †  |  j  Dƒ ƒ S(   uø  Concatenate two cyclers.

    The keys must match exactly.

    This returns a single Cycler which is equivalent to
    `itertools.chain(left, right)`

    Examples
    --------

    >>> num = cycler('a', range(3))
    >>> let = cycler('a', 'abc')
    >>> num.concat(let)
    cycler('a', [0, 1, 2, 'a', 'b', 'c'])

    Parameters
    ----------
    left, right : `Cycler`
        The two `Cycler` instances to concatenate

    Returns
    -------
    ret : `Cycler`
        The concatenated `Cycler`
    u   
	u   Keys do not match:u   Intersection: {both!r}u   Disjoint: {just_one!r}t   botht   just_onec         3` s*   |  ]  } t  | ˆ  | ˆ | ƒ Vq d  S(   N(   R6   (   R/   R7   (   t   _lt   _r(    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>Ñ  s    (   R   t   joinRB   R   R:   R   R	   (   R   R   RY   (    (   Rm   Rn   s%   lib/python2.7/site-packages/cycler.pyRd   ¬  s    	c          O` sÐ   |  r | r t  d ƒ ‚ n  t |  ƒ d k r] t |  d t ƒ sO t  d ƒ ‚ n  t |  d ƒ St |  ƒ d k ry t |  Œ  St |  ƒ d k rš t  d ƒ ‚ n  | rÀ t t d „  t j | ƒ Dƒ ƒ St  d ƒ ‚ d	 S(
   uí  
    Create a new `Cycler` object from a single positional argument,
    a pair of positional arguments, or the combination of keyword arguments.

    cycler(arg)
    cycler(label1=itr1[, label2=iter2[, ...]])
    cycler(label, itr)

    Form 1 simply copies a given `Cycler` object.

    Form 2 composes a `Cycler` as an inner product of the
    pairs of keyword arguments. In other words, all of the
    iterables are cycled simultaneously, as if through zip().

    Form 3 creates a `Cycler` from a label and an iterable.
    This is useful for when the label cannot be a keyword argument
    (e.g., an integer or a name that has a space in it).

    Parameters
    ----------
    arg : Cycler
        Copy constructor for Cycler (does a shallow copy of iterables).

    label : name
        The property key. In the 2-arg form of the function,
        the label can be any hashable object. In the keyword argument
        form of the function, it must be a valid python identifier.

    itr : iterable
        Finite length iterable of the property values.
        Can be a single-property `Cycler` that would
        be like a key change, but as a shallow copy.

    Returns
    -------
    cycler : Cycler
        New `Cycler` for the given property

    uB   cyl() can only accept positional OR keyword arguments -- not both.i   i    uE   If only one positional argument given, it must  be a Cycler instance.i   ud   Only a single Cycler can be accepted as the lone positional argument. Use keyword arguments instead.c         s` s$   |  ] \ } } t  | | ƒ Vq d  S(   N(   R6   (   R/   R7   R!   (    (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>  s    u4   Must have at least a positional OR keyword argumentsN(	   RN   RA   R   R   R6   R   R	   R;   R<   (   t   argst   kwargs(    (    s%   lib/python2.7/site-packages/cycler.pyt   cyclerÔ  s    (
 c         ` st   t  | t ƒ rd | j } t | ƒ d k r? d } t | ƒ ‚ n  | j ƒ  ‰  ‡  f d †  | Dƒ } n  t j |  | ƒ S(   uI  
    Create a new `Cycler` object from a property name and
    iterable of values.

    Parameters
    ----------
    label : hashable
        The property key.

    itr : iterable
        Finite length iterable of the property values.

    Returns
    -------
    cycler : Cycler
        New `Cycler` for the given property
    i   u2   Can not create Cycler from a multi-property Cyclerc         3` s   |  ] } | ˆ  Vq d  S(   N(    (   R/   R!   (   RU   (    s%   lib/python2.7/site-packages/cycler.pys	   <genexpr>,  s    (   R   R   R   RA   R   RV   R5   (   R0   R3   R   RY   (    (   RU   s%   lib/python2.7/site-packages/cycler.pyR6     s    	(   Rg   t
   __future__R    R   R   R   R;   t	   itertoolsR   R   t	   six.movesR   R   t   operatorR   R	   R   t   __version__R   t   objectR   Rd   Rr   R6   (    (    (    s%   lib/python2.7/site-packages/cycler.pyt   <module>)   s   "	ÿ `	(	=