o
    hEA                     @  s  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dZededZedZedZd+ddZd,ddZ G dd deeef Z!ed-dd Z"ed.d$d Z"ed/d'd Z"d(d  Z"d/d)d*Z#dS )0a  
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                 C  s`   | g kr
t t| ni }|durt t|ni }t| }t| }||@ r,td||B 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_key r(   c/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/cycler/__init__.py_process_keys>   s   r*   Cycler[K, V]Cycler[K, U]Cycler[K, V | U]c                   s   | j |j krtdj| j |j @ | j |j A dttttttt	f  f | 
  ttttttt	f  f |
 tt fd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  s&    | ]}t | | |  V  qd S N_cycler.0k_l_rr(   r)   	<genexpr>t   s   $ zconcat.<locals>.<genexpr>)r"   r#   formatr   r   r   r   r   r   r   by_keyr   r
   )r   r   r(   r6   r)   concatX   s   ""r<   c                   @  s  e Zd ZdZdd Z		dIdJddZdd ZedKddZdLddZ	e
dMddZdNd!d"ZdOd$d%ZdPd)d*ZedPd+d,ZedQd.d,Zd/d, ZedPd0d1ZedQd2d1Zd3d1 ZdRd4d5ZdSd6d7ZdTd9d:ZdUd=d>ZdZdVd@dAZdVdBdCZdWdEdFZeZdXdGdHZeZdS )Y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                 C  s   t | S r0   )r   selfr(   r(   r)   __call__      zCycler.__call__Nr   r   r   Cycler[K, V] | Noneopr   c                 C  s   t |trt|j|j|j| _n|durdd |D | _ng | _t |tr0t|j|j|j| _nd| _t| j| j| _|| _dS )zf
        Semi-private init.

        Do not use this directly, use `cycler` function instead.
        Nc                 S  s   g | ]}t  |qS r(   )copyr4   vr(   r(   r)   
<listcomp>   s    z#Cycler.__init__.<locals>.<listcomp>)
isinstancer=   _left_right_opr*   _keys)r?   r   r   rC   r(   r(   r)   __init__   s   


zCycler.__init__c                 C  s
   || j v S r0   )rL   )r?   r5   r(   r(   r)   __contains__   s   
zCycler.__contains__r   r   c                 C  s
   t | jS )z!The keys this Cycler knows about.)r!   rL   r>   r(   r(   r)   r"      s   
zCycler.keysoldr   newNonec                   s    krdS  | j v rtd d  d  d| j vr,td d  d d| j  | j   | jdurL| jjv rL| j  dS t| j	t
r[| j	  dS  fd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                   s   g | ]} | iqS r(   r(   )r4   entryrP   rO   r(   r)   rG      s    z%Cycler.change_key.<locals>.<listcomp>)rL   r#   KeyErrorremover
   rJ   r"   
change_keyrH   rI   r=   )r?   rO   rP   r(   rT   r)   rW      s"   	

zCycler.change_keylabelitrIterable[V]r+   c                   s,   | d}t  fd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  s    | ]} |iV  qd S r0   r(   rE   rX   r(   r)   r9          z$Cycler._from_iter.<locals>.<genexpr>)listrI   rL   )clsrX   rY   retr(   r[   r)   
_from_iter   s   zCycler._from_iterkeyslicec                   s6   t  tr|  }tt fdd| D S td)Nc                 3  s"    | ]\}}t ||  V  qd S r0   r1   r4   r5   rF   ra   r(   r)   r9           z%Cycler.__getitem__.<locals>.<genexpr>z+Can only use slices with Cycler.__getitem__)rH   rb   r;   r   r
   itemsr#   )r?   ra   transr(   rd   r)   __getitem__   s   
zCycler.__getitem__!Generator[dict[K, V], None, None]c                 c  st    | j d u r| jD ]}t|V  q	d S | jd u rtd| | j| j D ]\}}i }|| || |V  q$d S )Nz=Operation cannot be None when both left and right are defined)rJ   rI   dictrK   	TypeErrorupdate)r?   r   aboutr(   r(   r)   __iter__  s   




zCycler.__iter__otherCycler[L, U]Cycler[K | L, V | U]c                 C  st   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r?   rq   r(   r(   r)   __add__  s     zCycler.__add__c                 C     d S r0   r(   rv   r(   r(   r)   __mul__$     zCycler.__mul__intc                 C  rx   r0   r(   rv   r(   r(   r)   ry   (  rz   c                   s   t  tr)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 t  t	r@| 
 }tt fdd| D S tS )z
        Outer product of two cyclers (`itertools.product`) or integer
        multiplication.

        Parameters
        ----------
        other : Cycler or int
        c                 3  s"    | ]\}}t ||  V  qd S r0   r1   rc   rq   r(   r)   r9   >  re   z!Cycler.__mul__.<locals>.<genexpr>)rH   r=   r   r   r   r   r   r   r   r{   r;   r   r
   rf   NotImplemented)r?   rq   rg   r(   r|   r)   ry   ,  s   
	  
c                 C  rx   r0   r(   rv   r(   r(   r)   __rmul__C  rz   zCycler.__rmul__c                 C  rx   r0   r(   rv   r(   r(   r)   r~   G  rz   c                 C  s   | | S r0   r(   rv   r(   r(   r)   r~   K  rA   c                 C  sD   t ttti}| jd u rt| jS t| j}t| j}|| j ||S r0   )ru   minr   r	   rJ   rt   rI   rK   )r?   op_dictl_lenr_lenr(   r(   r)   __len__N  s   



zCycler.__len__c                 C  L   t |ts	tdt| }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)
rH   r=   rk   rD   r*   rL   rI   ru   rK   rJ   r?   rq   old_selfr(   r(   r)   __iadd__X     

zCycler.__iadd__Cycler[K, V] | intc                 C  r   )z
        In-place outer product of two cyclers (`itertools.product`).

        Parameters
        ----------
        other : Cycler
        z"Cannot *= with a non-Cycler object)
rH   r=   rk   rD   r*   rL   rI   r   rK   rJ   r   r(   r(   r)   __imul__j  r   zCycler.__imul__objectboolc                 C  sJ   t |tsdS t| t|krdS | j|jA rdS tdd t| |D S )NFc                 s  s    | ]	\}}||kV  qd S r0   r(   )r4   rm   rn   r(   r(   r)   r9     s    z Cycler.__eq__.<locals>.<genexpr>)rH   r=   rt   r"   allru   rv   r(   r(   r)   __eq__|  s   
zCycler.__eq__strc                   sn   t dtdi}| jd u r$| j  t fdd| D }d d|dS || jd}d	}|j| j	|| jd
S )N+*c                 3      | ]}|  V  qd S r0   r(   rE   labr(   r)   r9     r\   z"Cycler.__repr__.<locals>.<genexpr>zcycler(rR   )?z({left!r} {op} {right!r}))r   rC   r   )
ru   r   rJ   r"   popr]   getrK   r:   rI   )r?   op_maprY   rC   msgr(   r   r)   __repr__  s   

zCycler.__repr__c                 C  st   d}t | jtd}|D ]
}|d|d7 }qt| D ]}|d7 }|D ]}|d|| d7 }q"|d7 }q|d	7 }|S )
Nz<table>rd   z<th>z</th>z<tr>z<td>z</td>z</tr>z</table>)sortedr"   reprr    )r?   outputsorted_keysra   dr5   r(   r(   r)   _repr_html_  s   
zCycler._repr_html_dict[K, list[V]]c                 C  s>   | j }dd |D }| D ]}|D ]}|| ||  qq|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                 S  s   i | ]}|t  qS r(   )r]   r3   r(   r(   r)   
<dictcomp>  s    z!Cycler.by_key.<locals>.<dictcomp>)r"   append)r?   r"   ro   r   r5   r(   r(   r)   r;     s   zCycler.by_keyc                 C  s    |   }ttdd | D S )z
        Simplify the cycler into a sum (but no products) of cyclers.

        Returns
        -------
        simple : Cycler
        c                 s      | ]
\}}t ||V  qd S r0   r1   rc   r(   r(   r)   r9         z"Cycler.simplify.<locals>.<genexpr>)r;   r   r
   rf   )r?   rg   r(   r(   r)   simplify  s   zCycler.simplify)NN)r   r   r   rB   rC   r   )r   r   )rO   r   rP   r   r   rQ   rX   r   rY   rZ   r   r+   )ra   rb   r   r+   )r   ri   )rq   rr   r   rs   )rq   r{   r   r+   )r   r{   )rq   r+   r   r+   )rq   r   r   r+   )rq   r   r   r   )r   r   )r   r   )r   r+   )__name__
__module____qualname____doc__r@   rM   rN   propertyr"   rW   classmethodr`   rh   rp   rw   r   ry   r~   r   r   r   r   __hash__r   r   r;   
_transposer   r<   r(   r(   r(   r)   r=   w   sH     
$







	



r=   argc                 C  rx   r0   r(   )r   r(   r(   r)   cycler  rz   r   kwargsrZ   Cycler[str, V]c                  K  rx   r0   r(   )r   r(   r(   r)   r     rz   rX   rY   c                 C  rx   r0   r(   )rX   rY   r(   r(   r)   r     rz   c                  O  s   | 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r3t d|rAttd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                 s  r   r0   r1   rc   r(   r(   r)   r9     r   zcycler.<locals>.<genexpr>z4Must have at least a positional OR keyword arguments)rk   rt   rH   r=   r2   r   r
   rf   )argsr   r(   r(   r)   r     s&   &c                   sN   t |tr!|j}t|dkrd}t||   fd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  r   r0   r(   rE   r   r(   r)   r9   ;  r\   z_cycler.<locals>.<genexpr>)rH   r=   r"   rt   r#   r   r`   )rX   rY   r"   r   r(   r   r)   r2   "  s   
r2   )r   r   r   r   r   r   )r   r+   r   r,   r   r-   )r   r+   r   r+   )r   rZ   r   r   r   )$r   
__future__r   collections.abcr   r   r   rD   	functoolsr   	itertoolsr   r   operatorr	   r
   typingr   r   r   r   r   r   r   r   r   __version__r   r   r   r   r*   r<   r=   r   r2   r(   r(   r(   r)   <module>   s4    +,

  ^@