X wKg ddlmZddlmZddlmZmZmZmZm Z Gdde Z de dee dee fd Z de d ee d ee d ee dee f d Z dde d ee deee dee fdZedkraddlmZeGddZe dedddedddedddgZeeedSdS))Fraction)ceil)castListOptionalSequenceProtocolcJeZdZUdZdZeeed<dZeed<dZ eed<dS)Edgez1Any object that defines an edge (such as Layout).Nsizeratio minimum_size) __name__ __module__ __qualname____doc__r rint__annotations__rrw/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/rich/_ratio.pyr r sI;;D(3-E3NNNL#rr totaledgesreturnc@d|D}t}d|vrdtt||D}|td|Dz }|dkrdt||DS||td|D}|D]$\}}||jz|jkr |j||<n8%|d} |D](\}}t ||jz| zd\} } | ||<)nd|vttt|S) aDivide 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 g|] }|jpd SN)r ).0edges r z!ratio_resolve..s 3 3 3Tdi4 3 3 3rNc&g|]\}\}}| ||fSrr)rindexr r s rr!z!ratio_resolve..&s1   #|d|DM||rc3K|]}|pdV dS)rNr)rr s r z ratio_resolve..,s&<./s;D$.2\$#(qtrc3.K|]\}}|jpdVdS)r N)r)r_r s rr%z ratio_resolve..5s,KKDDJO!KKKKKKrr ) r enumeratezipsumrrdivmodrrr) rrsizes _Fractionflexible_edges remainingportionr#r remainderr s r ratio_resolver3s" 4 3U 3 3 3EI %--  '0UE1B1B'C'C    C<>"%eU"3"3  ) sKKNKKKKK   *  KE4#t'888#0e 9" ! I- $ $ t"(4:)= )I1"M"Mi#e E %--H S 5 ! !!rratiosmaximumsvaluescTdt||D}t|}|s |ddS|}g}|j}t|||D]U\}} } |rB|dkr.Ys% L L L{udt"ee L L LrNr)r*r+appendminround) rr4r5r6 total_ratiototal_remainingresultr;rmaximumvalue distributeds r ratio_reducerDKsM Lc&(6K6K L L LFf++K aaayOF ]F!$VXv!>!>w  [1__guU_-D{-R'S'STTK F5;& ' ' ' { *O 5 KK F5MMMM MrNminimumscp|rdt||D}t|}|dks Jd|}g}|j}|dgt|z}n|}t||D]F\}} |dkr$t | t ||z|z } n|} || ||z}|| z}G|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 g|] \}}|r|nd Sr9r)rr_mins rr!z$ratio_distribute..ys%PPP;5$4&%%QPPPrrzSum of ratios must be > 0)r*r+r;lenmaxr) rr4rEr>r?distributed_totalr; _minimumsrminimumrCs rratio_distributerNksQPP#fh:O:OPPPf++K ???7???O#%  %FC#f++%  fi00''w ??gtEO,Ck,Q'R'RSSKK)K{u ;& r__main__) dataclasscFeZdZUdZeeed<dZeed<dZeed<dS)ENr r rr) rrrr rrrrrrrrrRrRsC"hsm"""s crrRnr r) fractionsrmathrtypingrrrrr r rr3rDrNr dataclassesrPrRresolvedprintr+rrrrZs;;;;;;;;;;;;;;8:":"Xd^:"S :":":":"z S -1#Y@DS  #YBDH!! !S !-5d3i-@! #Y!!!!H z%%%%%%Y }S11T1a==!!D!Q--4A"OPPH E##h--r