From 3317c08db036ffbfe6c6f96530d6e9d8b05c34d6 Mon Sep 17 00:00:00 2001 From: ianb Date: Mon, 19 Feb 2007 02:08:01 +0000 Subject: add .response() method to HTTPException objects (from damjam) --- paste/httpexceptions.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'paste/httpexceptions.py') diff --git a/paste/httpexceptions.py b/paste/httpexceptions.py index 5792d76..ce8bef2 100644 --- a/paste/httpexceptions.py +++ b/paste/httpexceptions.py @@ -222,10 +222,7 @@ class HTTPException(Exception): 'server': SERVER_NAME, 'body': body } - def wsgi_application(self, environ, start_response, exc_info=None): - """ - This exception as a WSGI application - """ + def prepare_content(self, environ): if self.headers: headers = list(self.headers) else: @@ -245,6 +242,20 @@ class HTTPException(Exception): replace_header( headers, 'content-type', cur_content_type + '; charset=utf8') + return headers, content + + def response(self, environ): + from paste.wsgiwrappers import WSGIResponse + headers, content = self.prepare_content(environ) + resp = WSGIResponse(code=self.code, content=content) + resp.headers.update(dict(headers)) + return resp + + def wsgi_application(self, environ, start_response, exc_info=None): + """ + This exception as a WSGI application + """ + headers, content = self.prepare_content(environ) start_response('%s %s' % (self.code, self.title), headers, exc_info) -- cgit v1.2.1