
    /Jf;                         d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
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  e j        e          Z G d de          Zd ZdS )    N)IOBase)ProtocolError)ReadTimeoutError)parsers)set_socket_timeout)IncompleteReadErrorr   ResponseStreamingError)ScalarTypes)XMLParseError)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eZedfdZefdZd Zd Zd ZdS )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                 0    || _         || _        d| _        d S )Nr   )_raw_stream_content_length_amount_read)self
raw_streamcontent_lengths      T/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/botocore/response.py__init__zStreamingBody.__init__5   s     %-    c                     d S N r   s    r   __del__zStreamingBody.__del__:   s	     	r   c                     	 t          | j        |           dS # t          $ r t                              dd            w xY w)z&Set the timeout seconds on the socket.zbCannot access the socket object of a streaming response.  It's possible the interface has changed.T)exc_infoN)r   r   AttributeErrorloggererror)r   timeouts     r   r   z StreamingBody.set_socket_timeout@   se    		t/99999 	 	 	LL- 	     	s	    (Ac                 X    	 | j                                         S # t          $ r Y dS w xY w)NF)r   readabler    r   s    r   r%   zStreamingBody.readableW   s>    	#,,... 	 	 	55	s    
))Nc                 >   	 | j                             |          }nE# t          $ r}t          |j        |          d}~wt
          $ r}t          |          d}~ww xY w| xj        t          |          z  c_        ||s|dk    r| 	                                 |S )zhRead at most amt bytes from the stream.

        If the amt argument is omitted, read all data.
        )endpoint_urlr"   N)r"   r   )
r   readURLLib3ReadTimeoutErrorr   urlURLLib3ProtocolErrorr	   r   len_verify_content_length)r   amtchunkes       r   r(   zStreamingBody.read]   s    
	2$))#..EE& 	@ 	@ 	@"Q????# 	2 	2 	2(q1111	2SZZ';u;q '')))s    
A=A
AAc                 4    | j                                         S r   )r   	readlinesr   s    r   r2   zStreamingBody.readlinesq   s    ))+++r   c                 6    |                      | 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__t   s     8999r   c                 Z    |                      | j                  }|r|S t                      )z-Return the next 1k chunk from the raw stream.)r(   r5   StopIteration)r   current_chunks     r   __next__zStreamingBody.__next__x   s.    		$":;; 	!  oor   c                     | j         S r   )r   r   s    r   	__enter__zStreamingBody.__enter__   s    r   c                 8    | j                                          d S r   r   close)r   typevalue	tracebacks       r   __exit__zStreamingBody.__exit__   s         r   Fc              #     K   d}|                      |          D ]L}||z                       d          }|dd         D ]}|                    |          d         V   |d         }M|r|                    |          d         V  dS dS )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   )r4   
splitlines)r   
chunk_sizekeependspendingr/   lineslines          r   
iter_lineszStreamingBody.iter_lines   s       %%j11 	  	 Eu_0066Ecrc
 3 3ooh//22222BiGG 	2$$X..q111111	2 	2r   c              #   L   K   	 |                      |          }|dk    rdS |V  ")z\Return an iterator to yield chunks of chunk_size bytes from the raw
        stream.
        Tr   N)r(   )r   rG   r9   s      r   r4   zStreamingBody.iter_chunks   s=      	  IIj11M##		 r   c                     | j         E| j        t          | j                   k    r*t          | j        t          | j                             d S d S )N)actual_bytesexpected_bytes)r   r   intr   r   s    r   r-   z$StreamingBody._verify_content_length   so     +0AS F
 F
 1
 1
 &!."4#788    ,+ 1
 1
r   c                 4    | j                                         S r   )r   tellr   s    r   rS   zStreamingBody.tell   s    $$&&&r   c                 8    | j                                          dS )z*Close the underlying http response stream.Nr>   r   s    r   r?   zStreamingBody.close   s         r   r   )__name__
__module____qualname____doc__r5   r   r   r   r%   r(   r2   r6   r:   r<   rC   nextrL   r4   r-   rS   r?   r   r   r   r   r   &   s'       
 
   
    .     (, , ,: : :       ! ! ! D$7% 2 2 2 2 &9        
 
 
' ' '! ! ! ! !r   r   c                 P   | j         d         }|j        |j        d}|d         dk    r|j        |d<   nC| j        r2t          |j        |d                             d                    |d<   n
|j        |d<   t          j	        |          }||
                    || j                  fS )Nprotocol)headersstatus_coder]   i,  bodyr\   zcontent-length)metadatar\   r]   contenthas_streaming_outputr   rawgetr   create_parserparseoutput_shape)operation_modelhttp_responser[   response_dictparsers        r   get_responserk      s    '
3H ($0 M ]#s** - 5f		- 6 -}Y7;;<LMM!
 !
f !. 5f"8,,F&,,3   r   )loggingior   urllib3.exceptionsr   r+   r   r)   botocorer   botocore.compatr   botocore.exceptionsr   r	   r
   r   botocore.hooksr   	getLoggerrU   r!   r   rk   r   r   r   <module>rt      s4          D D D D D D J J J J J J       . . . . . .          !           ) ) ) ) ) ) 2 2 2 2 2 2 
	8	$	$K! K! K! K! K!F K! K! K!\    r   