DETH Python Bindings
October 11, 2005 § Leave a comment
dictionaries.
The idea is that as a
client I could do something
like:
=====
import
deth
dict=deth.getDict(“http://somesite.com/users/“)
dict[“firstname”]=”Ernie”
dict[“lastname”]=”Prabhakar”
nextDict=deth.postDict(dict,
“http://somesite.com/users/“)
=====
And
hopefully something just as simple on the server. It would be nice to have a
cgi or something that would turn the url-encoded key-value pairs into a XOXO
‘dl’ entry, and simply pass that XHTML document over stdin. My server could
then just
do:
=====
import
deth
import
sys
doc=””
for
line in sys.stdin:
doc=doc+line
if “</html>” in
line:
dict=deth.HTMLtoDict(doc)
result=processDict(dict) # whatever
outDoc=deth.dicttoHTML(result)
sys.stdout.write(outDoc)
doc=””
=====
order=[
"firstname","lastname","sex",'"travel",
"age","description"
]
dict={
"@@tag":"form",
"@action":"http://somesite.com/users/",
"@class":"deth",
"@enctype":"application/x-www-form-urlencoded",
"@method":"post",
"@@order":order,
"firstname":"First name:",
"lastname":"Last name:",
"sex":{"@type":"radio", "male":"Male",
"female":"Female"},
"travel":{"@type":"checkbox", "car":"Car",
"bike":"Bicycle"},
"age":{"@@body":"Age:",
"@type":"select",
"0":"< 18", "18":"18-64",
"65":"65+"
},
"description":{
"@@body":"Description:",
"@type":"textarea",
"@value":"Default text"
}
}
Leave a Reply