o
    ˷e4                     @   s   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 )    N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.returnNc                 C   s    t  \| _| _d| _d| _d S )NF)ospiperead_fdwrite_fd_read_closed_write_closedself r   V/var/www/ideatree/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.closer   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r   r   r      s    


r   c                       s   e Zd ZdZdZddededdf fdd	Zee	dd
ede
d  fddZdeddfddZdeddfddZded fddZded fddZdddZdef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    _pipe_textr   Nc                    sT   | _ G  fddd}t tt|   |  j jd7  _ jj _d S )Nc                       s0   e Zd ZdZdefddZdef fddZdS )z&PosixPipeInput.__init__.<locals>.Stdinutf-8r   c                 S   s   dS )NTr   stdinr   r   r   isattyE   s   z-PosixPipeInput.__init__.<locals>.Stdin.isattyc                    s    j jS N)r   r   r*   r   r   r   filenoH   s   z-PosixPipeInput.__init__.<locals>.Stdin.filenoN)r"   r#   r$   encodingboolr,   intr.   r   r   r   r   StdinB   s    r2   r   )r   superr   r   r   	send_text	__class___id)r   r'   r(   r2   r5   r   r   r   >   s   	
zPosixPipeInput.__init__textc                 c   s0    t  }zt||dV  W |  d S |  w )N)r'   r(   )r   r   r   )clsr8   r   r   r   r   createR   s
   zPosixPipeInput.createdatac                 C   s   t | jj| d S r-   )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   r<   r   r   encoder=   r   r   r   r4   ^   s   zPosixPipeInput.send_textc                 C      t  S r-   r	   r   r   r   r   raw_modeb      zPosixPipeInput.raw_modec                 C   r@   r-   r	   r   r   r   r   cooked_modee   rB   zPosixPipeInput.cooked_modec                 C   s   | j   dS )zClose pipe fds.N)r   r    r   r   r   r   r   h   s   zPosixPipeInput.closec                 C   s   d| j  S )z@
        This needs to be unique for every `PipeInput`.
        zpipe-input-)r6   r   r   r   r   typeahead_hashp   s   zPosixPipeInput.typeahead_hash)r&   r!   )r"   r#   r$   r%   r6   r   strr   classmethodr   r   r:   bytesr>   r4   r   rA   rC   r   rD   __classcell__r   r   r7   r   r   0   s    
)sysplatformr   
contextlibr   typingr   r   r   r   utilsr
   baser   vt100r   __all__r   r   r   r   r   r   <module>   s    