3 �ga � @ s� d dl mZmZ d dlmZ d dlmZmZmZ ddl m Z mZ ddlm Z ddlmZmZmZ dd lmZ d ZG dd� de�ZG d d� de�ZG dd� ded�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZdS )� )�ABCMeta�abstractmethod)�chain)�Callable�Iterable�Union� )� Conversion� Formatting� )�Environment)�smart_decode�smart_encode�UTF8)�HTTPMessages� +-----------------------------------------+ | NOTE: binary data not shown in terminal | +-----------------------------------------+c @ s e Zd ZdZdS )�DataSuppressedErrorN)�__name__� __module__�__qualname__�message� r r �/usr/lib/python3.6/streams.pyr s r c @ s e Zd ZdZeZdS )�BinarySuppressedErrorzbAn error indicating that the body is binary and won't be written, e.g., for terminal output).N)r r r �__doc__�BINARY_SUPPRESSED_NOTICEr r r r r r s r c @ sb e Zd ZdZdeeegdf d�dd�Zed�dd �Ze e e d�d d��Ze e d�dd �ZdS )� BaseStreamz&Base HTTP message output stream class.TN)�msg�on_body_chunk_downloadedc C s( |s|st �|| _|| _|| _|| _dS )z� :param msg: a :class:`models.HTTPMessage` subclass :param with_headers: if `True`, headers will be included :param with_body: if `True`, body will be included N)�AssertionErrorr �with_headers� with_bodyr )�selfr r r r r r r �__init__ s zBaseStream.__init__)�returnc C s | j jj� S )zReturn the headers' bytes.)r �headers�encode)r! r r r �get_headers3 s zBaseStream.get_headersc C s dS )z)Return an iterator over the message body.Nr )r! r r r � iter_body7 s zBaseStream.iter_bodyc c s� | j r| j� V dV | jr�y,x&| j� D ]}|V | jr(| j|� q(W W n6 tk r~ } z| j rfdV |jV W Y dd}~X nX dS )z#Return an iterator over `self.msg`.s � N)r r&