[z3-checkins] r10657 - z3/modzope/trunk/src/modzope

philikon at codespeak.net philikon at codespeak.net
Fri Apr 15 12:03:09 MEST 2005


Author: philikon
Date: Fri Apr 15 12:03:09 2005
New Revision: 10657

Added:
   z3/modzope/trunk/src/modzope/interfaces.py   (contents, props changed)
Modified:
   z3/modzope/trunk/src/modzope/wsgi.py
Log:
interfaces for input and error streams, based on pep333


Added: z3/modzope/trunk/src/modzope/interfaces.py
==============================================================================
--- (empty file)
+++ z3/modzope/trunk/src/modzope/interfaces.py	Fri Apr 15 12:03:09 2005
@@ -0,0 +1,73 @@
+##############################################################################
+#
+# Copyright (c) 2005 Philipp "philiKON" von Weitershausen
+# 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 interfaces
+
+$Id$
+"""
+from zope.interface import Interface
+
+class IWSGIInputStream(Interface):
+    """WSGI input stream.
+
+    See http://python.org/peps/pep-0333.html#input-and-error-streams
+    """
+
+    def read(size):
+	"""Read number ``size`` number of bytes.
+
+	The server is not required to read past the client's specified
+	Content-Length, and is allowed to simulate an end-of-file
+	condition if the application attempts to read past that
+	point. The application should not attempt to read more data
+	than is specified by the CONTENT_LENGTH variable."""
+
+    def readline():
+	"""Read one entire line. The optional ``size`` argument is not
+	supported."""
+
+    def readlines(hint):
+	"""Read all lines.
+
+	The hint argument is optional for both caller and implementer.
+	The application is free not to supply it, and the server or
+	gateway is free to ignore it."""
+
+    def __iter__():
+	"""Return an iterator that iterates over the lines in the input
+	stream."""
+
+class IWSGIErrorStream(Interface):
+    """WSGI error stream.
+
+    See http://python.org/peps/pep-0333.html#input-and-error-streams
+    """
+
+    def flush():
+	"""Flush the internal buffer.
+
+	Since the errors stream may not be rewound, servers and
+	gateways are free to forward write operations immediately,
+	without buffering. In this case, the flush() method may be a
+	no-op. Portable applications, however, cannot assume that
+	output is unbuffered or that flush() is a no-op. They must
+	call flush() if they need to ensure that output has in fact
+	been written. (For example, to minimize intermingling of data
+	from multiple processes writing to the same error log.)"""
+
+    def write(str):
+	"""Write string to the stream."""
+
+    def writelines(seq):
+	"""Write sequence of lines to the stream.  This does not add line
+	separators."""

Modified: z3/modzope/trunk/src/modzope/wsgi.py
==============================================================================
--- z3/modzope/trunk/src/modzope/wsgi.py	(original)
+++ z3/modzope/trunk/src/modzope/wsgi.py	Fri Apr 15 12:03:09 2005
@@ -22,11 +22,14 @@
 $Id$
 """
 import sys
+from zope.interface import implements
+from modzope.interfaces import IWSGIInputStream, IWSGIErrorStream
 from wsgiref.handlers import BaseCGIHandler
 from mod_python import apache
 
 class ModPythonInputStream(object):
-    
+    implements(IWSGIInputStream)
+
     def __init__(self, request):
         self.request = request
 
@@ -48,6 +51,7 @@
     This enables logging to a custom error log file as defined with a
     ErrorLog directive.  Errors are printed to sys.stderr end up in
     the global apache error log file."""
+    implements(IWSGIErrorStream)
 
     def __init__(self, request):
         self.request = request


More information about the z3-checkins mailing list