File: //usr/local/lib/python3.10/dist-packages/rich/__pycache__/file_proxy.cpython-310.pyc
o
.��f� � @ s^ d dl Z d dlmZmZmZmZ ddlmZ ddlm Z er$ddl
mZ G dd� de j�Z
dS ) � N)�IO�
TYPE_CHECKING�Any�List� )�AnsiDecoder)�Text)�Consolec @ s| e Zd ZdZdddee ddfdd�Zedee fd d
��Zdede fdd
�Z
dedefdd�Zddd�Z
defdd�ZdS )� FileProxyzAWraps a file (e.g. sys.stdout) and redirects writes to a console.�consoler �file�returnNc C s || _ || _g | _t� | _d S �N)�_FileProxy__console�_FileProxy__file�_FileProxy__bufferr �_FileProxy__ansi_decoder)�selfr r � r �:/usr/local/lib/python3.10/dist-packages/rich/file_proxy.py�__init__ s zFileProxy.__init__c C s | j S )zGet proxied file.)r �r r r r �rich_proxied_file s zFileProxy.rich_proxied_file�namec C s t | j|�S r )�getattrr )r r r r r �__getattr__ s zFileProxy.__getattr__�textc s� t |t�stdt|�j� ���� j}g }|r7|�d�\}}}|r/|�d�|�| � |� � n|�|� n|s|rd� j
}|� td��� fdd�|D ��}|�|� W d � t
|�S 1 s_w Y t
|�S )Nz"write() argument must be str, not �
� c 3 s � | ] }� j �|�V qd S r )r �decode_line)�.0�liner 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* r r r, )r r1 r r r �flush2 s zFileProxy.flushc C s
| j �� S r )r �filenor r r r r4 8 s
zFileProxy.fileno)r
N)r'