diff options
| author | ianb <devnull@localhost> | 2005-06-12 18:21:41 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-06-12 18:21:41 +0000 |
| commit | 1ba255659ee9c0d2ed33cdcc07473be092f541cb (patch) | |
| tree | c708efb7e036b576b2e9f93f34b61d620b04bd00 /paste/wsgilib.py | |
| parent | 62f2e58dcbc34903de81b7eebf466fd48aa30676 (diff) | |
| download | paste-1ba255659ee9c0d2ed33cdcc07473be092f541cb.tar.gz | |
Added function for parsing QUERY_STRING
Diffstat (limited to 'paste/wsgilib.py')
| -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 |
