is there a function that does the opposite of urllib.urlencode?the cgi modules contains assorted stuff for parsing serialized HTTP
for example
urldecode('Cat=1&by=down&start=1827')
returns a dictionary with {'Cat':1, 'by':'down','start':1827)
forms and query strings. here's a quick way to get a dictionary:
{'start': '1827', 'by': 'down', 'Cat': '1'}>>import cgi
dict(cgi.parse_qsl("Cat=1&by=down&start=1827") )
there's also:
{'start': ['1827'], 'by': ['down'], 'Cat': ['1']}>>cgi.parse_qs("Cat=1&by=down&start=1827")
[('Cat', '1'), ('by', 'down'), ('start', '1827')]>>cgi.parse_qsl("Cat=1&by=down&start=1827")
(both these forms handle multiple instances of the same key)
to autoconvert things that look like integers, you can do e.g.
.... try:>>def safeint(x):
.... return int(x)
.... except ValueError:
.... return x # leave as is
....
cgi.parse_qsl("Cat=1&by=down&start=1827"))>>dict((k, safeint(v)) for k, v in
{'start': 1827, 'by': 'down', 'Cat': 1}
</F>