import urllib
def urldecode(query):
d = {}
a = query.split('&')
for s in a:
if s.find('='):
k,v = map(urllib.unquote, s.split('='))
try:
d[k].append(v)
except KeyError:
d[k] = [v]
return d
s = 'Cat=1&by=down&start=1827&start=1234&anotherCat=me%3Dow%7e'
print urldecode(s)
====================================================
prints out following and preserves the order of inputs for those keys given more than once as with 'start' key
{'start': ['1827', '1234'], 'anotherCat': ['me=ow~'], 'by': ['down'], 'Cat': ['1']}
0 Comments:
Subscribe to:
Post Comments (Atom)