[Zope3-checkins] SVN: Zope3/branches/srichter-wsgi-zserver/src/zope/server/http/wsgihttpserver.py Forgot this file. Oops.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Apr 12 14:55:42 EDT 2005


Log message for revision 29953:
  Forgot this file. Oops.
  

Changed:
  A   Zope3/branches/srichter-wsgi-zserver/src/zope/server/http/wsgihttpserver.py

-=-
Added: Zope3/branches/srichter-wsgi-zserver/src/zope/server/http/wsgihttpserver.py
===================================================================
--- Zope3/branches/srichter-wsgi-zserver/src/zope/server/http/wsgihttpserver.py	2005-04-12 18:35:25 UTC (rev 29952)
+++ Zope3/branches/srichter-wsgi-zserver/src/zope/server/http/wsgihttpserver.py	2005-04-12 18:55:41 UTC (rev 29953)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""WSGI-compliant HTTP Server that uses the Zope Publisher for executing a task.
+
+$Id: publisherhttpserver.py 29535 2005-03-17 22:44:37Z garrett $
+"""
+import re
+import sys
+from zope.server.http.httpserver import HTTPServer
+from zope.publisher.publish import publish
+
+
+class WSGIHTTPServer(HTTPServer):
+    """Zope Publisher-specific WSGI-compliant HTTP Server"""
+
+    def __init__(self, application, sub_protocol=None, *args, **kw):
+
+        if sys.platform[:3] == "win" and args[0] == 'localhost':
+            args = ('',) + args[1:]
+
+        self.application = application
+
+        if sub_protocol:
+            self.SERVER_IDENT += ' (%s)' %str(sub_protocol)
+
+        HTTPServer.__init__(self, *args, **kw)
+
+
+    def executeRequest(self, task):
+        """Overrides HTTPServer.executeRequest()."""
+        env = task.getCGIEnvironment()
+        env['wsgi.input'] = task.request_data.getBodyStream()
+
+        def start_response(status, headers):
+            # Prepare the headers for output
+            status, reason = re.match('([0-9]*) (.*)', status).groups()
+            task.setResponseStatus(status, reason)
+            task.appendResponseHeaders(['%s: %s' % i for i in headers])
+
+            # Return the write method used to write the response data.
+            return task.write
+
+        # Call the application to handle the request and write a response
+        self.application(env, start_response)


Property changes on: Zope3/branches/srichter-wsgi-zserver/src/zope/server/http/wsgihttpserver.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list