<s> """<STR_LIT>""" <EOL> from zope . interface import implementer <EOL> from twisted . conch import avatar , interfaces as iconch , error as econch <EOL> from twisted . conch . ssh import factory , keys , session <EOL> from twisted . python import components <EOL> from twisted . conch . insults import insults <EOL> class _Glue : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kw ) : <EOL> self . __dict__ . update ( kw ) <EOL> def __getattr__ ( self , name ) : <EOL> raise AttributeError ( self . name , "<STR_LIT>" , name ) <EOL> class TerminalSessionTransport : <EOL> def __init__ ( self , proto , chainedProtocol , avatar , width , height ) : <EOL> self . proto = proto <EOL> self . avatar = avatar <EOL> self . chainedProtocol = chainedProtocol <EOL> protoSession = self . proto . session <EOL> self . proto . makeConnection ( <EOL> _Glue ( write = self . chainedProtocol . dataReceived , <EOL> loseConnection = lambda : avatar . conn . sendClose ( protoSession ) , <EOL> name = "<STR_LIT>" ) ) <EOL> def loseConnection ( ) : <EOL> self . proto . loseConnection ( ) <EOL> self . chainedProtocol . makeConnection ( <EOL> _Glue ( write = self . proto . write , <EOL> loseConnection = loseConnection , <EOL> name = "<STR_LIT>" ) ) <EOL> self . chainedProtocol . terminalProtocol . terminalSize ( width , height ) <EOL> @ implementer ( iconch . ISession ) <EOL> class TerminalSession ( components . Adapter ) : <EOL> transportFactory = TerminalSessionTransport <EOL> chainedProtocolFactory = insults . ServerProtocol <EOL> def getPty ( self , term , windowSize , attrs ) : <EOL> self . height , self . width = windowSize [ : <NUM_LIT:2> ] <EOL> def openShell ( self , proto ) : <EOL> self . transportFactory ( <EOL> proto , self . chainedProtocolFactory ( ) , <EOL> iconch . IConchUser ( self . original ) , <EOL> self . width , self . height ) <EOL> def execCommand ( self , proto , cmd ) : <EOL> raise econch . ConchError ( "<STR_LIT>" ) <EOL> def closed ( self ) : <EOL> pass <EOL> class TerminalUser ( avatar . ConchUser , components . Adapter ) : <EOL> def __init__ ( self , original , avatarId ) : <EOL> components . Adapter . __init__ ( self , original ) <EOL> avatar . ConchUser . __init__ ( self ) <EOL> self . channelLookup [ '<STR_LIT>' ] = session . SSHSession <EOL> class TerminalRealm : <EOL> userFactory = TerminalUser <EOL> sessionFactory = TerminalSession <EOL> transportFactory = TerminalSessionTransport <EOL> chainedProtocolFactory = insults . ServerProtocol <EOL> def _getAvatar ( self , avatarId ) : <EOL> comp = components . Componentized ( ) <EOL> user = self . userFactory ( comp , avatarId ) <EOL> sess = self . sessionFactory ( comp ) <EOL> sess . transportFactory = self . transportFactory <EOL> sess . chainedProtocolFactory = self . chainedProtocolFactory <EOL> comp . setComponent ( iconch . IConchUser , user ) <EOL> comp . setComponent ( iconch . ISession , sess ) <EOL> return user <EOL> def __init__ ( self , transportFactory = None ) : <EOL> if transportFactory is not None : <EOL> self . transportFactory = transportFactory <EOL> def requestAvatar ( self , avatarId , mind , * interfaces ) : <EOL> for i in interfaces : <EOL> if i is iconch . IConchUser : <EOL> return ( iconch . IConchUser , <EOL> self . _getAvatar ( avatarId ) , <EOL> lambda : None ) <EOL> raise NotImplementedError ( ) <EOL> class ConchFactory ( factory . SSHFactory ) : <EOL> publicKey = '<STR_LIT>' <EOL> publicKeys = { <EOL> '<STR_LIT>' : keys . Key . fromString ( publicKey ) <EOL> } <EOL> del publicKey <EOL> privateKey = """<STR_LIT>""" <EOL> privateKeys = { <EOL> '<STR_LIT>' : keys . Key . fromString ( privateKey ) <EOL> } <EOL> del privateKey <EOL> def __init__ ( self , portal ) : <EOL> self . portal = portal </s>
