
    h
                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
JrJrJr  SSKJrJrJr   " S S\5      r " S	 S
\R(                  5      r " S S\5      rS rSS jr\S:X  a  \" 5         gg)zC
Asynchronous local terminal input handling

@author: Jp Calderone
    N)ServerProtocol)ColoredManhole)deferprotocolreactorstdio)failurelogreflectc                       \ rS rSrSrg)UnexpectedOutputError    N)__name__
__module____qualname____firstlineno____static_attributes__r       Z/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/stdio.pyr   r      s    r   r   c                   >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)TerminalProcessProtocol   c                 D    Xl         [        R                  " 5       U l        g N)protor   DeferredonConnection)selfr   s     r   __init__ TerminalProcessProtocol.__init__   s    
!NN,r   c                 ~    U R                   R                  U 5        U R                  R                  S 5        S U l        g r   )r   makeConnectionr   callback)r   s    r   connectionMade&TerminalProcessProtocol.connectionMade   s0    

!!$'""4( r   c                 :    U R                   R                  U5        g)zJ
Write to the terminal.

@param data: Data to write.
@type data: L{bytes}
N)	transportwriter   datas     r   r)   TerminalProcessProtocol.write$   s     	T"r   c                 :    U R                   R                  U5        g)zS
Receive data from the terminal.

@param data: Data received.
@type data: L{bytes}
N)r   dataReceivedr*   s     r   outReceived#TerminalProcessProtocol.outReceived-   s     	

%r   c                     U R                   R                  5         U R                  b@  U R                  R                  [        R
                  " [        U5      5      5        SU l        gg)zT
Report an error.

@param data: Data to include in L{Failure}.
@type data: L{bytes}
N)r(   loseConnectionr   connectionLostr	   Failurer   r*   s     r   errReceived#TerminalProcessProtocol.errReceived6   sK     	%%'::!JJ%%goo6KD6Q&RSDJ "r   c                 V    U R                   b  U R                   R                  U5        g g r   )r   childConnectionLost)r   childFDs     r   r8   +TerminalProcessProtocol.childConnectionLostB   s#    ::!JJ**73 "r   c                 d    U R                   b#  U R                   R                  U5        S U l         g g r   )r   r3   r   reasons     r   processEnded$TerminalProcessProtocol.processEndedF   s*    ::!JJ%%f-DJ "r   )r   r   N)r   r   r   r   r    r%   r)   r/   r5   r8   r>   r   r   r   r   r   r      s%    -!
#&
4r   r   c                       \ rS rSrSrS rSrg)ConsoleManholeL   zC
A manhole protocol specifically for use with L{stdio.StandardIO}.
c                 .    [         R                  " 5         g)zk
When the connection is lost, there is nothing more to do.  Stop the
reactor so that the process can exit.
N)r   stopr<   s     r   r3   ConsoleManhole.connectionLostQ   s    
 	r   r   N)r   r   r   r   __doc__r3   r   r   r   r   rA   rA   L   s    r   rA   c                     [         R                  R                  5       n[        R                  " U5      n[
        R                  " U5         [        R                  " [        U 5      5        [        R                  " 5         [        R                  " U[        R                  U5        [        R                  " US5        g ! [        R                  " U[        R                  U5        [        R                  " US5        f = f)Ns   c)sys	__stdin__filenotermios	tcgetattrttysetrawr   
StandardIOr   r   run	tcsetattrTCSANOWosr)   )klassfdoldSettingss      r   runWithProtocolrW   Y   s    				B##B'KJJrN#./"goo{;
\" 	"goo{;
\"s   4B> >?C=c                     [         R                  " [        SS5      5        U c  [        R                  SS  n U (       a  [
        R                  " U S   5      nO[        n[        U5        g )Nz	child.logw   r   )	r
   startLoggingopenrH   argvr   
namedClassrA   rW   )r]   rT   s     r   mainr_   e   sO    T+s+,|xx|""47+Er   __main__r   )rF   rS   rH   rK   rM   twisted.conch.insults.insultsr   twisted.conch.manholer   twisted.internetr   r   r   r   twisted.pythonr	   r
   r   	Exceptionr   ProcessProtocolr   rA   rW   r_   r   r   r   r   <module>rg      ss   
 
 
  
 8 0 < < 0 0	I 	/h66 /d
^ 
	#	 zF r   