diff options
Diffstat (limited to 'paste')
| -rw-r--r-- | paste/wsgilib.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/paste/wsgilib.py b/paste/wsgilib.py index 4f53ac1..20604b1 100644 --- a/paste/wsgilib.py +++ b/paste/wsgilib.py @@ -6,6 +6,7 @@ from Cookie import SimpleCookie from cStringIO import StringIO import mimetypes import os +import cgi __all__ = ['get_cookies', 'add_close', 'raw_interactive', 'interactive', 'construct_url', 'error_body_response', @@ -28,6 +29,28 @@ def get_cookies(environ): environ['paste.cookies'] = (cookies, header) return cookies +def parse_querystring(environ): + """ + Parses a query string into a list like ``[(name, value)]``. + Caches this value in case parse_querystring is called again + for the same request. + + You can pass the result to ``dict()``, but be aware that keys that + appear multiple times will be lost (only the last value will be + preserved). + """ + source = environ.get('QUERY_STRING', '') + if not source: + return [] + if 'paste.parsed_querystring' in environ: + parsed, check_source = environ['paste.parsed_querystring'] + if check_source == source: + return parsed + parsed = cgi.parse_qs(source, keep_blank_values=True, + strict_parsing=False) + environ['paste.parsed_querystring'] = (parsed, source) + return parsed + class add_close: """ An an iterable that iterates over app_iter, then calls |
