コード例 #1
0
ファイル: session.py プロジェクト: emil2k/joltem
    def openShell(self, protocol):
        """ Open a shell and connect it to proto. """

        peer_address = protocol.getPeer().address  # IAddress
        (host, port) = (peer_address.host, peer_address.port)
        log.msg("Open shell from %s:%d." % (host, port))
        serverProtocol = ServerProtocol(GatewayTerminalProtocol, self.avatar)
        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(wrapProtocol(serverProtocol))
コード例 #2
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())
コード例 #3
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(), b"\r\n")
コード例 #4
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")
コード例 #5
0
ファイル: __main__.py プロジェクト: zeeneddie/imaginary
def runTextServer(reactor, *argv):
    """
    Run a L{ConsoleTextServer}.
    """
    textServer = makeTextServer(reactor, *argv)
    StandardIO(ServerProtocol(lambda: textServer))
    return textServer.done
コード例 #6
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")
コード例 #7
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)
コード例 #8
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
コード例 #9
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")
コード例 #10
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])))
コード例 #11
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")
コード例 #12
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")
コード例 #13
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)
コード例 #14
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")
コード例 #15
0
 def setUp(self):
     self.protocol = ServerProtocol()
     self.transport = StringTransport()
     self.protocol.makeConnection(self.transport)
コード例 #16
0
class ServerProtocolOutputTests(unittest.TestCase):
    """
    Tests for the bytes L{ServerProtocol} writes to its transport when its
    methods are called.
    """
    # From ECMA 48: CSI is represented by bit combinations 01/11
    # (representing ESC) and 05/11 in a 7-bit code or by bit
    # combination 09/11 in an 8-bit code
    ESC = _ecmaCodeTableCoordinate(1, 11)
    CSI = ESC + _ecmaCodeTableCoordinate(5, 11)

    def setUp(self):
        self.protocol = ServerProtocol()
        self.transport = StringTransport()
        self.protocol.makeConnection(self.transport)

    def test_cursorUp(self):
        """
        L{ServerProtocol.cursorUp} writes the control sequence
        ending with L{CSFinalByte.CUU} to its transport.
        """
        self.protocol.cursorUp(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUU.value)

    def test_cursorDown(self):
        """
        L{ServerProtocol.cursorDown} writes the control sequence
        ending with L{CSFinalByte.CUD} to its transport.
        """
        self.protocol.cursorDown(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUD.value)

    def test_cursorForward(self):
        """
        L{ServerProtocol.cursorForward} writes the control sequence
        ending with L{CSFinalByte.CUF} to its transport.
        """
        self.protocol.cursorForward(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUF.value)

    def test_cursorBackward(self):
        """
        L{ServerProtocol.cursorBackward} writes the control sequence
        ending with L{CSFinalByte.CUB} to its transport.
        """
        self.protocol.cursorBackward(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUB.value)

    def test_cursorPosition(self):
        """
        L{ServerProtocol.cursorPosition} writes a control sequence
        ending with L{CSFinalByte.CUP} and containing the expected
        coordinates to its transport.
        """
        self.protocol.cursorPosition(0, 0)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1;1' + CSFinalByte.CUP.value)

    def test_cursorHome(self):
        """
        L{ServerProtocol.cursorHome} writes a control sequence ending
        with L{CSFinalByte.CUP} and no parameters, so that the client
        defaults to (1, 1).
        """
        self.protocol.cursorHome()
        self.assertEqual(self.transport.value(),
                         self.CSI + CSFinalByte.CUP.value)

    def test_index(self):
        """
        L{ServerProtocol.index} writes the control sequence ending in
        the 8-bit code table coordinates 4, 4.

        Note that ECMA48 5th Edition removes C{IND}.
        """
        self.protocol.index()
        self.assertEqual(self.transport.value(),
                         self.ESC + _ecmaCodeTableCoordinate(4, 4))

    def test_reverseIndex(self):
        """
        L{ServerProtocol.reverseIndex} writes the control sequence
        ending in the L{C1SevenBit.RI}.
        """
        self.protocol.reverseIndex()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.RI.value)

    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.
        self.protocol.nextLine()
        self.assertEqual(self.transport.value(), b"\r\n")

    def test_setModes(self):
        """
        L{ServerProtocol.setModes} writes a control sequence
        containing the requested modes and ending in the
        L{CSFinalByte.SM}.
        """
        modesToSet = [modes.KAM, modes.IRM, modes.LNM]
        self.protocol.setModes(modesToSet)
        self.assertEqual(
            self.transport.value(), self.CSI +
            b';'.join(map(intToBytes, modesToSet)) + CSFinalByte.SM.value)

    def test_setPrivateModes(self):
        """
        L{ServerProtocol.setPrivatesModes} writes a control sequence
        containing the requested private modes and ending in the
        L{CSFinalByte.SM}.
        """
        privateModesToSet = [
            privateModes.ERROR, privateModes.COLUMN, privateModes.ORIGIN
        ]
        self.protocol.setModes(privateModesToSet)
        self.assertEqual(
            self.transport.value(),
            self.CSI + b';'.join(map(intToBytes, privateModesToSet)) +
            CSFinalByte.SM.value)

    def test_resetModes(self):
        """
        L{ServerProtocol.resetModes} writes the control sequence
        ending in the L{CSFinalByte.RM}.
        """
        modesToSet = [modes.KAM, modes.IRM, modes.LNM]
        self.protocol.resetModes(modesToSet)
        self.assertEqual(
            self.transport.value(), self.CSI +
            b';'.join(map(intToBytes, modesToSet)) + CSFinalByte.RM.value)

    def test_singleShift2(self):
        """
        L{ServerProtocol.singleShift2} writes an escape sequence
        followed by L{C1SevenBit.SS2}
        """
        self.protocol.singleShift2()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.SS2.value)

    def test_singleShift3(self):
        """
        L{ServerProtocol.singleShift3} writes an escape sequence
        followed by L{C1SevenBit.SS3}
        """
        self.protocol.singleShift3()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.SS3.value)

    def test_selectGraphicRendition(self):
        """
        L{ServerProtocol.selectGraphicRendition} writes a control
        sequence containing the requested attributes and ending with
        L{CSFinalByte.SGR}
        """
        self.protocol.selectGraphicRendition(str(BLINK), str(UNDERLINE))
        self.assertEqual(
            self.transport.value(), self.CSI + intToBytes(BLINK) + b';' +
            intToBytes(UNDERLINE) + CSFinalByte.SGR.value)

    def test_horizontalTabulationSet(self):
        """
        L{ServerProtocol.horizontalTabulationSet} writes the escape
        sequence ending in L{C1SevenBit.HTS}
        """
        self.protocol.horizontalTabulationSet()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.HTS.value)

    def test_eraseToLineEnd(self):
        """
        L{ServerProtocol.eraseToLineEnd} writes the control sequence
        sequence ending in L{CSFinalByte.EL} and no parameters,
        forcing the client to default to 0 (from the active present
        position's current location to the end of the line.)
        """
        self.protocol.eraseToLineEnd()
        self.assertEqual(self.transport.value(),
                         self.CSI + CSFinalByte.EL.value)

    def test_eraseToLineBeginning(self):
        """
        L{ServerProtocol.eraseToLineBeginning} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 1 (from the beginning of the line up to and include the
        active present position's current location.)
        """
        self.protocol.eraseToLineBeginning()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.EL.value)

    def test_eraseLine(self):
        """
        L{ServerProtocol.eraseLine} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 2 (the entire line.)
        """
        self.protocol.eraseLine()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'2' + CSFinalByte.EL.value)

    def test_eraseToDisplayEnd(self):
        """
        L{ServerProtocol.eraseToDisplayEnd} writes the control
        sequence sequence ending in L{CSFinalByte.ED} and no parameters,
        forcing the client to default to 0 (from the active present
        position's current location to the end of the page.)
        """
        self.protocol.eraseToDisplayEnd()
        self.assertEqual(self.transport.value(),
                         self.CSI + CSFinalByte.ED.value)

    def test_eraseToDisplayBeginning(self):
        """
        L{ServerProtocol.eraseToDisplayBeginning} writes the control
        sequence sequence ending in L{CSFinalByte.ED} a parameter of 1
        (from the beginning of the page up to and include the active
        present position's current location.)
        """
        self.protocol.eraseToDisplayBeginning()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.ED.value)

    def test_eraseToDisplay(self):
        """
        L{ServerProtocol.eraseDisplay} writes the control sequence
        sequence ending in L{CSFinalByte.ED} a parameter of 2 (the
        entire page)
        """
        self.protocol.eraseDisplay()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'2' + CSFinalByte.ED.value)

    def test_deleteCharacter(self):
        """
        L{ServerProtocol.deleteCharacter} writes the control sequence
        containing the number of characters to delete and ending in
        L{CSFinalByte.DCH}
        """
        self.protocol.deleteCharacter(4)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'4' + CSFinalByte.DCH.value)

    def test_insertLine(self):
        """
        L{ServerProtocol.insertLine} writes the control sequence
        containing the number of lines to insert and ending in
        L{CSFinalByte.IL}
        """
        self.protocol.insertLine(5)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'5' + CSFinalByte.IL.value)

    def test_deleteLine(self):
        """
        L{ServerProtocol.deleteLine} writes the control sequence
        containing the number of lines to delete and ending in
        L{CSFinalByte.DL}
        """
        self.protocol.deleteLine(6)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'6' + CSFinalByte.DL.value)

    def test_setScrollRegionNoArgs(self):
        """
        With no arguments, L{ServerProtocol.setScrollRegion} writes a
        control sequence with no parameters, but a parameter
        separator, and ending in C{b'r'}.
        """
        self.protocol.setScrollRegion()
        self.assertEqual(self.transport.value(), self.CSI + b';' + b'r')

    def test_setScrollRegionJustFirst(self):
        """
        With just a value for its C{first} argument,
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        that parameter, a parameter separator, and finally a C{b'r'}.
        """
        self.protocol.setScrollRegion(first=1)
        self.assertEqual(self.transport.value(), self.CSI + b'1;' + b'r')

    def test_setScrollRegionJustLast(self):
        """
        With just a value for its C{last} argument,
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        a parameter separator, that parameter, and finally a C{b'r'}.
        """
        self.protocol.setScrollRegion(last=1)
        self.assertEqual(self.transport.value(), self.CSI + b';1' + b'r')

    def test_setScrollRegionFirstAndLast(self):
        """
        When given both C{first} and C{last}
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        the first parameter, a parameter separator, the last
        parameter, and finally a C{b'r'}.
        """
        self.protocol.setScrollRegion(first=1, last=2)
        self.assertEqual(self.transport.value(), self.CSI + b'1;2' + b'r')

    def test_reportCursorPosition(self):
        """
        L{ServerProtocol.reportCursorPosition} writes a control
        sequence ending in L{CSFinalByte.DSR} with a parameter of 6
        (the Device Status Report returns the current active
        position.)
        """
        self.protocol.reportCursorPosition()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'6' + CSFinalByte.DSR.value)
コード例 #17
0
ファイル: root.py プロジェクト: AsherBond/opennode-management
 def __init__(self, session):
     ServerProtocol.__init__(self)
     self.session = session
     self.transport = WebTransport(session)
コード例 #18
0
ファイル: server.py プロジェクト: saghul/TunnelIt
 def openShell(self, protocol):
     server_protocol = ServerProtocol(SSHNoSessionProtocol, self)
     server_protocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(server_protocol))
コード例 #19
0
class ServerProtocolOutputTests(unittest.TestCase):
    """
    Tests for the bytes L{ServerProtocol} writes to its transport when its
    methods are called.
    """
    # From ECMA 48: CSI is represented by bit combinations 01/11
    # (representing ESC) and 05/11 in a 7-bit code or by bit
    # combination 09/11 in an 8-bit code
    ESC = _ecmaCodeTableCoordinate(1, 11)
    CSI = ESC + _ecmaCodeTableCoordinate(5, 11)

    def setUp(self):
        self.protocol = ServerProtocol()
        self.transport = StringTransport()
        self.protocol.makeConnection(self.transport)


    def test_cursorUp(self):
        """
        L{ServerProtocol.cursorUp} writes the control sequence
        ending with L{CSFinalByte.CUU} to its transport.
        """
        self.protocol.cursorUp(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUU.value)


    def test_cursorDown(self):
        """
        L{ServerProtocol.cursorDown} writes the control sequence
        ending with L{CSFinalByte.CUD} to its transport.
        """
        self.protocol.cursorDown(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUD.value)


    def test_cursorForward(self):
        """
        L{ServerProtocol.cursorForward} writes the control sequence
        ending with L{CSFinalByte.CUF} to its transport.
        """
        self.protocol.cursorForward(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUF.value)


    def test_cursorBackward(self):
        """
        L{ServerProtocol.cursorBackward} writes the control sequence
        ending with L{CSFinalByte.CUB} to its transport.
        """
        self.protocol.cursorBackward(1)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.CUB.value)


    def test_cursorPosition(self):
        """
        L{ServerProtocol.cursorPosition} writes a control sequence
        ending with L{CSFinalByte.CUP} and containing the expected
        coordinates to its transport.
        """
        self.protocol.cursorPosition(0, 0)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1;1' + CSFinalByte.CUP.value)


    def test_cursorHome(self):
        """
        L{ServerProtocol.cursorHome} writes a control sequence ending
        with L{CSFinalByte.CUP} and no parameters, so that the client
        defaults to (1, 1).
        """
        self.protocol.cursorHome()
        self.assertEqual(self.transport.value(),
                         self.CSI + CSFinalByte.CUP.value)


    def test_index(self):
        """
        L{ServerProtocol.index} writes the control sequence ending in
        the 8-bit code table coordinates 4, 4.

        Note that ECMA48 5th Edition removes C{IND}.
        """
        self.protocol.index()
        self.assertEqual(self.transport.value(),
                         self.ESC + _ecmaCodeTableCoordinate(4, 4))


    def test_reverseIndex(self):
        """
        L{ServerProtocol.reverseIndex} writes the control sequence
        ending in the L{C1SevenBit.RI}.
        """
        self.protocol.reverseIndex()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.RI.value)


    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.
        self.protocol.nextLine()
        self.assertEqual(self.transport.value(), b"\r\n")


    def test_setModes(self):
        """
        L{ServerProtocol.setModes} writes a control sequence
        containing the requested modes and ending in the
        L{CSFinalByte.SM}.
        """
        modesToSet = [modes.KAM, modes.IRM, modes.LNM]
        self.protocol.setModes(modesToSet)
        self.assertEqual(self.transport.value(),
                         self.CSI +
                         b';'.join(map(intToBytes, modesToSet)) +
                         CSFinalByte.SM.value)


    def test_setPrivateModes(self):
        """
        L{ServerProtocol.setPrivatesModes} writes a control sequence
        containing the requested private modes and ending in the
        L{CSFinalByte.SM}.
        """
        privateModesToSet = [privateModes.ERROR,
                             privateModes.COLUMN,
                             privateModes.ORIGIN]
        self.protocol.setModes(privateModesToSet)
        self.assertEqual(self.transport.value(),
                         self.CSI +
                         b';'.join(map(intToBytes, privateModesToSet)) +
                         CSFinalByte.SM.value)


    def test_resetModes(self):
        """
        L{ServerProtocol.resetModes} writes the control sequence
        ending in the L{CSFinalByte.RM}.
        """
        modesToSet = [modes.KAM, modes.IRM, modes.LNM]
        self.protocol.resetModes(modesToSet)
        self.assertEqual(self.transport.value(),
                         self.CSI +
                         b';'.join(map(intToBytes, modesToSet)) +
                         CSFinalByte.RM.value)


    def test_singleShift2(self):
        """
        L{ServerProtocol.singleShift2} writes an escape sequence
        followed by L{C1SevenBit.SS2}
        """
        self.protocol.singleShift2()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.SS2.value)


    def test_singleShift3(self):
        """
        L{ServerProtocol.singleShift3} writes an escape sequence
        followed by L{C1SevenBit.SS3}
        """
        self.protocol.singleShift3()
        self.assertEqual(self.transport.value(),
                         self.ESC + C1SevenBit.SS3.value)


    def test_selectGraphicRendition(self):
        """
        L{ServerProtocol.selectGraphicRendition} writes a control
        sequence containing the requested attributes and ending with
        L{CSFinalByte.SGR}
        """
        self.protocol.selectGraphicRendition(str(BLINK), str(UNDERLINE))
        self.assertEqual(self.transport.value(),
                         self.CSI +
                         intToBytes(BLINK) + b';' + intToBytes(UNDERLINE) +
                         CSFinalByte.SGR.value)


    def test_horizontalTabulationSet(self):
        """
        L{ServerProtocol.horizontalTabulationSet} writes the escape
        sequence ending in L{C1SevenBit.HTS}
        """
        self.protocol.horizontalTabulationSet()
        self.assertEqual(self.transport.value(),
                         self.ESC +
                         C1SevenBit.HTS.value)


    def test_eraseToLineEnd(self):
        """
        L{ServerProtocol.eraseToLineEnd} writes the control sequence
        sequence ending in L{CSFinalByte.EL} and no parameters,
        forcing the client to default to 0 (from the active present
        position's current location to the end of the line.)
        """
        self.protocol.eraseToLineEnd()
        self.assertEqual(self.transport.value(),
                         self.CSI + CSFinalByte.EL.value)


    def test_eraseToLineBeginning(self):
        """
        L{ServerProtocol.eraseToLineBeginning} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 1 (from the beginning of the line up to and include the
        active present position's current location.)
        """
        self.protocol.eraseToLineBeginning()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.EL.value)


    def test_eraseLine(self):
        """
        L{ServerProtocol.eraseLine} writes the control
        sequence sequence ending in L{CSFinalByte.EL} and a parameter
        of 2 (the entire line.)
        """
        self.protocol.eraseLine()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'2' + CSFinalByte.EL.value)


    def test_eraseToDisplayEnd(self):
        """
        L{ServerProtocol.eraseToDisplayEnd} writes the control
        sequence sequence ending in L{CSFinalByte.ED} and no parameters,
        forcing the client to default to 0 (from the active present
        position's current location to the end of the page.)
        """
        self.protocol.eraseToDisplayEnd()
        self.assertEqual(self.transport.value(),
                         self.CSI + CSFinalByte.ED.value)


    def test_eraseToDisplayBeginning(self):
        """
        L{ServerProtocol.eraseToDisplayBeginning} writes the control
        sequence sequence ending in L{CSFinalByte.ED} a parameter of 1
        (from the beginning of the page up to and include the active
        present position's current location.)
        """
        self.protocol.eraseToDisplayBeginning()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'1' + CSFinalByte.ED.value)


    def test_eraseToDisplay(self):
        """
        L{ServerProtocol.eraseDisplay} writes the control sequence
        sequence ending in L{CSFinalByte.ED} a parameter of 2 (the
        entire page)
        """
        self.protocol.eraseDisplay()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'2' + CSFinalByte.ED.value)


    def test_deleteCharacter(self):
        """
        L{ServerProtocol.deleteCharacter} writes the control sequence
        containing the number of characters to delete and ending in
        L{CSFinalByte.DCH}
        """
        self.protocol.deleteCharacter(4)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'4' + CSFinalByte.DCH.value)


    def test_insertLine(self):
        """
        L{ServerProtocol.insertLine} writes the control sequence
        containing the number of lines to insert and ending in
        L{CSFinalByte.IL}
        """
        self.protocol.insertLine(5)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'5' + CSFinalByte.IL.value)


    def test_deleteLine(self):
        """
        L{ServerProtocol.deleteLine} writes the control sequence
        containing the number of lines to delete and ending in
        L{CSFinalByte.DL}
        """
        self.protocol.deleteLine(6)
        self.assertEqual(self.transport.value(),
                         self.CSI + b'6' + CSFinalByte.DL.value)


    def test_setScrollRegionNoArgs(self):
        """
        With no arguments, L{ServerProtocol.setScrollRegion} writes a
        control sequence with no parameters, but a parameter
        separator, and ending in C{b'r'}.
        """
        self.protocol.setScrollRegion()
        self.assertEqual(self.transport.value(), self.CSI + b';' + b'r')


    def test_setScrollRegionJustFirst(self):
        """
        With just a value for its C{first} argument,
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        that parameter, a parameter separator, and finally a C{b'r'}.
        """
        self.protocol.setScrollRegion(first=1)
        self.assertEqual(self.transport.value(), self.CSI + b'1;' + b'r')


    def test_setScrollRegionJustLast(self):
        """
        With just a value for its C{last} argument,
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        a parameter separator, that parameter, and finally a C{b'r'}.
        """
        self.protocol.setScrollRegion(last=1)
        self.assertEqual(self.transport.value(), self.CSI + b';1' + b'r')


    def test_setScrollRegionFirstAndLast(self):
        """
        When given both C{first} and C{last}
        L{ServerProtocol.setScrollRegion} writes a control sequence with
        the first parameter, a parameter separator, the last
        parameter, and finally a C{b'r'}.
        """
        self.protocol.setScrollRegion(first=1, last=2)
        self.assertEqual(self.transport.value(), self.CSI + b'1;2' + b'r')


    def test_reportCursorPosition(self):
        """
        L{ServerProtocol.reportCursorPosition} writes a control
        sequence ending in L{CSFinalByte.DSR} with a parameter of 6
        (the Device Status Report returns the current active
        position.)
        """
        self.protocol.reportCursorPosition()
        self.assertEqual(self.transport.value(),
                         self.CSI + b'6' + CSFinalByte.DSR.value)
コード例 #20
0
 def setUp(self):
     self.protocol = ServerProtocol()
     self.transport = StringTransport()
     self.protocol.makeConnection(self.transport)
コード例 #21
0
 def __init__(self, session):
     ServerProtocol.__init__(self)
     self.session = session
     self.transport = WebTransport(session)