开发者

Twisted and enabling command line history

In a previous question of mine I got this answer:

Subclass twisted.conch.recvline.HistoricRecvLine instead of twisted.protocols.basic.LineReceiver. keystrokeReceived is one of the several additional protocol callbacks available when you are using a terminal instead of a TCP connection. – Jean-Paul Calderone

But what if what to have both terminal and TCP Connection? When I subclass HistoricRecvLine I lose the functionality of the TCP connection? So let's start it from the beginning. My .py开发者_StackOverflow中文版 file is:

class WebCheckerCommandProtocol(basic.LineReceiver):

    def connectionMade(self):
        self.sendLine("checker console. Type 'help' for help.")

    def lineReceived(self, line):
        ...

    def connectionLost(self, reason):
        # stop the reactor, only because this is meant to be run in Stdio.
        reactor.stop()

    def do_listservers(self):
        "Cmd to Query all available Servers - Takes no arguments"
        conn = httplib.HTTPConnection(ip+":"+port)
        conn.request(.....)
        response = conn.getresponse()
        print response.status, response.reason
        data = response.read()
    def do_sessions(self):
        conn = httplib.HTTPConnection(ip+":"+port)
        conn.request(.....)

    def do_logUser(self, name):
        conn = httplib.HTTPConnection(ip+":"+port)
        conn.request(.....)


class SimpleServer(LineReceiver):

    def connectionMade(self):
        print 'Connection from: ', self.transport.client

    def connectionLost(self, reason):
        print self.transport.client, 'Disconnected'

    def dataReceived(self, line):
        """Here the XML Parser"""
        print line

if __name__ == "__main__":
    factory = Factory()
    factory.protocol = SimpleServer

    stdio.StandardIO(SimpleServer())
    reactor.listenTCP(1234, factory)
    reactor.run()

How to enable command history? How do I combine all that you suggest me to achieve what I want?

Obviously I'm missing something!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜