[Zope-Checkins] CVS: Releases/Zope/lib/python/ZPublisher - HTTPResponse.py:1.53.8.1

Evan Simpson evan@zope.com
Fri, 15 Mar 2002 17:30:08 -0500


Update of /cvs-repository/Releases/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv32186

Modified Files:
      Tag: Zope-2_5-branch
	HTTPResponse.py 
Log Message:
Add HTTP_TRACEBACK_STYLE environment variable.


=== Releases/Zope/lib/python/ZPublisher/HTTPResponse.py 1.53 => 1.53.8.1 ===
 __version__='$Revision$'[11:-2]
 
-import  types, sys,  re
+import types, os, sys, re
 from string import translate, maketrans
 from types import StringType, InstanceType, LongType
 from BaseResponse import BaseResponse
@@ -92,6 +92,17 @@
 
 accumulate_header={'set-cookie': 1}.has_key
 
+tb_style = os.environ.get('HTTP_TRACEBACK_STYLE', '').lower()
+if tb_style == 'none':
+    tb_delims = None, None
+elif tb_style == 'js':
+    tb_delims = ('''<pre onclick="this.firstChild.data=this.lastChild.data">
+        &sect;<!--''',  '--></pre>')
+elif tb_style == 'plain':
+    tb_delims = '<pre>', '</pre>'
+else:
+    tb_delims = '<!--', '-->'
+
 class HTTPResponse(BaseResponse):
     """\
     An object representation of an HTTP response.
@@ -399,9 +410,9 @@
         tb = '\n'.join(tb)
         tb = self.quoteHTML(tb)
         if self.debug_mode: _tbopen, _tbclose = '<PRE>', '</PRE>'
-        else:               _tbopen, _tbclose = '''<pre
-          onclick="this.firstChild.data=this.lastChild.data">
-        &sect;<!--''',  '--></pre>'
+        else:               _tbopen, _tbclose = tb_delims
+        if _tbopen is None:
+            return ''
         return "\n%s\n%s\n%s" % (_tbopen, tb, _tbclose)
 
     def redirect(self, location, status=302, lock=0):