Python port of the node.js querystring module
Project description
This repo is a port of the node.js querystring module.
It contains two methods, parse_qs and stringify_obj that are functionally equivalent to the querystring.parse and querystring.stringify node counterparts. It also contains default encode_uri_component and decode_uri_component functions that can be used for convenience.
Installation
pip install querystring
Usage
Parsing a query string
>>> querystring.parse_qs('foo=bar&baz=qux&baz=quux&corge=') {u'foo': u'bar', u'baz': [u'qux', u'quux'], u'corge': u''}
>>> querystring.parse_qs('foo:bar;baz:qux;baz:quux;corge:', sep=';', eq=':') {u'foo': u'bar', u'baz': [u'qux', u'quux'], u'corge': u''}
>>> def gbk_decode(s): ... return urllib.unquote(s) ... >>> querystring.parse_qs('foo=bar&w=%D6%D0%CE%C4', decode_fn=gbk_decode) {'foo': 'bar', 'w': '\xd6\xd0\xce\xc4'} # u'中文'
Converting an object back into a query string
>>> querystring.stringify_obj({'foo': 'bar', 'baz': ['qux', 'quux'], 'corge': ''}) 'foo=bar&baz=qux&baz=quux&corge='
>>> querystring.stringify_obj({'foo': 'bar', 'baz': ['qux', 'quux'], 'corge': ''}, sep=';', eq=':') 'foo:bar;baz:qux;baz:quux;corge:'
>>> def gbk_encode(s): ... return urllib.quote(unicode(s).encode('gbk')) ... >>> querystring.stringify_obj({'foo': 'bar', 'w': u'中文'}, encode_fn=gbk_encode) 'foo=bar&w=%D6%D0%CE%C4'
Motivation
We were looking for a simple module to parse query parameters in a sensible way, and were unsatisfied by how urlparse handled params (putting all values in a list), so we made this.
License
Copyright Refinery29, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file querystring-0.1.0.tar.gz
.
File metadata
- Download URL: querystring-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b48eb7259cef632b817dd388c223d0799d2c5bc1a23e3daa154a4e0b481e41d5 |
|
MD5 | 17201172438c0f5e08c7bd76c83efb5c |
|
BLAKE2b-256 | bc97f3cce4f2e490bb52864defa91fc2e244b0b8e0dd673ddd13b2054e847244 |