a
    lc4                     @   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                   @   sH   e Zd ZdZddddZddddZdddd	Zddd
dZdS )_PipezCWrapper around os.pipe, that ensures we don't double close any end.Nreturnc                 C   s    t  \| _| _d| _d| _d S )NF)ospiperead_fdwrite_fd_read_closed_write_closedself r   [/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/input/posix_pipe.py__init__   s    z_Pipe.__init__c                 C   s    | 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   s    z_Pipe.close_readc                 C   s    | j r
dS t| j d| _ dS )z"Close write-end if not yet closed.NT)r   r   r   r   r   r   r   r   close_write"   s    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)__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eedd fddZee	dee
d  dd	d
ZeddddZeddddZed dddZed dddZddddZe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    N)_pipe_textr   c                    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edddZed 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   r0   r   )r   superr   r   r   	send_text	__class___id)r   r%   r&   r0   r3   r   r   r   >   s    	
zPosixPipeInput.__init__)textr   c                 c   s0   t  }zt||dV  W |  n
|  0 d S )N)r%   r&   )r   r   r   )clsr6   r   r   r   r   createR   s    zPosixPipeInput.create)datar   c                 C   s   t | jj| d S r+   )r   writer   r   r   r9   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   r2   ^   s    zPosixPipeInput.send_textr   c                 C   s   t  S r+   r	   r   r   r   r   raw_modeb   s    zPosixPipeInput.raw_modec                 C   s   t  S r+   r	   r   r   r   r   cooked_modee   s    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-)r4   r   r   r   r   typeahead_hashp   s    zPosixPipeInput.typeahead_hash)r$   )r$   )r    r!   r"   r#   r4   r   strr   classmethodr   r   r8   bytesr<   r2   r   r>   r?   r   r@   __classcell__r   r   r5   r   r   0   s   )sysplatformr   
contextlibr   typingr   r   r   r   utilsr
   baser   Zvt100r   __all__r   r   r   r   r   r   <module>   s   