<s> """<STR_LIT>""" <EOL> from zope . interface import implementer <EOL> from twisted . internet import protocol <EOL> from twisted . application import service , strports <EOL> from twisted . cred import portal , checkers <EOL> from twisted . python import usage <EOL> from twisted . conch . insults import insults <EOL> from twisted . conch import manhole , manhole_ssh , telnet <EOL> class makeTelnetProtocol : <EOL> def __init__ ( self , portal ) : <EOL> self . portal = portal <EOL> def __call__ ( self ) : <EOL> auth = telnet . AuthenticatingTelnetProtocol <EOL> args = ( self . portal , ) <EOL> return telnet . TelnetTransport ( auth , * args ) <EOL> class chainedProtocolFactory : <EOL> def __init__ ( self , namespace ) : <EOL> self . namespace = namespace <EOL> def __call__ ( self ) : <EOL> return insults . ServerProtocol ( manhole . ColoredManhole , self . namespace ) <EOL> @ implementer ( portal . IRealm ) <EOL> class _StupidRealm : <EOL> def __init__ ( self , proto , * a , ** kw ) : <EOL> self . protocolFactory = proto <EOL> self . protocolArgs = a <EOL> self . protocolKwArgs = kw <EOL> def requestAvatar ( self , avatarId , * interfaces ) : <EOL> if telnet . ITelnetProtocol in interfaces : <EOL> return ( telnet . ITelnetProtocol , <EOL> self . protocolFactory ( * self . protocolArgs , ** self . protocolKwArgs ) , <EOL> lambda : None ) <EOL> raise NotImplementedError ( ) <EOL> class Options ( usage . Options ) : <EOL> optParameters = [ <EOL> [ "<STR_LIT>" , "<STR_LIT:t>" , None , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:s>" , None , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" ] ] <EOL> def __init__ ( self ) : <EOL> usage . Options . __init__ ( self ) <EOL> self [ '<STR_LIT>' ] = None <EOL> def postOptions ( self ) : <EOL> if self [ '<STR_LIT>' ] is None and self [ '<STR_LIT>' ] is None : <EOL> raise usage . UsageError ( "<STR_LIT>" ) <EOL> def makeService ( options ) : <EOL> """<STR_LIT>""" <EOL> svc = service . MultiService ( ) <EOL> namespace = options [ '<STR_LIT>' ] <EOL> if namespace is None : <EOL> namespace = { } <EOL> checker = checkers . FilePasswordDB ( options [ '<STR_LIT>' ] ) <EOL> if options [ '<STR_LIT>' ] : <EOL> telnetRealm = _StupidRealm ( telnet . TelnetBootstrapProtocol , <EOL> insults . ServerProtocol , <EOL> manhole . ColoredManhole , <EOL> namespace ) <EOL> telnetPortal = portal . Portal ( telnetRealm , [ checker ] ) <EOL> telnetFactory = protocol . ServerFactory ( ) <EOL> telnetFactory . protocol = makeTelnetProtocol ( telnetPortal ) <EOL> telnetService = strports . service ( options [ '<STR_LIT>' ] , <EOL> telnetFactory ) <EOL> telnetService . setServiceParent ( svc ) <EOL> if options [ '<STR_LIT>' ] : <EOL> sshRealm = manhole_ssh . TerminalRealm ( ) <EOL> sshRealm . chainedProtocolFactory = chainedProtocolFactory ( namespace ) <EOL> sshPortal = portal . Portal ( sshRealm , [ checker ] ) <EOL> sshFactory = manhole_ssh . ConchFactory ( sshPortal ) <EOL> sshService = strports . service ( options [ '<STR_LIT>' ] , <EOL> sshFactory ) <EOL> sshService . setServiceParent ( svc ) <EOL> return svc </s>
