
    h                     F   S r SSKrSSKJr  SSKJrJrJr  SSK	J
r
  SSKJr  S\S\4S	 jr\" S
5      rS
rSrSrSrSr\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S
5      r\" S5      r\" S5      r \" S5      r!\" S5      r"\" S5      r#\" S5      r$\" S5      r%\" S5      r&\" S5      r'\" S5      r(\" S5      r)\" S 5      r*\" S!5      r+\" S"5      r,\" S#5      r-\" S$5      r.\" S%5      r/\" S&5      r0\" S'5      r1\" S(5      r2\" S
5      r3\" S
5      r4\" S5      r5\" S5      r6\" S5      r7\" S5      r8\" S5      r9\" S5      r:\" S
5      r;\" S5      r<\" S5      r=\" S5      r>\" S)5      r?\" S*5      r@\" S5      rA\" S5      rB\" S5      rC\" S5      rD\" S5      rE\" S5      rF\" S5      rG\" S+5      rH\" S,5      rI\" S5      rJ\" S-5      rK\" S.5      rL\" S/5      rM\" S05      rN\" S15      rO\" S25      rP\" S35      rQ\" S45      rR\" S55      rS\" S65      rT\" S75      rU\" S85      rV\" S95      rW\" S:5      rX\" S5      rY\" S5      rZ\" S
5      r[\" S5      r\\" S5      r]\" S;5      r^\" S<5      r_\" S=5      r`\" S>5      ra\" S?5      rb\" S@5      rc " SA SB\R                  5      re " SC SD\R                  5      rg " SE SF\h5      ri " SG SH\i5      rj " SI SJ\j5      rk " SK SL\j5      rl " SM SN\j5      rm " SO SP\j5      rn\" \e5       " SQ SR\R                  5      5       rp " SS ST\R                  5      rq " SU SV5      rr " SW SX\q\r5      rs " SY SZ\p\r5      rtSS[KuJvrv   " S\ S]\vR                  \p5      rxSS^KyJzrz   " S_ S`\x5      r{/ SaQr|g)bz?
Telnet protocol implementation.

@author: Jean-Paul Calderone
    N)implementer)defer
interfacesprotocol)Logger)	iterbytesireturnc                     [        U 45      $ )a  Create a byte sequence of length 1.

U{RFC 854<https://tools.ietf.org/html/rfc854>} specifies codes in decimal,
but Python can only handle L{bytes} literals in octal or hexadecimal.
This helper function bridges that gap.

@param i: The value of the only byte in the sequence.
)bytes)r	   s    [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/telnet.py_chrr      s     !;                      	   
                  "                                                                                                               @                c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
ITelnetProtocol   c                     g)a-  
A command was received but not understood.

@param command: the command received.
@type command: L{str}, a single character.
@param argument: the argument to the received command.
@type argument: L{str}, a single character, or None if the command that
    was unhandled does not provide an argument.
N )commandarguments     r   unhandledCommand ITelnetProtocol.unhandledCommand       r   c                     g)a  
A subnegotiation command was received but not understood.

@param command: the command being subnegotiated. That is, the first
    byte after the SB command.
@type command: L{str}, a single character.
@param data: all other bytes of the subneogation. That is, all but the
    first bytes between SB and SE, with IAC un-escaping applied.
@type data: L{bytes}, each a single character
NrK   )rL   datas     r   unhandledSubnegotiation'ITelnetProtocol.unhandledSubnegotiation   rP   r   c                     g)a7  
Enable the given option locally.

This should enable the given option on this side of the
telnet connection and return True.  If False is returned,
the option will be treated as still disabled and the peer
will be notified.

@param option: the option to be enabled.
@type option: L{bytes}, a single character.
NrK   options    r   enableLocalITelnetProtocol.enableLocal   rP   r   c                     g)z
Indicate whether the peer should be allowed to enable this option.

Returns True if the peer should be allowed to enable this option,
False otherwise.

@param option: the option to be enabled.
@type option: L{bytes}, a single character.
NrK   rV   s    r   enableRemoteITelnetProtocol.enableRemote   rP   r   c                     g)z
Disable the given option locally.

Unlike enableLocal, this method cannot fail.  The option must be
disabled.

@param option: the option to be disabled.
@type option: L{bytes}, a single character.
NrK   rV   s    r   disableLocalITelnetProtocol.disableLocal   rP   r   c                     g)z
Indicate that the peer has disabled this option.

@param option: the option to be disabled.
@type option: L{bytes}, a single character.
NrK   rV   s    r   disableRemoteITelnetProtocol.disableRemote   rP   r   rK   N)__name__
__module____qualname____firstlineno__rN   rS   rX   r[   r^   ra   __static_attributes__rK   r   r   rH   rH      s     	
		r   rH   c                   2    \ rS rSrS rS rS rS rS rSr	g)	ITelnetTransport   c                     g)aP  
Indicate a desire for the peer to begin performing the given option.

Returns a Deferred that fires with True when the peer begins performing
the option, or fails with L{OptionRefused} when the peer refuses to
perform it.  If the peer is already performing the given option, the
Deferred will fail with L{AlreadyEnabled}.  If a negotiation regarding
this option is already in progress, the Deferred will fail with
L{AlreadyNegotiating}.

Note: It is currently possible that this Deferred will never fire,
if the peer never responds, or if the peer believes the option to
already be enabled.
NrK   rV   s    r   doITelnetTransport.do   rP   r   c                     g)a  
Indicate a desire for the peer to cease performing the given option.

Returns a Deferred that fires with True when the peer ceases performing
the option.  If the peer is not performing the given option, the
Deferred will fail with L{AlreadyDisabled}.  If negotiation regarding
this option is already in progress, the Deferred will fail with
L{AlreadyNegotiating}.

Note: It is currently possible that this Deferred will never fire,
if the peer never responds, or if the peer believes the option to
already be disabled.
NrK   rV   s    r   dontITelnetTransport.dont   rP   r   c                     g)ai  
Indicate our willingness to begin performing this option locally.

Returns a Deferred that fires with True when the peer agrees to allow us
to begin performing this option, or fails with L{OptionRefused} if the
peer refuses to allow us to begin performing it.  If the option is
already enabled locally, the Deferred will fail with L{AlreadyEnabled}.
If negotiation regarding this option is already in progress, the
Deferred will fail with L{AlreadyNegotiating}.

Note: It is currently possible that this Deferred will never fire,
if the peer never responds, or if the peer believes the option to
already be enabled.
NrK   rV   s    r   willITelnetTransport.will   rP   r   c                     g)a  
Indicate that we will stop performing the given option.

Returns a Deferred that fires with True when the peer acknowledges
we have stopped performing this option.  If the option is already
disabled locally, the Deferred will fail with L{AlreadyDisabled}.
If negotiation regarding this option is already in progress,
the Deferred will fail with L{AlreadyNegotiating}.

Note: It is currently possible that this Deferred will never fire,
if the peer never responds, or if the peer believes the option to
already be disabled.
NrK   rV   s    r   wontITelnetTransport.wont  rP   r   c                     g)a2  
Send a subnegotiation request.

@param about: A byte indicating the feature being negotiated.
@param data: Any number of L{bytes} containing specific information
about the negotiation being requested.  No values in this string
need to be escaped, as this function will escape any value which
requires it.
NrK   )aboutrR   s     r   requestNegotiation#ITelnetTransport.requestNegotiation  rP   r   rK   N)
rc   rd   re   rf   rl   ro   rr   ru   ry   rg   rK   r   r   ri   ri      s      	r   ri   c                       \ rS rSrSrg)TelnetErrori#  rK   Nrc   rd   re   rf   rg   rK   r   r   r|   r|   #      r   r|   c                   "    \ rS rSrS\4S jrSrg)NegotiationErrori'  r
   c                     U R                   R                  S-   U R                   R                  -   S-   [        U R                  S   5      -   $ )N.:r   )	__class__rd   rc   reprargsselfs    r   __str__NegotiationError.__str__(  sO    NN%%nn%%&  499Q< 	!	
r   rK   N)rc   rd   re   rf   strr   rg   rK   r   r   r   r   '  s    
 
r   r   c                       \ rS rSrSrg)OptionRefusedi2  rK   Nr}   rK   r   r   r   r   2  r~   r   r   c                       \ rS rSrSrg)AlreadyEnabledi6  rK   Nr}   rK   r   r   r   r   6  r~   r   r   c                       \ rS rSrSrg)AlreadyDisabledi:  rK   Nr}   rK   r   r   r   r   :  r~   r   r   c                       \ rS rSrSrg)AlreadyNegotiatingi>  rK   Nr}   rK   r   r   r   r   >  r~   r   r   c                   F    \ rS rSr\" 5       rS rS rS rS r	S r
S rSrg	)
TelnetProtocoliB  c                     g NrK   r   rL   rM   s      r   rN   TelnetProtocol.unhandledCommandF      r   c                     g r   rK   r   rL   rR   s      r   rS   &TelnetProtocol.unhandledSubnegotiationI  r   r   c                     g r   rK   r   rW   s     r   rX   TelnetProtocol.enableLocalL  r   r   c                     g r   rK   r   s     r   r[   TelnetProtocol.enableRemoteO  r   r   c                     g r   rK   r   s     r   r^   TelnetProtocol.disableLocalR  r   r   c                     g r   rK   r   s     r   ra   TelnetProtocol.disableRemoteU  r   r   rK   N)rc   rd   re   rf   r   _logrN   rS   rX   r[   r^   ra   rg   rK   r   r   r   r   B  s'    8Dr   r   c                   j   \ rS rSrSrSrS rS r " S S5      rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r\\\\S.rS r S  r!S! r"S" r#S# r$\!\"\#\$S.r%S$ r&S% r'S& r(S' r)S( r*\'\(\)\*S.r+S) r,S* r-S+ r.S, r/S- r0\-\.\/\0S.r1S. r2S/ r3S0 r4S1 r5S2r6g3)4TelnetiY  a!  
@ivar commandMap: A mapping of bytes to callables.  When a
telnet command is received, the command byte (the first byte
after IAC) is looked up in this dictionary.  If a callable is
found, it is invoked with the argument of the command, or None
if the command takes no argument.  Values should be added to
this dictionary if commands wish to be handled.  By default,
only WILL, WONT, DO, and DONT are handled.  These should not
be overridden, as this class handles them correctly and
provides an API for interacting with them.

@ivar negotiationMap: A mapping of bytes to callables.  When
a subnegotiation command is received, the command byte (the
first byte after SB) is looked up in this dictionary.  If
a callable is found, it is invoked with the argument of the
subnegotiation.  Values should be added to this dictionary if
subnegotiations are to be handled.  By default, no values are
handled.

@ivar options: A mapping of option bytes to their current
state.  This state is likely of little use to user code.
Changes should not be made to it.

@ivar state: A string indicating the current parse state.  It
can take on the values "data", "escaped", "command", "newline",
"subnegotiation", and "subnegotiation-escaped".  Changes
should not be made to it.

@ivar transport: This protocol's transport object.
rR   c                     0 U l         0 U l        [        U R                  [        U R
                  [        U R                  [        U R                  0U l
        g r   )optionsnegotiationMapWILLtelnet_WILLWONTtelnet_WONTDO	telnet_DODONTtelnet_DONT
commandMapr   s    r   __init__Telnet.__init__|  sD     $""$""$""	
r   c                 :    U R                   R                  U5        g r   	transportwriter   rR   s     r   _writeTelnet._write  s    T"r   c                   @    \ rS rSrSr " S S5      rS rS\4S jrSr	g	)
Telnet._OptionStatei  z
Represents the state of an option on both sides of a telnet
connection.

@ivar us: The state of the option on this side of the connection.

@ivar him: The state of the option on the other side of the
    connection.
c                   2    \ rS rSrSrSrSrSrS\4S jr	Sr
g)	 Telnet._OptionState._Perspectivei  a  
Represents the state of an option on side of the telnet
connection.  Some options can be enabled on a particular side of
the connection (RFC 1073 for example: only the client can have
NAWS enabled).  Other options can be enabled on either or both
sides (such as RFC 1372: each side can have its own flow control
state).

@ivar state: C{'yes'} or C{'no'} indicating whether or not this
    option is enabled on one side of the connection.

@ivar negotiating: A boolean tracking whether negotiation about
    this option is in progress.

@ivar onResult: When negotiation about this option has been
    initiated by this side of the connection, a L{Deferred}
    which will fire with the result of the negotiation.  L{None}
    at other times.
noFNr
   c                 :    U R                   SU R                  -  -   $ )N*)statenegotiatingr   s    r   r   (Telnet._OptionState._Perspective.__str__  s    zzS4+;+;%;<<r   rK   )rc   rd   re   rf   __doc__r   r   onResultr   r   rg   rK   r   r   _Perspectiver     s$    ( EKH= =r   r   c                 X    U R                  5       U l        U R                  5       U l        g r   )r   ushimr   s    r   r   Telnet._OptionState.__init__  s"    '')DG((*DHr   r
   c                 <    SU R                    SU R                   S3$ )Nz<_OptionState us=z him=>)r   r   r   s    r   __repr__Telnet._OptionState.__repr__  s    &twwiuTXXJa@@r   )r   r   N)
rc   rd   re   rf   r   r   r   r   r   rg   rK   r   r   _OptionStater     s$    		= 	=8	+	Ac 	Ar   r   c                 T    U R                   R                  XR                  5       5      $ r   )r   
setdefaultr   r   opts     r   getOptionStateTelnet.getOptionState  s     ||&&s,=,=,?@@r   c                 B    U R                  [        [        -   U-   5        g r   )r   IACr   r   s     r   _do
Telnet._do  s    C"Hv%&r   c                 B    U R                  [        [        -   U-   5        g r   )r   r   r   r   s     r   _dontTelnet._dont      C$J'(r   c                 B    U R                  [        [        -   U-   5        g r   )r   r   r   r   s     r   _willTelnet._will  r   r   c                 B    U R                  [        [        -   U-   5        g r   )r   r   r   r   s     r   _wontTelnet._wont  r   r   c                    U R                  U5      nUR                  R                  (       d  UR                  R                  (       a  [        R
                  " [        U5      5      $ UR                  R                  S:X  a  [        R
                  " [        U5      5      $ SUR                  l        [        R                  " 5       =UR                  l
        nU R                  U5        U$ )z/
Indicate our willingness to enable an option.
yesT)r   r   r   r   r   failr   r   r   Deferredr   r   r   rW   sds       r   rr   Telnet.will  s     '44quu00::0899TTZZ5 ::nV455#ADD % 00ADDMAJJvHr   c                    U R                  U5      nUR                  R                  (       d  UR                  R                  (       a  [        R
                  " [        U5      5      $ UR                  R                  S:X  a  [        R
                  " [        U5      5      $ SUR                  l        [        R                  " 5       =UR                  l
        nU R                  U5        U$ )z2
Indicate we are not willing to enable an option.
r   T)r   r   r   r   r   r   r   r   r   r   r   r   r   s       r   ru   Telnet.wont  s     '44quu00::0899TTZZ4::of566#ADD % 00ADDMAJJvHr   c                    U R                  U5      nUR                  R                  (       d  UR                  R                  (       a  [        R
                  " [        U5      5      $ UR                  R                  S:X  a  [        R
                  " [        U5      5      $ SUR                  l        [        R                  " 5       =UR                  l
        nU R                  U5        U$ )Nr   T)r   r   r   r   r   r   r   r   r   r   r   r   r   s       r   rl   	Telnet.do  s    '44quu00::0899UU[[E!::nV455 $AEE!&!11AEENQHHVHr   c                    U R                  U5      nUR                  R                  (       d  UR                  R                  (       a  [        R
                  " [        U5      5      $ UR                  R                  S:X  a  [        R
                  " [        U5      5      $ SUR                  l        [        R                  " 5       =UR                  l
        nU R                  U5        U$ )Nr   T)r   r   r   r   r   r   r   r   r   r   r   r   r   s       r   ro   Telnet.dont  s    '44quu00::0899UU[[D ::of566 $AEE!&!11AEENQJJvHr   c                     UR                  [        [        S-  5      nU R                  [        [        -   U-   U-   [        -   [        -   5        g)z
Send a negotiation message for the option C{about} with C{data} as the
payload.

@param data: the payload
@type data: L{bytes}
@see: L{ITelnetTransport.requestNegotiation}
r   N)replacer   r   SBSE)r   rx   rR   s      r   ry   Telnet.requestNegotiation  s<     ||Cq)C"Hu$t+c1B67r   c                    / n[        U5       GH  nU R                  S:X  a5  U[        :X  a	  SU l        M'  US:X  a	  SU l        M6  UR                  U5        MI  U R                  S:X  a  U[        :X  a  UR                  U5        SU l        M}  U[        :X  a  SU l        / U l        M  U[        [        [        [        [        [        [        [        [        [        4
;   aH  SU l        U(       a%  U R!                  SR#                  U5      5        US S 2	 U R%                  US 5        GM  U[&        [(        [*        [,        4;   a  SU l        X0l        GMA  [1        SU5      eU R                  S:X  aU  SU l        U R.                  nU ?U(       a%  U R!                  SR#                  U5      5        US S 2	 U R%                  XC5        GM  U R                  S:X  aw  SU l        US	:X  a  UR                  S	5        GM  US
:X  a  UR                  S5        GM  U[        :X  a  UR                  S5        SU l        GM"  UR                  SU-   5        GM9  U R                  S:X  a2  U[        :X  a
  SU l        GM]  U R
                  R                  U5        GM{  U R                  S:X  a  U[2        :X  aU  SU l        U R
                  nU ?U(       a%  U R!                  SR#                  U5      5        US S 2	 U R5                  U5        GM  SU l        U R
                  R                  U5        GM  [1        S5      e   U(       a!  U R!                  SR#                  U5      5        g g )NrR   escaped   newlinesubnegotiationr   rL   Stumped   
    zsubnegotiation-escapedzHow'd you do this?)r   r   r   appendr   commandsEORNOPDMBRKIPAOAYTECELGAapplicationDataReceivedjoincommandReceivedr   r   r   r   rL   
ValueErrorr   	negotiate)r   rR   appDataBufferbrL   r  s         r   dataReceivedTelnet.dataReceived  s   4AzzV#8!*DJ%Z!*DJ!((+y(8!((+!'DJ"W!1DJ$&DM3Rb"c2r2FF!'DJ$44SXXm5LM)!,((D14r400!*DJ#$L$Y22y(#
,,L 00-1HI%a($$W0y(#
:!((/%Z!((/#X "((/!*DJ!((3//8!9DJMM((+777!'DJ#}}H$44SXXm5LM)!,NN8,!1DJMM((+ !566S !V ((-)@A r   c                    U R                   R                  5        H  nUR                  R                  b8  UR                  R                  nS UR                  l        UR	                  U5        UR
                  R                  c  Mk  UR
                  R                  nS UR
                  l        UR	                  U5        M     g r   )r   valuesr   r   errbackr   )r   reasonr   r   s       r   connectionLostTelnet.connectionLostY  s    \\((*Exx  ,HH%%$(!		&!yy!!-II&&%)		"		&! +r   c                     g)z%
Called with application-level data.
NrK   r   s     r   r  Telnet.applicationDataReceivedd  rP   r   c                     g)z8
Called for commands for which no handler is installed.
NrK   r   s      r   rN   Telnet.unhandledCommandi  rP   r   c                 t    U R                   R                  U5      nUc  U R                  X5        g U" U5        g r   )r   getrN   )r   rL   rM   cmdFuncs       r   r  Telnet.commandReceivedn  s1    //%%g.?!!'4Hr   c                     g)z?
Called for subnegotiations for which no handler is installed.
NrK   r   s      r   rS   Telnet.unhandledSubnegotiationu  rP   r   c                     US   USS  pU R                   R                  U5      nUc  U R                  X!5        g U" U5        g )Nr   r   )r   r$  rS   )r   rR   rL   r%  s       r   r  Telnet.negotiatez  sC    Qab%%))'2?((7DMr   c                     U R                  U5      nU R                  UR                  R                  UR                  R                  4   " XU5        g r   )r   willMapr   r   r   r   rW   r   s      r   r   Telnet.telnet_WILL  <    'QUU[[!%%"3"334TfEr   c                     U R                  U5      (       a#  SUR                  l        U R                  U5        g U R	                  U5        g Nr   )r[   r   r   r   r   r   r   rW   s      r   will_no_falseTelnet.will_no_false  s6    V$$#EIIOHHVJJvr   c                    SUR                   l        SUR                   l        UR                   R                  nS UR                   l        UR	                  S5        U R                  U5      (       d   SR                  U5      5       eg )Nr   FTz?enableRemote must return True in this context (for option {!r}))r   r   r   r   callbackr[   formatr   r   rW   r   s       r   will_no_trueTelnet.will_no_true  sv    		 %		II!			

4  
 
 	
LSS
	
 
r   c                     g r   rK   r2  s      r   will_yes_falseTelnet.will_yes_false       	r   c                 2      SR                  UU5      5       e)NzBwill_yes_true can never be entered, but was called with {!r}, {!r}r7  r2  s      r   will_yes_trueTelnet.will_yes_true  s(     	
OVV
	
r   ))r   F)r   T)r   F)r   Tc                     U R                  U5      nU R                  UR                  R                  UR                  R                  4   " XU5        g r   )r   wontMapr   r   r   r-  s      r   r   Telnet.telnet_WONT  r/  r   c                     g r   rK   r2  s      r   wont_no_falseTelnet.wont_no_false  s     	r   c                     SUR                   l        UR                   R                  nS UR                   l        UR                  [	        U5      5        g NF)r   r   r   r  r   r8  s       r   wont_no_trueTelnet.wont_no_true  s:     %		II!					-'(r   c                 j    SUR                   l        U R                  U5        U R                  U5        g Nr   )r   r   ra   r   r2  s      r   wont_yes_falseTelnet.wont_yes_false  s'    		6"

6r   c                     SUR                   l        SUR                   l        UR                   R                  nS UR                   l        UR	                  S5        U R                  U5        g Nr   FT)r   r   r   r   r6  ra   r8  s       r   wont_yes_trueTelnet.wont_yes_true  sN    		 %		II!			

46"r   c                     U R                  U5      nU R                  UR                  R                  UR                  R                  4   " XU5        g r   )r   doMapr   r   r   r-  s      r   r   Telnet.telnet_DO  s<    '

144::qtt///0&Ar   c                     U R                  U5      (       a#  SUR                  l        U R                  U5        g U R	                  U5        g r1  )rX   r   r   r   r   r2  s      r   do_no_falseTelnet.do_no_false  s6    F##"EHHNJJvJJvr   c                     SUR                   l        SUR                   l        UR                   R                  nS UR                   l        UR	                  S5        U R                  U5        g )Nr   FT)r   r   r   r   r6  rX   r8  s       r   
do_no_trueTelnet.do_no_true  sN    $HH 	

4 r   c                     g r   rK   r2  s      r   do_yes_falseTelnet.do_yes_false  r>  r   c                 2      SR                  UU5      5       e)Nz@do_yes_true can never be entered, but was called with {!r}, {!r}r@  r2  s      r   do_yes_trueTelnet.do_yes_true  s(     	
MTT
	
r   c                     U R                  U5      nU R                  UR                  R                  UR                  R                  4   " XU5        g r   )r   dontMapr   r   r   r-  s      r   r   Telnet.telnet_DONT  s<    'QTTZZ!1!1124FCr   c                     g r   rK   r2  s      r   dont_no_falseTelnet.dont_no_false  r>  r   c                     SUR                   l        UR                   R                  nS UR                   l        UR                  [	        U5      5        g rJ  )r   r   r   r  r   r8  s       r   dont_no_trueTelnet.dont_no_true  s<      %HH 			-'(r   c                 j    SUR                   l        U R                  U5        U R                  U5        g rN  )r   r   r^   r   r2  s      r   dont_yes_falseTelnet.dont_yes_false  s'    &!

6r   c                     SUR                   l        SUR                   l        UR                   R                  nS UR                   l        UR	                  S5        U R                  U5        g rR  )r   r   r   r   r6  r^   r8  s       r   dont_yes_trueTelnet.dont_yes_true  sN    $HH 	

4&!r   c                     gz(
Reject all attempts to enable options.
FrK   r   s     r   rX   Telnet.enableLocal*       r   c                     grt  rK   r   s     r   r[   Telnet.enableRemote0  rv  r   c                      [        SU< 35      e)aa  
Signal a programming error by raising an exception.

L{enableLocal} must return true for the given value of C{option} in
order for this method to be called.  If a subclass of L{Telnet}
overrides enableLocal to allow certain options to be enabled, it must
also override disableLocal to disable those options.

@raise NotImplementedError: Always raised.
z.Don't know how to disable local telnet option NotImplementedErrorr   s     r   r^   Telnet.disableLocal6  s     "<VJG
 	
r   c                      [        SU< 35      e)ae  
Signal a programming error by raising an exception.

L{enableRemote} must return true for the given value of C{option} in
order for this method to be called.  If a subclass of L{Telnet}
overrides enableRemote to allow certain options to be enabled, it must
also override disableRemote tto disable those options.

@raise NotImplementedError: Always raised.
z/Don't know how to disable remote telnet option rz  r   s     r   ra   Telnet.disableRemoteE  s     "=fZH
 	
r   )rL   r   r  r   r   r   N)7rc   rd   re   rf   r   r   r   r   r   r   r   r   r   r   rr   ru   rl   ro   ry   r  r  r  rN   r  rS   r  r   r3  r9  r<  rA  r,  r   rG  rK  rO  rS  rD  r   rY  r\  r_  rb  rV  r   rh  rk  rn  rq  re  rX   r[   r^   ra   rg   rK   r   r   r   r   Y  sO   @ E
#,A ,A\A')))


8OBb	"


F


 %"&$	GF)# %"&$	GB!

 # $"	ED
)" %"&$	G

r   r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	ProtocolTransportMixiniU  c                 Z    U R                   R                  UR                  SS5      5        g )Nr  s   
)r   r   r   r   s     r   r   ProtocolTransportMixin.writeV  s    T\\%9:r   c                 :    U R                   R                  U5        g r   )r   writeSequence)r   seqs     r   r  $ProtocolTransportMixin.writeSequenceY  s    $$S)r   c                 8    U R                   R                  5         g r   )r   loseConnectionr   s    r   r  %ProtocolTransportMixin.loseConnection\  s    %%'r   c                 6    U R                   R                  5       $ r   )r   getHostr   s    r   r  ProtocolTransportMixin.getHost_      ~~%%''r   c                 6    U R                   R                  5       $ r   )r   getPeerr   s    r   r  ProtocolTransportMixin.getPeerb  r  r   rK   N)
rc   rd   re   rf   r   r  r  r  r  rg   rK   r   r   r  r  U  s    ;*(((r   r  c                   j    \ rS rSrSrSrSrSrSS jrS r	S r
S rS	 rS
 rS rS rS rS rS rSrg)TelnetTransportif  a  
@ivar protocol: An instance of the protocol to which this
transport is connected, or None before the connection is
established and after it is lost.

@ivar protocolFactory: A callable which returns protocol instances
which provide L{ITelnetProtocol}.  This will be invoked when a
connection is established.  It is passed *protocolArgs and
**protocolKwArgs.

@ivar protocolArgs: A tuple of additional arguments to
pass to protocolFactory.

@ivar protocolKwArgs: A dictionary of additional arguments
to pass to protocolFactory.
FNc                 Z    [         R                  U 5        Ub  Xl        X l        X0l        g g r   )r   r   protocolFactoryprotocolArgsprotocolKwArgs)r   r  akws       r   r   TelnetTransport.__init__}  s+    &#2  !"$ 'r   c                 R   U R                   b  U R                   " U R                  0 U R                  D6U l        [        R                  U R                  5      (       d   e U R                  nXR                  l        U R                  R                  U 5        g g ! [         a     N)f = fr   )	r  r  r  r   rH   
providedByfactoryAttributeErrormakeConnection)r   r  s     r   connectionMadeTelnetTransport.connectionMade  s    + 00""&*&9&9DM #--dmm<<<<0,, )0%MM((. , " s    B 
B&%B&c                     [         R                  X5        U R                  b   U R                  R                  U5        U ?g g ! U ?f = fr   )r   r  r   r   r  s     r   r  TelnetTransport.connectionLost  sD    d+==$",,V4M	 % Ms   A Ac                 8    U R                   R                  U5      $ r   )r   rX   r   s     r   rX   TelnetTransport.enableLocal  s    }}((00r   c                 8    U R                   R                  U5      $ r   )r   r[   r   s     r   r[   TelnetTransport.enableRemote      }}))&11r   c                 8    U R                   R                  U5      $ r   )r   r^   r   s     r   r^   TelnetTransport.disableLocal  r  r   c                 8    U R                   R                  U5      $ r   )r   ra   r   s     r   ra   TelnetTransport.disableRemote  s    }}**622r   c                 :    U R                   R                  X5        g r   )r   rS   r   s      r   rS   'TelnetTransport.unhandledSubnegotiation  s    --g<r   c                 :    U R                   R                  X5        g r   )r   rN   r   s      r   rN    TelnetTransport.unhandledCommand  s    &&w9r   c                 :    U R                   R                  U5        g r   r   r  r   s     r   r  'TelnetTransport.applicationDataReceived      ""4(r   c                 N    [         R                  XR                  SS5      5        g )N   s   )r  r   r   r   s     r   r   TelnetTransport.write  s    $$T<<+MNr   r   r  r  r  r   )rc   rd   re   rf   r   disconnectingr  r   r   r  r  rX   r[   r^   ra   rS   rN   r  r   rg   rK   r   r   r  r  f  sP    " MOH%/"1223=:)Or   r  c                   V    \ rS rSrSrS rS rS rS rS r	S r
S	 r\S
0rS rS rSrg)TelnetBootstrapProtocoli  Nc                 (    Xl         X l        X0l        g r   )r  r  r  )r   r  r   r  s       r   r    TelnetBootstrapProtocol.__init__  s    .  r   c                   ^ ^ T R                   T R                  R                  [        '   T R                  T R                  R                  [
        '   [
        [        [        4 H2  mT R                  R                  T5      R                  UU 4S j5        M4     [        4 H2  mT R                  R                  T5      R                  UU 4S j5        M4     T R                  " T R                  0 T R                  D6T l         T R                  nUT R                  l        T R                  R#                  T 5        g ! [          a     N(f = f)Nc                 :   > TR                   R                  SU TS9$ )NzError do {opt!r}r   r   failurefr   r   s    r   <lambda>8TelnetBootstrapProtocol.connectionMade.<locals>.<lambda>  s    $))++,>s+Kr   c                 :   > TR                   R                  SU TS9$ )NzError setting will {opt!r}r  r  r  s    r   r  r    s    $))++,H!QT+Ur   )telnet_NAWSr   r   NAWStelnet_LINEMODELINEMODESGArl   
addErrbackECHOrr   r  r  r  r   r  r  r  )r   r  r   s   ` @r   r  &TelnetBootstrapProtocol.connectionMade  s    .2.>.>%%d+262F2F%%h/dC(CNNc"--K ) 7CNN$//U 
 ,,d.?.?W4CVCVW	,llG %,DMM!$$T*  		s   D: :
EEc                 j    U R                   b   U R                   R                  U5        U ? g g ! U ? f = fr   )r   r  r  s     r   r  &TelnetBootstrapProtocol.connectionLost  s6    ==$",,V4M	 % Ms   . 2c                 :    U R                   R                  U5        g r   r  r   s     r   r  $TelnetBootstrapProtocol.dataReceived  r  r   c                 0    U[         :X  a  gU[        :X  a  ggNTF)r  r  r   s     r   rX   #TelnetBootstrapProtocol.enableLocal  s    $;CZr   c                     U[         :X  a,  U R                  R                  [         [        [        -   5        gU[
        :X  a  gU[        :X  a  ggr  )r  r   ry   MODELINEMODE_TRAPSIGr  r  r   s     r   r[   $TelnetBootstrapProtocol.enableRemote  s=    (?NN--h?O8OPD[CZr   c                    [        U5      S:X  aN  [        R                  " SSR                  U5      5      u  p#U R                  R
                  R                  X#5        g U R                  R                  S[        U5      S9  g )Nr   z!HHr   z$Wrong number of NAWS bytes: {nbytes})nbytes)	lenstructunpackr  r   terminalProtocolterminalSizer   error)r   rR   widthheights       r   r  #TelnetBootstrapProtocol.telnet_NAWS  sZ    
 t9>"MM%$@MEMM**77FIIOOB3t9OUr   SLCc                     g r   rK   r   s     r   r  'TelnetBootstrapProtocol.telnet_LINEMODE  s     	r   c                     [        [        U5      /S-  6 nU H'  u  p4nS[        U5      [        U5      [        U5      4  M)     g )Nr   r  )zipiterord)r   rR   chunksslcFunctionslcValueslcWhats         r   linemode_SLC$TelnetBootstrapProtocol.linemode_SLC  s?    tDzlQ&'.4*K73{#S]CL@ /5r   r  )rc   rd   re   rf   r   r   r  r  r  rX   r[   r  LINEMODE_SLClinemodeSubcommandsr  r  rg   rK   r   r   r  r    sC    H!
+0")		V (/Ar   r  )basicc                   .    \ rS rSrSrSrS rS rS rSr	g)	StatefulTelnetProtocoli  r  Discardc                 l    [         R                  R                  X5        [        R                  X5        g r   )r  LineReceiverr  r   r  s     r   r  %StatefulTelnetProtocol.connectionLost  s$    ))$7%%d3r   c                     U R                   n[        U SU-   5      " U5      nUb3  U R                   U:X  a  X0l         g U R                  R                  S5        g g )Ntelnet_z$state changed and new state returned)r   getattrr   warn)r   lineoldStatenewStates       r   lineReceived#StatefulTelnetProtocol.lineReceived  sN    ::4X!56t<zzX%%
		EF	  r   c                     g r   rK   r   r   s     r   telnet_Discard%StatefulTelnetProtocol.telnet_Discard!  r   r   )r   N)
rc   rd   re   rf   	delimiterr   r  r  r  rg   rK   r   r   r  r    s    IE4Gr   r  )credentialsc                   J    \ rS rSrSrSrSrS rS rS r	S r
S	 rS
 rS rSrg)AuthenticatingTelnetProtocoli(  a  
A protocol which prompts for credentials and attempts to authenticate them.

Username and password prompts are given (the password is obscured).  When the
information is collected, it is passed to a portal and an avatar implementing
L{ITelnetProtocol} is requested.  If an avatar is returned, it connected to this
protocol's transport, and this protocol's transport is connected to it.
Otherwise, the user is re-prompted for credentials.
UserNc                     Xl         g r   )portal)r   r  s     r   r   %AuthenticatingTelnetProtocol.__init__6  s    r   c                 :    U R                   R                  S5        g )N
   Username: r   r   s    r   r  +AuthenticatingTelnetProtocol.connectionMade9  s    ]+r   c                     [         R                  X5        U R                  b1   U R                  R                  U5        U R                  5         U ?U ?g g ! U ?U ?f = fr   )r  r  r   logoutr  s     r   r  +AuthenticatingTelnetProtocol.connectionLost<  sU    --d;==$/,,V4M4; %
 M4;s   +A Ac                     Xl         U R                  R                  [        5        U R                  R	                  S5        g)Ns
   Password: Password)usernamer   rr   r  r   r  s     r   telnet_User(AuthenticatingTelnetProtocol.telnet_UserE  s.    D!]+r   c                    ^ ^^ T R                   UsmmT ? UU U4S jnT R                  R                  [        5      R	                  U5        g)Nc                    > [         R                  " TT5      nTR                  R                  US [        5      nUR                  TR                  5        UR                  TR                  5        g r   )	r
  UsernamePasswordr  loginrH   addCallback_cbLoginr  _ebLogin)ignoredcredsr   passwordr   r  s      r   r  ;AuthenticatingTelnetProtocol.telnet_Password.<locals>.loginO  sM    008DE!!%?AMM$--(LL'r   r  )r  r   ru   r  r   )r   r   r  r%  r  s   `  @@r   telnet_Password,AuthenticatingTelnetProtocol.telnet_PasswordK  s?    !]]D(M	( 	D!--e4r   c                     Uu  p#nU[         L d   eX0l        X@l        SU l        UR                  " U R
                  5        X0R
                  l        g )NCommand)rH   r   r  r   r  r   )r   ial	interfacer   r  s        r   r!  %AuthenticatingTelnetProtocol._cbLoginX  sG    &)#	VO+++ 
/"*r   c                 ~    U R                   R                  S5        U R                   R                  S5        SU l        g )Ns   
Authentication failed
r  r  )r   r   r   )r   r  s     r   r"  %AuthenticatingTelnetProtocol._ebLoginb  s.    9:]+
r   )r  r  r   r   r  )rc   rd   re   rf   r   r   r   r   r  r  r  r'  r!  r"  rg   rK   r   r   r  r  (  s6     EH,/+r   r  )r|   r   r   r   r   r   rH   ri   r   r   r  r  )}r   r  zope.interfacer   twisted.internetr   r   	iinternetr   twisted.loggerr   twisted.python.compatr   intr   r   r  EDITTRAPSIGMODE_ACKSOFT_TABLIT_ECHONULLBELBSHTLFVTFFCRr  r  r  r  r  r   r  r  r	  r
  r  r  r  r  r  r   r   r   r   r   r   LINEMODE_MODELINEMODE_EDITr  LINEMODE_MODE_ACKLINEMODE_SOFT_TABLINEMODE_LIT_ECHOLINEMODE_FORWARDMASKr  LINEMODE_SLC_SYNCHLINEMODE_SLC_BRKLINEMODE_SLC_IPLINEMODE_SLC_AOLINEMODE_SLC_AYTLINEMODE_SLC_EORLINEMODE_SLC_ABORTLINEMODE_SLC_EOFLINEMODE_SLC_SUSPLINEMODE_SLC_ECLINEMODE_SLC_ELLINEMODE_SLC_EWLINEMODE_SLC_RPLINEMODE_SLC_LNEXTLINEMODE_SLC_XONLINEMODE_SLC_XOFFLINEMODE_SLC_FORW1LINEMODE_SLC_FORW2LINEMODE_SLC_MCLLINEMODE_SLC_MCRLINEMODE_SLC_MCWLLINEMODE_SLC_MCWRLINEMODE_SLC_MCBOLLINEMODE_SLC_MCEOLLINEMODE_SLC_INSRTLINEMODE_SLC_OVERLINEMODE_SLC_ECRLINEMODE_SLC_EWRLINEMODE_SLC_EBOLLINEMODE_SLC_EEOLLINEMODE_SLC_DEFAULTLINEMODE_SLC_VALUELINEMODE_SLC_CANTCHANGELINEMODE_SLC_NOSUPPORTLINEMODE_SLC_LEVELBITSLINEMODE_SLC_ACKLINEMODE_SLC_FLUSHINLINEMODE_SLC_FLUSHOUTLINEMODE_EOFLINEMODE_SUSPLINEMODE_ABORT	IProtocolrH   
ITransportri   	Exceptionr|   r   r   r   r   r   Protocolr   r   r  r  r  twisted.protocolsr  r  r  twisted.credr
  r  __all__rK   r   r   <module>ry     sX  
  & E E ! +	C 	E 	 Aw

 Aw
1g	!W	!W 
"X	"X 
"X	"XAw
1gBx8
3i	#Y
3i	#Y
3i	#Y	#Y
3i	#Y	#Y	#Y	#YCyCy	#Y Cy 3iQQ7 G G H Aw Aw!W 7 q'q'7 7 !W 7 G r(r(r(r("X 8 H "X "X 8 8 H H "X "X "X H 8 8 H H Aw !W q' a a 9 Bx R CyS	cAi)) AHHy++ HV	) 	
{ 
	$ 		% 		& 		) 	 _X&&  ,y
X y
x( ("JOf4 JOZVAn.D VAr $U// , %=#9 =@r   