1. Thomas Lotze
  2. ophelia


Thomas Lotze  committed f982a0b

Added a debug mode for the WSGI application.

  • Participants
  • Parent commits 1a7a7e9
  • Branches wsgi-only

Comments (0)

Files changed (5)

File CHANGES.txt

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

File ophelia/CONFIGURATION.txt

View file
  • Ignore whitespace
 For boolean variables such as redirect_index, the values "on", "true", or
 "yes" (case-insensitive) are taken to mean True, anything else means False.
+    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

File ophelia/tests/fixtures/templates/raise.html

View file
  • Ignore whitespace
+raise Exception('message')

File ophelia/tests/test_wsgi.py

View file
  • Ignore whitespace
         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):

File ophelia/wsgi.py

View file
  • Ignore whitespace
                 with_filenames=True, *exc_info))
             if isinstance(msg, unicode):
                 msg = msg.encode('utf-8')
-            text = "<pre>\n%s\n</pre>" % msg
+            if boolean(env.get('debug', False)):
+                text = '<pre>\n%s\n</pre>' % msg
+            else:
+                text = 'Something went wrong with the server software.'
             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()