Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib/python3.5/site-packages/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/__pycache__/cycler.cpython-35.pyc




��VW>�@s�dZddlmZmZmZmZddlZddlmZm	Z	ddl
mZmZddl
mZmZddlZdZdd	�ZGd
d�de�Zdd
�Zdd�Zdd�ZdS)a�
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': '-.'}
�)�absolute_import�division�print_function�unicode_literalsN)�product�cycle)�zip�reduce)�mul�addz0.10.0cCs�|dk	rtt|��ni}|dk	rBtt|��ni}t|j��}t|j��}||@r�td��||BS)a
    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
    Nz"Can not compose overlapping cycles)�next�iter�set�keys�
ValueError)�left�rightZl_peekZr_peekZl_keyZr_key�r�7/opt/alt/python35/lib/python3.5/site-packages/cycler.py�
_process_keys7s
$$
rc@seZdZdZdd�Zdddd�Zedd��Zd	d
�Zdd�Z	e
d
d��Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZeZd'd(�Zd)d*�ZdS)+�Cyclera
    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.

    cCs
t|�S)N)r)�selfrrr�__call__mszCycler.__call__NcCs�t|t�r0t|j|j|j�|_n.|dk	rUdd�|D�|_n	d|_t|t�r�t|j|j|j�|_n.|dk	r�dd�|D�|_n	d|_t|j|j�|_||_dS)z\Semi-private init

        Do not use this directly, use `cycler` function instead.
        NcSsg|]}tj|��qSr)�copy)�.0�vrrr�
<listcomp>zs	z#Cycler.__init__.<locals>.<listcomp>cSsg|]}tj|��qSr)r)rrrrrr�s	)�
isinstancer�_left�_right�_opr�_keys)rrr�oprrr�__init__ps!	!	zCycler.__init__cCs
t|j�S)z2
        The keys this Cycler knows about
        )rr!)rrrrr�szCycler.keyscs��krdS�|jkr8td���f���|jkr`td���f��|jj��|jj��|jdk	r��|jjkr�|jj���nJt|j	t
�r�|j	j���n"��fdd�|j	D�|_	dS)a
        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.

        Nz-Can't replace %s with %s, %s is already a keyz)Can't replace %s with %s, %s is not a keycs g|]}�|�i�qSrr)r�entry)�new�oldrrr�s	z%Cycler.change_key.<locals>.<listcomp>)r!r�KeyError�removerrr�
change_keyrrr)rr&r%r)r%r&rr)�s
!zCycler.change_keyccsUxN|j|j|j�D]4\}}t�}|j|�|j|�|VqWdS)z�
        Compose the 'left' and 'right' components of this cycle
        with the proper operation (zip or product as of now)
        N)r rr�dict�update)r�a�b�outrrr�_compose�s
%	

zCycler._composecsD|d�}t�fdd�|D��|_t�g�|_|S)a�
        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`
        Nc3s|]}�|iVqdS)Nr)rr)�labelrr�	<genexpr>�sz$Cycler._from_iter.<locals>.<genexpr>)�listrrr!)�clsr0�itr�retr)r0r�
_from_iter�s"zCycler._from_itercsTt�t�rD|j�}tt�fdd�tj|�D��Std��dS)Nc3s(|]\}}t||��VqdS)N)�_cycler)r�kr)�keyrrr1�sz%Cycler.__getitem__.<locals>.<genexpr>z+Can only use slices with Cycler.__getitem__)r�slice�by_keyr	r�six�	iteritemsr)rr9�transr)r9r�__getitem__�s
zCycler.__getitem__cCs3|jdkr)tdd�|jD��S|j�S)Ncss|]}t|�VqdS)N)r*)r�lrrrr1�sz"Cycler.__iter__.<locals>.<genexpr>)rr
rr/)rrrr�__iter__�szCycler.__iter__cCsLt|�t|�kr<tdjt|�t|����t||t�S)z�
        Pair-wise combine two equal length cycles (zip)

        Parameters
        ----------
        other : Cycler
           The second Cycler
        z1Can only add equal length cycles, not {0} and {1})�lenr�formatrr)r�otherrrr�__add__�s		zCycler.__add__cskt�t�rt|�t�St�t�rc|j�}tt�fdd�tj|�D��St	SdS)z�
        Outer product of two cycles (`itertools.product`) or integer
        multiplication.

        Parameters
        ----------
        other : Cycler or int
           The second Cycler or integer
        c3s(|]\}}t||��VqdS)N)r7)rr8r)rDrrr1sz!Cycler.__mul__.<locals>.<genexpr>N)
rrr�intr;r	rr<r=�NotImplemented)rrDr>r)rDr�__mul__�s
zCycler.__mul__cCs||S)Nr)rrDrrr�__rmul__szCycler.__rmul__cCs`tttti}|jdkr.t|j�St|j�}t|j�}||j||�S)N)r�minrr
rrBrr )rZop_dictZl_lenZr_lenrrr�__len__s
zCycler.__len__cCspt|t�std��tj|�}t||�|_||_t|_t|j|j	|j�|_	|S)z�
        In-place pair-wise combine two equal length cycles (zip)

        Parameters
        ----------
        other : Cycler
           The second Cycler
        z"Cannot += with a non-Cycler object)
rr�	TypeErrorrrr!rrr r)rrD�old_selfrrr�__iadd__s			zCycler.__iadd__cCspt|t�std��tj|�}t||�|_||_t|_t|j|j	|j�|_	|S)z�
        In-place outer product of two cycles (`itertools.product`)

        Parameters
        ----------
        other : Cycler
           The second Cycler
        z"Cannot *= with a non-Cycler object)
rrrLrrr!rrr r)rrDrMrrr�__imul__&s			zCycler.__imul__cCsPt|�t|�krdS|j|jAr0dStdd�t||�D��S)z 
        Check equality
        Fcss!|]\}}||kVqdS)Nr)rr,r-rrrr1Bsz Cycler.__eq__.<locals>.<genexpr>)rBr�allr)rrDrrr�__eq__9s
z
Cycler.__eq__cs�tdtdi}|jdkre|jj��t�fdd�|D��}djd�d|�S|j|jd�}d	}|jd
|j	d|d|j�SdS)
N�+�*c3s|]}|�VqdS)Nr)rr)�labrrr1Hsz"Cycler.__repr__.<locals>.<genexpr>zcycler({lab!r}, {itr!r})rTr4�?z({left!r} {op} {right!r})rr"r)
rrrr�popr2rC�getr r)rZop_mapr4r"�msgr)rTr�__repr__DszCycler.__repr__cCs�d}t|jdt�}x$|D]}|djd|�7}q"WxSt|�D]E}|d7}x(|D] }|djd||�7}qfW|d7}qOW|d7}|S)	Nz<table>r9z<th>{key!r}</th>z<tr>z<td>{val!r}</td>�valz</tr>z</table>)�sortedr�reprrCr
)r�outputZsorted_keysr9�dr8rrr�_repr_html_Os



zCycler._repr_html_cCs]|j}tdd�|D��}x4|D],}x#|D]}||j||�q6Wq)W|S)a�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.
        css|]}|t�fVqdS)N)r2)rr8rrrr1ssz Cycler.by_key.<locals>.<genexpr>)rr*�append)rrr.r^r8rrrr;]s	

z
Cycler.by_keycCs/|j�}ttdd�tj|�D��S)z�Simplify the Cycler

        Returned as a composition using only sums (no multiplications)

        Returns
        -------
        simple : Cycler
            An equivalent cycler using only summationcss$|]\}}t||�VqdS)N)r7)rr8rrrrr1�sz"Cycler.simplify.<locals>.<genexpr>)r;r	rr<r=)rr>rrr�simplify}szCycler.simplifycCs
t||�S)aFConcatenate 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`
        )�concat)rrDrrrrb�sz
Cycler.concat)�__name__�
__module__�__qualname__�__doc__rr#�propertyrr)r/�classmethodr6r?rArErHrIrKrNrOrQrYr_r;Z
_transposerarbrrrrrMs,#	rcs�|j|jkr\djdddg�jd|j|j@d|j|jA�}t|��|j��|j��tt��fdd�|jD��S)	a�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`
    z
	zKeys do not match:zIntersection: {both!r}zDisjoint: {just_one!r}ZbothZjust_onec3s*|] }t|�|�|�VqdS)N)r7)rr8)�_l�_rrrr1�szconcat.<locals>.<genexpr>)r�joinrCrr;r	r)rrrXr)rirjrrb�s	rbcOs�|r|rtd��t|�dkrWt|dt�sItd��t|d�St|�dkrst|�St|�dkr�td��|r�ttdd�tj|�D��Std	��d
S)a�
    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

    zBcyl() can only accept positional OR keyword arguments -- not both.�rzEIf only one positional argument given, it must  be a Cycler instance.�zdOnly a single Cycler can be accepted as the lone positional argument. Use keyword arguments instead.css$|]\}}t||�VqdS)N)r7)rr8rrrrr1szcycler.<locals>.<genexpr>z4Must have at least a positional OR keyword argumentsN)	rLrBrrr7r	rr<r=)�args�kwargsrrr�cycler�s(
#rpcsqt|t�ra|j}t|�dkr<d}t|��|j���fdd�|D�}tj||�S)aI
    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
    rlz2Can not create Cycler from a multi-property Cyclerc3s|]}|�VqdS)Nr)rr)rTrrr1,sz_cycler.<locals>.<genexpr>)rrrrBrrVr6)r0r4rrXr)rTrr7s	r7)rf�
__future__rrrrr<�	itertoolsrrZ	six.movesrr	�operatorr
rr�__version__r�objectrrbrpr7rrrr�<module>)s"�`(=