Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /usr/local/lib/python3.9/site-packages/prompt_toolkit/input/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/lib/python3.9/site-packages/prompt_toolkit/input/__pycache__/win32.cpython-39.pyc
a

��Sh1x�@s�ddlmZddlZddlZddlmZddlmZddlm	Z	ddl
mZejdksZJ�esrddl
Z
dd	lmZdd
lmZmZmZddlmZmZddlmZmZmZmZmZdd
lmZddlmZm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3gd�Z4dZ5dZ6dZ7dZ8dZ9Gdd�de1�Z:Gdd�de:�Z;Gdd�d�Z<Gd d!�d!�Z=Gd"d#�d#�Z>e	dd$d%d&�d'd(��Z?e	dd%d)�d*d+��Z@Gd,d-�d-�ZAGd.d/�d/eA�ZBd0d1�d2d3�ZCdS)4�)�annotationsN)�abstractmethod)�get_running_loop)�contextmanager�)�SPHINX_AUTODOC_RUNNING�win32)�windll)�Array�byref�pointer)�DWORD�HANDLE)�Callable�ContextManager�Iterable�Iterator�TextIO��run_in_executor_with_context)�create_win32_event�wait_for_handles)�KeyPress)�Keys)�MouseButton�MouseEventType)�INPUT_RECORD�KEY_EVENT_RECORD�MOUSE_EVENT_RECORD�STD_INPUT_HANDLE�
EventTypes�)�REVERSE_ANSI_SEQUENCES)�Input)�Vt100Parser)�
Win32Input�ConsoleInputReader�raw_mode�cooked_mode�attach_win32_input�detach_win32_input�ic@s4eZdZdZdd�dd�Zeedd�dd���Zd	S)
�_Win32InputBasez;
    Base class for `Win32Input` and `Win32PipeInput`.
    �None��returncCst�|_dS�N)�
_Win32Handles�
win32_handles��self�r5�D/usr/local/lib/python3.9/site-packages/prompt_toolkit/input/win32.py�__init__Asz_Win32InputBase.__init__rcCsdSr0r5r3r5r5r6�handleDsz_Win32InputBase.handleN)�__name__�
__module__�__qualname__�__doc__r7�propertyrr8r5r5r5r6r,<s
r,cs�eZdZdZd'ddd��fdd�
Zdd	d
�dd�Zd	d
�dd�Zdd
�dd�Zdd
�dd�Ze	dd
�dd��Z
d	d
�dd�Zd	d
�dd�Zdd
�dd�Z
dd
�d d!�Zdd
�d"d#�Ze	d$d
�d%d&��Z�ZS)(r%z<
    `Input` class that reads from the Windows console.
    Nz
TextIO | Noner-)�stdinr/cs2t���t�|_||jr&t�|_nt�|_dSr0)�superr7�_is_win_vt100_input_enabled�_use_virtual_terminal_input�Vt100ConsoleInputReader�console_input_readerr&)r4r>��	__class__r5r6r7Os

zWin32Input.__init__�Callable[[], None]zContextManager[None])�input_ready_callbackr/cCs
t||�S)zj
        Return a context manager that makes this input active in the current
        event loop.
        )r))r4rGr5r5r6�attachZszWin32Input.attachr.cCst|�S)z{
        Return a context manager that makes sure that this input is not active
        in the current event loop.
        )r*r3r5r5r6�detachaszWin32Input.detach�list[KeyPress]cCst|j���Sr0)�listrC�readr3r5r5r6�	read_keyshszWin32Input.read_keyscCsdSr0r5r3r5r5r6�flushkszWin32Input.flush�boolcCsdS)NFr5r3r5r5r6�closednszWin32Input.closedcCst|jd�S)N)� use_win10_virtual_terminal_input)r'rAr3r5r5r6r'rs�zWin32Input.raw_modecCst�Sr0)r(r3r5r5r6r(wszWin32Input.cooked_mode�intcCs
tj��Sr0)�sysr>�filenor3r5r5r6rTzszWin32Input.fileno�strcCsdS)Nzwin32-inputr5r3r5r5r6�typeahead_hash�szWin32Input.typeahead_hashcCs|j��dSr0)rC�closer3r5r5r6rW�szWin32Input.closercCs|jjSr0)rCr8r3r5r5r6r8�szWin32Input.handle)N)r9r:r;r<r7rHrIrMrNr=rPr'r(rTrVrWr8�
__classcell__r5r5rDr6r%Jsr%c"@s�eZdZdZejejejejej	ej
ejejej
ejejejejejejejejejejejejejejejejejejej ej!ej"ej#ej$ej%d�!Z&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<d�Z=dZ>dZ?dZ@dZAdZBd.d
dd�d
d�ZCdd�dd�ZDdd�dd�ZEddd�dd�ZFdddd�dd�ZGeHddd �d!d"��ZIeHdd
d#�d$d%��ZJd&dd'�d(d)�ZKd*dd'�d+d,�ZLd-S)/r&z|
    :param recognize_paste: When True, try to discover paste actions and turn
        the event into a BracketedPaste.
    )!�����������	�
���
������������������)�!�"�#�$�%�&�'�(�-�.�p�q�r�s�t�u�v�w�x�y�z�{rr!��r+TrOr-)�recognize_paster/cCsZd|_||_|tj��r.ttj�t	��|_
n(t�dtj
tjB�|_tt�|j��|_
dS)N�CONIN$)�_fdconr�rSr>�isattyrr	�kernel32�GetStdHandlerr8�os�open�O_RDWR�O_BINARY�msvcrt�
get_osfhandle)r4r�r5r5r6r7�s
zConsoleInputReader.__init__r.cCs|jdurt�|j�dS�zClose fdcon.N�r�r�rWr3r5r5r6rW�s
zConsoleInputReader.close�Iterable[KeyPress]c		#s0d}td�}t|}|�}t�jgdd�s.dStj��jt|�|t|��t��	||��}�fdd�|D�}t��
|��}�j�r"��|��r"t
|�}|D]�}g}|r�t|jt�r�|jtjtjhvr�|�|j�zt|�}Wq�ty�d}Yq�0q�|�rttjd�|��V|dur�|Vq�n
|EdHdS)��
        Return a list of `KeyPress` instances. It won't return anything when
        there was nothing to read.  (This function doesn't block.)

        http://msdn.microsoft.com/en-us/library/windows/desktop/ms684961(v=vs.85).aspx
        �r��timeoutNcsg|]}��|��qSr5)�_insert_key_data)�.0�keyr3r5r6�
<listcomp>�z+ConsoleInputReader.read.<locals>.<listcomp>�)r
rrr8r	r��ReadConsoleInputWrrK�	_get_keys�_merge_paired_surrogatesr��	_is_paste�iter�
isinstancer�r�ControlJ�ControlM�append�data�next�
StopIterationrZBracketedPaste�join)	r4�	max_countrL�arrtype�
input_records�all_keys�gen�kr�r5r3r6rL�s>�
��
zConsoleInputReader.readr)�	key_pressr/cCs6|jr
|St|jt�r&t�|jd�}nd}t|j|�S)z@
        Insert KeyPress data, for vt100 compatibility.
        r�)r�r�r�rr"�getr)r4r�r�r5r5r6r�*sz#ConsoleInputReader._insert_key_datar
�Array[INPUT_RECORD]zIterator[KeyPress]�rLr�r/ccstt|j�D]d}||}|jtvr
t|jt|j�}t|t�rT|jrT|�	|�EdHq
t|t
�r
|�|�EdHq
dS)�R
        Generator that yields `KeyPress` objects from the input records.
        N)�range�value�	EventTyper �getattr�Eventr�r�KeyDown�_event_to_key_pressesr�
_handle_mouse)r4rLr��i�ir�evr5r5r6r�8s

zConsoleInputReader._get_keysrJ)�key_pressesr/ccs�d}|D]�}t|jt�}|o6d|jko2dkn}|oTd|jkoPdkn}|r�|r�|j|j�dd��d�}t||�}n|Vd}|r�|}q|Vq|r�|VdS)zm
        Combines consecutive KeyPresses with high and low surrogates into
        single characters
        Nu�u�u�u�z	utf-16-le�
surrogatepass)r�r�r�encode�decoder)r�Zbuffered_high_surrogater�Zis_textZis_high_surrogateZis_low_surrogateZfullcharr5r5r6r�Ps*���z+ConsoleInputReader._merge_paired_surrogates)�keysr/cCsJd}d}|D],}t|jt�s$|d7}|jtjkr|d7}q|dkoH|dkS)a<
        Return `True` when we should consider this list of keys as a paste
        event. Pasted text on windows will be turned into a
        `Keys.BracketedPaste` event. (It's not 100% correct, but it is probably
        the best possible way to detect pasting of text and handle that
        correctly.)
        rr!)r�r�rr�)r�Z
text_countZ
newline_countr�r5r5r6r�qs
zConsoleInputReader._is_paster)r�r/cCs�t|t�r|jsJ�d}|j}|jj}|�dd�}|dkrZ|j|jvr�t	|j|jd�}n:||j
vr�|j
|tjkrxd}t	|j
||�}n
t	||�}||j
@s�||j@�r||j@�r|�rtjtjtjtjtjtjtjtjtjtjtjtjtjtjtjtjtj tj!i	}|�"|j#|j#�|_#||j
@�s2||j@�r�|�r�tjtj$tjtj%tjtj&tjtj'tjtj(tjtj)tjtj*tj+tj,tjtj-tj tj.i
}|�"|j#|j#�|_#||j@�r|�rtj/tj0tjtj1tjtj2tjtj3tjtj4tjtj5tjtj6tjtj7tj+tj8tjtj9tj tj:i}|�"|j#|j#�|_#||j
@�s6||j@�rT|�rT|j;dk�rTt	tj<d�}||j
@�sl||j@�r�|�r�|j#tjk�r�t	tj=d�|gS|�r�||j>@}|�r�t	tj=d�|gS|gSngSdS)zU
        For this `KEY_EVENT_RECORD`, return a list of `KeyPress` instances.
        Nzutf-8r��r��
� )?r�rr�ZControlKeyState�uChar�UnicodeCharr�ZVirtualKeyCode�keycodesr�mappingsrr��LEFT_CTRL_PRESSED�RIGHT_CTRL_PRESSED�
SHIFT_PRESSED�LeftZControlShiftLeft�RightZControlShiftRight�UpZControlShiftUp�DownZControlShiftDown�HomeZControlShiftHome�EndZControlShiftEnd�InsertZControlShiftInsert�PageUpZControlShiftPageUp�PageDownZControlShiftPageDownr�r�ZControlLeftZControlRightZ	ControlUpZControlDownZControlHomeZ
ControlEndZ
ControlInsert�DeleteZ
ControlDeleteZ
ControlPageUpZControlPageDownZTabZBackTabZ	ShiftLeftZ
ShiftRightZShiftUpZ	ShiftDownZ	ShiftHomeZShiftEndZShiftInsertZShiftDeleteZShiftPageUpZ
ShiftPageDownr��ControlSpace�Escape�LEFT_ALT_PRESSED)r4r��resultZcontrol_key_state�u_charZ
ascii_char�mappingZmeta_pressedr5r5r6r��s�
�
����	������
�������
�

z(ConsoleInputReader._event_to_key_pressesrcCs�|j}|j}d}tj}|t@r6|dkr.tj}qTtj}n|tkrFtj	}n|t
krTtj}|t@rbtj
}|dur�|dkrztj}ntj}d�|j|jt|jj�t|jj�g�}ttj|�gS)zK
        Handle mouse events. Return a list of KeyPress instances.
        Nr�;)Z
EventFlagsZButtonStater�NONE�
MOUSE_WHEELEDrZ	SCROLL_UPZSCROLL_DOWN�FROM_LEFT_1ST_BUTTON_PRESSED�LEFT�RIGHTMOST_BUTTON_PRESSED�RIGHT�MOUSE_MOVEDZ
MOUSE_MOVEZ
MOUSE_DOWNZMOUSE_UPr�r�rUZ
MousePosition�X�YrrZWindowsMouseEvent)r4r�Zevent_flagsZbutton_stateZ
event_type�buttonr�r5r5r6r�s4

��z ConsoleInputReader._handle_mouseN)T)Mr9r:r;r<rr�r�ZControlAZControlBZControlCZControlDZControlEZControlFZControlGZControlHZControlIr�ZControlKZControlLr�ZControlNZControlOZControlPZControlQZControlRZControlSZControlTZControlUZControlVZControlWZControlXZControlYZControlZZControlBackslashZControlSquareCloseZControlCircumflexZControlUnderscoreZ	Backspacer�r�r�r�r�r�r�r�r�r�r�ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12r�r�ZRIGHT_ALT_PRESSEDr�r�r�r7rWrLr�r��staticmethodr�r�r�r�r5r5r5r6r&�s��'�
> r&c@sLeZdZdZdd�dd�Zdd�dd�Zdd�d	d
�Zddd
d�dd�ZdS)rBa�
    Similar to `ConsoleInputReader`, but for usage when
    `ENABLE_VIRTUAL_TERMINAL_INPUT` is enabled. This assumes that Windows sends
    us the right vt100 escape sequences and we parse those with our vt100
    parser.

    (Using this instead of `ConsoleInputReader` results in the "data" attribute
    from the `KeyPress` instances to be more correct in edge cases, because
    this responds to for instance the terminal being in application cursor keys
    mode.)
    r-r.csld�_g�_t�fdd���_�tj��r@ttj	�
t���_n(t
�dt
jt
jB��_tt��j���_dS)Ncs�j�|�Sr0)�_bufferr�)r�r3r5r6�<lambda>Mr�z2Vt100ConsoleInputReader.__init__.<locals>.<lambda>r�)r�r�r$�
_vt100_parserrSr>r�rr	r�r�rr8r�r�r�r�r�r�r3r5r3r6r7Hs
�
z Vt100ConsoleInputReader.__init__cCs|jdurt�|j�dSr�r�r3r5r5r6rWYs
zVt100ConsoleInputReader.closer�cCsxd}td�}t|}|�}t|jgdd�s.gStj�|jt|�|t|��|�||�D]}|j	�
|�qV|j}g|_|S)r�r�rr�)r
rrr8r	r�r�rr�r��feedr�)r4r�rLr�r�Zkey_datar�r5r5r6rL^s�zVt100ConsoleInputReader.readr
r�z
Iterator[str]r�ccs^t|j�D]N}||}|jtvr
t|jt|j�}t|t�r
|jr
|j	j
}|dkr
|Vq
dS)r�r�N)r�r�r�r r�r�r�rr�r�r�)r4rLr�r�r�r�r�r5r5r6r��s
z!Vt100ConsoleInputReader._get_keysN)r9r:r;r<r7rWrLr�r5r5r5r6rB;s
%rBc@s@eZdZdZdd�dd�Zdddd�d	d
�Zddd�d
d�ZdS)r1a�
    Utility to keep track of which handles are connectod to which callbacks.

    `add_win32_handle` starts a tiny event loop in another thread which waits
    for the Win32 handle to become ready. When this happens, the callback will
    be called in the current asyncio event loop using `call_soon_threadsafe`.

    `remove_win32_handle` will stop this tiny event loop.

    NOTE: We use this technique, so that we don't have to use the
          `ProactorEventLoop` on Windows and we can wait for things like stdin
          in a `SelectorEventLoop`. This is important, because our inputhook
          mechanism (used by IPython), only works with the `SelectorEventLoop`.
    r-r.cCsi|_i|_dSr0)�_handle_callbacks�_remove_eventsr3r5r5r6r7�sz_Win32Handles.__init__rrF)r8�callbackr/cs~�j}|durtd��|���t���|j|<t���|j|<dd����fdd��dd�����fdd��t��d	�dS)
z7
        Add a Win32 handle to the event loop.
        N�Invalid handle.r-r.c
s*z��Wt��d�nt��d�0dS)N��looprr5)r�r�waitr5r6�ready�sz-_Win32Handles.add_win32_handle.<locals>.readycs2t��g�}|�ur$tj���dS����dSr0)rr	r�ZCloseHandle�call_soon_threadsafe)r�)r8rr�remove_eventr5r6r�s
z,_Win32Handles.add_win32_handle.<locals>.waitr)r��
ValueError�remove_win32_handlerr�rr�r)r4r8r�Zhandle_valuer5)r�r8rrrrr6�add_win32_handle�s



z_Win32Handles.add_win32_handlezCallable[[], None] | None)r8r/cCsj|jdurdSz|j�|j�}Wnty2Yn0tj�|�z|j�|j�WStydYdS0dS)zt
        Remove a Win32 handle from the event loop.
        Return either the registered handler or `None`.
        N)r�r��pop�KeyErrorr	r�ZSetEventr�)r4r8�eventr5r5r6r�s
z!_Win32Handles.remove_win32_handleN)r9r:r;r<r7r	rr5r5r5r6r1�s+r1rFzIterator[None])�inputr�r/c
csz|j}|j}|jdurtd��|�|�}|�||�z$dVW|�|�|rv|�||�n|�|�|rt|�||�0dS)z�
    Context manager that makes this input active in the current event loop.

    :param input: :class:`~prompt_toolkit.input.Input` object.
    :param input_ready_callback: Called when the input is ready to read.
    Nr�r2r8r�rrr	)r
r�r2r8�previous_callbackr5r5r6r)�s



�
r))r
r/c
csZ|j}|j}|jdurtd��|�|�}zdVW|rV|�||�n|rT|�||�0dS)Nrr)r
r2r8rr5r5r6r*s

�r*c@sPeZdZdZddddd�dd	�Zdd
�dd�Zdd
�d
d�Zddd�dd�ZdS)r'z�
    ::

        with raw_mode(stdin):
            ''' the windows terminal is now in 'raw' mode. '''

    The ``fileno`` attribute is ignored. This is to be compatible with the
    `raw_input` method of `.vt100_input`.
    NFz
int | NonerOr-)rTrQr/cCsttj�t��|_||_dSr0)rr	r�r�rr8rQ)r4rTrQr5r5r6r7,szraw_mode.__init__r.cCs,t�}tj�|jt|��||_|��dSr0)r
r	r��GetConsoleModer8r�
original_mode�_patch)r4rr5r5r6�	__enter__2szraw_mode.__enter__cCsDd}d}d}|jj||B|B@}|jr0|tO}tj�|j|�dS�Nr+rr!)rr�rQ�ENABLE_VIRTUAL_TERMINAL_INPUTr	r��SetConsoleModer8)r4�ENABLE_ECHO_INPUT�ENABLE_LINE_INPUT�ENABLE_PROCESSED_INPUTZnew_moder5r5r6r:s
�zraw_mode._patch�object)�ar/cGstj�|j|j�dSr0)r	r�rr8r)r4rr5r5r6�__exit__Iszraw_mode.__exit__)NF)r9r:r;r<r7rrrr5r5r5r6r'!s�r'c@seZdZdZdd�dd�ZdS)r(zx
    ::

        with cooked_mode(stdin):
            ''' The pseudo-terminal stdin is now used in cooked mode. '''
    r-r.cCs0d}d}d}tj�|j|jj||B|BB�dSr)r	r�rr8rr�)r4rrrr5r5r6rVs
��zcooked_mode._patchN)r9r:r;r<rr5r5r5r6r(Nsr(rOr.c
Csjttj�t��}td�}tj�|t|��z*tj�|tt	��}|dkWtj�||�Stj�||�0dS)z_
    Returns True when we're running Windows and VT100 escape sequences are
    supported.
    rr!N)
rr	r�r�rr
rrrr)Zhconsolerr�r5r5r6r@cs��r@)D�
__future__rr�rS�abcr�asyncior�
contextlibr�utilsr�platformr��ctypesr	r
rrZctypes.wintypesr
r�typingrrrrrZprompt_toolkit.eventlooprZprompt_toolkit.eventloop.win32rrZ(prompt_toolkit.key_binding.key_processorrZprompt_toolkit.keysrZprompt_toolkit.mouse_eventsrrZprompt_toolkit.win32_typesrrrrr Zansi_escape_sequencesr"�baser#Zvt100_parserr$�__all__r�r�r�r�rr,r%r&rBr1r)r*r'r(r@r5r5r5r6�<module>sVB2`X-

Yohohohohohooho | Sanrei Aya