
    ^MhEA                       d Z ddlmZ ddlmZmZmZ ddl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mZmZmZmZmZmZ d	Z ed
e          Z ede          Z ed          Z ed          Zd'dZd(dZ  G d deeef                   Z!ed)d            Z"ed*d!            Z"ed+d$            Z"d% Z"d+d&Z#dS ),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': '-.'}
    )annotations)HashableIterable	GeneratorN)reduce)productcycle)muladd)	TypeVarGenericCallableUnionDictListAnyoverloadcastz0.12.1K)boundLVUleft#Cycler[K, V] | Iterable[dict[K, V]]right*Cycler[K, V] | Iterable[dict[K, V]] | Nonereturnset[K]c                @   | g k    rt          t          |                     ni }|t          t          |                    ni }t          |                                          }t          |                                          }||z  rt	          d          ||z  S )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)r   r   l_peekr_peekl_keyr_keys         O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/cycler/__init__.py_process_keysr+   >   s    " .2RZZd4jj)))RF.3.?d5kk***RF&&E&&Eu} ?=>>>5=    Cycler[K, V]Cycler[K, U]Cycler[K, V | U]c                H   | j         |j         k    r>t          d                    | j         |j         z  | j         |j         z                      t          t          t
          t          t          t          t          f                  f         | 
                                          t          t          t
          t          t          t          t          f                  f         |
                                          t          t          fd| j         D                       S )aS  
    Concatenate `Cycler`\s, as if chained using `itertools.chain`.

    The keys must match exactly.

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

    Returns
    -------
    `Cycler`
        The concatenated cycler.
    zBKeys do not match:
	Intersection: {both!r}
	Disjoint: {just_one!r})bothjust_onec              3  V   K   | ]#}t          ||         |         z             V  $d S N_cycler).0k_l_rs     r*   	<genexpr>zconcat.<locals>.<genexpr>t   s9      EEa2a52a5=11EEEEEEr,   )r$   r%   formatr   r   r   r   r   r   r   by_keyr   r   )r   r   r9   r:   s     @@r*   concatr>   X   s    $ yEJ''-vY+di%*6L (. ( (
 
 	
 
d1d5A;''($++--	8	8B	d1d5A;''(%,,..	9	9B#EEEEE49EEEFFFr,   c                  4   e Zd ZdZd Z	 	 d6d7d
Zd Zed8d            Zd9dZ	e
d:d            Zd;dZd<dZd=d!Zed=d"            Zed>d$            Zd% Zed=d&            Zed>d'            Zd( Zd?d)Zd@d*ZdAd,ZdBd/ZdZdCd1ZdCd2ZdDd4ZeZdEd5ZeZdS )F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, right : Cycler or None
        The 'left' and 'right' cyclers.
    op : func or None
        Function which composes the 'left' and 'right' cyclers.
    c                     t          |           S r4   )r	   selfs    r*   __call__zCycler.__call__   s    T{{r,   Nr   r   r   Cycler[K, V] | Noneopr   c                   t          |t                    r&t          |j        |j        |j                  | _        n|d |D             | _        ng | _        t          |t                    r&t          |j        |j        |j                  | _        nd| _        t          | j        | j                  | _        || _        dS )zf
        Semi-private init.

        Do not use this directly, use `cycler` function instead.
        Nc                6    g | ]}t          j         |          S  )copy)r7   vs     r*   
<listcomp>z#Cycler.__init__.<locals>.<listcomp>   s     5551$)A,,555r,   )
isinstancer@   _left_right_opr+   _keys)rC   r   r   rF   s       r*   __init__zCycler.__init__   s     dF## 		:@
DK; ;DJJ  65555DJJDJeV$$ 	/5U\590 0DKK DK*4:t{CC
r,   c                    || j         v S r4   )rQ   )rC   r8   s     r*   __contains__zCycler.__contains__   s    DJr,   r   r   c                *    t          | j                  S )z!The keys this Cycler knows about.)r#   rQ   rB   s    r*   r$   zCycler.keys   s     4:r,   oldr   newNonec           	        k    rdS | j         v rt          d d d d          | j         vrt          d d d d          | j                                        | j                                        | j        +| j        j        v r| j                                       dS t          | j	        t                    r| j	                                       dS fd| j	        D             | _	        dS )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 z with , z is already a keyz is not a keyc                $    g | ]}|         iS rI   rI   )r7   entryrW   rV   s     r*   rL   z%Cycler.change_key.<locals>.<listcomp>   s"    DDD3c
+DDDr,   )rQ   r%   KeyErrorremover   rO   r$   
change_keyrM   rN   r@   )rC   rV   rW   s    ``r*   r_   zCycler.change_key   sM    #::F$*IIICII3III   dj  EEECEE3EEE   	
#
s;"sdk.>'>'>K""3,,,,, 
F++ 	EJ!!#s+++++
 EDDDDDDDDJJJr,   labelitrIterable[V]r-   c                n     | d          }t          fd|D                       |_        h|_        |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 : hashable
            The property key.

        itr : iterable
            Finite length iterable of the property values.

        Returns
        -------
        `Cycler`
            New 'base' cycler.
        Nc              3      K   | ]}|iV  	d S r4   rI   )r7   rK   r`   s     r*   r;   z$Cycler._from_iter.<locals>.<genexpr>   s'      11%111111r,   )listrN   rQ   )clsr`   ra   rets    `  r*   
_from_iterzCycler._from_iter   sD    (  CII1111S11111	G	
r,   keyslicec                    t          t                    rG|                                 }t          t          fd|                                D                       S t          d          )Nc              3  J   K   | ]\  }}t          ||                   V  d S r4   r5   )r7   r8   rK   ri   s      r*   r;   z%Cycler.__getitem__.<locals>.<genexpr>   s5      MMtq!1S6 2 2MMMMMMr,   z+Can only use slices with Cycler.__getitem__)rM   rj   r=   r   r   itemsr%   )rC   ri   transs    ` r*   __getitem__zCycler.__getitem__   s_    c5!! 	LKKMME#MMMMu{{}}MMMNNNJKKKr,   !Generator[dict[K, V], None, None]c              #  *  K   | j         | j        D ]}t          |          V  d S | j        t	          d          |                     | j        | j                   D ]5\  }}i }|                    |           |                    |           |V  6d S )Nz=Operation cannot be None when both left and right are defined)rO   rN   dictrP   	TypeErrorupdate)rC   r   abouts        r*   __iter__zCycler.__iter__  s      ;
 ! !4jj    ! ! xS   T[99  1

1

1					 r,   otherCycler[L, U]Cycler[K | L, V | U]c           
        t          |           t          |          k    r/t          dt          |            dt          |                     t          t          t          t          t
          t          f         t          t          t          f         f         |           t          t          t          t
          t          f         t          t          t          f         f         |          t                    S )z
        Pair-wise combine two equal length cyclers (zip).

        Parameters
        ----------
        other : Cycler
        z&Can only add equal length cycles, not z and )
lenr%   r@   r   r   r   r   r   r   ziprC   ry   s     r*   __add__zCycler.__add__  s     t99E

""UTUUUUU   adU1a4[01488adU1a4[01599
 
 	
r,   c                    d S r4   rI   r   s     r*   __mul__zCycler.__mul__$      r,   intc                    d S r4   rI   r   s     r*   r   zCycler.__mul__(  r   r,   c           
     D   t          t                    rt          t          t          t          t          t
          f         t          t          t          f         f         |           t          t          t          t          t
          f         t          t          t          f         f                   t                    S t          t                    rG| 
                                }t          t          fd|                                D                       S t          S )z
        Outer product of two cyclers (`itertools.product`) or integer
        multiplication.

        Parameters
        ----------
        other : Cycler or int
        c              3  D   K   | ]\  }}t          ||z            V  d S r4   r5   )r7   r8   rK   ry   s      r*   r;   z!Cycler.__mul__.<locals>.<genexpr>>  s5      FF1gaU++FFFFFFr,   )rM   r@   r   r   r   r   r   r   r   r   r=   r   r   rm   NotImplemented)rC   ry   rn   s    ` r*   r   zCycler.__mul__,  s     eV$$ 	"VE!Q$Kq!t45t<<VE!Q$Kq!t45u==  
 s## 	"KKMMEFFFFFFF   "!r,   c                    d S r4   rI   r   s     r*   __rmul__zCycler.__rmul__C  r   r,   c                    d S r4   rI   r   s     r*   r   zCycler.__rmul__G  r   r,   c                    | |z  S r4   rI   r   s     r*   r   zCycler.__rmul__K  s    e|r,   c                    t           t          t          t          i}| j        t          | j                  S t          | j                  }t          | j                  } || j                 ||          S r4   )r~   minr   r
   rO   r}   rN   rP   )rC   op_dictl_lenr_lens       r*   __len__zCycler.__len__N  s\    >A3QT=U;tz??"DJDK   wtx ...r,   c                   t          |t                    st          d          t          j        |           }t	          ||          | _        || _        t          | _        t          |j        |j	        |j                  | _	        | S )z
        In-place pair-wise combine two equal length cyclers (zip).

        Parameters
        ----------
        other : Cycler
        z"Cannot += with a non-Cycler object)
rM   r@   rs   rJ   r+   rQ   rN   r~   rP   rO   rC   ry   old_selfs      r*   __iadd__zCycler.__iadd__X  sp     %(( 	B@AAA9T??"8U33

U[%,	BBr,   Cycler[K, V] | intc                   t          |t                    st          d          t          j        |           }t	          ||          | _        || _        t          | _        t          |j        |j	        |j                  | _	        | S )z
        In-place outer product of two cyclers (`itertools.product`).

        Parameters
        ----------
        other : Cycler
        z"Cannot *= with a non-Cycler object)
rM   r@   rs   rJ   r+   rQ   rN   r   rP   rO   r   s      r*   __imul__zCycler.__imul__j  sp     %(( 	B@AAA9T??"8U33

U[%,	BBr,   objectboolc                    t          |t                    sdS t          |           t          |          k    rdS | j        |j        z  rdS t	          d t          | |          D                       S )NFc              3  (   K   | ]\  }}||k    V  d S r4   rI   )r7   ru   rv   s      r*   r;   z Cycler.__eq__.<locals>.<genexpr>  s*      77da16777777r,   )rM   r@   r}   r$   allr~   r   s     r*   __eq__zCycler.__eq__|  sr    %(( 	5t99E

""59uz! 	577c$&6&6777777r,   strc                *   t           dt          di}| j        =| j                                        t          fd| D                       }dd|dS |                    | j        d          }d}|                    | j	        || j        	          S )
N+*c              3  (   K   | ]}|         V  d S r4   rI   r7   rK   labs     r*   r;   z"Cycler.__repr__.<locals>.<genexpr>  s'      ,,!qv,,,,,,r,   zcycler(rZ   )?z({left!r} {op} {right!r}))r   rF   r   )
r~   r   rO   r$   popre   getrP   r<   rN   )rC   op_mapra   rF   msgr   s        @r*   __repr__zCycler.__repr__  s    sGS);)--//C,,,,t,,,,,C.S..c....DHc**B-C::4:"DK:HHHr,   c                    d}t          | j        t                    }|D ]}|d|dz  }t          |           D ] }|dz  }|D ]}|d||         dz  }|dz  }!|d	z  }|S )
Nz<table>)ri   z<th>z</th>z<tr>z<td>z</td>z</tr>z</table>)sortedr$   reprr"   )rC   outputsorted_keysri   dr8   s         r*   _repr_html_zCycler._repr_html_  s    TYD111 	* 	*C)S))))FFd 	 	AfF  / /.1....gFF*r,   dict[K, list[V]]c                    | j         }d |D             }| D ](}|D ]#}||                             ||                    $)|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.
        c                ,    i | ]}|t                      S rI   )re   )r7   r8   s     r*   
<dictcomp>z!Cycler.by_key.<locals>.<dictcomp>  s     9 9 9qDFF 9 9 9r,   )r$   append)rC   r$   rw   r   r8   s        r*   r=   zCycler.by_key  sc    * y 9 9D 9 9 9 	$ 	$A $ $Aad####$
r,   c                    |                                  }t          t          d |                                D                       S )z
        Simplify the cycler into a sum (but no products) of cyclers.

        Returns
        -------
        simple : Cycler
        c              3  <   K   | ]\  }}t          ||          V  d S r4   r5   r7   r8   rK   s      r*   r;   z"Cycler.simplify.<locals>.<genexpr>  s.      DDdaGAqMMDDDDDDr,   )r=   r   r   rm   )rC   rn   s     r*   simplifyzCycler.simplify  s8     cDDekkmmDDDEEEr,   )NN)r   r   r   rE   rF   r   )r   r   )rV   r   rW   r   r   rX   r`   r   ra   rb   r   r-   )ri   rj   r   r-   )r   rp   )ry   rz   r   r{   )ry   r   r   r-   )r   r   )ry   r-   r   r-   )ry   r   r   r-   )ry   r   r   r   )r   r   )r   r   )r   r-   )__name__
__module____qualname____doc__rD   rR   rT   propertyr$   r_   classmethodrh   ro   rx   r   r   r   r   r   r   r   r   __hash__r   r   r=   
_transposer   r>   rI   r,   r*   r@   r@   w   sL        6   &*	    @      X"E "E "E "EH    [0L L L L   
 
 
 
$    X    X" " ".    X    X  / / / /   $   $8 8 8 8 H	I 	I 	I 	I      < JF F F F  FFFr,   r@   argc                    d S r4   rI   )r   s    r*   cyclerr         Cr,   kwargsrb   Cycler[str, V]c                     d S r4   rI   )r   s    r*   r   r     r   r,   r`   ra   c                    d S r4   rI   )r`   ra   s     r*   r   r     r   r,   c                    | r|rt          d          t          |           dk    r?t          | d         t                    st          d          t          | d                   S t          |           dk    r	t	          |  S t          |           dk    rt          d          |r1t          t          d |                                D                       S t          d          )	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

    zEcycler() can only accept positional OR keyword arguments -- not both.   r   zDIf 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.c              3  <   K   | ]\  }}t          ||          V  d S r4   r5   r   s      r*   r;   zcycler.<locals>.<genexpr>  s.      EEdaGAqMMEEEEEEr,   z4Must have at least a positional OR keyword arguments)rs   r}   rM   r@   r6   r   r   rm   )argsr   s     r*   r   r     s    L  
 
S
 
 	
 4yyA~~$q'6** 	(   d1g	Ta~	TQB
 
 	

  GcEEfllnnEEEFFF
J
K
KKr,   c                    t          |t                    rM|j        }t          |          dk    rd}t	          |          |                                fd|D             }t                              | |          S )aD  
    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
    r   z2Can not create Cycler from a multi-property Cyclerc              3  (   K   | ]}|         V  d S r4   rI   r   s     r*   r;   z_cycler.<locals>.<genexpr>;  s'      ##!qv######r,   )rM   r@   r$   r}   r%   r   rh   )r`   ra   r$   r   r   s       @r*   r6   r6   "  s|      #v 	$xt99>>FCS//!hhjj $###s###UC(((r,   )r   r   r   r   r   r   )r   r-   r   r.   r   r/   )r   r-   r   r-   )r   rb   r   r   r   )$r   
__future__r   collections.abcr   r   r   rJ   	functoolsr   	itertoolsr   r	   operatorr
   r   typingr   r   r   r   r   r   r   r   r   __version__r   r   r   r   r+   r>   r@   r   r6   rI   r,   r*   <module>r      s  ( (V # " " " " " 9 9 9 9 9 9 9 9 9 9        $ $ $ $ $ $ $ $         U U U U U U U U U U U U U U U U U U U U U UGCx   GCx   GCLLGCLL   4G G G G>Y Y Y Y YWQT] Y Y Yx
 
   
 
   
 
   
=L =L =L@) ) ) ) ) )r,   