扭曲并启用命令行历史记录

发布于 2024-09-10 08:52:02 字数 1769 浏览 2 评论 0原文

在我之前的一个问题中,我得到了这样的答案:

子类twisted.conch.recvline.HistoricRecvLine而不是twisted.protocols.basic.LineReceiverkeytripReceived 是当您使用终端而不是 TCP 连接时可用的几个附加协议回调之一。 – 让-保罗·卡尔德龙

但是如果同时拥有终端和 TCP 连接怎么办?当我子类化 HistoricRecvLine 时,我会失去 TCP 连接的功能吗?那么让我们从头开始吧。我的 .py 文件是:

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()

如何启用命令历史记录?我如何结合您建议的所有内容来实现我想要的目标?

显然我错过了一些东西!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文