
    ]h                     
   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZmZ d dlmZ ddlmZ ddl m!Z!m"Z" dd	l#m$Z$m%Z% dd
l&m'Z'm(Z(m)Z)m*Z*m+Z+ er$d dl m,Z, ddl&m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5  ede6e7      Z8de9de9dee9   dee7e	f   ded   deee9e9f   ee9e9f   f   fdZ:de	de9de9dee7e	f   de6f
dZ; G d d e<      Z= G d! d"e<      Z> G d# d$ee8         Z?y)%    N)BytesIOStringIO)AnyCallablecastDict	GeneratorGenericIOIteratorListOptionaloverloadTupleTypeVarUnionTYPE_CHECKING)DecodeErrorHttpResponseErrorIncompleteReadError)with_current_context   )!validate_and_format_range_headers)parse_length_from_content_rangeprocess_storage_error)deserialize_blob_propertiesget_page_ranges_result)adjust_blob_size_for_encryptiondecrypt_blob&get_adjusted_download_range_and_offsetis_encryption_v2parse_encryption_data)IncrementalDecoder)_EncryptionData)AzureBlobStorage)BlobOperations)BlobProperties)StorageConfigurationTstart_range	end_rangelengthencryption_optionsencryption_datar$   returnc                 |    d\  }}|j                  d      |j                  d      t        | |||      S | |f||ffS )N)r   r   keyresolver)getr    )r*   r+   r,   r-   r.   start_offset
end_offsets          b/var/www/core.comfia.cic-ware.com/crm/lib/python3.12/site-packages/azure/storage/blob/_download.pyprocess_range_and_offsetr7   ,   s`      $L*e$04F4J4J:4V4b5	 	 #lJ%???    datar4   r5   
encryptionc           	         | t        d      dj                  t        |             }|r|j                  d      |j                  d      W	 t	        |j                  d      xs d|j                  d      |j                  d      |||| j
                  j                        S |S # t        $ r}t        d| j
                  |      |d }~ww xY w)	NzResponse cannot be None.r8   r1   r2   requiredFzDecryption failed.)messageresponseerror)	
ValueErrorjoinlistr3   r   r>   headers	Exceptionr   )r9   r4   r5   r:   contentr?   s         r6   process_contentrF   >   s    |344hhtDz"G:>>%(4
z8R8^	rz*3eu%z*%%  N  	r#,@4==`eflqq	rs   AB% %	C.CCc                   T   e Zd Z	 	 	 	 	 d"dddededededed	ed
eeef   ded   dedee   dee	eeef         dee
eee   gdf      deddfdZdedeeef   fdZdeeddf   fdZdeddfdZdedeeef   fdZdeddfdZdededdfdZdededefdZded edeeef   fd!Zy)#_ChunkDownloaderNclientr&   
total_size
chunk_sizecurrent_progressr*   r+   validate_contentr-   r.   r$   streamparallelnon_empty_rangesprogress_hookkwargsr/   c                 `   || _         || _        || _        || _        || _        || _        |
| _        |rt        j                         nd | _	        |rt        j                         nd | _
        || _        |r|
j                         nd| _        || _        || _        |	| _        || _        || _        y Nr   )rI   rP   rK   rJ   start_index	end_indexrN   	threadingLockstream_lockprogress_lockrQ   tellstream_startprogress_totalr-   r.   rM   request_options)selfrI   rJ   rK   rL   r*   r+   rM   r-   r.   rN   rO   rP   rQ   rR   s                  r6   __init__z_ChunkDownloader.__init__U   s    "  0 %$&" /79>>+T19Y^^-t* .6FKKM1 / #5. !1%r8   chunk_startc                     || j                   z   | j                  kD  r| j                  }||fS || j                   z   }||fS N)rK   rV   r_   ra   	chunk_ends      r6   _calculate_rangez!_ChunkDownloader._calculate_range   sH    (4>>9I I%% $doo5II%%r8   c              #      K   | j                   }|| j                  k  r$| || j                  z  }|| j                  k  r#y y wrc   )rU   rV   rK   )r_   indexs     r6   get_chunk_offsetsz"_ChunkDownloader.get_chunk_offsets   s>       dnn$KT__$E dnn$s   >AAc                     | j                  |      \  }}| j                  ||dz
        \  }}||z
  }|dkD  r$| j                  ||       | j                  |       y y )Nr   r   )rf   _download_chunk_write_to_stream_update_progress)r_   ra   re   
chunk_data_r,   s         r6   process_chunkz_ChunkDownloader.process_chunk   se    !%!6!6{!CY,,[)a-H
A[(A:!!*k:!!&) r8   c                 T    | j                  |      \  }}| j                  ||dz
        S )Nr   )rf   rk   rd   s      r6   yield_chunkz_ChunkDownloader.yield_chunk   s.    !%!6!6{!CY##KQ??r8   r,   c                    | j                   r+| j                   5  | xj                  |z  c_        d d d        n| xj                  |z  c_        | j                  r'| j                  | j                  | j                         y y # 1 sw Y   =xY wrc   )rZ   r]   rQ   rJ   )r_   r,   s     r6   rm   z!_ChunkDownloader._update_progress   sz    ## .##v-#. . 6)t22DOOD . .s   BB
rn   c                 6   | j                   rf| j                   5  | j                  j                  | j                  || j                  z
  z          | j                  j                  |       d d d        y | j                  j                  |       y # 1 sw Y   y xY wrc   )rY   rN   seekr\   rU   write)r_   rn   ra   s      r6   rl   z!_ChunkDownloader._write_to_stream   s|    !! .  !2!2kDDTDT6T!UV!!*-. . KKj)	. .s   ABBgiven_range_startgiven_range_endc                 h    | j                   y| j                   D ]  }||d   k  r y|d   |k  r y y)NFstartTend)rP   )r_   rw   rx   source_ranges       r6   _do_optimizez_ChunkDownloader._do_optimize   sW       ( 11 	L g!66 e$'88 	" r8   re   c           	         | j                   t        d      t        |||| j                   | j                        \  }}| j	                  |d   |d         r|d   |d   z
  dz   }d|z  }||fS t        |d   |d   | j                        \  }}d}	d}
|	rtd }	  | j                  j                  d||| j                  | j                  | j                  d| j                  \  }}	 t        ||d   |d   | j                         }d	}	|	rtj&                  }| j                  j)                  d      r(|j*                  j,                  | j                  d   _        |fS # t        $ r}t        |       Y d }~d }~ww xY w# t        t        t         f$ r7}|
dz  }
|
dk  rt        ||
      |t#        j$                  d       Y d }~d }~ww xY w)Nz0Required argument is missing: encryption_optionsr   r       )check_content_md5T   rangerange_get_content_md5rM   data_stream_totaldownload_stream_currentFr?   modified_access_conditions )r-   r@   r7   r.   r}   r   rM   rI   downloadrJ   r]   r^   r   r   rF   r   r   timesleepcontent_lengthr3   
propertiesetagif_match)r_   ra   re   download_rangeoffsetr   rn   range_headerrange_validationretry_activeretry_totalr>   ro   r?   s                 r6   rk   z _ChunkDownloader._download_chunk   s   ""*OPP!9It/F/FH\H\"
 ^A.q0AB+A.1BBQFN >1JN >))K .Oq!q!"&"7"7.*L*  LK $
1"6$++"6"6 #*.>)-)>)>*.//040C0C# ..#KAx"!06!9fQiQUQhQh!iJ#(L! , &44N ##''(DENVNaNaNfNf$$%ABK>))% ) 1)%001 ,->L "1$K"a'/UCNJJqMM	"s1   AE % E< 	E9$E44E9<G-GG)NNNNN)__name__
__module____qualname__intboolr   strr   r   r   r   r`   r   rf   r	   ri   rp   bytesrr   rm   rl   r}   rk   r   r8   r6   rH   rH   T   s    8<"&;?HL-& -& -& 	-&
 -& -& -& -& !cN-& ""34-& -& 3--& #4S#X#78-&  #x})=t)C DE-& -&  
!-&^&C &E#s(O &%9S$_#= %* * *@s @uUCZ/@ @Es Et E*5 *s *t *c C D 22*3 2*3 2*5PSCT 2*r8   rH   c            
       l    e Zd ZdZdededee   deddf
dZdefd	Z	de
e   fd
ZdefdZeZdefdZy)_ChunkIteratorz,Iterator for chunks in blob download stream.sizerE   
downloaderrK   r/   Nc                 ^    || _         || _        || _        || _        d | _        |dk(  | _        y rT   )r   _chunk_size_current_content_iter_downloader_iter_chunks	_complete)r_   r   rE   r   rK   s        r6   r`   z_ChunkIterator.__init__   s4    	% ' *BFr8   c                     | j                   S rc   r   r_   s    r6   __len__z_ChunkIterator.__len__      yyr8   c                     | S rc   r   r   s    r6   __iter__z_ChunkIterator.__iter__  s    r8   c                    | j                   rt        d      | j                  sEt        | j                        | j
                  kD  r| j                         S d| _         | j                  S | j                  s| j                  j                         | _        t        | j                        | j
                  k\  r| j                         S 	 t        | j                        }| xj                  | j                  j                  |      d   z  c_        | j                         S # t        $ r+}d| _         | j                  r| j                  cY d }~S |d }~ww xY w)NzDownload completeTr   )r   StopIterationr   lenr   r   _get_chunk_datar   ri   nextrr   )r_   
next_chunkes      r6   __next__z_ChunkIterator.__next__  s$   >> 344$$4(()D,<,<<++--!DN(((   $ 5 5 G G ID t$$%)9)99''))	d//0J!!T%:%:%F%Fz%RST%UU! ##%%  	!DN$$,,,G		s%   AD 	E&EE
EEc                 t    | j                   d | j                   }| j                   | j                  d  | _         |S rc   )r   r   )r_   rn   s     r6   r   z_ChunkIterator._get_chunk_data/  s=    **+=T-=-=>
 $ 5 5d6F6F6G Hr8   )r   r   r   __doc__r   r   r   rH   r`   r   r   r   r   r   r   r   r8   r6   r   r      sp    6#S #5 #hGW>X #fi #nr # (5/ &% &< D r8   r   c                      e Zd ZU dZeed<   	 eed<   	 ded<   	 eed<   	 	 	 	 	 	 	 	 	 	 	 	 d(dd	d
ddee   dee   dede	ee
f   dedededee   dee   de
ddfdZd Zd)dZed        Zd Zdee   fdZed*dedefd       Zedddee   defd       Zd*dddedee   defdZdefd Zd!ee   defd"Zd# Zd$ Zd+d%Zd,d&Zd+d'Zy)-StorageStreamDownloaderz<
    A streaming object to download from Azure Storage.
    name	containerr'   r   r   Nclientsr%   configr(   r*   r+   rM   r-   max_concurrencyencodingdownload_clsrR   r/   c                    || _         |	| _        d| _        || _        || _        || _        || _        || _        |
| _        || _	        |xs i | _
        |j                  dd       | _        || _        d | _        d | _        d| _        d| _        d | _        d | _        d| _        d| _        d| _        d| _        d | _        d | _        d| _        | j
                  xs d| _        || j                  d<   | j                  j9                  d      | j                  j9                  d      | j;                          | j                  s| j                  j<                  n| j                  j>                  }| j6                  }| j                  | j                  |z
  |k  r| j                  }n||z   dz
  }tA        ||| j                  | j                  | j&                        \  | _!        | _"        | jG                         | _        tI        d	| j                  jJ                        | _%        | j                   | jJ                  _         | j                  | jJ                  _        | j                  | jJ                  _        d
| j6                   d| j                  | j                  n| j"                  dz
   d| j"                   | jJ                  _&        d | jJ                  _'        y )Nr   rQ   r8   Tclsr1   r2   r   r'   zbytes -/)(r   r   r   _clients_config_start_range
_end_range_max_concurrency	_encoding_validate_content_encryption_optionspop_progress_hook_request_options	_response_location_moder   
_file_size_non_empty_ranges_encryption_data_download_offset_raw_download_offset_read_offset_current_content_offset
_text_mode_decoder_first_chunk_download_startr3   _get_encryption_data_requestmax_single_get_sizemax_chunk_get_sizer7   _initial_range_initial_offset_initial_requestr   r   content_rangecontent_md5)r_   r   r   r*   r+   rM   r-   r   r   r   r   r   rR   first_get_sizeinitial_request_startinitial_request_ends                   r6   r`   z StorageStreamDownloader.__init__E  s    	"	'# /!!1#5#; $jj$? &"36!%=A !"$%!'($*.8< #005A (4e$##''.:d>V>V>Z>Z[e>f>r--/ 594J4JDLL,,PTP\P\PoPo 	 !% 4 4??&4??=R+RUc+c"&//"7."H1"L4L!OO$$!!5
1T1 ..0/1J1JK#yy$(NN!  $yy+1$2F2F1Gq?C?ZDOO`d`o`ors`s+ttu,0OO+<*>% '+#r8   c                     | j                   S rc   r   r   s    r6   r   zStorageStreamDownloader.__len__  r   r8   c                 (   | j                   j                  dd       }t        | j                   d<   t        d | j                  j
                  j                  di | j                         }t        |j                        | _	        || j                   d<   y )Nr   r'   r   )
r   r   r   r   r   blobget_propertiesr"   metadatar   )r_   r   r   s      r6   r   z4StorageStreamDownloader._get_encryption_data_request  s    ,,00='Be$*,MDMM,>,>,M,M,fPTPePe,fg
 !6j6I6I J (4e$r8   c                     t        | j                        r| j                  | j                  k\  S | j                  | j                  k\  S rc   )r!   r   r   r   r   r   s    r6   _download_completez*StorageStreamDownloader._download_complete  s:    D112((DII55((DII55r8   c                    t        | j                  d   | j                  d   dd| j                        \  }}d}d}|r	 t        t        t
        t           t        f    | j                  j                  j                  d||| j                  d dd| j                        \  }}|| _        t        |j                  j                        | _        | j                   t#        d      t%        | j                   | j&                        | _        | j(                  O| j*                  Ct-        | j                   | j*                  z
  | j(                  | j*                  z
  dz         | _        n<| j*                  | j                   | j*                  z
  | _        n| j                   | _        	 | j.                  dk(  rd| _        n7t;        | j<                  d   | j<                  d   | j>                        | _        d}|r| xjH                  tK        | j8                        z  c_$        | xjL                  jN                  z  c_&        |j                  jP                  dk(  r8	 | j                  jR                  jU                         }
tW        |
      d   | _,        | jZ                  sC| j                  j]                  d      r(|j                  j^                  | j                  d   _0        |S # t0        $ r}| j*                  |j2                  r|j2                  j4                  d	k(  rs	  | j                  j                  j                  d| j                  ddd
| j                  \  }}n!# t0        $ r}	t7        |	       Y d }	~	nd }	~	ww xY wd| _        d| _        nt7        |       Y d }~d }~ww xY w# t@        t0        tB        f$ r8}|dz  }|dk  rt1        ||      |tE        jF                  d       Y d }~d }~ww xY w# t0        $ r Y rw xY w)Nr   r   F)start_range_requiredend_range_requiredr   Tr   r   z?Required Content-Range response header is missing or malformed.i  )rM   r   r   r8   r   PageBlobr   r   )1r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   r   r   r   r   minr   r   r>   status_coder   r   rF   r   r   r   r   r   r   r   r   r   r   	blob_type	page_blobget_page_rangesr   r   r   r3   r   r   )r_   r   r   r   r   location_moder>   r?   ro   r   page_rangess              r6   r   z(StorageStreamDownloader._initial_request  s   )J""!&$"44*
&& 11*.uXc]C5G/HJe$--J\J\JeJe K&*:%)%;%;&*,-K ++K +'x '4# #B(BUBUBcBc"d??*$%fgg"A$//SWShSh"i??.43D3D3P #DOOd6G6G$G[_[l[lIlopIp qDI&&2 $$2C2C CDI $DI.99>,/D),; ,,Q/,,Q/00	-D)  %} H 	T%:%:!;;!!X%<%<<! ((J6"mm55EEG)?)LQ)O& &&4+@+@+D+DEa+bKSK^K^KcKcD!!">?Ho % 1$$,ENND^D^beDe1&Admm&8&8&A&A '-1-C-C./45' #33	'8 - 1-a001 !"DI&'DO)%0'1@ ():KH q !#+E?UJ

1	" % so    E#K! $AN' 7O6 !	N$*1NAMN	M<'M72N7M<<NN$'O3;-O..O36	PPc                 0   | j                   rt        d      | j                  rt        j                  d       d}| j
                  r| j                  s| j
                  r8| j                  t        | j                        z   }t        | j                        }n| j                  }d}| j                  | j                  z   }t        d| j                  j                  | j                  | j                  | j                  j                   |||| j"                  | j$                  | j&                  | j(                  d| j*                  }| j
                  r| j                  nd}t-        | j                  t/        t0        |      || j                  j                         S )	a  
        Iterate over chunks in the download stream. Note, the iterator returned will
        iterate over the entire download content, regardless of any data that was
        previously read.

        NOTE: If the stream has been partially read, some data may be re-downloaded by the iterator.

        :returns: An iterator of the chunks in the download stream.
        :rtype: Iterator[bytes]

        .. admonition:: Example:

            .. literalinclude:: ../samples/blob_samples_hello_world.py
                :start-after: [START download_a_blob_in_chunk]
                :end-before: [END download_a_blob_in_chunk]
                :language: python
                :dedent: 12
                :caption: Download a blob using chunks().
        zRStream has been partially read in text mode. chunks is not supported in text mode.z<Encoding is ignored with chunks as only bytes are supported.Nr   )rI   rP   rJ   rK   rL   r*   r+   rM   r-   r.   use_locationr8   )r   rE   r   rK   r   )r   r@   r   warningswarnr   r   r   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   )r_   iter_downloaderrz   rL   r{   initial_contents         r6   chunkszStorageStreamDownloader.chunks  sV   ( ??qrr>>MMXY  (?(?  ,,s43H3H/II#&t'<'<#= ,,#$ &&2C. }}))!%!7!799<<::!1!!%!7!7#'#;#; $ 5 5!00 ''O 483D3D$//#0&||66	8 	8r8   c                      y rc   r   )r_   r   s     r6   readzStorageStreamDownloader.readY      r8   )charsr  c                     y rc   r   )r_   r  s     r6   r  zStorageStreamDownloader.read]  r  r8   c                @   |dkD  r!| j                   rt        j                  d       |dkD  r|t        d      | j                   s|t        d      | j                  r|dkD  rt        d      | j                  du r|t        d      |d	k(  s3|d	k(  s.| j
                  r2| j                  t        | j                        k\  r| j                   sd
S dS | j                  s|| j                   vd| _         t        j                  | j                         d      | _        | j                  j                  t        t        | j                        | j
                        | _        n| j                  d| _        | j                  r$t               }||d	k  rt         j"                  n|}n!t%               }|d	kD  r|nt         j"                  }|t         j"                  k(  }d	}| j                  }t'        t        | j                        | j                  z
  ||z
        }|j)                  | j                  |||z          }||z  }| xj                  |z  c_        | xj*                  |z  c_        | j-                          ||z
  }	|	d	kD  r| j
                  s| j.                  | j0                  z   }| j.                  | j2                  z   }
| j4                  dkD  }t7        d| j8                  j:                  | j<                  | j2                  | j>                  j@                  | j*                  ||
||| jB                  | jD                  | jF                  | jH                  | jJ                  d| jL                  }d| _'        |jQ                         }|r| j                  s|r| j2                  | j0                  z
  | j>                  j@                  kD  rod	dl)}|jT                  jW                  | j4                        5 }tY        |j[                  t]        |j^                        |jQ                                      ddd       n|D ]  }|j_                  |        | ja                          n@tc        |d      x}1|	d	kD  r+|je                  |      \  }}| xj0                  t        |      z  c_        | xjf                  |z  c_3        | j                  r9| j                  -| j                  j                  || j
                        | _        n|| _        |	t        | j                        k  r|j)                  | j                  d|	       }n|j)                  | j                        }|| _        | xj*                  |z  c_        |	|z  }	| j-                          tc        |d      x}|	d	kD  r+|ji                         }| j                  s8| j                   r,	 t        t        |      j                  | j                         }|S |S # 1 sw Y   xY w# tj        $ r t        j                  d        w xY w)a  
        Read the specified bytes or chars from the stream. If `encoding`
        was specified on `download_blob`, it is recommended to use the
        chars parameter to read a specific number of chars to avoid decoding
        errors. If size/chars is unspecified or negative all bytes will be read.

        :param int size:
            The number of bytes to download from the stream. Leave unspecified
            or set negative to download all bytes.
        :keyword Optional[int] chars:
            The number of chars to download from the stream. Leave unspecified
            or set negative to download all chars. Note, this can only be used
            when encoding is specified on `download_blob`.
        :returns:
            The requested data as bytes or a string if encoding was specified. If
            the return value is empty, there is no more data to read.
        :rtype: T
        zSize parameter specified with text encoding enabled. It is recommended to use chars to read a specific number of characters instead.Nz#Cannot specify both size and chars.z$Must specify encoding to read chars.z>Stream has been partially read in text mode. Please use chars.Fz>Stream has been partially read in bytes mode. Please use size.r   r8    Tstrict)finalr   rI   rP   rJ   rK   rL   r*   r+   rN   rO   rM   r-   r.   r   rQ   zEncountered a decoding error while decoding blob data from a partial read. Try using the `chars` keyword instead to read in text mode.r   )6r   r   r   r@   r   r   r   r   r   codecsgetincrementaldecoderr   decoder   r   r   sysmaxsizer   r   rv   r   _check_and_report_progressr   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   ri   concurrent.futuresfuturesThreadPoolExecutorrB   mapr   rp   _complete_readr   rr   r   getvalueUnicodeDecodeError)r_   r   r  output_streamreadallcountrz   r,   r  	remainingr{   rO   r   chunks_iter
concurrentexecutorr   chunkrn   r   r9   s                        r6   r  zStorageStreamDownloader.readb  ss   & "9MMC "9*BCC~~%"3CDD??tby]^^??e#(9]^^ AI!((T-I-ISQUQfQfMg-g"nn34"45#49S"DOHF88HRDM$(MM$8$8UD112$:Q:Q %9 %SD!__$#DO ??$JM"'-5A:3;;5D#IM!84D#++% ,,S../$2N2NNPTW\P\]""4#8#8uv~#NO$$,$T!'')5L	q=!8!8((4+@+@@E&&2C,,q0H) }}))!%!7!799<<::!%!2!2!$!!%!7!7#'#;#; $ 5 5!00"11 ''J" !&D
 %668KtT-B-B!BdllFeFe e-#++>>t?T?TU YaX\\01I1IJ&88:   '2 =
"00<= ##% !%[$ 77uDUV1;1G1G1N.J))S_<)--?-4==+D040D0DZW[WnWn0D0o-0:- 3t'<'<#==,2243H3H)3TU,2243H3HI37D0%%-%%I335# !%[$ 77uDUV& %%'4>>E4(//? tW H & R s   *=W0)W= 0W:= Xc                 "    | j                         S )z
        Read the entire contents of this blob.
        This operation is blocking until all data is downloaded.

        :returns: The requested data as bytes or a string if encoding was specified.
        :rtype: T
        )r  r   s    r6   r  zStorageStreamDownloader.readall  s     yy{r8   rN   c                 L   | j                   rt        d      | j                  rt        j                  d       | j
                  dkD  }|rPd}t        j                  dk\  r|j                         st        |      	 |j                  |j                                | j                  | j                  z
  }|dk  ryt        | j                         | j"                  z
  }| j"                  }|j%                  t'        t(        | j                   |||z                }| xj"                  |z  c_        | xj                  |z  c_        | j*                  r&| j+                  | j                  | j                         | j,                  r|S | j.                  | j                  z   }	| j.                  | j                  z   }
t1        d	| j2                  j4                  | j6                  | j                  | j8                  j:                  | j                  |	|
||| j<                  | j>                  | j@                  | jB                  | j*                  d| jD                  }|roddl#}|jH                  jK                  | j
                        5 }tM        |jO                  tQ        |jR                        |jU                                      ddd       n&|jU                         D ]  }|jS                  |        | jW                          |S # t        t        f$ r}t        |      |d}~ww xY w# 1 sw Y   >xY w)
af  Download the contents of this file to a stream.

        :param IO[bytes] stream:
            The stream to download to. This can be an open file-handle,
            or any writable stream. The stream must be seekable if the download
            uses more than one parallel connection.
        :returns: The number of bytes read.
        :rtype: int
        zTStream has been partially read in text mode. readinto is not supported in text mode.zEEncoding is ignored with readinto as only byte streams are supported.r   z&Target stream handle must be seekable.)r   Nr   r  r   ),r   r@   r   r   r   r   r  version_infoseekableru   r[   NotImplementedErrorAttributeErrorr   r   r   r   r   rv   r   r   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r  r  r  rB   r  r   rp   ri   r  )r_   rN   rO   error_messageexcremaining_sizecurrent_remainingrz   r  
data_startdata_endr   r  r   r!  s                  r6   readintoz StorageStreamDownloader.readinto  s    ??stt>>MMab ((1,DM4'0A //9FKKM*
 T%6%66Q   5 569U9UU,,T%)>)>uUM^E^)_`a$$-$U" 1 1499= ""!!))D,=,==
''$))3% 
==%%!33yy||66!.."!33#77 11,,--
 ##

" %##66t7L7LM QYX\\,Z-E-EF"446   $557 0((/0 	o (8 9 /S89Z s$   ;K7 9=L7LLLL#c                     | j                   | _        | j                   | _        | j                   | _        t	        | j
                        | _        y)z/Adjusts all offsets to the end of the download.N)r   r   r   r   r   r   r   r   s    r6   r  z&StorageStreamDownloader._complete_readN  s9     $		$(II! II'*4+@+@'A$r8   c                     | j                   rJ| j                  t        | j                        k(  r'| j                  | j                  | j
                         yyy)zReports progress if necessary.N)r   r   r   r   r   r   r   s    r6   r  z2StorageStreamDownloader._check_and_report_progressU  sH     4#?#?3tG\G\C]#] 5 5tyyA $^r8   c                     t        j                  dt               | j                  rt	        d      || _        | j                         S )aq  DEPRECATED: Download the contents of this file.

        This operation is blocking until all data is downloaded.

        This method is deprecated, use func:`readall` instead.

        :param int max_concurrency:
            The number of parallel connections with which to download.
        :returns: The contents of the file as bytes.
        :rtype: bytes
        z3content_as_bytes is deprecated, use readall insteadz\Stream has been partially read in text mode. content_as_bytes is not supported in text mode.)r   r   DeprecationWarningr   r@   r   r  )r_   r   s     r6   content_as_bytesz(StorageStreamDownloader.content_as_bytes\  sJ     	A	
 ?? O P P !0||~r8   c                     t        j                  dt               | j                  rt	        d      || _        || _        | j                         S )a  DEPRECATED: Download the contents of this blob, and decode as text.

        This operation is blocking until all data is downloaded.

        This method is deprecated, use func:`readall` instead.

        :param int max_concurrency:
            The number of parallel connections with which to download.
        :param str encoding:
            Test encoding to decode the downloaded bytes. Default is UTF-8.
        :returns: The content of the file as a str.
        :rtype: str
        z2content_as_text is deprecated, use readall insteadz[Stream has been partially read in text mode. content_as_text is not supported in text mode.)r   r   r2  r   r@   r   r   r  )r_   r   r   s      r6   content_as_textz'StorageStreamDownloader.content_as_texts  sQ     	@	
 ?? N O O !0!||~r8   c                     t        j                  dt               | j                  rt	        d      || _        | j                  |       | j                  S )a'  DEPRECATED: Download the contents of this blob to a stream.

        This method is deprecated, use func:`readinto` instead.

        :param IO[T] stream:
            The stream to download to. This can be an open file-handle,
            or any writable stream. The stream must be seekable if the download
            uses more than one parallel connection.
        :param int max_concurrency:
            The number of parallel connections with which to download.
        :returns: The properties of the downloaded blob.
        :rtype: Any
        z6download_to_stream is deprecated, use readinto insteadz^Stream has been partially read in text mode. download_to_stream is not supported in text mode.)r   r   r2  r   r@   r   r.  r   )r_   rN   r   s      r6   download_to_streamz*StorageStreamDownloader.download_to_stream  sT     	D	
 ?? Q R R !0fr8   )NNNNNNr   NNNN)r/   N)r  )r   )r   zUTF-8) r   r   r   r   r   __annotations__r   r   r   r   r   r   r`   r   r   propertyr   r   r   r   r  r   r)   r  r  r   r.  r  r  r3  r5  r7  r   r8   r6   r   r   5  s    I0N6  =
I-
 '+)-%)#'!%-1 "&+/\+#\+ '\+ c]	\+
 C=\+ \+ !cN\+ \+ \+ \+ 3-\+ x(\+ \+ 
\+|4 6 6
aF98 98v  a   -1 Xc] a  OT O OXc] Oa Ob Or%y OS ObBB.4r8   r   )@r  r  rW   r   r   ior   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   azure.core.exceptionsr   r   r   azure.core.tracing.commonr   _shared.request_handlersr   _shared.response_handlersr   r   _deserializer   r   _encryptionr   r   r    r!   r"   r#   r$   
_generatedr%   _generated.operationsr&   _modelsr'   _shared.modelsr(   r   r   r)   r   r7   rF   objectrH   r   r   r   r8   r6   <module>rG     sJ    
          V U : G ] M  ),,5'4 C@@@ SM@ S#X	@
 /0@ 5c?E#s(O+,@$# S c tTWY\T\~ bg ,f*v f*R5V 5pp	gaj p	r8   