コード例 #1
0
ファイル: Interface.py プロジェクト: yigitbey/esbot
def runReactorWithTerminal(terminalProtocol, *args):
    import os, tty, sys, termios
    from twisted.internet import stdio
    from twisted.conch.insults.insults import ServerProtocol
    
    #Fix quitter so it doesn't close stdin
    #so we can call quit() from the terminal
    #and not mess up our terminal
    class NewQuitter(quit.__class__):
        def __call__(self, code=None):
            raise SystemExit(code)
    if isinstance(__builtins__, dict):
        __builtins__['quit'] = NewQuitter('quit')
        __builtins__['exit'] = NewQuitter('exit')
    else:
        __builtins__.quit = NewQuitter('quit')
        __builtins__.exit = NewQuitter('exit')
    
    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    try:
        p = ServerProtocol(terminalProtocol, *args)
        stdio.StandardIO(p)
        reactor.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, "\r\x1bc\r")
コード例 #2
0
ファイル: __main__.py プロジェクト: zeeneddie/imaginary
def runTextServer(reactor, *argv):
    """
    Run a L{ConsoleTextServer}.
    """
    textServer = makeTextServer(reactor, *argv)
    StandardIO(ServerProtocol(lambda: textServer))
    return textServer.done
コード例 #3
0
def runWithProtocol(klass):
    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    try:
        stdio.StandardIO(ServerProtocol(klass))
        reactor.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, b"\r\x1bc\r")
コード例 #4
0
ファイル: test_wiring.py プロジェクト: zeeneddie/imaginary
 def test_connectionMadePrompt(self):
     """
     L{CharacterSelectionTextServer} prompts the player upon connection,
     giving them the option to create a character.
     """
     testWorld = buildWorld(self)
     transport = StringTransport()
     terminal = ServerProtocol(lambda: testWorld.proto)
     terminal.makeConnection(transport)
     self.assertIn("0) Create", transport.io.getvalue())
コード例 #5
0
 def test_nextLine(self):
     """
     L{ServerProtocol.nextLine} writes C{"\r\n"} to its transport.
     """
     # Why doesn't it write ESC E?  Because ESC E is poorly supported.  For
     # example, gnome-terminal (many different versions) fails to scroll if
     # it receives ESC E and the cursor is already on the last row.
     protocol = ServerProtocol()
     transport = StringTransport()
     protocol.makeConnection(transport)
     protocol.nextLine()
     self.assertEqual(transport.value(), "\r\n")
コード例 #6
0
    def doWork(self):
        """
        Service startup.
        """

        # Set up the terminal for interactive action
        self.terminalFD = sys.__stdin__.fileno()
        self._oldTerminalSettings = termios.tcgetattr(self.terminalFD)
        tty.setraw(self.terminalFD)

        self.protocol = ServerProtocol(lambda: ShellProtocol(self))
        StandardIO(self.protocol)
        return succeed(None)
コード例 #7
0
def start_console():
    ag = AMPGateway("localhost", 25600)

    if fancy_console:
        global oldSettings
        fd = sys.__stdin__.fileno()
        oldSettings = termios.tcgetattr(fd)
        tty.setraw(fd)
        p = ServerProtocol(BravoManhole, ag)
    else:
        p = BravoConsole(ag)

    StandardIO(p)
    return p
コード例 #8
0
def runReactorWithTerminal(terminalProtocol, *args):
    import os, tty, sys, termios
    from twisted.internet import stdio
    from twisted.conch.insults.insults import ServerProtocol

    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    try:
        p = ServerProtocol(terminalProtocol, *args)
        stdio.StandardIO(p)
        reactor.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, "\r\x1bc\r")
コード例 #9
0
    def make_manhole_server(self, port, username, password):
        from twisted.application.internet import TCPServer
        from twisted.cred.portal import Portal
        from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
        from twisted.conch.manhole import ColoredManhole
        from twisted.conch.manhole_ssh import ConchFactory, TerminalRealm
        from twisted.conch.insults.insults import ServerProtocol

        rlm = TerminalRealm()
        rlm.chainedProtocolFactory = lambda: ServerProtocol(
            ColoredManhole, None)

        auth_checker = InMemoryUsernamePasswordDatabaseDontUse(
            **{username: password})

        return TCPServer(port, ConchFactory(Portal(rlm, [auth_checker])))
コード例 #10
0
    def indirect(self, interface):
        """
        Create an L{IConchUser} avatar which will use L{ShellServer} to
        interact with the connection.
        """
        if interface is IConchUser:
            componentized = Componentized()

            user = _BetterTerminalUser(componentized, None)
            session = _BetterTerminalSession(componentized)
            session.transportFactory = TerminalSessionTransport
            session.chainedProtocolFactory = lambda: ServerProtocol(ShellServer, self.store)

            componentized.setComponent(IConchUser, user)
            componentized.setComponent(ISession, session)

            return user

        raise NotImplementedError(interface)
コード例 #11
0
def run():
    log.startLogging(file('child.log', 'w'))
    fd = sys.__stdin__.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setraw(fd)
    try:
        locals = {
            "tcp": basic.tcp,
            "serial": basic.serial,
            "knauer": knauer,
            "gilson": gilson,
            "s": shortcuts
        }
        p = ServerProtocol(ConsoleManhole, namespace=locals)
        stdio.StandardIO(p)
        reactor.run()
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, "\r\x1bc\r")
コード例 #12
0
ファイル: console.py プロジェクト: zhangaigh/rce
def runWithProtocol(klass, masterIP, port):
    """ Function overridden from twisted.conch.stdio to allow Ctrl+C interrupt

        @param klass:     A callable which will be invoked with
                          *a, **kw and should return an ITerminalProtocol
                          implementor. This will be invoked when a connection
                          to this ServerProtocol is established.

        @param masterIP:  IP of the master server.
        @type  masterIP:  string
    """
    fd = sys.stdin.fileno()
    oldSettings = termios.tcgetattr(fd)
    tty.setcbreak(fd)

    try:
        p = ServerProtocol(klass, masterIP, port)
        stdio.StandardIO(p)
        reactor.run()  #@UndefinedVariable
    finally:
        termios.tcsetattr(fd, termios.TCSANOW, oldSettings)
        os.write(fd, "\r\x1bc\r")
コード例 #13
0
 def setUp(self):
     self.protocol = ServerProtocol()
     self.transport = StringTransport()
     self.protocol.makeConnection(self.transport)