o
    DfV                     @  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	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)contextmanager)ContextManagerIterator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   X/home/ubuntu/webapp/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   isattyG   s   z-PosixPipeInput.__init__.<locals>.Stdin.isattyintc                   s    j jS N)r   r   r.   r   r   r   filenoJ   s   z-PosixPipeInput.__init__.<locals>.Stdin.filenoN)r   r-   )r   r1   )r$   r%   r&   encodingr0   r3   r   r   r   r   StdinD   s    
r5   r   )r   superr   r   r   	send_text	__class___id)r   r)   r*   r5   r8   r   r   r   @   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   createT   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   `   s   zPosixPipeInput.send_textContextManager[None]c                 C     t  S r2   r
   r   r   r   r   raw_moded      zPosixPipeInput.raw_modec                 C  rF   r2   r
   r   r   r   r   cooked_modeg   rH   zPosixPipeInput.cooked_modec                 C  s   | j   dS )zClose pipe fds.N)r   r"   r   r   r   r   r   j   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_hashr   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   2   s    




)
__future__r   sysplatformr   
contextlibr   typingr   r   r   r   utilsr   baser   vt100r   __all__r   r   r   r   r   r   <module>   s    