U
    „}ag`  ã                   @   s2  d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 e j
dkrPd dlmZ nd dlmZ G dd„ deƒZee	e ee d	œd
d„Zeee ee ee ee dœdd„Zdeee eee  ee dœdd„Zedk�r.d 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 )é    N)Ú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   úO/var/www/html/publicvenv/lib/python3.8/site-packages/pip/_vendor/rich/_ratio.pyr      s   
r   )ÚtotalÚedgesÚreturnc                 C   sð   dd„ |D ƒ}t }d|krâdd„ tt||ƒƒD ƒ}| tdd„ |D ƒƒ }|dkrddd„ t||ƒD ƒS ||td	d„ |D ƒƒƒ}|D ]&\}}||j |jkr€|j||<  qq€|dƒ}	|D ](\}}t||j |	 d
ƒ\}
}	|
||< q´qâq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 k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>2   s     z ratio_resolve.<locals>.<genexpr>r   c                 S   s&   g | ]\}}|d kr|j p dn|‘qS )Nr   )r   )r   r   r   r   r   r   r   5   s   ÿc                 s   s   | ]\}}|j pd V  qdS )r   N)r   )r   Ú_r   r   r   r   r    ;   s     r   )
r   Ú	enumerateÚzipÚsumr   r   Údivmodr   r   r   )r   r   ZsizesZ	_FractionZflexible_edgesÚ	remainingZportionr   r   Ú	remainderr   r   r   r   Úratio_resolve   s2    þþ ÿ

r(   )r   ÚratiosÚmaximumsÚvaluesr   c                 C   sž   dd„ t ||ƒD ƒ}t|ƒ}|s,|dd… S | }g }|j}t |||ƒD ]R\}}	}
|r�|dkr�t|	t|| | ƒƒ}||
| ƒ ||8 }||8 }qF||
ƒ qF|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   s   g | ]\}}|r|nd ‘qS ©r   r   )r   r   Ú_maxr   r   r   r   _   s     z ratio_reduce.<locals>.<listcomp>Nr   )r#   r$   ÚappendÚminÚround)r   r)   r*   r+   Útotal_ratioÚtotal_remainingÚresultr.   r   ÚmaximumÚvalueÚdistributedr   r   r   Úratio_reduceQ   s    

r7   )r   r)   Úminimumsr   c                 C   s®   |rdd„ t ||ƒD ƒ}t|ƒ}|dks0tdƒ‚| }g }|j}|dkrVdgt|ƒ }n|}t ||ƒD ]D\}}	|dkrŒt|	t|| | ƒƒ}
n|}
||
ƒ ||8 }||
8 }qd|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   s   g | ]\}}|r|nd ‘qS r,   r   )r   r   Ú_minr   r   r   r      s     z$ratio_distribute.<locals>.<listcomp>r   zSum of ratios must be > 0N)r#   r$   ÚAssertionErrorr.   ÚlenÚmaxr   )r   r)   r8   r1   r2   Zdistributed_totalr.   Z	_minimumsr   Úminimumr6   r   r   r   Úratio_distributeq   s$    
r>   Ú__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   rA   ˜   s   
rA   én   r   )N)ÚsysZ	fractionsr   Úmathr   Útypingr   r   r   r   Úversion_infor
   Úpip._vendor.typing_extensionsr   r   r(   r7   r>   r   Údataclassesr@   rA   ZresolvedÚprintr$   r   r   r   r   Ú<module>   s6   
>   þ! ÿ  
þ$
(