File: //opt/alt/python37/lib/python3.7/site-packages/rich/__pycache__/file_proxy.cpython-37.pyc
B
��f� � @ s^ d dl Z d dlmZmZmZmZ ddlmZ ddlm Z erHddl
mZ G dd� de j�Z
dS ) � N)�IO�
TYPE_CHECKING�Any�List� )�AnsiDecoder)�Text)�Consolec @ sx e Zd ZdZdee dd�dd�Zeee d�dd ��Zee d
�dd�Z
eed
�dd�Zdd�dd�Z
ed�dd�ZdS )� FileProxyzAWraps a file (e.g. sys.stdout) and redirects writes to a console.r N)�console�file�returnc C s || _ || _g | _t� | _d S )N)�_FileProxy__console�_FileProxy__file�_FileProxy__bufferr �_FileProxy__ansi_decoder)�selfr r � r �@/opt/alt/python37/lib/python3.7/site-packages/rich/file_proxy.py�__init__ s zFileProxy.__init__)r
c C s | j S )zGet proxied file.)r )r r r r �rich_proxied_file s zFileProxy.rich_proxied_file)�namer
c C s t | j|�S )N)�getattrr )r r r r r �__getattr__ s zFileProxy.__getattr__)�textr
c s� t |t�stdt|�j� ���� j}g }xF|rn|�d�\}}}|r`|�d�|�| � |� � q*|�|� P q*W |r�� j
}|�, td��� fdd�|D ��}|�|� W d Q R X t
|�S )Nz"write() argument must be str, not �
� c 3 s | ]}� j �|�V qd S )N)r Zdecode_line)�.0�line)r r r � <genexpr>- s z"FileProxy.write.<locals>.<genexpr>)�
isinstance�str� TypeError�type�__name__r � partition�append�join�clearr r �print�len)r r �buffer�linesr �new_liner �outputr )r r �write s$
zFileProxy.writec C s, d� | j�}|r| j�|� | jd d �= d S )Nr )r'