o
    �õ±j‰  ã                   @  s¤   d dl mZ d dlZejdksJ ‚d dlZd dlmZ d dlmZm	Z	 d dl
mZmZ ddlmZ d	d
lmZ d	dlmZ dgZG dd„ dƒZG dd„ deeƒZdS )é    )ÚannotationsNÚwin32)ÚIterator)ÚAbstractContextManagerÚcontextmanager)ÚTextIOÚcasté   ©ÚDummyContexté   )Ú	PipeInput)Ú
Vt100InputÚPosixPipeInputc                   @  s8   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„ZdS )Ú_PipezCWrapper around os.pipe, that ensures we don't double close any end.ÚreturnÚNonec                 C  s    t  ¡ \| _| _d| _d| _d S )NF)ÚosÚpipeÚread_fdÚwrite_fdÚ_read_closedÚ_write_closed©Úself© r   ú’/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/prompt_toolkit/input/posix_pipe.pyÚ__init__   s   
z_Pipe.__init__c                 C  ó    | j rdS t | j¡ d| _ dS )z!Close read-end if not yet closed.NT)r   r   Úcloser   r   r   r   r   Ú
close_read   ó   
z_Pipe.close_readc                 C  r   )z"Close write-end if not yet closed.NT)r   r   r   r   r   r   r   r   Úclose_write%   r!   z_Pipe.close_writec                 C  s   |   ¡  |  ¡  dS )zClose both read and write ends.N)r    r"   r   r   r   r   r   -   s   z_Pipe.closeN©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r"   r   r   r   r   r   r      s    


r   c                      sx   e Zd ZdZdZdd ‡ fd
d„Zeedd!dd„ƒƒZd"dd„Z	d#dd„Z
d$dd„Zd$dd„Zd%dd„Zd&dd„Z‡  ZS )'r   a  
    Input that is send through a pipe.
    This is useful if we want to send the input programmatically into the
    application. Mostly useful for unit testing.

    Usage::

        with PosixPipeInput.create() as input:
            input.send_text('inputdata')
    r   Ú Ú_piper   Ú_textÚstrr   r   c                   sT   |ˆ _ G ‡ fdd„dƒ}tƒ  tt|ƒ ƒ¡ ˆ  |¡ ˆ j jd7  _ˆ jjˆ _d S )Nc                      s(   e Zd ZdZd
dd„Zd‡ fdd„Zd	S )z&PosixPipeInput.__init__.<locals>.Stdinúutf-8r   Úboolc                 S  s   dS )NTr   ©Ústdinr   r   r   ÚisattyH   s   z-PosixPipeInput.__init__.<locals>.Stdin.isattyÚintc                   s   ˆ j jS ©N)r   r   r.   r   r   r   ÚfilenoK   s   z-PosixPipeInput.__init__.<locals>.Stdin.filenoN)r   r-   )r   r1   )r$   r%   r&   Úencodingr0   r3   r   r   r   r   ÚStdinE   s    
r5   r   )r   Úsuperr   r   r   Ú	send_textÚ	__class__Ú_id)r   r)   r*   r5   ©r8   r   r   r   A   s   	
zPosixPipeInput.__init__ÚtextúIterator[PosixPipeInput]c                 c  s0   � t ƒ }zt||d�V  W | ¡  d S | ¡  w )N)r)   r*   )r   r   r   )Úclsr;   r   r   r   r   ÚcreateU   s
   €zPosixPipeInput.createÚdataÚbytesc                 C  s   t  | jj|¡ d S r2   )r   Úwriter   r   ©r   r?   r   r   r   Ú
send_bytes^   s   zPosixPipeInput.send_bytesc                 C  s   t  | jj| d¡¡ dS )zSend text to the input.r,   N)r   rA   r   r   ÚencoderB   r   r   r   r7   a   s   zPosixPipeInput.send_textúAbstractContextManager[None]c                 C  ó   t ƒ S r2   r
   r   r   r   r   Úraw_modee   ó   zPosixPipeInput.raw_modec                 C  rF   r2   r
   r   r   r   r   Úcooked_modeh   rH   zPosixPipeInput.cooked_modec                 C  s   | j  ¡  dS )zClose pipe fds.N)r   r"   r   r   r   r   r   k   s   zPosixPipeInput.closec                 C  s   d| j › �S )z@
        This needs to be unique for every `PipeInput`.
        zpipe-input-)r9   r   r   r   r   Útypeahead_hashs   s   zPosixPipeInput.typeahead_hash)r(   )r)   r   r*   r+   r   r   )r;   r+   r   r<   )r?   r@   r   r   )r?   r+   r   r   )r   rE   r#   )r   r+   )r$   r%   r&   r'   r9   r   Úclassmethodr   r>   rC   r7   rG   rI   r   rJ   Ú__classcell__r   r   r:   r   r   3   s    




)Ú
__future__r   ÚsysÚplatformr   Úcollections.abcr   Ú
contextlibr   r   Útypingr   r   Úutilsr   Úbaser   Úvt100r   Ú__all__r   r   r   r   r   r   Ú<module>   s    ÿ