File: //lib/python3.6/site-packages/botocore/__pycache__/response.cpython-36.pyc
3
�T_ � @ s� d dl Z d dlZd dlmZ d dlmZ d dlmZmZm Z d dl
mZmZ d dl
mZ d dlmZ eje�ZG dd � d e�Zd
d� ZdS )� N)�ScalarTypes)�first_non_none_response)�json�set_socket_timeout�
XMLParseError)�IncompleteReadError�ReadTimeoutError)r )�parsersc @ sh e Zd ZdZdZdd� Zdd� Zddd �Zd
d� Zdd
� Z e Z
ddd�Zefdd�Zdd� Z
dd� 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.
� c C s || _ || _d| _d S )Nr )�_raw_stream�_content_length�_amount_read)�selfZ
raw_streamZcontent_length� r �/usr/lib/python3.6/response.py�__init__+ s zStreamingBody.__init__c C s: yt | 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 Ztimeoutr r r r 0 s z StreamingBody.set_socket_timeoutNc C sv y| j j|�}W n0 tk
r@ } zt|j|d��W Y dd}~X nX | jt|�7 _|dksj| rr|dkrr| j� |S )zhRead at most amt bytes from the stream.
If the amt argument is omitted, read all data.
)Zendpoint_urlr Nr )r �read�URLLib3ReadTimeoutErrorr Zurlr �len�_verify_content_length)r Zamt�chunk�er r r r G s zStreamingBody.readc C s | j | j�S )zCReturn an iterator to yield 1k chunks from the raw stream.
)�iter_chunks�_DEFAULT_CHUNK_SIZE)r r r r �__iter__Y s zStreamingBody.__iter__c C s | j | j�}|r|S t� �dS )z6Return the next 1k chunk from the raw stream.
N)r r �
StopIteration)r �
current_chunkr r r �__next__^ s zStreamingBody.__next__c c sh d}xL| j |�D ]>}|| jd�}x"|dd� D ]}|j� d V q0W |d }qW |rd|j� d V dS )z�Return 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.
� TN� r ���r% )r �
splitlines)r �
chunk_size�pendingr �lines�liner r r �
iter_linesh s zStreamingBody.iter_linesc c s$ x| j |�}|dkrP |V qW dS )z\Return an iterator to yield chunks of chunk_size bytes from the raw
stream.
r# N)r )r r'