
    &`i,%                         d dl Z d dlZd dlmZ  G d d          Z e j        dd e                                D                       Zed             Z	e	e_
        d Zee_        dS )	    N)urlparsec                       e Zd ZdZed             Zed             Zed             Zed             Zed             Z	ed             Z
eded	ed
efd            ZdS )ProtocolsProviderz~Note that these must be preinstalled on all nodes in the Ray cluster; it is not sufficient to install them in the runtime_env.c                 
    h dS )N>
   gss3uvgcspipfileabfssazurecondahttps clss    u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/runtime_env/protocol.pyget_protocolszProtocolsProvider.get_protocols   s    
 
 
 	
    c                 
    h dS )N>   r   r   r   r   r   r   r   r   s    r   get_remote_protocolsz&ProtocolsProvider.get_remote_protocols&   s    >>>>r   c                 J   	 ddl }ddlm} n%# t          $ r t          d| j        z             w xY w|                                }|                                r|                    d          }n-ddlm	} ddl
m} |                    d ||          	          }d
|i}||fS )zSet up S3 protocol handling.

        Returns:
            tuple: (open_file function, transport_params)

        Raises:
            ImportError: If required dependencies are not installed.
        r   NopenzBYou must `pip install smart_open[s3]` to fetch URIs in s3 bucket. r   )UNSIGNED)Config)signature_version)configclient)boto3
smart_openr   ImportError_MISSING_DEPENDENCIES_WARNINGSessionget_credentialsr    botocorer   botocore.configr   )r   r!   	open_filesession	s3_clientr   r   transport_paramss           r   _handle_s3_protocolz%ProtocolsProvider._handle_s3_protocol*   s    	LLL4444444 	 	 	/141RS  	 --//""$$ 	Vt,,II *)))))......T&&82T2T2TUUI$i0***s   
 "/c                 p    	 ddl m} ddlm} n%# t          $ r t	          d| j        z             w xY w|dfS )zSet up Google Cloud Storage protocol handling.

        Returns:
            tuple: (open_file function, transport_params)

        Raises:
            ImportError: If required dependencies are not installed.
        r   )storager   zTYou must `pip install smart_open[gcs]` to fetch URIs in Google Cloud Storage bucket.N)google.cloudr/   r"   r   r#   r$   )r   r/   r)   s      r   _handle_gs_protocolz%ProtocolsProvider._handle_gs_protocolM   sx    	,,,,,,4444444 	 	 	@34  	 $s    "1c                     	 ddl m} ddlm} ddlm} n%# t          $ r t          d| j        z             w xY wt          j	        d          }|st          d          d| d	}d
 || |                      i}||fS )a  Set up Azure blob storage protocol handling.

        Returns:
            tuple: (open_file function, transport_params)

        Raises:
            ImportError: If required dependencies are not installed.
            ValueError: If required environment variables are not set.
        r   DefaultAzureCredential)BlobServiceClientr   zpYou must `pip install azure-storage-blob azure-identity smart_open[azure]` to fetch URIs in Azure Blob Storage. AZURE_STORAGE_ACCOUNTz`Azure Blob Storage authentication requires AZURE_STORAGE_ACCOUNT environment variable to be set.zhttps://z.blob.core.windows.net/r    )account_url
credential)azure.identityr4   azure.storage.blobr5   r"   r   r#   r$   osgetenv
ValueError)r   r4   r5   r)   azure_storage_account_namer7   r,   s          r   _handle_azure_protocolz(ProtocolsProvider._handle_azure_protocolc   s   		======<<<<<<4444444 	 	 	834  	 &(Y/F%G%G") 	H  
 U!;TTT'''4J4J4L4L  
 ***s    "7c                     	 ddl ddlm n%# t          $ r t          d| j        z             w xY wddfd
}|dfS )a&  Set up Azure Blob File System Secure (ABFSS) protocol handling.

        Returns:
            tuple: (open_file function, transport_params)

        Raises:
            ImportError: If required dependencies are not installed.
            ValueError: If the ABFSS URI format is invalid.
        r   Nr3   z\You must `pip install adlfs azure-identity` to fetch URIs in Azure Blob File System Secure. r,   c                   t          |           }|j        r	d|j        vrt          d|            |j                            dd          \  }}|st          d|            |r|                    d          st          d|            |                    d          d         }|st          d	|            	                    |             
          }|                    | |          S )N@z6Invalid ABFSS URI format - missing container@account:    z1Invalid ABFSS URI format - empty container name: z.dfs.core.windows.netzSInvalid ABFSS URI format - invalid hostname (must end with .dfs.core.windows.net): .r   z/Invalid ABFSS URI format - empty account name: )account_namer8   )r   netlocr=   splitendswithAzureBlobFileSystemr   )
urimoder,   parsedcontainer_parthostname_partr>   
filesystemr4   adlfss
           r   r)   z;ProtocolsProvider._handle_abfss_protocol.<locals>.open_file   sG   c]]F = Cv}$<$< RSRR   -3M,?,?Q,G,G)NM "  MMM  
 ! (>(>?V(W(W  ojmoo  
 *7)<)<S)A)A!)D&-  KcKK  
 2271133 3  J ??3---r   )rQ   r9   r4   r#   r$   )r   r)   r4   rQ   s     @@r   _handle_abfss_protocolz(ProtocolsProvider._handle_abfss_protocol   s    	LLL======= 	 	 	C34  	 6: $	. $	. $	. $	. $	. $	. $	. $	.L $s   
 "1protocol
source_uri	dest_filec                    ||                                  v sJ d}d}|dk    r|t          d          d         }ddd}n|dk    r|                                 \  }}n|dk    r|                                 \  }}n|dk    r|                                 \  }}na|d	k    r|                                 \  }}nC	 d
dlm} n;# t          $ r. t          d|	                                 d| j
        z             w xY w ||d|          5 }t          |d          5 }|                    |                                           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )ax  Download file from remote URI to destination file.

        Args:
            protocol: The protocol to use for downloading (e.g., 's3', 'https').
            source_uri: The source URI to download from.
            dest_file: The destination file path to save to.

        Raises:
            ImportError: If required dependencies for the protocol are not installed.
        Nr   zfile://rA   c                "    t          | |          S Nr   )rK   rL   r,   s      r   r)   z8ProtocolsProvider.download_remote_uri.<locals>.open_file   s    C&r   r   r   r   r   r   r   z+You must `pip install smart_open` to fetch z URIs. rbwb)r   lenr-   r1   r?   rR   r"   r   r#   upperr$   writeread)r   rS   rT   rU   tpr)   finfouts           r   download_remote_uriz%ProtocolsProvider.download_remote_uri   s`    333555555	v#C	NN$4$45J9= ' ' ' ' ' ' 3355MIrr3355MIrr  6688MIrr  6688MIrr8888888   !: ( 0 0: : :78   Yz4"=== 	'i&& '$

388::&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'sB   :C 8C9
E'(EE'E	E'E	E''E+.E+N)__name__
__module____qualname__r$   classmethodr   r   r-   r1   r?   rR   strrb   r   r   r   r   r      s        	9 " 
 
 [
0 ? ? [?  +  + [ +D   [* %+ %+ [%+N : : [:x *'3 *'C *'C *' *' *' [*' *' *'r   r   Protocolc                 8    i | ]}|                                 |S r   r\   ).0rS   s     r   
<dictcomp>rl      s$    RRRHX^^xRRRr   c                 N      fdt                                           D             S )Nc                 D    g | ]}|                                          S r   rj   )rk   rS   r   s     r   
<listcomp>z%_remote_protocols.<locals>.<listcomp>   s5       "*HNN  r   )r   r   r   s   `r   _remote_protocolsrp      s:       .?.T.T.V.V   r   c                 D    t                               | j        ||          S rX   )r   rb   value)selfrT   rU   s      r   _download_remote_urirt     s    00ZSSSr   )enumr;   urllib.parser   r   Enumr   rh   rf   rp   remote_protocolsrt   rb   r   r   r   <module>ry      s     				 ! ! ! ! ! !m' m' m' m' m' m' m' m'` 49RR0A0O0O0Q0QRRR     . T T T  4   r   