summaryrefslogtreecommitdiff
path: root/repoze/bfg/wsgi.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-01-25 02:30:46 +0000
committerChris McDonough <chrism@agendaless.com>2009-01-25 02:30:46 +0000
commitcfd4e5e06d05dac3e8f1c03b63bc3cf37242334a (patch)
tree506481ffc66fef568749c27bcd2611fe9a98d1b0 /repoze/bfg/wsgi.py
parentfbd7ff75bde1c59c1b791b0db1be4f81f81d2d3d (diff)
downloadpyramid-cfd4e5e06d05dac3e8f1c03b63bc3cf37242334a.tar.gz
pyramid-cfd4e5e06d05dac3e8f1c03b63bc3cf37242334a.tar.bz2
pyramid-cfd4e5e06d05dac3e8f1c03b63bc3cf37242334a.zip
- You can now override the NotFound and Unauthorized responses that
:mod:`repoze.bfg` generates when a view cannot be found or cannot be invoked due to lack of permission. See the "ZCML Hooks" chapter in the docs for more information. - Use a homegrown Unauthorized error instead of ``webob.exc.Unauthorized`` (the latter is slow). - Various speed micro-tweaks.
Diffstat (limited to 'repoze/bfg/wsgi.py')
-rw-r--r--repoze/bfg/wsgi.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/repoze/bfg/wsgi.py b/repoze/bfg/wsgi.py
index b0feef29e..38cca58a3 100644
--- a/repoze/bfg/wsgi.py
+++ b/repoze/bfg/wsgi.py
@@ -1,3 +1,5 @@
+from cgi import escape
+
try:
from functools import wraps
except ImportError:
@@ -31,3 +33,26 @@ def wsgiapp(wrapped):
def decorator(context, request):
return request.get_response(wrapped)
return wraps(wrapped)(decorator) # pickleability
+
+class HTTPException(object):
+ def __call__(self, environ, start_response, exc_info=False):
+ try:
+ msg = escape(environ['message'])
+ except KeyError:
+ msg = ''
+ html = """<body>
+ <html><title>%s</title><body><h1>%s</h1>
+ <code>%s</code>
+ """ % (self.status, self.status, msg)
+ headers = [('Content-Length', len(html)), ('Content-Type', 'text/html')]
+ start_response(self.status, headers)
+ return [html]
+
+class NotFound(HTTPException):
+ """ The default NotFound WSGI application """
+ status = '404 Not Found'
+
+class Unauthorized(HTTPException):
+ """ The default Unauthorized WSGI application """
+ status = '401 Unauthorized'
+