From cfd4e5e06d05dac3e8f1c03b63bc3cf37242334a Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 25 Jan 2009 02:30:46 +0000 Subject: - 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. --- repoze/bfg/wsgi.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'repoze/bfg/wsgi.py') 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 = """ + %s

%s

+ %s + """ % (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' + -- cgit v1.2.3