diff options
author | ianb <devnull@localhost> | 2006-01-27 18:36:53 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2006-01-27 18:36:53 +0000 |
commit | 88a0a43744329c9d1b63f7e6316915418bf85869 (patch) | |
tree | 0298107a61c0a9e1d9a5cc16ebf19318c537949c /paste/request.py | |
parent | 8897742342d90aa5f647a8b75e51c413beda040b (diff) | |
download | paste-88a0a43744329c9d1b63f7e6316915418bf85869.tar.gz |
Added a method to resolve a relative URI in the context of a WSGI request (urljoin+construct_url)
Diffstat (limited to 'paste/request.py')
-rw-r--r-- | paste/request.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/paste/request.py b/paste/request.py index cce44b0..2d191d9 100644 --- a/paste/request.py +++ b/paste/request.py @@ -12,13 +12,16 @@ environment to solve common requirements. script_name=None, path_info=None, querystring=None) * path_info_split(path_info) * path_info_pop(environ) + * resolve_relative_url(url, environ) """ import cgi from Cookie import SimpleCookie +import urlparse __all__ = ['get_cookies', 'parse_querystring', 'parse_formvars', - 'construct_url', 'path_info_split', 'path_info_pop'] + 'construct_url', 'path_info_split', 'path_info_pop', + 'resolve_relative_url'] def get_cookies(environ): """ @@ -151,6 +154,17 @@ def construct_url(environ, with_query_string=True, with_path_info=True, url += '?' + querystring return url +def resolve_relative_url(url, environ): + """ + Resolve the given relative URL as being relative to the + location represented by the environment. This can be used + for redirecting to a relative path. Note: if url is already + absolute, this function will (intentionally) have no effect + on it. + """ + cur_url = construct_url(environ, with_query_string=False) + return urlparse.urljoin(cur_url, url) + def path_info_split(path_info): """ Splits off the first segment of the path. Returns (first_part, |