diff options
Diffstat (limited to 'repoze/bfg/wsgi.py')
| -rw-r--r-- | repoze/bfg/wsgi.py | 25 |
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' + |
