def do_GET(self): global firstClient sp = self.path[1:] if compat.unquote_plus(sp) == 'SHUTDOWN THE SERVER': if server_mode: page = "Server must be killed with SIGTERM." type = "text/plain" else: print('Server shutting down!') os._exit(0) elif sp == '': # First request. type = 'text/html' if not server_mode and firstClient: firstClient = False page = get_static_index_page(True) else: page = get_static_index_page(False) word = 'green' elif sp.endswith('.html'): # Trying to fetch a HTML file TODO: type = 'text/html' usp = compat.unquote_plus(sp) if usp == 'NLTK Wordnet Browser Database Info.html': word = '* Database Info *' if os.path.isfile(usp): page = open(usp).read() else: page = (html_header % word) + \ '<p>The database info file:'\ '<p><b>' + usp + '</b>' + \ '<p>was not found. Run this:' + \ '<p><b>python dbinfo_html.py</b>' + \ '<p>to produce it.' + html_trailer else: # Handle files here. word = sp page = get_static_page_by_path(usp) elif sp.startswith("search"): # This doesn't seem to work with MWEs. type = 'text/html' parts = (sp.split("?")[1]).split("&") word = [ p.split("=")[1].replace("+", " ") for p in parts if p.startswith("nextWord") ][0] page, word = page_from_word(word) elif sp.startswith("lookup_"): # TODO add a variation of this that takes a non ecoded word or MWE. type = 'text/html' sp = sp[len("lookup_"):] page, word = page_from_href(sp) elif sp == "start_page": # if this is the first request we should display help # information, and possibly set a default word. type = 'text/html' page, word = page_from_word("wordnet") else: type = 'text/plain' page = "Could not parse request: '%s'" % sp # Send result. self.send_head(type) self.wfile.write(page.encode('utf8'))
def do_GET(self): global firstClient sp = self.path[1:] if compat.unquote_plus(sp) == 'SHUTDOWN THE SERVER': if server_mode: page = "Server must be killed with SIGTERM." type = "text/plain" else: print('Server shutting down!') os._exit(0) elif sp == '': # First request. type = 'text/html' if not server_mode and firstClient: firstClient = False page = get_static_index_page(True) else: page = get_static_index_page(False) word = 'green' elif sp.endswith('.html'): # Trying to fetch a HTML file TODO: type = 'text/html' usp = compat.unquote_plus(sp) if usp == 'NLTK Wordnet Browser Database Info.html': word = '* Database Info *' if os.path.isfile(usp): with open(usp, 'r') as infile: page = infile.read() else: page = (html_header % word) + \ '<p>The database info file:'\ '<p><b>' + usp + '</b>' + \ '<p>was not found. Run this:' + \ '<p><b>python dbinfo_html.py</b>' + \ '<p>to produce it.' + html_trailer else: # Handle files here. word = sp page = get_static_page_by_path(usp) elif sp.startswith("search"): # This doesn't seem to work with MWEs. type = 'text/html' parts = (sp.split("?")[1]).split("&") word = [p.split("=")[1].replace("+", " ") for p in parts if p.startswith("nextWord")][0] page, word = page_from_word(word) elif sp.startswith("lookup_"): # TODO add a variation of this that takes a non ecoded word or MWE. type = 'text/html' sp = sp[len("lookup_"):] page, word = page_from_href(sp) elif sp == "start_page": # if this is the first request we should display help # information, and possibly set a default word. type = 'text/html' page, word = page_from_word("wordnet") else: type = 'text/plain' page = "Could not parse request: '%s'" % sp # Send result. self.send_head(type) self.wfile.write(page.encode('utf8'))