[Zope-dev] request.get vs request.form.get
Maurits van Rees
m.van.rees at zestsoftware.nl
Fri Nov 23 13:46:39 EST 2007
I have been busy with zope.formlib. See this weblog entry for some
background:
http://maurits.vanrees.org/weblog/archive/2007/11/search-forms-with-zope-formlib-and-batching
This is Plone 3 with Zope 2.10.4 btw.
I discovered there is a difference between getting a value from the
request or from request.form when unicode is involved. From a pdb
session:
>>> request.form.get('SearchableText')
u'\xff'
>>> request.get('SearchableText')
'\xc3\xbf'
This is the character ÿ: a y with something extra on top. :) You can
see the same in a python prompt (I hope this is readable for
everyone):
>>> u"ÿ"
u'\xff'
>>> "ÿ"
'\xc3\xbf'
This gave me problems while using zope.formlib. In the method
zope.app.form.browser.textwidgets.TextWidget._getFormInput() the value
is fetched from the request and not request.form. So you get a
UnicodeDecodeError. In the weblog entry I mentioned I post some code
to guard against that in a setUpWidgets method in your own form page:
deliberately overwrite the variable in the request by the variable in
request.form.
But what I want to ask here is: does something need to be fixed
somewhere in zope?
Should the value in request and request.form really be the same
always? Probably: always unicode?
Should zope.app.form.browser.textwidgets.TextWidget._getFormInput()
get the value from the form instead of from the request?
Thanks,
--
Maurits van Rees | http://maurits.vanrees.org/ [NL]
Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
I can assure you mine are still greater."
More information about the Zope-Dev
mailing list