
    tni                         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dS )    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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      N/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/botocore/response.py__init__zStreamingBody.__init__6   s     %-    c                     d S N r   s    r   __del__zStreamingBody.__del__;   s	     	r   c                     	 t          | j        |           dS # t          $ r t                              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9999 	 	 	;   	s    &?c                 X    	 | j                                         S # t          $ r Y dS w xY w)NF)r   readabler   r   s    r   r$   zStreamingBody.readableV   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_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$))#..EE& 	@ 	@ 	@"Q????# 	2 	2 	2(q1111	2SZZ';u;q '')))    
A=A
AAc                 B   	 | j                             |          }nE# t          $ r}t          |j        |          d}~wt
          $ r}t          |          d}~ww xY w| xj        |z  c_        |dk    r't          |          dk    r| 	                                 |S )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   r5   zStreamingBody.readintop   s    	2*33A66KK& 	@ 	@ 	@"Q????# 	2 	2 	2(q1111	2[(!A

 '')))r3   c                 4    | j                                         S r   )r   	readlinesr   s    r   r9   zStreamingBody.readlines   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__   s     8999r   c                 Z    |                      | 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.    		$":;; 	!  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   )r;   
splitlines)r   
chunk_sizekeependspendingr1   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   rN   r@   s      r   r;   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   rZ   zStreamingBody.tell   s    $$&&&r   c                 8    | j                                          dS )z*Close the underlying http response stream.NrE   r   s    r   rF   zStreamingBody.close   s         r   r   )__name__
__module____qualname____doc__r<   r   r   r	   r$   r*   r5   r9   r=   rA   rC   rJ   nextrS   r;   r/   rZ   rF   r   r   r   r   r   '   s6       
 
   
    *     (   , , ,: : :       ! ! ! D$7% 2 2 2 2 &9        
 
 
' ' '! ! ! ! !r   r   c                 N   | j         j        }|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)headersstatus_coderc   i,  bodyrb   zcontent-length)service_modelresolved_protocolrb   rc   contenthas_streaming_outputr   rawgetr   create_parserparseoutput_shape)operation_modelhttp_responseprotocolresponse_dictparsers        r   get_responsers      s    ,>H ($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   r   botocore.compatr   r	   botocore.exceptionsr
   r   botocore.hooksr   	getLoggerr\   r    r   rs   r   r   r   <module>r|      s:          D D D D D D J J J J J J                       
 3 2 2 2 2 2		8	$	$Y! Y! Y! Y! Y!F Y! Y! Y!x    r   