
    F\h                     L    S r SSKJr  SSKJr  SSKJr  SSKJr   " S S5      rg	)
zv
OS-independent base for an event and VT sequence scanner

See unix_eventqueue and windows_eventqueue for subclasses.
    )deque   )keymap)Event)tracec                       \ rS rSrS\S\\\4   SS4S jrS\S-  4S jr	S\
4S jrS\4S	 jrS
\SS4S jrS\\-  SS4S jrSrg)BaseEventQueue!   encodingkeymap_dictreturnNc                     [         R                  " U5      U l        U R                  U l         [        SU R                   S9  Xl        [        5       U l        [        5       U l        g )Nzkeymap {k!r}k)	r   compile_keymapcompiled_keymapr   r   r   events	bytearraybuf)selfr   r   s      ./usr/lib/python3.13/_pyrepl/base_eventqueue.py__init__BaseEventQueue.__init__"   sG    %44[A**n, $)G;    c                 Z    U R                   (       a  U R                   R                  5       $ g)z*
Retrieves the next event from the queue.
N)r   popleftr   s    r   getBaseEventQueue.get*   s!     ;;;;&&((r   c                 $    U R                   (       + $ )z
Checks if the queue is empty.
)r   r   s    r   emptyBaseEventQueue.empty3   s     ;;r   c                 <    U R                   n[        5       U l         U$ )z.
Flushes the buffer and returns its contents.
)r   r   )r   olds     r   	flush_bufBaseEventQueue.flush_buf9   s     hh;
r   eventc                 N    [        SUS9  U R                  R                  U5        g)z"
Inserts an event into the queue.
zadded event {event})r'   N)r   r   append)r   r'   s     r   insertBaseEventQueue.insertA   s!     	#515!r   charc           	      R   [        U[        [        45      (       d   e[        U[        5      (       a  UO
[        U5      nUR	                  5       nU R
                  R                  U5        XR                  ;   a  U R                  U R                  L a  [        U R
                  5      S:X  d   eU R                  U   n[        SUS9  [        U[        5      (       a  X0l        g
U R                  [        SX0R                  5       5      5        U R                  U l        g
U R
                  (       a  U R
                  S   S:X  am  [        S5        U R                  U l        U R                  [        SS[        S	5      5      5        U R                  5       SS
  H  nU R!                  U5        M     g
 [        U R
                  5      R#                  U R$                  5      nU R                  [        SXPR                  5       5      5        U R                  U l        g
! [&         a     g
f = f)zQ
Processes a character by updating the buffer and handling special key mappings.
r   zfound map {k!r}r   keyr      z,unrecognized escape sequence, propagating...   N)
isinstanceintbytesordto_bytesr   r)   r   r   lenr   dictr*   r   r%   r   pushdecoder   UnicodeError)r   r,   ord_charr   _cdecodeds         r   r9   BaseEventQueue.pushH   s    $e----%dC004c$i  "!;;{{d222488})))D!A#q)!T""E%NN,<=>"22XX$((1++ @A..DKKKeVYw-?@Ann&qr*		" +E/00? E%..2BCD..DK	   s   0.H 
H&%H&)r   r   r   r   r   )__name__
__module____qualname____firstlineno__strr8   r4   r   r   r   boolr!   r   r%   r*   r3   r9   __static_attributes__ r   r   r	   r	   !   sw     4s
3C  UT\ t 9 "E "d "&/u &/ &/r   r	   N)	__doc__collectionsr    r   consoler   r   r	   rG   r   r   <module>rL      s$   *    M/ M/r   