扭曲并启用命令行历史记录
在我之前的一个问题中,我得到了这样的答案:
子类
twisted.conch.recvline.HistoricRecvLine
而不是twisted.protocols.basic.LineReceiver
。keytripReceived
是当您使用终端而不是 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 oftwisted.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论