
    %`i                     8   d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	m
ZmZmZmZ dedeeeef                  fdZd	ed
eeef         defdZ
ddee         defdZd	edefdZ ed          defd            Zd	edefdZe j        fde j        defdZdS )    N)closing)	lru_cache)OptionalTupleUnion)build_addressis_ipv6 node_ip_address_from_perspectiveparse_addressaddressreturnc                      t          |           S )zParse a network address string into host and port.

    Args:
        address: The address string to parse (e.g., "localhost:8000", "[::1]:8000").

    Returns:
        Tuple with (host, port) if port found, None if no colon separator.
    )_parse_addressr   s    m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_common/network_utils.pyr   r      s     '"""    hostportc                 "    t          | |          S )zBuild a network address string from host and port.

    Args:
        host: The hostname or IP address.
        port: The port number (int or string).

    Returns:
        Formatted address string (e.g., "localhost:8000" or "[::1]:8000").
    )_build_address)r   r   s     r   r   r      s     $%%%r   c                      t          |           S )an  IP address by which the local node can be reached *from* the `address`.

    If no address is given, defaults to public DNS servers for detection.

    Args:
        address: The IP address and port of any known live service on the
            network you care about.

    Returns:
        The IP address by which the local node can be reached from the address.
    )!_node_ip_address_from_perspectiver   s    r   r
   r
   '   s     -W555r   c                      t          |           S )zCheck if a host is resolved to IPv6.

    Args:
        host: The IP or domain name to check (must be without port).

    Returns:
        True if the host is resolved to IPv6, False if IPv4.
    )_is_ipv6r   s    r   r	   r	   6   s     D>>r      )maxsizec                      t           j        t           j        fD ]I} 	 t          j        dd| t           j                  }|d         d         d         c S # t
          $ r Y Fw xY wdS )zgGet localhost loopback ip with IPv4/IPv6 support.

    Returns:
        The localhost loopback IP.
    	localhostNr      	127.0.0.1)socketAF_INETAF_INET6getaddrinfoSOCK_STREAM	Exception)family
dns_results     r   get_localhost_ipr*   B   s     >6?3  	+T66+= J a=#A&&&& 	 	 	H	 ;s   4A
A A c                 
    | dv S )zCheck if the given host string represents a localhost address.

    Args:
        host: The hostname or IP address to check.

    Returns:
        True if the host is a localhost address, False otherwise.
    )r   r!   z::1 r   s    r   is_localhostr-   W   s     444r   r(   c                     t          t          j        | t          j                            5 }|                    d           |                                d         cddd           S # 1 swxY w Y   dS )zFind a free port on the local machine.

    Args:
        family: The socket address family (AF_INET for IPv4, AF_INET6 for IPv6).
            Defaults to AF_INET.

    Returns:
        An available port number.
    ) r   r   N)r   r"   r&   bindgetsockname)r(   ss     r   find_free_portr3   c   s     
vv'9::	;	; "q	w}}q!" " " " " " " " " " " " " " " " " "s   /A))A-0A-)N)r"   
contextlibr   	functoolsr   typingr   r   r   ray._rayletr   r   r	   r   r
   r   r   r   strintboolr*   r-   r#   AddressFamilyr3   r,   r   r   <module>r<      s                ) ) ) ) ) ) ) ) ) )           	#3 	#8E#s(O#< 	# 	# 	# 	#
& 
&5c? 
&s 
& 
& 
& 
&6 6hsm 6s 6 6 6 6	# 	$ 	 	 	 	 1#    (	5s 	5t 	5 	5 	5 	5 39. " "6/ "S " " " " " "r   