o
    Ëý°jM  ã                   @   s^   d dl Z d dlmZmZmZmZ ddlmZ ddlm	Z	 er$ddl
mZ G dd„ de jƒZdS )	é    N)ÚListÚAnyÚIOÚTYPE_CHECKINGé   )ÚAnsiDecoder)ÚText)ÚConsolec                   @   sn   e Zd ZdZdddee ddfdd„Zedee fd	d
„ƒZdede	fdd„Z
dedefdd„Zddd„ZdS )Ú	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   úŽ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/rich/file_proxy.pyÚ__init__   s   zFileProxy.__init__c                 C   s   | j S )zGet proxied file.)r   ©r   r   r   r   Úrich_proxied_file   s   zFileProxy.rich_proxied_fileÚnamec                 C   s   t | j|ƒS r   )Úgetattrr   )r   r   r   r   r   Ú__getattr__   s   zFileProxy.__getattr__Útextc                    sÒ   t |tƒstdt|ƒj› �ƒ‚ˆ j}g }|r8| d¡\}}}|r0| d |¡| ¡ |d d …= n| |¡ n|s|reˆ j	}|� t
dƒ ‡ fdd„|D ƒ¡}| |¡ W d   ƒ t|ƒS 1 s`w   Y  t|ƒS )Nz"write() argument must be str, not Ú
Ú c                 3   s   � | ]	}ˆ j  |¡V  qd S r   )r   Údecode_line)Ú.0Úliner   r   r   Ú	<genexpr>,   s   € 
ÿz"FileProxy.write.<locals>.<genexpr>)Ú
isinstanceÚstrÚ	TypeErrorÚtypeÚ__name__r   Ú	partitionÚappendÚjoinr   r   ÚprintÚlen)r   r   ÚbufferÚlinesr!   Únew_liner   Úoutputr   r   r   Úwrite   s.   

ùÿ
üûzFileProxy.writec                 C   s.   | j }|r| j d |¡¡ |d d …= d S d S )Nr   )r   r   r+   r*   )r   r-   r   r   r   Úflush2   s
   þzFileProxy.flush)r   N)r'   Ú
__module__Ú__qualname__Ú__doc__r   r$   r   Úpropertyr   r   r   Úintr1   r2   r   r   r   r   r
      s    r
   )ÚioÚtypingr   r   r   r   Úansir   r   r   r   r	   Ú
TextIOBaser
   r   r   r   r   Ú<module>   s    