
    Zi>                     D    d dl mZmZ ddddddddd	d
d
Zd ZddefdZdS )    )DecimalInvalidOperation                  )
numKkMGTPEc                    t          | t          t          t          f          rt          |           S t	          |           } | }d}t          |           dk    r0| d         dk    r$| d         t          v r| dd         }| dd         }n6t          |           dk    r#| d         t          v r| dd         }| dd         }	 t          |          }n0# t          $ r# t          d	                    |                    w xY w||S |
                    d          rd}n8t          |          dk    rd	}n"t          d
	                    |                     |dk    r"t          d
	                    |                     |d         t          vr"t          d
	                    |                     t          t          |d                            }|||z  z  S )a  
    Parse kubernetes canonical form quantity like 200Mi to a decimal number.
    Supported SI suffixes:
    base1024: Ki | Mi | Gi | Ti | Pi | Ei
    base1000: n | u | m | "" | k | M | G | T | P | E

    See https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go

    Input:
    quantity: string. kubernetes canonical form quantity

    Returns:
    Decimal

    Raises:
    ValueError on invalid or unknown input
    Nr	   r   ir   r   zInvalid number format: {}     z{} has unknown suffixkir   )
isinstanceintfloatr   strlen
_EXPONENTSr   
ValueErrorformatendswith)quantitynumbersuffixbaseexponents        T/root/projects/butler/venv/lib/python3.11/site-packages/kubernetes/utils/quantity.pyparse_quantityr,      s   $ (S%122 !x   8}}HFF
8}}hrlc11B<:%%crc]Fbcc]F	X!		
 : :#2#"##E E E E4;;FCCDDDE ~s C	V		077AABBB ~~077AABBBay
""077AABBBz&),--HTX%&&s   ?C -C<Nreturnc                    |st          |           S |                    d          rd}n(t          |          dk    rd}nt          |  d          |dk    rt          |  d          |d         t          vrt          |  d          | t          |t          |d                  z            z  }|r|                    |          }t          |          |z   S )a@  
    Takes a decimal and produces a string value in kubernetes' canonical quantity form,
    like "200Mi".Users can specify an additional decimal number to quantize the output.

    Example -  Relatively increase pod memory limits:

    # retrieve my_pod
    current_memory: Decimal = parse_quantity(my_pod.spec.containers[0].resources.limits.memory)
    desired_memory = current_memory * 1.2
    desired_memory_str = format_quantity(desired_memory, suffix="Gi", quantize=Decimal(1))
    # patch pod with desired_memory_str

    'quantize=Decimal(1)' ensures that the result does not contain any fractional digits.

    Supported SI suffixes:
    base1024: Ki | Mi | Gi | Ti | Pi | Ei
    base1000: n | u | m | "" | k | M | G | T | P | E

    See https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go

    Input:
    quantity: Decimal.  Quantity as a number which is supposed to converted to a string
                        with SI suffix.
    suffix: string.     The desired suffix/unit-of-measure of the output string
    quantize: Decimal.  Can be used to round/quantize the value before the string
                        is returned. Defaults to None.

    Returns:
    string. Canonical Kubernetes quantity string containing the SI suffix.

    Raises:
    ValueError if the SI suffix is not supported.
    r   r   r   r   z has unknown suffixr   r   )r    r%   r!   r#   r"   r   quantize)quantity_valuer(   r/   r)   different_scales        r+   format_quantityr2   X   s    F  #>"""s A	V		N???@@@~~N???@@@ay
""N???@@@$wtz&)7L/L'M'MMO =)228<<&((    )N)decimalr   r   r"   r,   r    r2    r3   r+   <module>r6      s    . - - - - - - - 
			
	
	
	
	
	
	
 
7' 7' 7't6) 6)c 6) 6) 6) 6) 6) 6)r3   