diff options
| author | ianb <devnull@localhost> | 2005-06-12 23:03:33 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-06-12 23:03:33 +0000 |
| commit | 0622424de7ef499ccaf0e0e74cae30bf26986345 (patch) | |
| tree | 1d194b9a070aab9bf29caa1ba723b93a7de35b2b /paste | |
| parent | afcab7257f5dc0410072fcd69111588eba1f9814 (diff) | |
| download | paste-0622424de7ef499ccaf0e0e74cae30bf26986345.tar.gz | |
Added new arguments to construct_url
Diffstat (limited to 'paste')
| -rw-r--r-- | paste/wsgilib.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/paste/wsgilib.py b/paste/wsgilib.py index 20604b1..d3f52cb 100644 --- a/paste/wsgilib.py +++ b/paste/wsgilib.py @@ -7,6 +7,7 @@ from cStringIO import StringIO import mimetypes import os import cgi +import urllib __all__ = ['get_cookies', 'add_close', 'raw_interactive', 'interactive', 'construct_url', 'error_body_response', @@ -143,9 +144,12 @@ def interactive(*args, **kw): return full.getvalue() interactive.proxy = 'raw_interactive' -def construct_url(environ, with_query_string=True, with_path_info=True): +def construct_url(environ, with_query_string=True, with_path_info=True, + add_path=None, add_vars=None): """ - Reconstructs the URL from the WSGI environment. + Reconstructs the URL from the WSGI environment. If add_path is + given, it is appended to the path. If add_vars is given, it is + appended to the URL variables. """ url = environ['wsgi.url_scheme']+'://' @@ -164,9 +168,20 @@ def construct_url(environ, with_query_string=True, with_path_info=True): url += environ.get('SCRIPT_NAME','') if with_path_info: url += environ.get('PATH_INFO','') + if add_path: + assert add_path.startswith('/'), ( + "add_path must start with '/' (you gave %r)" % add_path) + url += add_path if with_query_string: if environ.get('QUERY_STRING'): url += '?' + environ['QUERY_STRING'] + if add_vars: + if not isinstance(add_vars, str): + add_vars = urllib.urlencode(add_vars, doseq=True) + if with_query_string and environ.get('QUERY_STRING'): + url += '&' + add_vars + else: + url += '?' + add_vars return url def error_body_response(error_code, message): |
