o
    h                     @   s   d dl mZ d dlmZ d dlmZmZmZmZm	Z	 G dd de	Z
dedee
 dee fd	d
Zdedee dee dee dee f
ddZ	ddedee deee  dee fddZedkrd dlmZ eG dd dZededddedddedddgZeee dS dS )    )Fraction)ceil)castListOptionalSequenceProtocolc                   @   s:   e Zd ZU dZdZee ed< dZeed< dZ	eed< dS )Edgez1Any object that defines an edge (such as Layout).Nsize   ratiominimum_size)
__name__
__module____qualname____doc__r
   r   int__annotations__r   r    r   r   J/var/www/html/venv/lib/python3.10/site-packages/pip/_vendor/rich/_ratio.pyr	      s
   
 r	   totaledgesreturnc                 C   s   dd |D }t }d|v rtdd tt||D }| tdd |D  }|dkr2dd t||D S ||td	d |D }|D ]\}}||j |jkrS|j||<  nq@|d}	|D ]\}}t||j |	 d
\}
}	|
||< qZnd|v sttt	 |S )a  Divide total space to satisfy size, ratio, and minimum_size, constraints.

    The returned list of integers should add up to total in most cases, unless it is
    impossible to satisfy all the constraints. For instance, if there are two edges
    with a minimum size of 20 each and `total` is 30 then the returned list will be
    greater than total. In practice, this would mean that a Layout object would
    clip the rows that would overflow the screen height.

    Args:
        total (int): Total number of characters.
        edges (List[Edge]): Edges within total space.

    Returns:
        List[int]: Number of characters for each edge.
    c                 S   s   g | ]}|j pd qS N)r
   ).0edger   r   r   
<listcomp>   s    z!ratio_resolve.<locals>.<listcomp>Nc                 S   s$   g | ]\}\}}|d u r||fqS r   r   )r   indexr
   r   r   r   r   r   &   s
    
c                 s   s    | ]}|pd V  qdS )r   Nr   )r   r
   r   r   r   	<genexpr>,   s    z ratio_resolve.<locals>.<genexpr>r   c                 S   s&   g | ]\}}|d u r|j pdn|qS )Nr   )r   )r   r
   r   r   r   r   r   /   s     c                 s   s    | ]
\}}|j p
d V  qdS )r   N)r   )r   _r   r   r   r   r   5   s    r   )
r   	enumeratezipsumr   r   divmodr   r   r   )r   r   sizes	_Fractionflexible_edges	remainingportionr   r   	remainderr
   r   r   r   ratio_resolve   s4   

$r*   ratiosmaximumsvaluesc                 C   s   dd t ||D }t|}|s|dd S | }g }|j}t |||D ])\}}	}
|rH|dkrHt|	t|| | }||
|  ||8 }||8 }q#||
 q#|S )ad  Divide an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        maximums (List[int]): List of maximums values for each slot.
        values (List[int]): List of values

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    c                 S      g | ]
\}}|r
|nd qS r   r   )r   r   _maxr   r   r   r   Y       z ratio_reduce.<locals>.<listcomp>Nr   )r!   r"   appendminround)r   r+   r,   r-   total_ratiototal_remainingresultr2   r   maximumvaluedistributedr   r   r   ratio_reduceK   s   

r;   Nminimumsc                 C   s   |rdd t ||D }t|}|dksJ d| }g }|j}|du r+dgt| }n|}t ||D ]"\}}	|dkrFt|	t|| | }
n|}
||
 ||8 }||
8 }q2|S )a<  Distribute an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        minimums (List[int]): List of minimum values for each slot.

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    c                 S   r.   r/   r   )r   r   _minr   r   r   r   y   r1   z$ratio_distribute.<locals>.<listcomp>r   zSum of ratios must be > 0N)r!   r"   r2   lenmaxr   )r   r+   r<   r5   r6   distributed_totalr2   	_minimumsr   minimumr:   r   r   r   ratio_distributek   s$   
rC   __main__)	dataclassc                   @   s6   e Zd ZU dZee ed< dZeed< dZeed< dS )ENr
   r   r   r   )	r   r   r   r
   r   r   r   r   r   r   r   r   r   rF      s   
 rF   n   r   r   )	fractionsr   mathr   typingr   r   r   r   r   r	   r   r*   r;   rC   r   dataclassesrE   rF   resolvedprintr"   r   r   r   r   <module>   sB    =
!

$(