[Debtags-commits] [SCM] Debian Data Export - A tool to publish Debian information branch, werkzeug, updated. 4c5f5ac4f61882b675668bbdb5af99ec4ba6f0ee

Enrico Zini enrico at enricozini.org
Sun Nov 28 20:31:46 UTC 2010


The following commit has been merged in the werkzeug branch:
commit 4c5f5ac4f61882b675668bbdb5af99ec4ba6f0ee
Author: Enrico Zini <enrico at enricozini.org>
Date:   Sun Nov 28 20:31:05 2010 +0000

    Reenabled cgi and fcgi front-ends

diff --git a/dde/cgi.py b/dde/cgi.py
index ca26733..a871377 100644
--- a/dde/cgi.py
+++ b/dde/cgi.py
@@ -8,7 +8,7 @@ def option_parser_config_hook(parser):
 def should_start(opts):
     return "SCRIPT_NAME" in os.environ
 
-def start(tree):
+def start(backend):
     # Taken from /usr/share/python-support/python-flup/flup/server/cgi.py
     # Which in turn wasn taken from <http://www.python.org/dev/peps/pep-0333/>
     # which was placed in the public domain.
@@ -58,9 +58,9 @@ def start(tree):
         headers_set[:] = [status,response_headers]
         return write
 
-    dw = dde.wsgi.DDE(tree, environ.get("SCRIPT_NAME", ""))
+    app = dde.wsgi.make_app(backend, environ.get("SCRIPT_NAME", ""))
 
-    result = dw.application(environ, start_response)
+    result = app(environ, start_response)
     try:
         for data in result:
             if data:    # don't send headers until body appears
diff --git a/dde/fcgi.py b/dde/fcgi.py
index a859119..d8eb0ab 100644
--- a/dde/fcgi.py
+++ b/dde/fcgi.py
@@ -17,7 +17,7 @@ def option_parser_config_hook(parser):
 def should_start(opts):
     return opts.fastcgi or "FCGI_WEB_SERVER_ADDRS" in os.environ
 
-def start(opts, args, tree):
+def start(opts, args, backend):
     if not HAS_FCGI:
         print >>sys.stderr, "FastCGI mode requires the Flup Python module"
         sys.exit(1)
@@ -26,5 +26,5 @@ def start(opts, args, tree):
 
     baseurl = opts.baseurl or ""
 
-    app = dde.wsgi.DDE(tree, baseurl)
-    WSGIServer(app.application).run()
+    app = dde.wsgi.make_app(backend, baseurl)
+    WSGIServer(app).run()
diff --git a/dde/wsgi.py b/dde/wsgi.py
index b09c42d..ac94dcb 100644
--- a/dde/wsgi.py
+++ b/dde/wsgi.py
@@ -41,12 +41,12 @@ class Template(werkzeug.Template):
     }
     default_context.update(werkzeug.Template.default_context)
 
-def make_dde_response(val, type, **kw):
+def make_dde_response(val, **kw):
     """
     Turn the result from dde's get_data or get_list into a werkzeug
     response
     """
-    renderer = dde.TYPE_INFO[type]
+    renderer = dde.TYPE_INFO[local.dde_type]
     r = renderer(**kw)
 
     if dde.util.isgen(val):
@@ -393,10 +393,10 @@ def query(path=None):
         else:
             return make_doc_response()
     elif "list" in args:
-        res = backend.get_list(path, **args)
+        res = local.backend.get_list(path, **args)
         return make_dde_response(res)
     else:
-        res = backend.get_data(path, **args)
+        res = local.backend.get_data(path, **args)
         return make_dde_response(res)
 
 class DDEWSGIApplication(object):
diff --git a/src/dde b/src/dde
index f7a9b6a..22fec87 100755
--- a/src/dde
+++ b/src/dde
@@ -6,7 +6,7 @@ VERSION="0.1"
 UDD_HOST="localhost"
 UDD_PORT=54321
 
-import dde, dde.server #, dde.fcgi, dde.cgi
+import dde, dde.server, dde.fcgi, dde.cgi
 import sys, os
 from urllib import quote_plus, unquote_plus
 import octofuss as ot
@@ -38,14 +38,14 @@ if __name__ == "__main__":
     parser.add_option("-t", "--type", type="str", help="List elements with a short description")
     parser.add_option("--help", action="store_true", help="Show help")
     parser.add_option("--cgitest", type="str", help="Test running as CGI, with the given query string")
-    #parser.add_option("--fastcgi", action="store_true", help="Run with fascgi")
+    parser.add_option("--fastcgi", action="store_true", help="Run with fascgi")
     parser.add_option("--verbose", action="store_true", help="Verbose output")
     parser.add_option("--debug", action="store_true", help="Debug output")
     #parser.set_defaults(type = "yaml")
 
     dde.server.option_parser_config_hook(parser)
-    #dde.fcgi.option_parser_config_hook(parser)
-    #dde.cgi.option_parser_config_hook(parser)
+    dde.fcgi.option_parser_config_hook(parser)
+    dde.cgi.option_parser_config_hook(parser)
     #config = dde.server.config_storage()
 
     (opts, args) = parser.parse_args()
@@ -65,18 +65,21 @@ if __name__ == "__main__":
     backend = dde.DDE()
     backend.load_plugins(debug=True)
 
-    #if opts.cgitest:
-    #    query = opts.cgitest.split("?", 1)
-    #    os.environ["PATH_INFO"] = query.pop(0)
-    #    if len(query) > 0:
-    #        os.environ["QUERY_STRING"] = query[0]
-    #    os.environ["SCRIPT_NAME"] = "http://example.run:1234/scriptpath/"
+    if opts.cgitest:
+        query = opts.cgitest.split("?", 1)
+        os.environ["PATH_INFO"] = query.pop(0)
+        if len(query) > 0:
+            os.environ["QUERY_STRING"] = query[0]
+        os.environ["SCRIPT_NAME"] = "http://example.run:1234/scriptpath/"
+        os.environ["SERVER_NAME"] = "example.run"
+        os.environ["SERVER_PORT"] = "1234"
+        os.environ["REQUEST_METHOD"] = "GET"
 
-    #if dde.fcgi.should_start(opts):
-    #    dde.fcgi.start(opts, args, tree)
-    #elif dde.cgi.should_start(opts):
-    #    dde.cgi.start(tree)
-    if dde.server.should_start(opts):
+    if dde.fcgi.should_start(opts):
+        dde.fcgi.start(opts, args, backend)
+    elif dde.cgi.should_start(opts):
+        dde.cgi.start(backend)
+    elif dde.server.should_start(opts):
         dde.server.start(opts, args, backend)
     else:
         import dde.cmd #, codecs

-- 
Debian Data Export - A tool to publish Debian information



More information about the Debtags-commits mailing list