
    &`i                     X    d dl Z d dlZd dlmZ d dlmZ  G d d          Zdede	fdZ
dS )	    N)Path)Unionc                       e Zd ZdZdefdZdedd fdZedefd            Z	edd            Z
edefd	            Zedefd
            Zd Zedej        j        deeef         defd            Zd Zd ZdS )URIam  Represents a URI, supporting path appending and retrieving parent URIs.

    Example Usage:

        >>> s3_uri = URI("s3://bucket/a?scheme=http&param=1")
        >>> s3_uri
        URI<s3://bucket/a?scheme=http&param=1>
        >>> str(s3_uri / "b" / "c")
        's3://bucket/a/b/c?scheme=http&param=1'
        >>> str(s3_uri.parent)
        's3://bucket?scheme=http&param=1'
        >>> str(s3_uri)
        's3://bucket/a?scheme=http&param=1'
        >>> s3_uri.parent.name, s3_uri.name
        ('bucket', 'a')
        >>> local_path = URI("/tmp/local")
        >>> str(local_path)
        '/tmp/local'
        >>> str(local_path.parent)
        '/tmp'
        >>> str(local_path / "b" / "c")
        '/tmp/local/b/c'

    Args:
        uri: The URI to represent.
            Ex: s3://bucket?scheme=http&endpoint_override=localhost%3A900
            Ex: file:///a/b/c/d
    uric                 "   t           j                            |          | _        | j        j        st          |          | _        d S t          t          j        	                    | j        j
        | j        j        z                       | _        d S N)urllibparseurlparse_parsedschemer   _pathospathnormpathnetloc)selfr   s     o/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/air/_internal/uri_utils.py__init__zURI.__init__%   sj    |,,S11|" 	YcDJJJbg..t|/BT\EV/VWWXXDJJJ    subpathreturnc                 F   t          | j                                      t          |                    sJ | j        |f            t          | j                                      t          |          d          }t	          |                     | j        |                    S )ao  Returns a new URI that strips the given subpath from the end of this URI.

        Example:
            >>> uri = URI("s3://bucket/a/b/c/?param=1")
            >>> str(uri.rstrip_subpath(Path("b/c")))
            's3://bucket/a?param=1'

            >>> uri = URI("/tmp/a/b/c/")
            >>> str(uri.rstrip_subpath(Path("/b/c/.//")))
            '/tmp/a'

         )strr   endswithreplacer   _get_str_representationr   )r   r   stripped_paths      r   rstrip_subpathzURI.rstrip_subpath-   s~     4:''G55LL
G7LLL5DJ//GbAA4//mLLMMMr   c                     | j         j        S r	   )r   namer   s    r   r#   zURI.name>   s    zr   c                     | j         j        dk    sJ t          |            d            t          |                     | j        | j         j                            S )N.z has no valid parent URI)r   parentr   r   r   r   r$   s    r   r'   z
URI.parentB   sT    z C'''CII)O)O)O'''4//dj>OPPQQQr   c                     | j         j        S r	   )r   r   r$   s    r   r   z
URI.schemeG   s    |""r   c                 *    t          | j                  S r	   )r   r   r$   s    r   r   zURI.pathK   s    4:r   c                     t          |t                    sJ t          |                     | j        | j        |z                      S r	   )
isinstancer   r   r   r   r   )r   path_to_appends     r   __truediv__zURI.__truediv__O   sF    .#.....((tzN7RSS
 
 	
r   
parsed_urir   c                     |j         st          |          S |                    t          |          d                                          S )Nr   )r   r   )r   r   _replacegeturl)clsr.   r   s      r   r   zURI._get_str_representationU   sF       	t99""#d))""==DDFFFr   c                 (    dt          |            dS )NzURI<>)r   r$   s    r   __repr__zURI.__repr__]   s    "c$ii""""r   c                 B    |                      | j        | j                  S r	   )r   r   r   r$   s    r   __str__zURI.__str__`   s    ++DL$*EEEr   N)r   r   )__name__
__module____qualname____doc__r   r   r   r!   propertyr#   r'   r   r   r-   classmethodr
   r   ParseResultr   r   r5   r7    r   r   r   r      s~        :YC Y Y Y YNd Nu N N N N" c    X R R R XR # # # # X# c    X
 
 
 G1G9>sDy9IG	G G G [G# # #F F F F Fr   r   r   r   c                 d    t          t          j                            |           j                  S r	   )boolr
   r   r   r   )r   s    r   is_urirB   d   s#    %%d++2333r   )r   urllib.parser
   pathlibr   typingr   r   r   rA   rB   r?   r   r   <module>rF      s    				                ZF ZF ZF ZF ZF ZF ZF ZFz4 4 4 4 4 4 4 4r   