
    %`i1              	       |   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZmZ d dlmZ d dlmZ d dlmZmZmZmZmZ d dlZddded	ed
eeef         fdZddded	ed
efdZd
e j        fdZ e            Zded
e j         fdZ!dZ"dZ#deeef         d
eeef         fdZ$ej%        ej&        z   Z'de(fdZ) e            Z*d2de(fdZ+d Z,d Z-dee         fdZ.d3dee         fdZ/d Z0	 	 d4d!ed"efd#Z1d$ Z2d% Z3d& Z4d' Z5d( Z6d5d*ed+ed,efd-Z7 G d. d/e          Z8 G d0 d1e8          Z9dS )6    N)ABCabstractmethod)	signature)
ModuleType)Any	CoroutineDictOptionalTupleFreload_module	full_pathr   returnc                d   d| v rE|                      d          dk    rt          d|  d          |                     d          \  }}n,|                     d          }| d|         }| |dz   d         }t	          j        |          }|rt	          j        |           |t          ||          fS )ai  Given a full import path to a module attr, return the imported module and attr.

    If `reload_module` is set, the module will be reloaded using `importlib.reload`.

    Args:
        full_path: The full import path to the module and attr.
        reload_module: Whether to reload the module.

    Returns:
        A tuple of the imported module and attr.
    :   zGot invalid import path "z-". An import path may have at most one colon..N)count
ValueErrorsplitrfind	importlibimport_modulereloadgetattr)r   r   module_name	attr_namelast_period_idxmodules         e/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_common/utils.pyimport_module_and_attrr!      s     i??3!##:I : : :   "+!5!5YY#//#.. 0 01o1334	$[11F !   769----    c                0    t          | |          d         S )a  Given a full import path to a module attr, return the imported attr.

    If `reload_module` is set, the module will be reloaded using `importlib.reload`.

    For example, the following are equivalent:
        MyClass = import_attr("module.submodule:MyClass")
        MyClass = import_attr("module.submodule.MyClass")
        from module.submodule import MyClass

    Returns:
        Imported attr
    r   r   )r!   )r   r   s     r    import_attrr$   3   s     ")=III!LLr"   c                  >   t           j        } | j        dk    rt| j        dk    ri	 t	          j                    }|J |S # t          $ rB}dt          |          v sJ t	          j                    	                                cY d}~S d}~ww xY wt	          j	                    S )aj  Get a running async event loop if one exists, otherwise create one.

    This function serves as a proxy for the deprecating get_event_loop().
    It tries to get the running loop first, and if no running loop
    could be retrieved:
    - For python version <3.10: it falls back to the get_event_loop
        call.
    - For python version >= 3.10: it uses the same python implementation
        of _get_event_loop() at asyncio/events.py.

    Ideally, one should use high level APIs like asyncio.run() with python
    version >= 3.7, if not possible, one should create and manage the event
    loops explicitly.
       
   Nzno running event loop)
sysversion_infomajorminorasyncioget_running_loopRuntimeErrorstrget_event_loop_policyget_event_loop)	vers_infoloopes      r    get_or_create_event_loopr5   C   s      I!	2 5 5	D+--D###K 	D 	D 	D +c!ff4444022AACCCCCCCC		D !###s   = 
B	7B>B	B		coroutinec                     t                                          |           }t                              |           |                    t          j                   |S )a1  Schedule a task reliably to the event loop.

    This API is used when you don't want to cache the reference of `asyncio.Task`.
    For example,

    ```
    get_event_loop().create_task(coroutine(*args))
    ```

    The above code doesn't guarantee to schedule the coroutine to the event loops

    When using create_task in a  "fire and forget" way, we should keep the references
    alive for the reliable execution. This API is used to fire and forget
    asynchronous execution.

    https://docs.python.org/3/library/asyncio-task.html#creating-tasks
    )r5   create_task_BACKGROUND_TASKSaddadd_done_callbackdiscard)r6   tasks     r    run_background_taskr>   g   sP    $ $%%11)<<D$
 	,4555Kr"   zaccelerator_type:bundleoptions_dictc                 .   |                      d          pi                                 }d|v sd|v rt          d          d|v sd|v rt          d          t          |v rt          d|           |                      d	          }|                      d
          }|                      d          }|                      d          }|                      d          }|||d<   |||d<   |t	          |          |d<   |||d<   |d|t
           | <   |S )zDetermine a task's resource requirements.

    Args:
        options_dict: The dictionary that contains resources requirements.

    Returns:
        A dictionary of the resource requirements for the task.
    	resourcesCPUGPUz@The resources dictionary must not contain the key 'CPU' or 'GPU'memoryobject_store_memoryzSThe resources dictionary must not contain the key 'memory' or 'object_store_memory'zOThe resource should not include `bundle` which is reserved for Ray. resources: num_cpusnum_gpusaccelerator_typeNgMbP?)getcopyr   $PLACEMENT_GROUP_BUNDLE_RESOURCE_NAMEintRESOURCE_CONSTRAINT_PREFIX)r@   rB   rG   rH   rE   rF   rI   s          r    resources_from_ray_optionsrO      s    !!+..4"::<<I	Ui//N
 
 	
 
Y		"79"D"D@
 
 	
 
.	:	:;/8; ;
 
 	

 
++H
++Hh''F&**+@AA#''(:;;#	%#	%!&kk	(&+>	'(#GL	/C1ACCDr"   lengthc                 ^    d                     t          j        t          |                     S )zjGenerates random string of length consisting exclusively of
    - Lower-case ASCII chars
    - Digits
     )k)joinrandomchoicesRANDOM_STRING_ALPHABET)rP   s    r    get_random_alphanumeric_stringrX      s&    
 776>"8FCCCDDDr"   r   backc                     t          j                    }	 || dz            }|j         d|j         S # t          $ r Y dS w xY w)aL  
    Get the location (filename and line number) of a function caller, `back`
    frames up the stack.

    Args:
        back: The number of frames to go up the stack, not including this
            function.

    Returns:
        A string with the filename and line number of the caller.
        For example, "myfile.py:123".
    r   r   UNKNOWN)inspectstackfilenamelineno
IndexError)rY   r]   frames      r    get_call_locationrb      s[     MOOEdQh.115<111   yys   1 
??c                     dt           j        v rt           j        d         S t          j                            d          r dt           j        v rt           j        d         S t          j                            d          st          j                            d          r+t           j                            t           j        d          } nt          j	                    } | S )N
RAY_TMPDIRlinuxTMPDIRdarwintmp)
osenvironr(   platform
startswithpathrT   septempfile
gettempdir)tempdirs    r    get_user_temp_dirrr      s    rz!!z,''		 	 	)	) (h"*.D.Dz(##		 	 	*	* (cl.E.Eg.N.N ( ',,rvu--%''Nr"   c                  Z    t           j                            t                      d          S )Nray)ri   rm   rT   rr    r"   r    get_ray_temp_dirrv      s    7<<)++U333r"   temp_dirc                 b    | t                      } t          j                            | d          S )Nray_current_cluster)rv   ri   rm   rT   )rw   s    r    get_ray_address_filerz      s*    #%%7<<"7888r"   c                     t          |           }t          j                            |          r(	 t          j        |           d S # t
          $ r Y d S w xY wd S N)rz   ri   rm   existsremoveOSError)rw   address_files     r    reset_ray_addressr      sl    '11L	w~~l## 	Il##### 	 	 	DD	 s   A 
AAc                    |                      d          }t          |          dk     rt          d          d                    |dd                   }|d         }t	          j        |          }t          ||          S )z`Load a class at runtime given a full path.

    Example of the path: mypkg.mysubpkg.myclass
    r      z:You need to pass a valid path like mymodule.provider_classN)r   lenr   rT   r   r   r   )rm   
class_datamodule_path	class_strr   s        r    
load_classr      su    
 CJ
:UVVV((:crc?++K2I$[11F69%%%r"   +/sys/fs/cgroup/memory/memory.limit_in_bytes/sys/fs/cgroup/memory.maxmemory_limit_filenamememory_limit_filename_v2c                 z   d}t           j                            |           r\t          | d          5 }t	          |                                                                          }ddd           n# 1 swxY w Y   nt           j                            |          rtt          |d          5 }|                                                                }|                                rt	          |          }nd}ddd           n# 1 swxY w Y   t          j	                    j
        }|t          ||          S |S )a  Return the total amount of system memory in bytes.

    Args:
        memory_limit_filename: The path to the file that contains the memory
            limit for the Docker container. Defaults to
            /sys/fs/cgroup/memory/memory.limit_in_bytes.
        memory_limit_filename_v2: The path to the file that contains the memory
            limit for the Docker container in cgroups v2. Defaults to
            /sys/fs/cgroup/memory.max.

    Returns:
        The total amount of system memory in bytes.
    Nr)ri   rm   r}   openrM   readstrip	isnumericpsutilvirtual_memorytotalmin)r   r   docker_limitfmax_filepsutil_memory_in_bytess         r    get_system_memoryr   
  s   , L	w~~+,, $'-- 	1qvvxx~~//00L	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1	0	1	1 $*C00 	$Avvxx~~''H!!## $"8}}  $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ $244: <!7888!!s$   4A22A69A6-ADD
D
c                 V    t          j        |           }|                                }|S r|   )binasciihexlifydecode)
identifierhex_identifiers     r    binary_to_hexr   9  s)    %j11N#**,,Nr"   c                 *    t          j        |           S r|   )r   	unhexlify)r   s    r    hex_to_binaryr   ?  s    n---r"   c                     	 t          j        | d           d S # t          $ r,}|j        t          j        t          j        fv rn Y d }~d S d }~ww xY w)Ni  )ri   chmodr   errnoEACCESEPERM)directory_pathr4   s     r    try_make_directory_sharedr   C  sk    
((((( 	 	 	 7u|U[111 DDDDD	s    
A!A

Ac                     t           j                            |           } t          j        | d           t	          |            d S )NT)exist_ok)ri   rm   
expandusermakedirsr   )r   s    r    try_to_create_directoryr   R  sB    W''77NK.... n-----r"   c                 b    t          t          |           j                  }t          |          S r|   )	frozensetr   
parameterslist)callableall_parameterss     r    get_function_argsr   [  s(    y22=>>Nr"   utf-8byte_str
allow_noneencode_typec                     | |rdS t          | t                    st          d|  d          |                     |          S )a  Make this unicode in Python 3, otherwise leave it as bytes.

    Args:
        byte_str: The byte string to decode.
        allow_none: If true, then we will allow byte_str to be None in which
            case we will return an empty string. TODO(rkn): Remove this flag.
            This is only here to simplify upgrading to flatbuffers 1.10.0.
        encode_type: The encoding type to use for decoding. Defaults to "utf-8".

    Returns:
        A byte string in Python 2 and a unicode string in Python 3.
    NrR   zThe argument z must be a bytes object.)
isinstancebytesr   r   )r   r   r   s      r    r   r   `  sS     Jrh&& MKKKKLLL??;'''r"   c                   *    e Zd Zedefd            ZdS )	TimerBaser   c                     t           )zReturn the current time.)NotImplementedErrorselfs    r    timezTimerBase.timev  s
     "!r"   N)__name__
__module____qualname__r   floatr   ru   r"   r    r   r   u  s9        "e " " " ^" " "r"   r   c                       e Zd ZdefdZdS )Timerr   c                 (    t          j                     S r|   )r   r   s    r    r   z
Timer.time}  s    y{{r"   N)r   r   r   r   r   ru   r"   r    r   r   |  s/        e      r"   r   )r   r|   )r   r   )Fr   ):r,   r   r   r   r\   ri   rU   stringr(   ro   r   abcr   r   r   typesr   typingr   r   r	   r
   r   r   r/   boolr!   r$   AbstractEventLoopr5   setr9   Taskr>   rN   rL   rO   ascii_lowercasedigitsrW   rM   rX   _PRINTED_WARNINGrb   rr   rv   rz   r   r   r   r   r   r   r   r   r   r   r   ru   r"   r    <module>r      s           				   



   # # # # # # # #             8 8 8 8 8 8 8 8 8 8 8 8 8 8  .3. . ..&*.
:s?. . . .> :? M M M3 M$ M3 M M M M $'"; $ $ $ $B CEE 9     < 1 '/ $+T#s(^ +S#X + + + +^  /&-? E3 E E E E 355  C    *  4 4 498C= 9 9 9 9     & & &  "O$?	," ,"," "	," ," ," ,"^  . . .  . . .     
( (S (d ( ( ( ( (*" " " " " " " "    I     r"   