python line editing telnet server

最后都变了- 提交于 2019-12-20 02:36:17

问题


I am creating a server in python (what it is doing is irrelevant), but I would like it to accept telnet connections and provide a command line interface with line editing capabilities (tabcompletion, emacs/vi-mode, etc) and history per session. I have successfully created the telnet session, disabled line mode and enabled server echo.

My initial thoughts were using readline but the python readline module seems to only work for a single session on stdin; and examining the underlying readline library that seems to be the way it works.

What I would like to do however is to create an instance (call it state if you like) for each client, and as characters (bytes) are received feed to the state. Once a complete line has been generated it would pass it to the server which may parse it.

So my question is if there is a library which handles this kind of thing, even a c-library would be sufficient.

EDIT: To clarify, I've got a fully functional server already, but I want the telnet interface as an add on to reconfigure, get information, etc.


回答1:


It sounds like you've got the TELNET part sorted, and now you want to provide features commonly found in shells like BASH, KSH etc. I've not tried it myself, but have a look as shython: "a versatile shell having features of both bash and python".




回答2:


Perhaps the cmd library could be of interest/help?




回答3:


You need telnetlib http://docs.python.org/library/telnetlib.html?highlight=telnet#module-telnetlib



来源:https://stackoverflow.com/questions/3412832/python-line-editing-telnet-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!