
    fV                        d dl mZ d dlZej                  dk7  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      Z G d dee      Zy)    )annotationsNwin32)contextmanager)ContextManagerIteratorTextIOcast   DummyContext   )	PipeInput)
Vt100InputPosixPipeInputc                  0    e Zd ZdZddZddZddZddZy)_PipezCWrapper around os.pipe, that ensures we don't double close any end.c                b    t        j                         \  | _        | _        d| _        d| _        y )NF)ospiperead_fdwrite_fd_read_closed_write_closedselfs    Z/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/input/posix_pipe.py__init__z_Pipe.__init__   s&    &(ggi#dm!"    c                j    | j                   ryt        j                  | j                         d| _         y)z!Close read-end if not yet closed.NT)r   r   closer   r   s    r   
close_readz_Pipe.close_read   s&    
 r   c                j    | j                   ryt        j                  | j                         d| _         y)z"Close write-end if not yet closed.NT)r   r   r    r   r   s    r   close_writez_Pipe.close_write$   s&    
!r   c                D    | j                          | j                          y)zClose both read and write ends.N)r!   r#   r   s    r   r    z_Pipe.close,   s    r   NreturnNone)__name__
__module____qualname____doc__r   r!   r#   r     r   r   r   r      s    I#
!"r   r   c                  x     e Zd ZdZdZdd fdZeeddd              ZddZ	ddZ
ddZddZdd	Zdd
Z x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   c                    | _          G  fdd      }t         	  t        t         |                     j                  |        j                  xj                  dz  c_         j                  j                   _        y )Nc                  &    e Zd ZdZddZd fdZy)&PosixPipeInput.__init__.<locals>.Stdinutf-8c                     y)NTr,   )stdins    r   isattyz-PosixPipeInput.__init__.<locals>.Stdin.isattyG   s    r   c                0    j                   j                  S N)r   r   )r3   r   s    r   filenoz-PosixPipeInput.__init__.<locals>.Stdin.filenoJ   s    yy(((r   N)r&   bool)r&   int)r(   r)   r*   encodingr4   r7   r   s   r   Stdinr0   D   s    H)r   r;   r   )r   superr   r	   r   	send_text	__class___id)r   _pipe_textr;   r>   s   `   r   r   zPosixPipeInput.__init__@   s`    		) 	) 	feg./u 	a>>%%r   c              #     K   t               }	 t        ||       |j                          y # |j                          w xY ww)N)r@   rA   )r   r   r    )clstextr   s      r   createzPosixPipeInput.createT   s3      w	 t488JJLDJJLs   A. AA  Ac                X    t        j                  | j                  j                  |       y r6   )r   writer   r   r   datas     r   
send_byteszPosixPipeInput.send_bytes]   s    
##T*r   c                v    t        j                  | j                  j                  |j	                  d             y)zSend text to the input.r1   N)r   rG   r   r   encoderH   s     r   r=   zPosixPipeInput.send_text`   s#    
##T[[%9:r   c                    t               S r6   r   r   s    r   raw_modezPosixPipeInput.raw_moded   
    ~r   c                    t               S r6   r   r   s    r   cooked_modezPosixPipeInput.cooked_modeg   rO   r   c                8    | j                   j                          y)zClose pipe fds.N)r   r#   r   s    r   r    zPosixPipeInput.closej   s     			r   c                     d| j                    S )z@
        This needs to be unique for every `PipeInput`.
        zpipe-input-)r?   r   s    r   typeahead_hashzPosixPipeInput.typeahead_hashr   s     TXXJ''r   ) )r@   r   rA   strr&   r'   )rD   rV   r&   zIterator[PosixPipeInput])rI   bytesr&   r'   )rI   rV   r&   r'   )r&   zContextManager[None]r%   )r&   rV   )r(   r)   r*   r+   r?   r   classmethodr   rE   rJ   r=   rN   rQ   r    rT   __classcell__)r>   s   @r   r   r   2   sN    	 C&(   +; (r   )
__future__r   sysplatformr   
contextlibr   typingr   r   r   r	   utilsr   baser   vt100r   __all__r   r   r,   r   r   <module>rc      sX    " 

||w  	 % 9 9     
 <D(Z D(r   