def do_POST(self): contentLength = self.headers.getheader('content-length') if contentLength: contentLength = int(contentLength) inputBody = self.rfile.read(contentLength) debug.println(debug.LEVEL_FINEST, "httpserver._HTTPRequestHandler received %s" \ % inputBody) if inputBody.startswith("speak:"): speech.speak(inputBody[6:]) self.send_response(200, 'OK') elif inputBody == "stop": speech.stop() self.send_response(200, 'OK') elif inputBody == "isSpeaking": self.send_response(200, 'OK') self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write("%s" % speech.isSpeaking()) elif inputBody.startswith("log:"): import logging logFile = inputBody[4:] for logger in ['braille', 'speech']: log = logging.getLogger(logger) formatter = logging.Formatter('%(name)s.%(message)s') try: loggingFileHandlers[logger].close() log.removeHandler(loggingFileHandlers[logger]) except: pass if logFile and len(logFile): loggingFileHandlers[logger] = logging.FileHandler( '%s.%s' % (logFile, logger), 'w') loggingFileHandlers[logger].setFormatter(formatter) log.addHandler(loggingFileHandlers[logger]) log.setLevel(logging.INFO) self.send_response(200, 'OK') elif inputBody.startswith("debug:"): split = inputBody.split(':') debug.debugLevel = int(split[1]) if debug.debugFile: debug.debugFile.close() debug.debugFile = None if (len(split) == 3) and (len(split[2])): debug.debugFile = open('%s.debug' % split[2], 'w', 0) self.send_response(200, 'OK') else: debug.println(debug.LEVEL_FINEST, "httpserver._HTTPRequestHandler received no data")
def pumpMessages(self): """ Main gobject callback for live region support. Handles both purging the message queue and outputting any queued messages that were queued up in the handleEvent() method. """ # If there are messages in the queue, we are monitoring, and we are not # currently speaking then speak queued message. # Note: Do all additional work within if statement to prevent # it from being done for each event loop callback # Note: isSpeaking() returns False way too early. A strategy using # a message length (in secs) could be used but don't forget many # parameters such as rate,expanded text and others must be considered. if len(self.msg_queue) > 0 \ and not speech.isSpeaking() \ and time.time() - orca_state.lastInputEvent.time > 1: # House cleaning on the message queue. # First we will purge the queue of old messages self.msg_queue.purgeByKeepAlive() # Next, we will filter the messages self.msg_queue.clumpContents() self.msg_queue.filterContents() # Let's get our queued information politeness, timestamp, message, obj = self.msg_queue.dequeue() # Form output message. No need to repeat labels and content. # TODO: really needs to be tested in real life cases. Perhaps # a verbosity setting? if message['labels'] == message['content']: utts = message['content'] else: utts = message['labels'] + message['content'] self._script.presentMessage(utts) # set the last live obj to be announced self.lastliveobj = obj # cache our message self._cacheMessage(utts) # We still want to maintain our queue if we are not monitoring if not self.monitoring: self.msg_queue.purgeByKeepAlive() # See you again soon, stay in event loop if we still have messages. if len(self.msg_queue) > 0: return True else: return False
def do_POST(self): contentLength = self.headers.getheader('content-length') if contentLength: contentLength = int(contentLength) inputBody = self.rfile.read(contentLength) debug.println(debug.LEVEL_FINEST, "httpserver._HTTPRequestHandler received %s" \ % inputBody) if inputBody.startswith("speak:"): speech.speak(inputBody[6:]) self.send_response(200, 'OK') elif inputBody == "stop": speech.stop() self.send_response(200, 'OK') elif inputBody == "isSpeaking": self.send_response(200, 'OK') self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write("%s" % speech.isSpeaking()) else: debug.println(debug.LEVEL_FINEST, "httpserver._HTTPRequestHandler received no data")