def interact(self, prompt=">>> "): """Starts up the REPL, prints banner message and passes user input to handle_answer.""" print self.banner handle_value = None # input_handler.handle() returns input_handler.QUIT when user wants to exit. while handle_value != input_handler.QUIT: try: answer = self.get_input(prompt) except EOFError: # User hit Ctrl-D, quit. print # get on a newline first break try: handle_value = input_handler.handle(answer) except Exception as e: # Catch everything print e else: if handle_value != input_handler.QUIT: print handle_value print "Bye!"
def navigate(self, query = None): # CherryPy passes all GET and POST variables as method parameters. # It doesn't make a difference where the variables come from, how # large their contents are, and so on. # # You can define default parameter values as usual. In this # example, the "name" parameter defaults to None so we can check # if a name was actually specified. if query: try: response = str(input_handler.handle(query)).strip() # Add a period and <br> instead of newlines return response.replace("\n", ".<br/>") except Exception as e: return "<hr><h1>Oops! Quest couldn't handle your input.</h1>" else: if query is None: # No name was specified return 'Please enter a query.' else: return 'No, really, enter a query.'