+
    j,i                        R t ^ RIHt ^ RIt^ RIHtHt ^RIHt R.t	R R lt
]
! ^ 4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^"4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^"4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^ 4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t]
! ^4      t ]
! ^4      t!]
! ^4      t"]
! ^4      t# ! R R4      t$R# )	z
Parser for the Telnet protocol. (Not a complete implementation of the telnet
specification, but sufficient for a command line interface.)

Inspired by `Twisted.conch.telnet`.
)annotationsN)Callable	Generator)loggerTelnetProtocolParserc                    V ^8  d   QhRRRR/# )   numberintreturnbytes )formats   "H/usr/lib/python3/dist-packages/prompt_toolkit/contrib/telnet/protocol.py__annotate__r      s      S U     c                    \        V 34      # N)r   )r	   s   &r   int2byter      s    &r   c                      ] tR t^8tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltRtR# )r   z
Parser for the Telnet protocol.
Usage::

    def data_received(data):
        print(data)

    def size_received(rows, columns):
        print(rows, columns)

    p = TelnetProtocolParser(data_received, size_received)
    p.feed(binary_data)
c               (    V ^8  d   QhRRRRRRRR/# )	r   data_received_callbackzCallable[[bytes], None]size_received_callbackzCallable[[int, int], None]ttype_received_callbackzCallable[[str], None]r   Noner   )r   s   "r   r   !TelnetProtocolParser.__annotate__G   s2         7  !;  "7	 
 
 r   c                	    Wn         W n        W0n        V P                  4       V n        V P                  P                  R 4       R # r   )r   r   r   _parse_coroutine_parsersend)selfr   r   r   s   &&&&r   __init__TelnetProtocolParser.__init__G   s8     '=#&<#'>$,,.$r   c                    V ^8  d   QhRRRR/# r   datar   r   r   r   )r   s   "r   r   r   T   s     * *% *D *r   c                	(    V P                  V4       R # r   )r   r    r%   s   &&r   received_data"TelnetProtocolParser.received_dataT   s    ##D)r   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r   W   s     # # #$ #r   c                4    \         P                  ! RV4       R# )zReceived telnet DO command.zDO %rNr   infor'   s   &&r   do_received TelnetProtocolParser.do_receivedW   s    GT"r   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r   [        % %% %D %r   c                4    \         P                  ! RV4       R# )zReceived telnet DONT command.zDONT %rNr,   r'   s   &&r   dont_received"TelnetProtocolParser.dont_received[       It$r   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r   _   r1   r   c                4    \         P                  ! RV4       R# )zReceived telnet WILL command.zWILL %rNr,   r'   s   &&r   will_received"TelnetProtocolParser.will_received_   r5   r   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r   c   r1   r   c                4    \         P                  ! RV4       R# )zReceived telnet WONT command.zWONT %rNr,   r'   s   &&r   wont_received"TelnetProtocolParser.wont_receivedc   r5   r   c               $    V ^8  d   QhRRRRRR/# )r   commandr   r%   r   r   r   )r   s   "r   r   r   g   s&     A A AU At Ar   c                	$   V\         8X  d   V P                  V4       R# V\        8X  d   V P                  V4       R# V\        8X  d   V P                  V4       R# V\        8X  d   V P                  V4       R# \        P                  ! R W4       R# )zcommand received %r %rN)
DOr.   DONTr3   WILLr8   WONTr<   r   r-   )r    r?   r%   s   &&&r   command_received%TelnetProtocolParser.command_receivedg   sg    b=T"_t$_t$_t$ KK0'@r   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r   w   s     9 9 94 9r   c                    \        V4      ^8X  d-   \        P                  ! RV4      w  r#V P                  W24       R# \        P
                  ! R4       R# )z%
Received NAWS. (Window dimensions.)
z!HHzWrong number of NAWS bytesN)lenstructunpackr   r   warning)r    r%   columnsrowss   &&  r   nawsTelnetProtocolParser.nawsw   s>     t9> #MM%6MG''6NN78r   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r      s     	M 	M% 	MD 	Mr   c                    VR,          VR,          rV\         8X  d%   VP                  R4      pV P                  V4       R# \        P                  ! R4       R# )z
Received terminal type.
       NrU   NNasciiz.Received a non-IS terminal type SubnegotiationN)ISdecoder   r   rL   )r    r%   subcmdttypes   &&  r   r[   TelnetProtocolParser.ttype   sC     Cy$r(R<KK(E((/NNKLr   c                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r      s     ? ?e ? ?r   c                    VR,          VR,          r2V\         8X  d   V P                  V4       R# V\        8X  d   V P                  V4       R# \        P
                  ! R\        V4      4       R# )z
Got negotiate data.
rS   rV   zNegotiate (%r got bytes)N)NAWSrO   TTYPEr[   r   r-   rI   )r    r%   r?   payloads   &&  r   	negotiateTelnetProtocolParser.negotiate   sM      9d2hd?IIgJJwKK2CI>r   c                   V ^8  d   QhRR/# )r   r   zGenerator[None, bytes, None]r   )r   s   "r   r   r      s     .& .&"> .&r   c           
   #    "    Rx pV\        ^ 4      8X  d   K  V\        8X  Ed   Rx pV\        8X  d   V P                  V4       KE  V\        \        \
        \        \        \        \        \        \        3	9   d   V P                  VR4       K  V\        \        \        \         39   d   Rx pV P                  W#4       K  V\"        8X  dl   . p Rx pV\        8X  d$   Rx pV\$        8X  d   M&VP'                  V4       K3  VP'                  V4       KF  V P)                  RP+                  V4      4       EK5  EK8  V P                  V4       EKL  5i)zG
Parser state machine.
Every 'yield' expression returns the next byte.
Nr   )r   IACr(   NOPDMBRKIPAOAYTECELGArE   rA   rB   rC   rD   SBSEappendrb   join)r    dd2d3r%   d4s   &     r   r   %TelnetProtocolParser._parse_coroutine   s     
 AHQK c9&&r* CS"b#r2rBB))"c2 BdD11B))"1 2XD"9!&B!Rx % $B KKONN388D>2! $ ""1%s   EEc                    V ^8  d   QhRRRR/# r$   r   )r   s   "r   r   r      s     + + +4 +r   c                `    V F'  pV P                   P                  \        V4      4       K)  	  R# )z
Feed data to the parser.
N)r   r   r   )r    r%   bs   && r   feedTelnetProtocolParser.feed   s$     ALLhqk* r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r!   r(   r.   r3   r8   r<   rE   rO   r[   rb   r   r|   __static_attributes__r   r   r   r   r   8   sK     *#%%%A 9	M?.&`+ +r   )%r   
__future__r   rJ   typingr   r   logr   __all__r   rg   SGArf   rA   rB   LINEMODErp   rC   rD   MODErq   ECHOr_   SUPPRESS_GO_AHEADr`   SENDrX   rh   ri   rj   rk   rl   rm   rn   ro   r   r   r   r   <module>r      s"   #  &  

 qkqksmc]}B<c]}}{c]{|B<QK {a[c]smc]c]smc]c]c]Y+ Y+r   