1

I read about all of the 'readline' module related articles but none could answer my issue. I'm trying to implement the auto completion in my script, which is a web server (using BaseHTTPRequestHandler as my request handler) which in it recieves as raw input data (from a list) and sends it to my clients.

Any help?

EDIT (Code added):

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)
Fernando Retimo
  • 1,003
  • 3
  • 13
  • 25

0 Answers0