a
    lcu)                     @   sP  U d dl Z e jdksJ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ g dZG dd deZi Zeeee f ee	g df  f e!d< ej"ee	g df ed dddZ#ej"eed dddZ$G dd dZ%G dd de%Z&dS )    Nwin32)AbstractEventLoop)
CallableContextManagerDict	GeneratorListOptionalSetTextIOTupleUnion)get_event_loop   )KeyPress   )Input)PosixStdinReader)Vt100Parser)
Vt100Inputraw_modecooked_modec                   @   s   e Zd ZU dZe Zee ed< e	ddddZ
eg df ed ddd	Zed d
ddZee d
ddZee d
ddZeed
ddZed d
ddZed d
ddZed
ddZed
ddZdS )r   zz
    Vt100 input for Posix systems.
    (This uses a posix file descriptor that can be registered in the event loop.)
    _fds_not_a_terminalN)stdinreturnc              
      s   z|   W nJ tjyV } z0dtjv r6td|ntd|W Y d }~n
d }~0 0 | }|  }|s|tjvrd}tj	||  tj
  tj| | _|   _g  _t j|jd _t fdd _d S )Nzidlelib.runz<Stdin is not a terminal. Running from Idle is not supported.zStdin is not a terminal.z*Warning: Input is not a terminal (fd=%r).
)encodingc                    s    j | S N)_bufferappend)Z	key_pressself V/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/input/vt100.py<lambda>U       z%Vt100Input.__init__.<locals>.<lambda>)filenoioUnsupportedOperationsysmodulesisattyr   r   stderrwriteflushaddr   _filenor   r   r   stdin_readerr   vt100_parser)r    r   er*   fdmsgr!   r   r"   __init__/   s0    
"


zVt100Input.__init__)input_ready_callbackr   c                 C   s
   t | |S )zj
        Return a context manager that makes this input active in the current
        event loop.
        )_attached_input)r    r6   r!   r!   r"   attachX   s    zVt100Input.attachr   c                 C   s   t | S )z{
        Return a context manager that makes sure that this input is not active
        in the current event loop.
        )_detached_inputr   r!   r!   r"   detach_   s    zVt100Input.detachc                 C   s&   | j  }| j| | j}g | _|S )zRead list of KeyPress.)r0   readr1   feedr   )r    dataresultr!   r!   r"   	read_keysf   s
    
zVt100Input.read_keysc                 C   s   | j   | j}g | _|S )zc
        Flush pending keys and return them.
        (Used for flushing the 'escape' key.)
        )r1   r-   r   )r    r?   r!   r!   r"   
flush_keyss   s    
zVt100Input.flush_keysc                 C   s   | j jS r   )r0   closedr   r!   r!   r"   rB      s    zVt100Input.closedc                 C   s   t | j S r   )r   r   r%   r   r!   r!   r"   r      s    zVt100Input.raw_modec                 C   s   t | j S r   )r   r   r%   r   r!   r!   r"   r      s    zVt100Input.cooked_modec                 C   s
   | j  S r   )r   r%   r   r!   r!   r"   r%      s    zVt100Input.filenoc                 C   s   d| j  S )Nzfd-)r/   r   r!   r!   r"   typeahead_hash   s    zVt100Input.typeahead_hash)__name__
__module____qualname____doc__setr   r
   int__annotations__r   r5   r   r   r8   r;   r   r   r@   rA   propertyboolrB   r   r   r%   strrC   r!   r!   r!   r"   r   %   s   
)r   _current_callbacks)NNN)inputcallbackr   c              
   #   s   t   tf}dd fdd}z| W n tyZ   tY n0  tf< z<dV  W  |r| |tf< qtf= n4 |rΈ| |tf< n
tf= 0 dS )z
    Context manager that makes this input active in the current event loop.

    :param input: :class:`~prompt_toolkit.input.Input` object.
    :param callback: Called when the input is ready to read.
    Nr9   c                      s   j r    dS )a:  Wrapper around the callback that already removes the reader when
        the input is closed. Otherwise, we keep continuously calling this
        callback, until we leave the context manager (which can happen a bit
        later). This fixes issues when piping /dev/null into a prompt_toolkit
        application.N)rB   remove_readerr!   rP   r3   rO   loopr!   r"   callback_wrapper   s    
z)_attached_input.<locals>.callback_wrapper)r   r%   rN   get
add_readerPermissionErrorEOFErrorrQ   )rO   rP   previousrT   r!   rR   r"   r7      s*    




r7   )rO   r   c              
   c   s   t  }|  }t||f}|r6|| d t||f< z&d V  W |r|||| |t||f< n|rz||| |t||f< 0 d S r   )r   r%   rN   rU   rQ   rV   )rO   rS   r3   rY   r!   r!   r"   r:      s    
r:   c                   @   sf   e Zd ZdZeddddZddddZeeed	d
dZeeed	ddZ	e
ddddZdS )r   z
    ::

        with raw_mode(stdin):
            ''' the pseudo-terminal stdin is now used in raw mode '''

    We ignore errors when executing `tcgetattr` fails.
    N)r%   r   c                 C   s:   || _ |  zt|| _W n tjy4   d | _Y n0 d S r   )r%   termios	tcgetattrattrs_beforeerror)r    r%   r!   r!   r"   r5      s    zraw_mode.__init__r9   c                 C   sx   zt | j}W n t jy$   Y nP0 | |tj |tj< | |tj |tj< d|tj	 t j
< t | jt j| d S )Nr   )rZ   r[   r%   r]   _patch_lflagttyZLFLAG_patch_iflagZIFLAGCCVMIN	tcsetattrTCSANOW)r    Znewattrr!   r!   r"   	__enter__   s    zraw_mode.__enter__attrsr   c                 C   s   |t jt jB t jB t jB  @ S r   rZ   ECHOICANONIEXTENISIGclsrg   r!   r!   r"   r^     s    zraw_mode._patch_lflagc                 C   s$   |t jt jB t jB t jB t jB  @ S r   )rZ   IXONIXOFFICRNLINLCRIGNCRrm   r!   r!   r"   r`     s    zraw_mode._patch_iflag)ar   c                 G   s<   | j d ur8zt| jtj| j  W n tjy6   Y n0 d S r   )r\   rZ   rc   r%   rd   r]   )r    rt   r!   r!   r"   __exit__"  s
    
zraw_mode.__exit__)rD   rE   rF   rG   rI   r5   re   classmethodr^   r`   objectru   r!   r!   r!   r"   r      s   	r   c                   @   s8   e Zd ZdZeeedddZeeedddZdS )r   z
    The opposite of ``raw_mode``, used when we need cooked mode inside a
    `raw_mode` block.  Used in `Application.run_in_terminal`.::

        with cooked_mode(stdin):
            ''' the pseudo-terminal stdin is now used in cooked mode. '''
    rf   c                 C   s   |t jt jB t jB t jB B S r   rh   rm   r!   r!   r"   r^   6  s    zcooked_mode._patch_lflagc                 C   s
   |t jB S r   )rZ   rq   rm   r!   r!   r"   r`   :  s    zcooked_mode._patch_iflagN)rD   rE   rF   rG   rv   rI   r^   r`   r!   r!   r!   r"   r   -  s
   r   )'r(   platform
contextlibr&   rZ   r_   asyncior   typingr   r   r   r   r   r	   r
   r   r   r   Zprompt_toolkit.eventloopr   Zkey_bindingr   baser   Zposix_utilsr   r1   r   __all__r   rN   rI   rJ   contextmanagerr7   r:   r   r   r!   r!   r!   r"   <module>   s4   
0o1R