<s> """<STR_LIT>""" <EOL> import warnings <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> DeprecationWarning , <EOL> stacklevel = <NUM_LIT:2> ) <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from twisted import copyright <EOL> from twisted . internet import protocol <EOL> ESC = chr ( <NUM_LIT> ) <EOL> BOLD_MODE_ON = ESC + "<STR_LIT>" <EOL> BOLD_MODE_OFF = ESC + "<STR_LIT>" <EOL> NULL = chr ( <NUM_LIT:0> ) <EOL> LF = chr ( <NUM_LIT:10> ) <EOL> CR = chr ( <NUM_LIT> ) <EOL> BEL = chr ( <NUM_LIT:7> ) <EOL> BS = chr ( <NUM_LIT:8> ) <EOL> HT = chr ( <NUM_LIT:9> ) <EOL> VT = chr ( <NUM_LIT:11> ) <EOL> FF = chr ( <NUM_LIT:12> ) <EOL> SE = chr ( <NUM_LIT> ) <EOL> NOP = chr ( <NUM_LIT> ) <EOL> DM = chr ( <NUM_LIT> ) <EOL> BRK = chr ( <NUM_LIT> ) <EOL> IP = chr ( <NUM_LIT> ) <EOL> AO = chr ( <NUM_LIT> ) <EOL> AYT = chr ( <NUM_LIT> ) <EOL> EC = chr ( <NUM_LIT> ) <EOL> EL = chr ( <NUM_LIT> ) <EOL> GA = chr ( <NUM_LIT> ) <EOL> SB = chr ( <NUM_LIT> ) <EOL> WILL = chr ( <NUM_LIT> ) <EOL> WONT = chr ( <NUM_LIT> ) <EOL> DO = chr ( <NUM_LIT> ) <EOL> DONT = chr ( <NUM_LIT> ) <EOL> IAC = chr ( <NUM_LIT:255> ) <EOL> ECHO = chr ( <NUM_LIT:1> ) <EOL> SUPGA = chr ( <NUM_LIT:3> ) <EOL> LINEMODE = chr ( <NUM_LIT> ) <EOL> HIDE = chr ( <NUM_LIT> ) <EOL> NOECHO = chr ( <NUM_LIT> ) <EOL> iacBytes = { <EOL> DO : '<STR_LIT>' , <EOL> DONT : '<STR_LIT>' , <EOL> WILL : '<STR_LIT>' , <EOL> WONT : '<STR_LIT>' , <EOL> IP : '<STR_LIT>' <EOL> } <EOL> def multireplace ( st , dct ) : <EOL> for k , v in dct . items ( ) : <EOL> st = st . replace ( k , v ) <EOL> return st <EOL> class Telnet ( protocol . Protocol ) : <EOL> """<STR_LIT>""" <EOL> gotIAC = <NUM_LIT:0> <EOL> iacByte = None <EOL> lastLine = None <EOL> buffer = '<STR_LIT>' <EOL> echo = <NUM_LIT:0> <EOL> delimiters = [ '<STR_LIT:\r\n>' , '<STR_LIT>' ] <EOL> mode = "<STR_LIT>" <EOL> def write ( self , data ) : <EOL> """<STR_LIT>""" <EOL> self . transport . write ( data ) <EOL> def connectionMade ( self ) : <EOL> """<STR_LIT>""" <EOL> self . write ( self . welcomeMessage ( ) + self . loginPrompt ( ) ) <EOL> def welcomeMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> x = self . factory . __class__ <EOL> return ( "<STR_LIT:\r\n>" + x . __module__ + '<STR_LIT:.>' + x . __name__ + <EOL> '<STR_LIT>' % copyright . version <EOL> ) <EOL> def loginPrompt ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def iacSBchunk ( self , chunk ) : <EOL> pass <EOL> def iac_DO ( self , feature ) : <EOL> pass <EOL> def iac_DONT ( self , feature ) : <EOL> pass <EOL> def iac_WILL ( self , feature ) : <EOL> pass <EOL> def iac_WONT ( self , feature ) : <EOL> pass <EOL> def iac_IP ( self , feature ) : <EOL> pass <EOL> def processLine ( self , line ) : <EOL> """<STR_LIT>""" <EOL> mode = getattr ( self , "<STR_LIT>" + self . mode ) ( line ) <EOL> if mode is not None : <EOL> self . mode = mode <EOL> def telnet_User ( self , user ) : <EOL> """<STR_LIT>""" <EOL> self . username = user <EOL> self . write ( IAC + WILL + ECHO + "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> def telnet_Password ( self , paswd ) : <EOL> """<STR_LIT>""" <EOL> self . write ( IAC + WONT + ECHO + "<STR_LIT>" ) <EOL> try : <EOL> checked = self . checkUserAndPass ( self . username , paswd ) <EOL> except : <EOL> return "<STR_LIT>" <EOL> if not checked : <EOL> return "<STR_LIT>" <EOL> self . loggedIn ( ) <EOL> return "<STR_LIT>" <EOL> def telnet_Command ( self , cmd ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def processChunk ( self , chunk ) : <EOL> """<STR_LIT>""" <EOL> self . buffer = self . buffer + chunk <EOL> for delim in self . delimiters : <EOL> idx = self . buffer . find ( delim ) <EOL> if idx != - <NUM_LIT:1> : <EOL> break <EOL> while idx != - <NUM_LIT:1> : <EOL> buf , self . buffer = self . buffer [ : idx ] , self . buffer [ idx + <NUM_LIT:2> : ] <EOL> self . processLine ( buf ) <EOL> if self . mode == '<STR_LIT>' : <EOL> self . transport . loseConnection ( ) <EOL> for delim in self . delimiters : <EOL> idx = self . buffer . find ( delim ) <EOL> if idx != - <NUM_LIT:1> : <EOL> break <EOL> def dataReceived ( self , data ) : <EOL> chunk = StringIO ( ) <EOL> for char in data : <EOL> if self . gotIAC : <EOL> if self . iacByte : <EOL> if self . iacByte == SB : <EOL> if char == SE : <EOL> self . iacSBchunk ( chunk . getvalue ( ) ) <EOL> chunk = StringIO ( ) <EOL> del self . iacByte <EOL> del self . gotIAC <EOL> else : <EOL> chunk . write ( char ) <EOL> else : <EOL> try : <EOL> getattr ( self , '<STR_LIT>' % iacBytes [ self . iacByte ] ) ( char ) <EOL> except KeyError : <EOL> pass <EOL> del self . iacByte <EOL> del self . gotIAC <EOL> else : <EOL> self . iacByte = char <EOL> elif char == IAC : <EOL> c = chunk . getvalue ( ) <EOL> if c : <EOL> why = self . processChunk ( c ) <EOL> if why : <EOL> return why <EOL> chunk = StringIO ( ) <EOL> self . gotIAC = <NUM_LIT:1> <EOL> else : <EOL> chunk . write ( char ) <EOL> c = chunk . getvalue ( ) <EOL> if c : <EOL> why = self . processChunk ( c ) <EOL> if why : <EOL> return why <EOL> def loggedIn ( self ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
