[z3-checkins] r10663 - z3/modzope/trunk/src/modzope
philikon at codespeak.net
philikon at codespeak.net
Fri Apr 15 12:45:57 MEST 2005
Author: philikon
Date: Fri Apr 15 12:45:57 2005
New Revision: 10663
Added:
z3/modzope/trunk/src/modzope/tests.py (contents, props changed)
Modified:
z3/modzope/trunk/src/modzope/wsgi.py
Log:
tests for ModPythonInputStream
Added: z3/modzope/trunk/src/modzope/tests.py
==============================================================================
--- (empty file)
+++ z3/modzope/trunk/src/modzope/tests.py Fri Apr 15 12:45:57 2005
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""modzope tests
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+
+def test_suite():
+ return unittest.TestSuite((
+ DocTestSuite('modzope.wsgi'),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
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:45:57 2005
@@ -27,6 +27,41 @@
from wsgiref.handlers import BaseCGIHandler
class ModPythonInputStream(object):
+ """Wraps a mod_python request as a WSGI-compliant input stream
+
+ For demonstration purposes, we use a regular StringIO object to
+ mimick the Apache request (though we can't be sure whether that
+ actually behaves equally)...
+
+ >>> demostring = ('Garfield likes lasagna\\r\\nJon likes Garfield\\r\\n'
+ ... 'Garfield hates Odie\\r\\n')
+ >>> from StringIO import StringIO
+ >>> from pprint import pprint
+
+ >>> req = StringIO(demostring)
+ >>> stream = ModPythonInputStream(req)
+ >>> stream.read() == demostring
+ True
+
+ >>> req = StringIO(demostring)
+ >>> stream = ModPythonInputStream(req)
+ >>> stream.readline()
+ 'Garfield likes lasagna\\r\\n'
+
+ >>> req = StringIO(demostring)
+ >>> stream = ModPythonInputStream(req)
+ >>> pprint(stream.readlines())
+ ['Garfield likes lasagna\\r\\n',
+ 'Jon likes Garfield\\r\\n',
+ 'Garfield hates Odie\\r\\n']
+
+ >>> req = StringIO(demostring)
+ >>> stream = ModPythonInputStream(req)
+ >>> pprint(list(iter(stream)))
+ ['Garfield likes lasagna\\r\\n',
+ 'Jon likes Garfield\\r\\n',
+ 'Garfield hates Odie\\r\\n']
+ """
implements(IWSGIInputStream)
def __init__(self, request):
@@ -34,13 +69,13 @@
def read(self, size=-1):
return self.request.read(size)
-
+
def readline(self):
return self.request.readline()
-
+
def readlines(self, hint=-1):
return self.request.readlines(hint)
-
+
def __iter__(self):
return iter(self.request.readlines())
More information about the z3-checkins
mailing list