[z3-checkins] r30335 - z3/deliverance/branches/namespaced
rafrombrc at codespeak.net
rafrombrc at codespeak.net
Fri Jul 21 22:14:24 CEST 2006
Author: rafrombrc
Date: Fri Jul 21 22:14:13 2006
New Revision: 30335
Modified:
z3/deliverance/branches/namespaced/mpfilter.py
Log:
* need to support multiple calls per request
Modified: z3/deliverance/branches/namespaced/mpfilter.py
==============================================================================
--- z3/deliverance/branches/namespaced/mpfilter.py (original)
+++ z3/deliverance/branches/namespaced/mpfilter.py Fri Jul 21 22:14:13 2006
@@ -8,33 +8,45 @@
appmap instance becomes a global, computed only once. If you need to
recompute the theme, for example, restart the Apache.
"""
+from cStringIO import StringIO
from mod_python import apache
from deliverance import AppMap
appmap = AppMap() # Theme is generated once at module import time
def outputfilter(filter):
-
- # Check for a flag to not apply theme
- args = filter.req.args
-
- # XXX: mod_python might prefer a better approach to reading
- xmlstring = ''
- s = filter.read()
- while s:
- xmlstring += s
- s = filter.read()
- if xmlstring:
+ if not hasattr(filter.req, 'notheme'):
+ # Check for a flag to not apply theme
+ args = filter.req.args
if args and args.find("notheme") > -1:
- filter.write(xmlstring)
+ filter.req.notheme = True
else:
- filter.write(appmap.publish(xmlstring))
+ filter.req.notheme = False
- if s is None:
+ try:
+ streambuffer = filter.req.streambuffer
+ except AttributeError:
+ filter.req.streambuffer = StringIO()
+ streambuffer = filter.req.streambuffer
+
+ streamlet = filter.readline()
+ while streamlet:
+ streambuffer.write(streamlet)
+ streamlet = filter.readline()
+
+ if streamlet is None:
+ try:
+ del filter.req.headers_out["Content-Length"]
+ except KeyError:
+ pass
+ if filter.req.notheme:
+ filter.write(streambuffer.getvalue())
+ else:
+ filter.write(appmap.publish(streambuffer.getvalue()))
filter.close()
-
+
def handler(req):
"""Basic filter applying to all mime types it is registered for"""
@@ -42,7 +54,7 @@
# dotted notation for xml:id compatibility
path_info = req.path_info[1:]
dotted_path = path_info.replace("/", ".")
-
+
response = appmap.publish(dotted_path)
req.content_type = "text/html"
req.write(response)
More information about the z3-checkins
mailing list