ephemeralz
Programmer
i need a function that decodes form data encoded in HTTP GET REQUEST URL:
and return a dictionary of key/value pairs representing the
form data. ‘+’ signs in values should be converted to spaces
{'user':'jdoe','name':['john doe']}
below is my attempt:
the problem to the code below is that it's not able to handle mutliple key with same values
import string
print context.standard_html_header(context,context.REQUEST)
firstKeyList=string.split(url,'?')
urlList=firstKeyList[-1]
urlKeyList=string.split(urlList,'&')
urlTuple = ('key',['values'])
urlList = range(len(urlKeyList))
urlTemp=''
urlFinal=''
urlDict= {}
for i in urlList:
urlValueList = string.split(urlKeyList,'=')
for j in range(len(urlValueList)-1):
string.join(string.split(urlValueList[j+1],'+')) + ")"
urlTuple = (urlValueList[j], "['" + string.join(string.split(urlValueList[j+1] + "']",'+')))
string.join(string.split(urlValueList[j+1],'+'))
string.join(string.split(urlValueList[j+1],'+')) + "'),"
urlList = urlTuple
urlList.reverse()
urlDict = dict(urlList)
print urlDict
print context.standard_html_footer(context,context.REQUEST)
return printed
and return a dictionary of key/value pairs representing the
form data. ‘+’ signs in values should be converted to spaces
{'user':'jdoe','name':['john doe']}
below is my attempt:
the problem to the code below is that it's not able to handle mutliple key with same values
import string
print context.standard_html_header(context,context.REQUEST)
firstKeyList=string.split(url,'?')
urlList=firstKeyList[-1]
urlKeyList=string.split(urlList,'&')
urlTuple = ('key',['values'])
urlList = range(len(urlKeyList))
urlTemp=''
urlFinal=''
urlDict= {}
for i in urlList:
urlValueList = string.split(urlKeyList,'=')
for j in range(len(urlValueList)-1):
string.join(string.split(urlValueList[j+1],'+')) + ")"
urlTuple = (urlValueList[j], "['" + string.join(string.split(urlValueList[j+1] + "']",'+')))
string.join(string.split(urlValueList[j+1],'+'))
string.join(string.split(urlValueList[j+1],'+')) + "'),"
urlList = urlTuple
urlList.reverse()
urlDict = dict(urlList)
print urlDict
print context.standard_html_footer(context,context.REQUEST)
return printed