
    !i                         S SK r S SKJr  S SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJr  S SKJrJrJr  S SKJr  \ R&                  " \5      r " S	 S
\5      rS rg)    N)IOBase)ProtocolError)ReadTimeoutError)ScalarTypesparsers)XMLParseErrorset_socket_timeout)IncompleteReadErrorr   ResponseStreamingError)first_non_none_responsec                       \ rS rSrSrSrS rS rS rS r	SS	 jr
S
 rS rS rS rS rS r\r\S4S jr\4S jrS rS rS rSrg)StreamingBody'   aI  Wrapper class for an http response body.

This provides a few additional conveniences that do not exist
in the urllib3 model:

    * Set the timeout on the socket (i.e read() timeouts)
    * Auto validation of content length, if the amount of bytes
      we read does not match the content length, an exception
      is raised.

i   c                 *    Xl         X l        SU l        g )Nr   )_raw_stream_content_length_amount_read)self
raw_streamcontent_lengths      P/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/botocore/response.py__init__StreamingBody.__init__6   s    %-    c                     g N r   s    r   __del__StreamingBody.__del__;   s     	r   c                 z     [        U R                  U5        g! [         a    [        R	                  S5        e f = f)z&Set the timeout seconds on the socket.zaCannot access the socket object of a streaming response. It's possible the interface has changed.N)r	   r   AttributeErrorlogger	exception)r   timeouts     r   r	    StreamingBody.set_socket_timeoutA   s>    	t//9 	; 	s    !:c                 X     U R                   R                  5       $ ! [         a     gf = f)NF)r   readabler"   r   s    r   r(   StreamingBody.readableV   s.    	##,,.. 		s    
))Nc                 2    U R                   R                  U5      nU =R                  [        U5      -  sl        Ub  U(       d  US:  a  U R                  5         U$ ! [         a  n[        UR                  US9eSnAf[
         a  n[        US9eSnAff = f)zXRead at most amt bytes from the stream.

If the amt argument is omitted, read all data.
endpoint_urlerrorNr-   r   )
r   readURLLib3ReadTimeoutErrorr   urlURLLib3ProtocolErrorr   r   len_verify_content_length)r   amtchunkes       r   r/   StreamingBody.read\   s    
	2$$))#.E 	SZ';uq '') ' 	@"Q??# 	2(q11	2s#   A 
B'A;;B	BBc                 *    U R                   R                  U5      nU =R                  U-  sl        US:X  a  [        U5      S:  a  U R                  5         U$ ! [         a  n[        UR                  US9eSnAf[
         a  n[        US9eSnAff = f)zcRead bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.r+   Nr.   r   )
r   readintor0   r   r1   r2   r   r   r3   r4   )r   bamount_readr7   s       r   r:   StreamingBody.readintop   s    	2**33A6K 	[(!A
 '') ' 	@"Q??# 	2(q11	2s#   A 
B#A77B	BBc                 6    U R                   R                  5       $ r   )r   	readlinesr   s    r   r?   StreamingBody.readlines   s    ))++r   c                 8    U R                  U R                  5      $ )z:Return an iterator to yield 1k chunks from the raw stream.)iter_chunks_DEFAULT_CHUNK_SIZEr   s    r   __iter__StreamingBody.__iter__   s     8 899r   c                 ^    U R                  U R                  5      nU(       a  U$ [        5       e)z-Return the next 1k chunk from the raw stream.)r/   rC   StopIteration)r   current_chunks     r   __next__StreamingBody.__next__   s'    		$":":;  or   c                     U R                   $ r   )r   r   s    r   	__enter__StreamingBody.__enter__   s    r   c                 8    U R                   R                  5         g r   r   close)r   typevalue	tracebacks       r   __exit__StreamingBody.__exit__   s     r   Fc              #      #    SnU R                  U5       H=  nX4-   R                  S5      nUSS  H  nUR                  U5      S   v   M     US   nM?     U(       a  UR                  U5      S   v   gg7f)zReturn an iterator to yield lines from the raw stream.

This is achieved by reading chunk of bytes (of size chunk_size) at a
time from the raw stream, and then yielding lines from there.
r   TNr   )rB   
splitlines)r   
chunk_sizekeependspendingr6   lineslines          r   
iter_linesStreamingBody.iter_lines   s      %%j1E_006Ecr
ooh/22 #BiG	 2
 $$X.q11 s   A4A6c              #   H   #     U R                  U5      nUS:X  a  gUv   M  7f)zLReturn an iterator to yield chunks of chunk_size bytes from the raw
stream.
r   N)r/   )r   rY   rH   s      r   rB   StreamingBody.iter_chunks   s.       IIj1M#	 s    "c                     U R                   bK  U R                  [        U R                   5      :w  a'  [        U R                  [        U R                   5      S9eg g )N)actual_bytesexpected_bytes)r   r   intr
   r   s    r   r4   $StreamingBody._verify_content_length   s\     +0A0AS  F
 1
 &!.."4#7#78 1
+r   c                 6    U R                   R                  5       $ r   )r   tellr   s    r   rh   StreamingBody.tell   s    $$&&r   c                 8    U R                   R                  5         g)z*Close the underlying http response stream.NrO   r   s    r   rP   StreamingBody.close   s     r   )r   r   r   r   )__name__
__module____qualname____firstlineno____doc__rC   r   r   r	   r(   r/   r:   r?   rD   rI   rL   rT   nextr^   rB   r4   rh   rP   __static_attributes__r   r   r   r   r   '   sp    
 
*( ,: ! D$7% 2 &9  
'!r   r   c                    U R                   R                  nUR                  UR                  S.nUS   S:  a  UR                  US'   OLU R
                  (       a,  [        UR                  US   R                  S5      5      US'   OUR                  US'   [        R                  " U5      nXR                  X0R                  5      4$ )N)headersstatus_coderu   i,  bodyrt   zcontent-length)service_modelresolved_protocolrt   ru   contenthas_streaming_outputr   rawgetr   create_parserparseoutput_shape)operation_modelhttp_responseprotocolresponse_dictparsers        r   get_responser      s    ,,>>H (($00M ]#s* - 5 5f		-	- -}Y7;;<LM!
f !. 5 5f""8,F,,33  r   )loggingior   urllib3.exceptionsr   r2   r   r0   botocorer   r   botocore.compatr   r	   botocore.exceptionsr
   r   botocore.hooksr   	getLoggerrl   r#   r   r   r   r   r   <module>r      sP      D J 
 3			8	$Y!F Y!xr   