[z3-checkins] r30478 - z3/deliverance/branches/namespaced
rafrombrc at codespeak.net
rafrombrc at codespeak.net
Mon Jul 24 20:54:24 CEST 2006
Author: rafrombrc
Date: Mon Jul 24 20:54:20 2006
New Revision: 30478
Modified:
z3/deliverance/branches/namespaced/mpfilter.py
Log:
* be more efficient in avoiding unnecessary work and passing on to the next
filter in the chain
* only apply to text/html content types
Modified: z3/deliverance/branches/namespaced/mpfilter.py
==============================================================================
--- z3/deliverance/branches/namespaced/mpfilter.py (original)
+++ z3/deliverance/branches/namespaced/mpfilter.py Mon Jul 24 20:54:20 2006
@@ -8,6 +8,7 @@
appmap instance becomes a global, computed only once. If you need to
recompute the theme, for example, restart the Apache.
"""
+import time
from cStringIO import StringIO
from mod_python import apache
@@ -15,7 +16,6 @@
appmap = AppMap() # Theme is generated once at module import time
def outputfilter(filter):
-
if not hasattr(filter.req, 'notheme'):
# Check for a flag to not apply theme
args = filter.req.args
@@ -23,10 +23,23 @@
filter.req.notheme = True
else:
filter.req.notheme = False
-
+
try:
streambuffer = filter.req.streambuffer
except AttributeError:
+ if filter.req.notheme:
+ # pass on if no theme
+ filter.pass_on()
+ return
+ elif not filter.req.headers_out.has_key("content-type"):
+ # pass on if no content type specified
+ filter.pass_on()
+ return
+ elif not filter.req.headers_out["content-type"].startswith("text/html"):
+ # pass on if not HTML
+ filter.pass_on()
+ return
+
filter.req.streambuffer = StringIO()
streambuffer = filter.req.streambuffer
@@ -36,14 +49,9 @@
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()))
+ output = appmap.publish(streambuffer.getvalue())
+ filter.req.headers_out["Content-Length"] = str(len(output))
+ filter.write(output)
filter.close()
More information about the z3-checkins
mailing list