
    MiU                     `   S r SSKrSSKrSSKrSSKrSSKr SSKrSSK	r\R                  " \5      r\\\4r Sr Sr Sr Sr S rS	 rSS\\\4S
 jrS r " S S\5      r " S S\R:                  5      r " S S\R:                  5      r " S S\R:                  5      r g! \
 a    Sr Nf = f)zPImplements file-like objects for reading and writing to/from Azure Blob Storage.    NTazurei   i  @    c                     [         R                  R                  U 5      nUR                  [        :X  d   eUR
                  nUR                  R                  S5      nU(       d  SnUnOUnUn[        [        XES9$ )N/z$root)schemecontainer_idblob_id)	
smart_openutilssafe_urlsplitr   SCHEMEnetlocpathlstripdict)uri_as_stringsrfirstsecondr   r	   s         j/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/smart_open/azure.py	parse_urir   ,   sk    				'	'	6B99IIEWW^^C F vLJJ    c                     [        U 5      n[        R                  R                  [        U5      n[	        US   US   U40 UD6$ )Nr   r	   )r   r
   r   check_kwargsopen)urimodetransport_params
parsed_urikwargss        r   open_urir!   =   sB    3J**41ABF
>*Jy,A4R6RRr   c           	      v   U(       d  [        S5      eU[        R                  R                  :X  a&  [	        U UUU[        R                  R
                  US9$ U[        R                  R                  :X  a  [        U UUUUS9$ U[        R                  R                  :X  a  [        U UUUUS9$ [        SU-  5      e)a  Open an Azure Blob Storage blob for reading or writing.

Parameters
----------
container_id: str
    The name of the container this object resides in.
blob_id: str
    The name of the blob within the bucket.
mode: str
    The mode for opening the object.  Must be either "rb", "wb", or "ab".
client: azure.storage.blob.BlobServiceClient, ContainerClient, or BlobClient
    The Azure Blob Storage client to use when working with azure-storage-blob.
blob_kwargs: dict, optional
    Additional parameters to pass to `BlobClient.commit_block_list` (for "wb")
    or `BlobClient.upload_blob` (for "ab"). For writing only.
buffer_size: int, optional
    The buffer size to use when performing I/O. For reading only.
min_part_size: int, optional
    The minimum part size for multipart uploads. For writing only.
max_concurrency: int, optional
    The number of parallel connections with which to download. For reading only.

z/you must specify the client to connect to Azure)buffer_sizeline_terminatormax_concurrency)blob_kwargsmin_part_sizez6Azure Blob Storage support for mode %r not implemented)
ValueErrorr
   	constantsREAD_BINARYReaderBINARY_NEWLINEWRITE_BINARYWriterAPPEND_BINARYAppendWriterNotImplementedError)r   r	   r   clientr&   r#   r'   r%   s           r   r   r   C   s    B JKKz##///#&00??+
 	
 
%%22	2#'
 	
 
%%33	3#'
 	
 ""Z]a"abbr   c                 
   [        U S5      (       a  U R                  U5      n [        U S5      (       a-  U R                  U:w  a  [        SU R                  < SU< 35      e[        U S5      (       a  U R	                  U5      n U $ )z
Return an Azure BlobClient starting with any of BlobServiceClient,
ContainerClient, or BlobClient plus container name and blob name.
get_container_clientcontainer_namezClient for z doesn't match container get_blob_client)hasattrr4   r5   r(   r6   )r2   	containerblobs      r   _get_blob_clientr:      s     v-..,,Y7v'((V-B-Bi-O$33Y@
 	

 v())''-Mr   c                   4    \ rS rSrSrS rS rS	S jrS rSr	g)

_RawReader   z Read an Azure Blob Storage file.c                 6    Xl         X l        SU l        X0l        g Nr   )_blob_size	_position_concurrency)selfr9   sizeconcurrencys       r   __init___RawReader.__init__   s    

'r   c                 &    Xl         U R                   $ )zSeek to the specified position (byte offset) in the Azure Blob Storage blob.

:param int position: The byte offset from the beginning of the blob.

Returns the position after seeking.
rB   )rD   positions     r   seek_RawReader.seek   s     "~~r   c                     U R                   U R                  :  a  gU R                  U5      nU =R                   [        U5      -  sl         U$ )Nr   )rB   rA   _download_blob_chunklen)rD   rE   binarys      r   read_RawReader.read   s<    >>TZZ'**40#f+%r   c                    U R                   U R                  :X  a  gUS:X  a/  U R                  R                  U R                  U R                  S9nO/U R                  R                  U R                  U R                  US9n[
        R                  " SU R                  5        [        U[        R                  R                  R                  5      (       a  UR                  5       nU$ UR                  5       nU$ )Nr   )offsetr%   )rV   r%   lengthz$reading with a max concurrency of %d)rA   rB   r@   download_blobrC   loggingdebug
isinstancer   storager9   StorageStreamDownloaderreadallrR   )rD   rE   streamrQ   s       r   rO   _RawReader._download_blob_chunk   s    ::'
 RZZZ--T^^UYUfUf-gFZZ--~~t7H7HQU . WF<d>O>OPfemm00HHII^^%F  [[]Fr   )r@   rC   rB   rA   NrU   )
__name__
__module____qualname____firstlineno____doc__rG   rL   rR   rO   __static_attributes__ r   r   r<   r<      s    *(r   r<   c                      \ rS rSrSrSr\\R                  R                  \
4S jrS r\S 5       rS rS rS	 r\R                  R$                  4S
 jrS rSS jrSS jrSS jrS rSS jrSS jrSS jrS rS rS rS rSr g)r+      zReads bytes from Azure Blob Storage.

Implements the io.BufferedIOBase interface of the standard library.

:raises azure.core.exceptions.ResourceNotFoundError: Raised when the blob to read from does not exist.
Nc                    Xl         X l        [        X1U5      U l        U R                  c1  [        R
                  R                  R                  SU< SU< 35      e U R                  R                  5       S   U l	        [        U R                  U R                  U5      U l        SU l        [        R                  R!                  U5      U l        XPl        g ! [         a
    SU l	         Nkf = f)Nzblob z not found in rE   r   )_container_name
_blob_namer:   r@   r   core
exceptionsResourceNotFoundErrorget_blob_propertiesrA   KeyErrorr<   _raw_readerrB   r
   
bytebuffer
ByteBuffer_current_part_line_terminator)rD   r8   r9   r2   r#   r$   r%   s          r   rG   Reader.__init__   s      ) &f>
::**''==-19= 	779&ADJ &djj$**oN'22==kJ /  	DJ	s   "C C+*C+c                 n    [         R                  S5        U R                  (       d  SU l        SU l        gg)zFlush and close this stream.close: calledN)loggerrZ   closedr@   rs   rD   s    r   closeReader.close   s)    _%{{DJ#D r   c                     U R                   S L $ Nr@   r}   s    r   r|   Reader.closed       zzT!!r   c                     g)z+Return True if the stream can be read from.Trh   r}   s    r   readableReader.readable       r   c                     g)zqIf False, seek(), tell() and truncate() will raise IOError.

We offer only seek support, and no truncate support.Trh   r}   s    r   seekableReader.seekable        r   c                 "    [         R                  ezUnsupported.ioUnsupportedOperationr}   s    r   detachReader.detach	      %%%r   c                 D   [         R                  SX5        U[        R                  R                  ;  a(  [        SU[        R                  R                  4-  5      eU[        R                  R                  :X  a  UnO=U[        R                  R                  :X  a  U R                  U-   nOU R                  U-   nX0l        U R                  R                  U5        [         R                  SU R                  5        U R                  R                  5         U R                  $ )zSeek to the specified position.

:param int offset: The offset in bytes.
:param int whence: Where the offset is from.

Returns the position after seeking.z seeking to offset: %r whence: %rz%invalid whence %i, expected one of %rzcurrent_pos: %r)r{   rZ   r
   r)   WHENCE_CHOICESr(   WHENCE_STARTWHENCE_CURRENTrB   rA   rs   rL   rv   empty)rD   rV   whencenew_positions       r   rL   Reader.seek  s     	7H--<<<DGQG[G[GjGjHl l m m Z))666!Lz++:::>>F2L::.L%l+&7  "~~r   c                     U R                   $ )z,Return the current position within the file.rJ   r}   s    r   tellReader.tell&  s    ~~r   c                 "    [         R                  er   r   rD   rE   s     r   truncateReader.truncate*  r   r   c                    US:X  a  gUS:  a<  U R                   U l        U R                  5       U R                  R	                  5       -   $ [        U R                  5      U:  a  U R                  U5      $ U R                  U R                   :X  a  U R                  5       $ U R                  U5        U R                  U5      $ )z6Read up to size bytes from the object and return them.r   r   )rA   rB   _read_from_bufferrs   rR   rP   rv   _fill_bufferr   s     r   rR   Reader.read.  s    19AX!ZZDN))+d.>.>.C.C.EEE
 t!!"d*))$//>>TZZ'))++$%%d++r   c                      U R                  US9$ )zThis is the same as read().)rE   )rR   r   s     r   read1Reader.read1B  s    yydy##r   c                 v    U R                  [        U5      5      nU(       d  gX!S[        U5      & [        U5      $ )zDRead up to len(b) bytes into b, and return the number of bytes read.r   N)rR   rP   )rD   bdatas      r   readintoReader.readintoF  s1    yyQ *3t94yr   c                 l   US:w  a  [        S5      e[        R                  " 5       nU R                  U R                  :X  a  [        U R                  5      S:X  d  U R                  R                  U R                  5      nUR                  U5        U =R                  [        U5      -  sl        UR                  U R                  5      (       a   UR                  5       $ U R                  5         U R                  U R                  :X  d  M  [        U R                  5      S:X  d  M  UR                  5       $ )zCRead up to and including the next newline.  Returns the bytes read.rU   z(limits other than -1 not implemented yetr   )r1   r   BytesIOrB   rA   rP   rv   readlinerw   writeendswithr   getvalue)rD   limitline	line_parts       r   r   Reader.readlineN  s    B;%&PQQ
 zz|>>TZZ/C8J8J4Kq4P**33D4I4IJIJJy!NNc)n,N!!$"7"788 }} !!# >>TZZ/C8J8J4Kq4P }}r   c                     US:  a  UO[        U R                  5      nU R                  R                  U5      nU =R                  [        U5      -  sl        U$ )z:Remove at most size bytes from our buffer and return them.r   )rP   rv   rR   rB   )rD   rE   parts      r   r   Reader._read_from_bufferf  sI     qytc$*<*<&=!!&&t,#d)#r   c                    [        XR                  R                  5      n[        U R                  5      U:  a  U R                  U R
                  :X  dx  U R                  R                  U R                  5      nUS:X  a  [        R                  S5        g[        U R                  5      U:  a  U R                  U R
                  :X  d  Mv  g g g g )Nr   z reached EOF while filling bufferT)
maxrv   _chunk_sizerP   rB   rA   fillrs   r{   rZ   )rD   rE   
bytes_reads      r   r   Reader._fill_buffero  s    4++778$$$%,T^^tzz5Q++001A1ABJQ?@	 $$$%,T^^tzz5Q,5Q,r   c                     U $ r   rh   r}   s    r   	__enter__Reader.__enter__w      r   c                 $    U R                  5         g r   )r~   rD   exc_typeexc_valexc_tbs       r   __exit__Reader.__exit__z  s    

r   c                 p    SU R                   R                  < SU R                  < SU R                  < S3$ N(z, )	__class__rb   rl   rm   r}   s    r   __str__Reader.__str__}  )    NN##  OO
 	
r   c                 n    U R                   R                  < SU R                  < SU R                  < S3$ N(container=, blob=r   r   r}   s    r   __repr__Reader.__repr__  )    NN##  OO
 	
r   )r@   rm   rl   rv   rw   rB   rs   rA   r   ra   )!rb   rc   rd   re   rf   r@   DEFAULT_BUFFER_SIZEr
   r)   r,   DEFAULT_MAX_CONCURRENCYrG   r~   propertyr|   r   r   r   r   rL   r   r   rR   r   r   r   r   r   r   r   r   r   rg   rh   r   r   r+   r+      s     E ,&00??30@$ " "& #-"6"6"C"C 2&,($0

r   r+   c                       \ rS rSrSrSrS\4S jrS rS r	S r
\S 5       rS	 rS
 r\R                   R"                  4S jrSS jrS rS rS rS rS rS rS rS rSrg)r.   i  ziWrites bytes to Azure Blob Storage.

Implements the io.BufferedIOBase interface of the standard library.
Nc                     Xl         X l        U=(       d    0 U l        XPl        SU l        SU l        SU l        [        R                  " 5       U l	        / U l
        [        X1U5      U l        g r?   )rl   rm   _blob_kwargs_min_part_size_total_size_total_parts_bytes_uploadedr   r   rv   _block_listr:   r@   rD   r8   r9   r2   r&   r'   s         r   rG   Writer.__init__  s`      )'-2+ ZZ\ &f>
r   c                     g r   rh   r}   s    r   flushWriter.flush      r   c                     [         R                  SU 5        U R                  (       d  / U l        SU l        [         R                  SU 5        g)zDo not commit block list on abort.

Uploaded (uncommitted) blocks will be garbage collected after 7 days.

See also https://stackoverflow.com/a/69673084/5511061.z %s: terminating multipart uploadNz%s: terminated multipart upload)r{   rZ   r|   r   r@   r}   s    r   	terminateWriter.terminate  s8     	7>{{!DDJ6=r   c                    [         R                  S5        U R                  (       d  [         R                  SU 5        U R                  R	                  5       S:  a  U R                  5         U R                  R                  " U R                  40 U R                  D6  / U l        S U l        [         R                  SU 5        g g )Nrz   z%s: completing multipart uploadr   z%s: completed multipart upload)
r{   rZ   r|   rv   r   _upload_partr@   commit_block_listr   r   r}   s    r   r~   Writer.close  s    _%{{LL:DA!!&&(1,!!#JJ(()9)9OT=N=NO!DDJLL94@ r   c                     U R                   S L $ r   r   r}   s    r   r|   Writer.closed  r   r   c                     gz+Return True if the stream supports writing.Trh   r}   s    r   writableWriter.writable  r   r   c                     gzyIf False, seek(), tell() and truncate() will raise IOError.

We offer only tell support, and no seek or truncate support.Trh   r}   s    r   r   Writer.seekable  r   r   c                 "    [         R                  er   r   rD   rV   r   s      r   rL   Writer.seek  r   r   c                 "    [         R                  er   r   r   s     r   r   Writer.truncate  r   r   c                     U R                   $ z#Return the current stream position.r   r}   s    r   r   Writer.tell      r   c                 .    [         R                  " S5      eNzdetach() not supportedr   r}   s    r   r   Writer.detach      %%&>??r   c                 d   [        U[        5      (       d   [        S[        < S[        U5      < 35      eU R                  R                  U5        U =R                  [        U5      -  sl        U R                  R                  5       U R                  :  a  U R                  5         [        U5      $ )zWrite the given bytes (binary string) to the Azure Blob Storage file.

There's buffering happening under the covers, so this may not actually
do any HTTP transfer right away.input must be one of , got: r[   _BINARY_TYPES	TypeErrortyperv   r   r   rP   r   r   r   rD   r   s     r   r   Writer.write  s     !]++-QUVWQXYZZ  #CF"""$(;(;;1vr   c                 X   U R                   S-   nU R                  R                  5       nU R                  U-   S-
  n [	        U5      R                  S5      n[        R                  " UR                  5       5      nU R                  R                  S5        U R                  R                  XPR                  R                  U5      5        U R                  R                  [        R                   R"                  R%                  US95        [&        R)                  SXUS-  5        U =R                   S-  sl         U =R                  U-  sl        [*        R,                  " U R                  R                  5       5      U l        U R                  R                  S[*        R.                  5        g )Nr       r   )block_idz+uploading part #%i, %i bytes (total %.3fGB)g      A)r   rv   r   r   strzfillbase64	b64encodeencoderL   r@   stage_blockrR   r   appendr   r\   r9   	BlobBlockr{   infor   r   SEEK_END)rD   part_numcontent_length
range_stopzero_padded_part_numr  s         r   r   Writer._upload_part  sK   $$q(++002))N:Q>
	
  #8}227;##$8$?$?$AB"

x););)@)@)PQ 2 2 < <h < OP9j;&>	

 	Q.ZZ(:(:(?(?(AB2;;/r   c                     U $ r   rh   r}   s    r   r   Writer.__enter__  r   r   c                 L    Ub  U R                  5         g U R                  5         g r   r   r~   r   s       r   r   Writer.__exit__      NNJJLr   c                 p    SU R                   R                  < SU R                  < SU R                  < S3$ r   r   r}   s    r   r   Writer.__str__  r   r   c                     U R                   R                  < SU R                  < SU R                  < SU R                  < S3$ )Nr   r   z, min_part_size=r   )r   rb   rl   rm   r   r}   s    r   r   Writer.__repr__   s2    NN##  OO	
 	
r   )
r@   r   rm   r   r   rl   rv   r   r   r   r   rb   rc   rd   re   rf   r@   _DEFAULT_MIN_PART_SIZErG   r   r   r~   r   r|   r   r   r
   r)   r   rL   r   r   r   r   r   r   r   r   r   rg   rh   r   r   r.   r.     s     E 0?*
>	A " " #-"6"6"C"C && @"04

r   r.   c                       \ rS rSrSrSrS\4S jrS rS r	S r
\S 5       rS	 rS
 r\R                   R"                  4S jrSS jrS rS rS rS rS rS rS rS rSrg)r0   i)  zhAppend bytes to Azure Blob Storage.

Implements the io.BufferedIOBase interface of the standard library.Nc                     Xl         X l        U=(       d    0 U l        XPl        SU l        [
        R                  " 5       U l        [        X1U5      U l	        g r?   )
rl   rm   r   r   r   r   r   rv   r:   r@   r   s         r   rG   AppendWriter.__init__/  sH      )'-2+ZZ\ &f>
r   c                     g r   rh   r}   s    r   r   AppendWriter.flushA  r   r   c                 j    U R                   (       d"  [        R                  " 5       U l        SU l        gg)z3AppendBlob cannot be aborted, so we do nothing hereN)r|   r   r   rv   r@   r}   s    r   r   AppendWriter.terminateD  s#    {{!#DDJ r   c                     U R                   (       d6  U R                  R                  5       S:  a  U R                  5         SU l        gg)zCNo action needed here, as the AppendBlob is automatically committedr   N)r|   rv   r   r   r@   r}   s    r   r~   AppendWriter.closeJ  s8    {{!!&&(1,!!#DJ r   c                     U R                   S L $ r   r   r}   s    r   r|   AppendWriter.closedQ  r   r   c                     gr   rh   r}   s    r   r   AppendWriter.writableU  r   r   c                     gr   rh   r}   s    r   r   AppendWriter.seekableY  r   r   c                 "    [         R                  er   r   r   s      r   rL   AppendWriter.seek_  r   r   c                 "    [         R                  er   r   r   s     r   r   AppendWriter.truncatec  r   r   c                     U R                   $ r  r  r}   s    r   r   AppendWriter.tellg  r  r   c                 .    [         R                  " S5      er
  r   r}   s    r   r   AppendWriter.detachk  r  r   c                 d   [        U[        5      (       d   [        S[        < S[        U5      < 35      eU R                  R                  U5        U =R                  [        U5      -  sl        U R                  R                  5       U R                  :  a  U R                  5         [        U5      $ )Nr  r  r  r  s     r   r   AppendWriter.writen  s    !]++6CT!WM  	  #CF"""$(;(;;1vr   c                    U R                   R                  5       nU R                  R                  " SU[        R
                  R                  R                  R                  SS.U R                  D6  [        R                  " 5       U l         g )NF)r   	blob_type	overwriterh   )rv   r   r@   upload_blobr   r\   r9   BlobType
APPENDBLOBr   r   r   )rD   r   s     r   r   AppendWriter._upload_party  sl    !!**,

 	
mm((11<<	
 		
  ZZ\r   c                     U $ r   rh   r}   s    r   r   AppendWriter.__enter__  r   r   c                 L    Ub  U R                  5         g U R                  5         g r   r+  r   s       r   r   AppendWriter.__exit__  r-  r   c                 p    SU R                   R                  < SU R                  < SU R                  < S3$ r   r   r}   s    r   r   AppendWriter.__str__  r   r   c                 n    U R                   R                  < SU R                  < SU R                  < S3$ r   r   r}   s    r   r   AppendWriter.__repr__  r   r   )r@   r   rm   rl   rv   r   r   r   r2  rh   r   r   r0   r0   )  s    K E ,?$ " " #-"6"6"C"C && @	*

r   r0   )!rf   r  r   rY   smart_open.bytebufferr
   smart_open.constantsazure.core.exceptionsr   azure.storage.blobImportErrorMISSING_DEPS	getLoggerrb   r{   bytes	bytearray
memoryviewr  r   r3  r   r   r   r!   r   r:   objectr<   BufferedIOBaser+   r.   r0   rh   r   r   <module>rh     s    W  	     
		8	$	:. Y	 H%  Q!    DK"S ',/>cB*, ,^A
R A
HZ
R Z
zo
2$$ o
i  Ls   B" "B-,B-