def _add_text_node(self, parent, name, value, doc): top_element = doc.createElement(name) if value is not None: top_element.appendChild(doc.createTextNode(encstr(value))) parent.appendChild(top_element)
path = environ["PATH_INFO"] f = getattr(self, "do_" + method) try: content = f(path, rfile, environ) resp = "200 OK" ct = "application/xml" except HTTPError, e: resp, content, ct = self._handle_error(e.code, e.msg, e, environ) except Exception, e: resp, content, ct = self._handle_error(500, str(e), e, environ) headers = [ ("Content-Type", ct), ("Content-Length", str(len(content))) ] self.logger.debug("Returning response: %s %s %s %s" % (headers, resp, content, type(content))) start_response(resp, headers) return [ encstr(content) ] def main(): import sys """ console = logging.StreamHandler() formatter = logging.Formatter('REST: %(levelname)s [%(funcName)s(%(filename)s:%(lineno)s] - %(message)s') console.setFormatter(formatter) console.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG) self.logger.addHandler(console) """ if len(sys.argv) > 1: port = int(sys.argv[1]) else: port = 8001