HEX
Server: nginx/1.28.0
System: Linux server-one 5.15.0-153-generic #163-Ubuntu SMP Thu Aug 7 16:37:18 UTC 2025 x86_64
User: root (0)
PHP: 8.3.23
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/rich/__pycache__/_ratio.cpython-310.pyc
o

.��fS�@sHddlZddlmZddlmZddlmZmZmZm	Z	ej
dkr(ddlmZnddlmZGdd�de�Z
d	ed
e	e
deefdd
�Zd	edeedeedeedeef
dd�Z	dd	edeedeeedeefdd�Zedkr�ddlmZeGdd�d��Zededdd�eddd�eddd�g�Zeee��dSdS)�N)�Fraction)�ceil)�cast�List�Optional�Sequence)��)�Protocolc@s:eZdZUdZdZeeed<dZeed<dZ	eed<dS)�Edgez1Any object that defines an edge (such as Layout).N�size��ratio�minimum_size)
�__name__�
__module__�__qualname__�__doc__rr�int�__annotations__rr�rr�6/usr/local/lib/python3.10/dist-packages/rich/_ratio.pyrs

r�total�edges�returncCs�dd�|D�}t}d|vrtdd�tt||��D�}|tdd�|D��}|dkr2dd�t||�D�S||td	d�|D���}|D]\}}||j|jkrS|j||<nq@|d�}	|D]\}}t||j|	d
�\}
}	|
||<qZnd|vs
ttt	|�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.
    cSsg|]}|jpd�qS�N)r)�.0�edgerrr�
<listcomp>%sz!ratio_resolve.<locals>.<listcomp>NcSs$g|]\}\}}|dur||f�qSrr)r�indexrrrrrr,s

�css�|]}|pdVqdS)rNr)rrrrr�	<genexpr>2s�z ratio_resolve.<locals>.<genexpr>rcSs&g|]\}}|dur|jpdn|�qS)Nr
)r)rrrrrrr5s���css�|]
\}}|jp
dVqdS)r
N)r)r�_rrrrr ;s�r
)
r�	enumerate�zip�sumrr�divmodrrr)rr�sizes�	_Fraction�flexible_edges�	remaining�portionrr�	remainderrrrr�
ratio_resolves4���
�
�$r,�ratios�maximums�valuescCs�dd�t||�D�}t|�}|s|dd�S|}g}|j}t|||�D])\}}	}
|rH|dkrHt|	t|||��}||
|�||8}||8}q#||
�q#|S)adDivide 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.
    cS�g|]
\}}|r
|nd�qS�rr)rr�_maxrrrr_�z ratio_reduce.<locals>.<listcomp>Nr)r#r$�append�min�round)rr-r.r/�total_ratio�total_remaining�resultr4r�maximum�value�distributedrrr�ratio_reduceQs

r=�minimumscCs�|rdd�t||�D�}t|�}|dksJd��|}g}|j}|dur+dgt|�}n|}t||�D]"\}}	|dkrFt|	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.
    cSr0r1r)rr�_minrrrrr3z$ratio_distribute.<locals>.<listcomp>rzSum of ratios must be > 0N)r#r$r4�len�maxr)rr-r>r7r8�distributed_totalr4�	_minimumsr�minimumr<rrr�ratio_distributeqs$

rE�__main__)�	dataclassc@s6eZdZUdZeeed<dZeed<dZeed<dS)�ENrr
rr)	rrrrrrrrrrrrrrH�s
rH�nr
r)�sys�	fractionsr�mathr�typingrrrr�version_infor
�typing_extensionsrrr,r=rEr�dataclassesrGrH�resolved�printr$rrrr�<module>sJ
=����
�!���
�
�$(�