Commits

Thomas Lotze committed f982a0b Draft

Added a debug mode for the WSGI application.

Comments (0)

Files changed (5)

 - Allow configuration settings to be passed to the WSGI application upon
   initialisation.
 
+- Added a debug mode for the WSGI application.
+
 - Declared the ``ophelia`` package a namespace to allow contribution packages
   to be called ``ophelia.xxx``.
 

ophelia/CONFIGURATION.txt

 For boolean variables such as redirect_index, the values "on", "true", or
 "yes" (case-insensitive) are taken to mean True, anything else means False.
 
+:debug:
+    Whether to include debug information such as formatted tracebacks in error
+    responses. This option is turned off by default.
+
 
 Delivery of documents straight from disk
 ========================================

ophelia/tests/fixtures/templates/raise.html

+raise Exception('message')
+<?xml?>

ophelia/tests/test_wsgi.py

         self.assertIn('<a href="http://localhost/smoke.html">'
                       'http://localhost/smoke.html</a>', r.body)
 
+    def test_debug_mode_is_off_by_default(self):
+        r = self.app.get('/raise.html', status=500)
+        self.assertNotIn('message', r.body)
+
+    def test_debug_mode_switched_on(self):
+        r = self.app.get(
+            '/raise.html', status=500, extra_environ={'debug': 'on'})
+        self.assertIn('message', r.body)
+
 
 class OnDiskDocumentsTest(unittest.TestCase):
 
                 with_filenames=True, *exc_info))
             if isinstance(msg, unicode):
                 msg = msg.encode('utf-8')
-            text = "<pre>\n%s\n</pre>" % msg
             logger.error(msg)
+            if boolean(env.get('debug', False)):
+                text = '<pre>\n%s\n</pre>' % msg
+            else:
+                text = 'Something went wrong with the server software.'
         else:
             status = "200 OK"
 
         """.replace(" ", "")
 
 
+def boolean(value):
+    if isinstance(value, basestring):
+        return value.lower() in ("on", "true", "yes")
+    else:
+        return bool(value)
+
+
 def paste_app_factory(global_conf, **local_conf):
     options = global_conf.copy()
     options.update(local_conf)