From a4a76101efeed6833e239221397ec8f6035beeee Mon Sep 17 00:00:00 2001 From: ianb Date: Thu, 2 Feb 2006 06:06:00 +0000 Subject: Added relative_redirect classmethod constructor to redirect exceptions --- paste/httpexceptions.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'paste/httpexceptions.py') diff --git a/paste/httpexceptions.py b/paste/httpexceptions.py index b61d8bc..4f2f366 100644 --- a/paste/httpexceptions.py +++ b/paste/httpexceptions.py @@ -74,6 +74,7 @@ References: import types from wsgilib import catch_errors_app from response import has_header, header_value +from request import resolve_relative_url from util.quoting import strip_html, html_quote, no_quote SERVER_NAME = 'WSGI Server' @@ -313,6 +314,18 @@ class _HTTPMove(HTTPRedirection): if detail is not None: self.detail = detail + def relative_redirect(cls, dest_uri, environ, detail=None, headers=None, comment=None): + """ + Create a redirect object with the dest_uri, which may be relative, + considering it relative to the uri implied by the given environ. + """ + location = resolve_relative_url(dest_uri, environ) + headers = headers or [] + headers.append(('Location', location)) + return cls(detail=detail, headers=headers, comment=comment) + + relative_redirect = classmethod(relative_redirect) + class HTTPMultipleChoices(_HTTPMove): code = 300 title = 'Multiple Choices' -- cgit v1.2.1