From e6d3daa93b95a5597575eb466b3a580ff26bb810 Mon Sep 17 00:00:00 2001 From: ianb Date: Tue, 13 Dec 2005 08:20:25 +0000 Subject: Deprecate the wsgilib.error_response functions; stop using them internally as well, in preference of httpexceptions.*.wsgi_application --- paste/urlparser.py | 87 +++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 50 deletions(-) (limited to 'paste/urlparser.py') diff --git a/paste/urlparser.py b/paste/urlparser.py index 64e2dcd..0e6efac 100644 --- a/paste/urlparser.py +++ b/paste/urlparser.py @@ -9,6 +9,7 @@ import mimetypes import wsgilib from paste.util import import_string from paste.deploy import converters +import httpexceptions class NoDefault: pass @@ -193,17 +194,13 @@ class URLParser(object): return self.get_application(environ, filename), filename def not_found(self, environ, start_response, debug_message=None): - status, headers, body = wsgilib.error_response( - environ, - '404 Not Found', + exc = httpexceptions.HTTPNotFound( 'The resource at %s could not be found' - '' - % (wsgilib.construct_url(environ), - environ.get('SCRIPT_NAME'), environ.get('PATH_INFO'), - self.directory), - debug_message=debug_message) - start_response(status, headers) - return [body] + % wsgilib.construct_url(environ), + comment='SCRIPT_NAME=%r; PATH_INFO=%r; looking in %r; debug: %s' + % (environ.get('SCRIPT_NAME'), environ.get('PATH_INFO'), + self.directory, debug_message or '(none)')) + return exc.wsgi_application(environ, start_response) def add_slash(self, environ, start_response): """ @@ -214,15 +211,11 @@ class URLParser(object): url += '/' if environ.get('QUERY_STRING'): url += '?' + environ['QUERY_STRING'] - status = '301 Moved Permanently' - status, headers, body = wsgilib.error_response( - environ, - status, - ''' -

The resource has moved to %s. You - should be redirected automatically.

''' % (url, url)) - start_response(status, headers + [('Location', url)]) - return [body] + exc = httpexceptions.HTTPMovedPermanently( + 'The resource has moved to %s - you should be redirected ' + 'automatically.''' % url, + headers=[('location', url)]) + return exc.wsgi_application(environ, start_response) def find_file(self, environ, base_filename): possible = [] @@ -441,38 +434,25 @@ class StaticURLParser(object): url += '/' if environ.get('QUERY_STRING'): url += '?' + environ['QUERY_STRING'] - status = '301 Moved Permanently' - status, headers, body = wsgilib.error_response( - environ, - status, - ''' -

The resource has moved to %s. You - should be redirected automatically.

''' % (url, url)) - start_response(status, headers + [('Location', url)]) - return [body] + exc = httpexceptions.HTTPMovedPermanently( + 'The resource has moved to %s - you should be redirected ' + 'automatically.''' % url, + headers=[('location', url)]) + return exc.wsgi_application(environ, start_response) def not_found(self, environ, start_response, debug_message=None): - status, headers, body = wsgilib.error_response( - environ, - '404 Not Found', - 'The resource at %s could not be found\n' - '