urldecode function?

Edwin.Madari at VerizonWireless.com Edwin.Madari at VerizonWireless.com
Thu Aug 14 17:17:54 EDT 2008


afraid not.. simple to create your own, NOTE that key words can be supplied more than once. Hence... 
============================================
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']}
 
 
hope that helps..
Edwin
 

-----Original Message-----
From: python-list-bounces+edwin.madari=verizonwireless.com at python.org [mailto:python-list-bounces+edwin.madari=verizonwireless.com at python.org]On Behalf Of rkmr.em at gmail.com
Sent: Thursday, August 14, 2008 12:32 PM
To: python-list at python.org
Subject: urldecode function?


hi
is there a function that does the opposite of urllib.urlencode? 

for example
urldecode('Cat=1&by=down&start=1827')

returns a dictionary with {'Cat':1, 'by':'down','start':1827)

thanks




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080814/19af5320/attachment-0001.html>


More information about the Python-list mailing list