File: //opt/cppython/lib/python3.8/site-packages/botocore/__pycache__/response.cpython-38.pyc
U
KD�g; � @ s� d dl Z d dlmZ d dlmZ d dlmZ d dlm Z d dl
mZ d dlm
Z
mZmZ d dlmZ d d l
mZ d d
lmZ e �e�ZG dd� de�Zd
d� ZdS )� N)�IOBase)�
ProtocolError)�ReadTimeoutError)�parsers)�set_socket_timeout)�IncompleteReadErrorr �ResponseStreamingError)�ScalarTypes)�
XMLParseError)�first_non_none_responsec @ s� e Zd ZdZdZdd� Zdd� Zdd� Zd d
� Zd#dd
�Z dd� Z
dd� Zdd� Zdd� Z
dd� ZeZedfdd�Zefdd�Zdd� Zdd � Zd!d"� ZdS )$�
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 C s || _ || _d| _d S )Nr )�_raw_stream�_content_length�_amount_read)�selfZ
raw_stream�content_length� r �>/opt/cppython/lib/python3.8/site-packages/botocore/response.py�__init__5 s zStreamingBody.__init__c C s d S �Nr �r r r r �__del__: s zStreamingBody.__del__c C s: zt | j|� W n$ tk
r4 tjddd� � Y nX dS )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 �timeoutr r r r @ s �z StreamingBody.set_socket_timeoutc C s( z| j �� W S tk
r" Y dS X d S )NF)r
�readabler r r r r r W s zStreamingBody.readableNc
C s� z| j �|�}W nZ tk
r@ } zt|j|d��W 5 d}~X Y n, tk
rj } zt|d��W 5 d}~X Y nX | jt|�7 _|dks�|s�|dkr�| � � |S )zhRead at most amt bytes from the stream.
If the amt argument is omitted, read all data.
)Zendpoint_urlr N)r r )
r
�read�URLLib3ReadTimeoutErrorr �url�URLLib3ProtocolErrorr r �len�_verify_content_length)r �amt�chunk�er r r r ] s zStreamingBody.readc C s
| j �� S r )r
� readlinesr r r r r'