[z3-checkins] r10668 - z3/modzope/trunk/src/modzope
philikon at codespeak.net
philikon at codespeak.net
Fri Apr 15 15:43:29 MEST 2005
Author: philikon
Date: Fri Apr 15 15:43:29 2005
New Revision: 10668
Modified:
z3/modzope/trunk/src/modzope/wsgi.py
Log:
test for ModPythonErrorStream.
make the writelines() method according to spec
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 15:43:29 2005
@@ -84,7 +84,43 @@
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."""
+ the global apache error log file.
+
+ >>> demostring = ('Garfield likes lasagna\\r\\nJon likes Garfield\\r\\n'
+ ... 'Garfield hates Odie\\r\\n')
+ >>> class FakeRequest(object):
+ ... def __init__(self):
+ ... self.debug = False
+ ... self.body = ''
+ ... self.errorlog = ''
+ ... def get_config(self):
+ ... return {'PythonDebug': self.debug}
+ ... def write(self, s):
+ ... self.body += s
+ ... def log_error(self, s):
+ ... self.errorlog += s
+
+ >>> req = FakeRequest()
+ >>> stream = ModPythonErrorStream(req)
+ >>> stream.write(demostring)
+ >>> req.errorlog == demostring
+ True
+ >>> req.body
+ ''
+
+ >>> req = FakeRequest()
+ >>> stream = ModPythonErrorStream(req)
+ >>> stream.debug = True
+ >>> stream.write(demostring)
+ >>> req.body == demostring
+ True
+
+ >>> req = FakeRequest()
+ >>> stream = ModPythonErrorStream(req)
+ >>> stream.writelines([l + '\\r\\n' for l in demostring.splitlines()])
+ >>> req.errorlog == demostring
+ True
+ """
implements(IWSGIErrorStream)
def __init__(self, request):
@@ -101,10 +137,11 @@
self.request.write(msg)
def writelines(self, seq):
- self.write('\r\n'.join(seq))
+ # PEP333 says you shouldn't add line separators
+ self.write(''.join(seq))
class ModPythonHandler(BaseCGIHandler):
-
+
def __init__(self, request):
from mod_python import apache
options = request.get_options()
More information about the z3-checkins
mailing list