
     h                         d dl Z d dl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 d dlmZ  e j&                  e      Z G d	 d
e      Zd Zy)    N)IOBase)ProtocolError)ReadTimeoutError)ScalarTypesparsers)XMLParseErrorset_socket_timeout)IncompleteReadErrorr   ResponseStreamingError)first_non_none_responsec                       e Zd ZdZdZd Zd Zd Zd ZddZ	d	 Z
d
 Zd Zd Zd Zd ZeZedfdZefdZd Zd Zd Zy)StreamingBodyae  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                 .    || _         || _        d| _        y )Nr   )_raw_stream_content_length_amount_read)self
raw_streamcontent_lengths      m/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/botocore/response.py__init__zStreamingBody.__init__6   s    %-    c                      y N r   s    r   __del__zStreamingBody.__del__;   s     	r   c                 x    	 t        | j                  |       y# t        $ r t        j	                  d        w xY w)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	   z StreamingBody.set_socket_timeoutA   s>    	t//9 	; 	s     9c                 V    	 | j                   j                         S # t        $ r Y yw xY w)NF)r   readabler   r   s    r   r$   zStreamingBody.readableV   s.    	##,,.. 		s    	((Nc                 ,   	 | j                   j                  |      }| xj                  t        |      z  c_        ||s|dkD  r| j                          |S # t        $ r}t        |j                  |      d}~wt
        $ r}t        |      d}~ww xY w)zhRead 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*   zStreamingBody.read\   s    
	2$$))#.E 	SZ';uq '') ' 	@"Q??# 	2(q11	2s#   A 	BA66BBBc                 .   	 | j                   j                  |      }| xj                  |z  c_        |dk(  rt        |      dkD  r| j                          |S # t        $ r}t        |j                  |      d}~wt
        $ r}t        |      d}~ww xY w)zcRead bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.r&   Nr)   r   )
r   readintor+   r   r,   r-   r   r   r.   r/   )r   bamount_readr2   s       r   r4   zStreamingBody.readintop   s    	2**33A6K 	[(!A
 '') ' 	@"Q??# 	2(q11	2s#   A 	B A77BBBc                 6    | j                   j                         S r   )r   	readlinesr   s    r   r8   zStreamingBody.readlines   s    ))++r   c                 8    | j                  | j                        S )z:Return an iterator to yield 1k chunks from the raw stream.)iter_chunks_DEFAULT_CHUNK_SIZEr   s    r   __iter__zStreamingBody.__iter__   s     8 899r   c                 T    | j                  | j                        }|r|S t               )z-Return the next 1k chunk from the raw stream.)r*   r;   StopIteration)r   current_chunks     r   __next__zStreamingBody.__next__   s'    		$":":;  or   c                     | j                   S r   )r   r   s    r   	__enter__zStreamingBody.__enter__   s    r   c                 8    | j                   j                          y r   r   close)r   typevalue	tracebacks       r   __exit__zStreamingBody.__exit__   s     r   Fc              #      K   d}| j                  |      D ];  }||z   j                  d      }|dd D ]  }|j                  |      d     |d   }= |r|j                  |      d    yyw)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   )r:   
splitlines)r   
chunk_sizekeependspendingr1   lineslines          r   
iter_lineszStreamingBody.iter_lines   s      %%j1 	 Eu_006Ecr
 3ooh/223BiG		 
 $$X.q11 s   A,A.c              #   D   K   	 | j                  |      }|dk(  ry| w)z\Return an iterator to yield chunks of chunk_size bytes from the raw
        stream.
        r   N)r*   )r   rM   r?   s      r   r:   zStreamingBody.iter_chunks   s/       IIj1M#	 s    c                     | j                   M| j                  t        | j                         k7  r*t        | j                  t        | j                               y y )N)actual_bytesexpected_bytes)r   r   intr
   r   s    r   r/   z$StreamingBody._verify_content_length   s\     +0A0AS  F
 1
 &!.."4#7#78 1
+r   c                 6    | j                   j                         S r   )r   tellr   s    r   rY   zStreamingBody.tell   s    $$&&r   c                 8    | j                   j                          y)z*Close the underlying http response stream.NrD   r   s    r   rE   zStreamingBody.close   s     r   r   )__name__
__module____qualname____doc__r;   r   r   r	   r$   r*   r4   r8   r<   r@   rB   rI   nextrR   r:   r/   rY   rE   r   r   r   r   r   '   sp    
 
*( ,: ! D$7% 2 &9  
'!r   r   c                    | j                   j                  }|j                  |j                  d}|d   dk\  r|j                  |d<   nG| j
                  r,t        |j                  |d   j                  d            |d<   n|j                  |d<   t        j                  |      }||j                  || j                        fS )N)headersstatus_coderb   i,  bodyra   zcontent-length)service_modelresolved_protocolra   rb   contenthas_streaming_outputr   rawgetr   create_parserparseoutput_shape)operation_modelhttp_responseprotocolresponse_dictparsers        r   get_responserr      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   r-   r   r+   botocorer   r   botocore.compatr   r	   botocore.exceptionsr
   r   botocore.hooksr   	getLoggerr[   r    r   rr   r   r   r   <module>r{      sR      D J 
 3			8	$Y!F Y!xr   