[Debtags-commits] [SCM] Debian Data Export - A tool to publish Debian information branch, werkzeug, updated. 1b9d03958b29eaf6f25f378abe5ebd94c06ca5ed
Enrico Zini
enrico at enricozini.org
Sun Nov 28 20:23:49 UTC 2010
The following commit has been merged in the werkzeug branch:
commit 1b9d03958b29eaf6f25f378abe5ebd94c06ca5ed
Author: Enrico Zini <enrico at enricozini.org>
Date: Sun Nov 28 20:23:10 2010 +0000
Rearranged old code
diff --git a/dde/wsgi.py b/dde/wsgi.py
index f27306e..b09c42d 100644
--- a/dde/wsgi.py
+++ b/dde/wsgi.py
@@ -420,8 +420,68 @@ class DDEWSGIApplication(object):
def make_app(backend, baseurl):
return local_manager.make_middleware(DDEWSGIApplication(backend))
+def option_parser_config_hook(parser):
+ "Add server-specific options to an OptionParser"
+ if not parser.has_option("--baseurl"):
+ parser.add_option("--baseurl", type="str", help="base URL to use to generate links to self. Default: %default")
+ parser.set_defaults(baseurl=None)
+ if not parser.has_option("--accesslog"):
+ parser.add_option("--accesslog", type="str", help="file where to log normal access information")
+ if not parser.has_option("--errorlog"):
+ parser.add_option("--errorlog", type="str", help="file where to log errors")
+ if not parser.has_option("--quiet"):
+ parser.add_option("--quiet", action="store_true", help="do not log to standard output")
-JS_QUERY="""
+class AccessLogFilter(logging.Filter):
+ def __init__(self):
+ logging.Filter.__init__(self)
+ def filter(self, rec):
+ if rec.levelno < logging.WARNING:
+ return 1
+ return 0
+
+def setup_logging(opts):
+ if opts.quiet:
+ logging.basicConfig(level=logging.ERROR)
+ else:
+ logging.basicConfig(level=logging.DEBUG)
+
+ if opts.accesslog:
+ accesslog = logging.handlers.TimedRotatingFileHandler(opts.accesslog, "D", 1, backupCount = 14)
+ accesslog.setLevel(logging.INFO)
+ accesslog.addFilter(AccessLogFilter())
+ logging.getLogger("").addHandler(accesslog)
+ logging.basicConfig(level=logging.DEBUG, filename=opts.accesslog, filemode="a")
+
+ if opts.errorlog:
+ errorlog = logging.handlers.TimedRotatingFileHandler(opts.errorlog, "D", 1, backupCount = 14)
+ errorlog.setLevel(logging.WARNING)
+ logging.getLogger("").addHandler(errorlog)
+
+if False:
+# class DDE(dde.base.DDE):
+# def js(self, res, namespace = "dde"):
+# body = JS_QUERY % dict(NS=namespace, QPATH=self.baseurl+"/q")
+# res.start_response(type = "text/javascript", length = len(body))
+# return (body,)
+#
+# elif type == "js":
+# log.info("JS %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
+# if len(path) > 0:
+# namespace = path[0]
+# else:
+# namespace = "dde"
+# return self.js(res, namespace)
+# else:
+# log.warning("ERROR %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
+# # FIXME: This is here only temporarily, because failed request to
+# # favicon.ico make loads of noise in the logs
+# return Result(start_response).http_error("404 Not found", "Page not found")
+#
+# def should_start(opts):
+# return False
+
+ JS_QUERY="""
//
// Communication with the server
//
@@ -546,112 +606,3 @@ var %(NS)s = new Object()
}
"""
-TYPE_DOC = {
- "html": """
-<p>Browser-friendly HTML documentation of the node.</p>
-
-<p>This is the default output type when no other type is requested.</p>
-
-<p>It is not useful for extracting information, because it sometimes only
-produces a sample of what is available, but it is convenient to navigate the
-data to find the URL that one needs to extract.</p>
-""",
-}
-
-def option_parser_config_hook(parser):
- "Add server-specific options to an OptionParser"
- if not parser.has_option("--baseurl"):
- parser.add_option("--baseurl", type="str", help="base URL to use to generate links to self. Default: %default")
- parser.set_defaults(baseurl=None)
- if not parser.has_option("--accesslog"):
- parser.add_option("--accesslog", type="str", help="file where to log normal access information")
- if not parser.has_option("--errorlog"):
- parser.add_option("--errorlog", type="str", help="file where to log errors")
- if not parser.has_option("--quiet"):
- parser.add_option("--quiet", action="store_true", help="do not log to standard output")
-
-class AccessLogFilter(logging.Filter):
- def __init__(self):
- logging.Filter.__init__(self)
- def filter(self, rec):
- if rec.levelno < logging.WARNING:
- return 1
- return 0
-
-def setup_logging(opts):
- if opts.quiet:
- logging.basicConfig(level=logging.ERROR)
- else:
- logging.basicConfig(level=logging.DEBUG)
-
- if opts.accesslog:
- accesslog = logging.handlers.TimedRotatingFileHandler(opts.accesslog, "D", 1, backupCount = 14)
- accesslog.setLevel(logging.INFO)
- accesslog.addFilter(AccessLogFilter())
- logging.getLogger("").addHandler(accesslog)
- logging.basicConfig(level=logging.DEBUG, filename=opts.accesslog, filemode="a")
-
- if opts.errorlog:
- errorlog = logging.handlers.TimedRotatingFileHandler(opts.errorlog, "D", 1, backupCount = 14)
- errorlog.setLevel(logging.WARNING)
- logging.getLogger("").addHandler(errorlog)
-
-if False:
- class DDE(dde.base.DDE):
- def js(self, res, namespace = "dde"):
- body = JS_QUERY % dict(NS=namespace, QPATH=self.baseurl+"/q")
- res.start_response(type = "text/javascript", length = len(body))
- return (body,)
-
- def application(self, environ, start_response):
- baseurl = environ.get("SCRIPT_NAME", self.baseurl)
- path_info = environ.get('PATH_INFO', '').strip("/")
- if not path_info:
- path = []
- type = "index"
- else:
- # Split the path info to build our query
- path = PATH_RE.split(path_info)
- type = path.pop(0)
-
- res = Result(start_response)
- if type == "q":
- log.info("QUERY %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
- # Very simple query string parsing, we do not need anything more than this
- qs = environ.get("QUERY_STRING", "")
- kw = dict()
- for q in qs.split("&"):
- t = q.split("=", 1)
- if len(t) == 0 or t[0] == "self":
- continue
- if len(t) == 1:
- kw[unquote_plus(t[0])] = None
- else:
- kw[unquote_plus(t[0])] = unquote_plus(t[1])
-
- return self.query(res, *path, **kw)
- elif type == "js":
- log.info("JS %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
- if len(path) > 0:
- namespace = path[0]
- else:
- namespace = "dde"
- return self.js(res, namespace)
- elif type == "index":
- log.info("INDEX %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
- return self.help(res)
- elif type == "typedoc":
- log.info("TYPEDOC %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
- if len(path) > 0:
- return self.typedoc(res, path[0])
- else:
- return self.typedoc(res, None)
- else:
- log.warning("ERROR %s %s %s", baseurl, path_info, environ.get("QUERY_STRING", ""))
- # FIXME: This is here only temporarily, because failed request to
- # favicon.ico make loads of noise in the logs
- return Result(start_response).http_error("404 Not found", "Page not found")
-
- def should_start(opts):
- return False
-
--
Debian Data Export - A tool to publish Debian information
More information about the Debtags-commits
mailing list