Python readline模块不会拦截TAB

时间:2015-01-04 15:00:58

标签: python console readline basehttprequesthandler

我阅读了所有'readline'模块相关文章,但没有人能回答我的问题。 我正在尝试在我的脚本中实现自动完成,这是一个Web服务器(使用BaseHTTPRequestHandler作为我的请求处理程序),它在其中接收为原始输入数据(从列表中)并将其发送给我的客户端。

任何帮助?

编辑(已添加代码):

from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
import urlparse
import re
import os
import base64
import httplib
import socket
from time import gmtime, strftime
import sys
from clint.textui import colored
import  subprocess
try:
    import readline
except:
    import pyreadline as readline



DICT = ['pig','cow','bird']

def complete(text, state):

    for animal in DICT:
        if animal.startswith(text):
            if not state:
                return amimal
            else:
                state -= 1

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        readline.parse_and_bind("tab: complete")
        readline.set_completer(complete)
        message = raw_input(">>")
        self.send_response(200)
        self.end_headers()
        self.wfile.write(message)
        return

    def do_POST(self):
        # Not relevant



if __name__ == '__main__':
    server = HTTPServer(('', 8090), RequestHandler)
    try:
        server.serve_forever()
    except KeyboardInterrupt: 
        sys.exit(0)

0 个答案:

没有答案