
    i	              	           d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ erd dlmZ dede
edf   d	dfd
Zddde
edf   deded	dfdZded	e	eeef      fdZy)    N)Path)TYPE_CHECKINGAnyDictOptionalUnion)msg)	CloudPathsrcdestr
   returnc                    ddl }t        |t              r6|j                  j	                         s|j                  j                  d       t        |      }|j                  d      r|j                  ddd      }t        |      }|j                  |d	|
      5 }| j                  d      5 }|j                  |j                                ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)zfUpload a file.

    src (Path): The source path.
    url (str): The destination URL to upload to.
    r   NT)parentsaz://azazure   wb)modetransport_paramsrbr   )
smart_open
isinstancer   parentexistsmkdirstr
startswithreplace_transport_paramsopenwriteread)r   r   r   r   output_file
input_files         c/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/weasel/util/remote.pyupload_filer(      s      ${{!!#KKd+t9Dw||D'1-(.	4*: 
 
 1	XX4X  	1Jjoo/0	11 1	1 	11 1s$   C), CC)C&	"C))C2F)forcer)   c                t   ddl }|j                         r|syt        |       } | j                  d      r| j	                  ddd      } t        |       }|j                  | dd|	      5 }|j                  d
      5 }t        j                  ||       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)zDownload a file using smart_open.

    url (str): The URL of the file.
    dest (Path): The destination path.
    force (bool): Whether to force download even if file exists.
        If False, the download will be skipped.
    r   Nr   r   r   r   r   disable)r   compressionr   r   r   )	r   r   r   r   r    r!   r"   shutilcopyfileobj)r   r   r)   r   r   r&   r%   s          r'   download_filer/   %   s     {{}U
c(C
~~gkk$+(-	$I@P 
 
 8	YYDY! 	8[z;7	88 8	8 	88 8s$   'B.:B"B."B+	'B..B7urlc                     | j                  d      ret        j                  j                  d      }|s+t	        j
                  dd       t        j                  d       ddlm	} d|j                  |      iS y )	Nzazure://AZURE_STORAGE_CONNECTION_STRINGzCAzure storage requires a connection string, which was not provided.zFAssign it to the environment variable AZURE_STORAGE_CONNECTION_STRING.r   r   )BlobServiceClientclient)r   osenvirongetr	   failsysexitazure.storage.blobr3   from_connection_string)r0   connection_stringr3   s      r'   r!   r!   >   sb    
~~j!JJNN+LM HHUX HHQK8+BBCTUVV    )r5   r-   r9   pathlibr   typingr   r   r   r   r   wasabir	   cloudpathlibr
   r   r(   boolr/   r!    r>   r'   <module>rE      s    	  
  < < &1T 1sK'7!8 1T 12 @E8	sK	 8(,88<8	823 8DcN#; r>   