
    &`i%                     t   d dl Z d dlZd dlmZmZmZmZmZ dedee         fdZ	dedee
         dee
         fdZ ed	          Zh d
ZdeddfdZ	 	 ddedee         dee         deeegef                  dee         dee         fdZdedee         dee         fdZdedee         dee         fdZdedee         dee         fdZdedee
         dee
         fdZdedee
         dee
         fdZdedee
         dee
         fdZdedee         dee         fdZdededefdZdeddfdZdS )    N)CallableListOptionalTypeTypeVarsreturnc                 T    d d |                      d          D             D             S )z`Return a list from a comma-separated string.

    Trims whitespace and skips empty entries.
    c                     g | ]}||S  r   .0parts     v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/_private/constants_utils.py
<listcomp>zstr_to_list.<locals>.<listcomp>   s    MMMTMDMMM    c              3   >   K   | ]}|                                 V  d S )N)stripr   s     r   	<genexpr>zstr_to_list.<locals>.<genexpr>   s*      DDtdjjllDDDDDDr   ,)split)r   s    r   str_to_listr      s2    
 NMDDqwws||DDDMMMMr   
bucket_strdefault_bucketsc           	         |                                  dk    r|S 	 d |                     d          D             }|st          d          t          d |D                       rt          d          t	          t          |                    |k    rt          d          |S # t          $ r(}t          d|  d	t          |                     |d
}~ww xY w)a}  Parse a comma-separated string of latency bucket values.

    Args:
        bucket_str: A comma-separated string of positive numbers in ascending order.
        default_buckets: Default bucket values to use if bucket_str is empty.

    Returns:
        A list of parsed float values.

    Raises:
        ValueError: If the format is invalid or values don't meet requirements.
     c                 P    g | ]#}t          |                                          $S r   )floatr   r   xs     r   r   z)parse_latency_buckets.<locals>.<listcomp>   s(    CCC5##CCCr   r   zEmpty bucket listc              3   "   K   | ]
}|d k    V  dS )r   Nr   r   s     r   r   z(parse_latency_buckets.<locals>.<genexpr>#   s&      ''!qAv''''''r   zBucket values must be positivez1Bucket values must be in strictly ascending orderzInvalid format for `zH`. Expected comma-separated positive numbers in ascending order. Error: N)r   r   
ValueErroranysortedset	Exceptionstr)r   r   bucketses       r   parse_latency_bucketsr*      s    RCCZ-=-=c-B-BCCC 	20111''w''''' 	?=>>>#g,,7**PQQQ   ]: ] ]TWXYTZTZ] ]
 
 	s   BB% %
C/#CCT>   MAX_CACHED_HANDLESCONTROLLER_MAX_CONCURRENCYREQUEST_LATENCY_BUCKETS_MSMAX_PER_REPLICA_RETRY_COUNTMODEL_LOAD_LATENCY_BUCKETS_MS"SERVE_REQUEST_PROCESSING_TIMEOUT_S&MAX_DEPLOYMENT_CONSTRUCTOR_RETRY_COUNTnamec                 v    d}|                      |          s!| t          v rdS t          d|  d| d          dS )z-Validate Ray Serve environment variable name.
RAY_SERVE_Nz*Got unexpected environment variable name `z3`! Ray Serve environment variables require prefix `z`. )
startswith_wrong_names_white_listr"   r3   required_prefixs     r   _validate_namer:   >   sq    "O???++ 
***FT T T?NT T T
 
 	
	
 
r   default
value_typevalidation_funcexpected_value_descriptionc                 n   t          |            t          j                            |           }||dS |}nt	          |            |}	  ||          }n1# t
          $ r$}t          d|  d| d|j         d          |d}~ww xY w|r, ||          s!t          d| d|  d| d	|j         d
	          |S )a  Get environment variable with type conversion and validation.

    This function retrieves an environment variable, converts it to the specified type,
    and optionally validates the converted value.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.
            If None, the function will return None without validation.
        value_type: Type to convert the environment variable value to (e.g., int, float, str).
        validation_func: Optional function that takes the converted value and returns
            a boolean indicating whether the value is valid.
        expected_value_description: Description of the expected value characteristics
            (e.g., "positive", "non-negative") used in error messages.
            Optional, expected only if validation_func is provided.

    Returns:
        The environment variable value converted to the specified type and validated,
        or the default value if the environment variable is not set.

    Raises:
        ValueError: If the environment variable value cannot be converted to the specified
            type, or if it fails the optional validation check. Also, if name validation fails.
    NzEnvironment variable `z	` value `z` cannot be converted to `z`!zGot unexpected value `z` for `z!` environment variable! Expected z `z`.)r:   osenvironget_deprecation_warningr"   __name__)	r3   r;   r<   r=   r>   explicitly_defined_valuerawvaluer)   s	            r   _get_env_valuerH   L   s7   > 4!z~~d33'?4CCT"""&
3   jTjjCjjS]Sfjjj
 
	
  
u55 
NU N N4 N N2N N6@6IN N N
 
 	

 Ls   
A 
B A??Bc                 .    t          | |t                    S )aN  Get environment variable as an integer.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as an integer.

    Raises:
        ValueError: If the value cannot be converted to an integer.
    rH   intr3   r;   s     r   get_env_intrM      s     $---r   c                 4    t          | |t          d d          S )aq  Get environment variable as a positive integer.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a positive integer.

    Raises:
        ValueError: If the value cannot be converted to an integer or is not positive.
    c                     | dk    S Nr   r   r    s    r   <lambda>z&get_env_int_positive.<locals>.<lambda>   s
    A r   positiverJ   rL   s     r   get_env_int_positiverT      s     $oozJJJr   c                 4    t          | |t          d d          S )au  Get environment variable as a non-negative integer.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a non-negative integer.

    Raises:
        ValueError: If the value cannot be converted to an integer or is negative.
    c                     | dk    S rP   r   rQ   s    r   rR   z*get_env_int_non_negative.<locals>.<lambda>   s
    Q r   non negativerJ   rL   s     r   get_env_int_non_negativerX      s     $.>.>OOOr   c                 .    t          | |t                    S )aE  Get environment variable as a float.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a float.

    Raises:
        ValueError: If the value cannot be converted to a float.
    rH   r   rL   s     r   get_env_floatr[      s     $///r   c                 4    t          | |t          d d          S )aj  Get environment variable as a positive float.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a positive float.

    Raises:
        ValueError: If the value cannot be converted to a float or is not positive.
    c                     | dk    S rP   r   rQ   s    r   rR   z(get_env_float_positive.<locals>.<lambda>   s
    !a% r   rS   rZ   rL   s     r   get_env_float_positiver^      s     $LLLr   c                 4    t          | |t          d d          S )an  Get environment variable as a non-negative float.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a non-negative float.

    Raises:
        ValueError: If the value cannot be converted to a float or is negative.
    c                     | dk    S rP   r   rQ   s    r   rR   z,get_env_float_non_negative.<locals>.<lambda>   s
    !q& r   rW   rZ   rL   s     r   get_env_float_non_negativera      s     $0@0@.QQQr   c                 .    t          | |t                    S )a:  Get environment variable as a string.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a string.
        Returns `None` if default is `None` and value not found.
    rH   r'   rL   s     r   get_env_strrd      s     $---r   c                 :    t          | |t                    }|dk    S )a  Get environment variable as a boolean.

    Environment variable values of "1" are interpreted as True, all others as False.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.
            Expects "0" or "1".

    Returns:
        True if the environment variable value is "1", False otherwise.
    1rc   )r3   r;   env_value_strs      r   get_env_boolrh      s      #4#66MCr   c           	          dt           dt           ffd}d}d| t          v s| dk    r3 ||           }t          j        d| d|  d	| d
t          d           dS dS )zLog replacement warning for wrong or legacy environment variables.

    TODO: remove this function for the '3.0.0' release.

    :param name: environment variable name
    r3   r	   c                 0    | dk    rdS | dk    rdS  |  S )N'RAY_SERVE_HANDLE_METRIC_PUSH_INTERVAL_S3RAY_SERVE_HANDLE_AUTOSCALING_METRIC_PUSH_INTERVAL_Sr1   &RAY_SERVE_REQUEST_PROCESSING_TIMEOUT_Sr   r8   s    r   get_new_namez*_deprecation_warning.<locals>.get_new_name  s8    <<<HH999;;%-t---r   z3.0.0r5   rk   zStarting from version `z` environment variable `z"` will be deprecated. Please use `z
` instead.   )
stacklevelN)r'   r7   warningswarnFutureWarning)r3   rn   change_versionnew_namer9   s       @r   rC   rC     s    .3 .3 . . . . . . N"O 	'''<<<<%%Mn M MM M8@M M M		
 	
 	
 	
 	
 	
 =<r   )NN)r@   rq   typingr   r   r   r   r   r'   r   r   r*   r+   r7   r:   boolrH   rK   rM   rT   rX   r[   r^   ra   rd   rh   rC   r   r   r   <module>rx      s&   				  : : : : : : : : : : : : : :N3 N49 N N N Nc DK DQVK    D GCLL   
 
 
 
 
 
$ 6:048 8
8a[8 Q8 hsDy12	8
 !)8 a[8 8 8 8v.c .HSM .hsm . . . . Ks KXc] Kx} K K K K P3 P# P8C= P P P P 0 0huo 0(5/ 0 0 0 0 M Mx M8E? M M M M RS R8E? RxPU R R R R .c .HSM .hsm . . . . s  S  T        "
s 
t 
 
 
 
 
 
r   