Re: problem with input elements and unicode/utf-8
--- In zope@yahoogroups.com, "Daryl Daly" <daryld@...> wrote:
I have setup a test case which seems to show the problem. This test removes the database component.
New install of zope 2.10.2: Zope Version (Zope 2.10.2-final, python 2.4.4, linux2) Python Version 2.4.4 (#1, Oct 23 2006, 13:58:00) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] System Platform linux2
I created a page template which contains: <html tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;; charset=utf-8');" > <head> <title tal:content="template/title">The title</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> <body tal:define="test_str python:u'This is a test \u00e9 \u00ae \u2022 \u2024 \u2219 \u03b2'.encode('utf-8')"> <span tal:content="test_str"></span> <form> <input name="t1" value="" tal:attributes="value test_str"> </form> </body> </html>
When this page is viewed in Firefox (v 1.5.0.9), it shows the characters correctly. When viewed in IE6, the non-ascii characters show as garbage.
If I add this to the zope.conf: <cgi-environment> HTTP_ACCEPT_CHARSET utf-8 </cgi-environment>
the non-ascii characters show correctly in IE6 (except one of them shows as a box - there is no 'garbage')
Is this zope.conf setup required for IE6 or am I doing something wrong?
Thanks, Daryl.
How about changing the following line 996 in /lib/python/zope/publisher/http.py ( as described in http://www.zope.org/Collectors/Zope/2280 ) header_present = 'HTTP_ACCEPT_CHARSET' in self.request to header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys() I think this is a bug. After doing that change, IE6 and IE7 behaved consistently. Regards Jost --------------------------------- Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
--On 21. Februar 2007 02:05:36 -0800 Jostein Leira <jleira@yahoo.com> wrote:
header_present = 'HTTP_ACCEPT_CHARSET' in self.request to
header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys()
I assume that the request implementation of Zope 3 and Zope 2 differ a bit when it comes to the 'in' operator. If request.keys() works for Zope 3 request as well I would like to see this fixed in Zope 3. Andreas
--On 21. Februar 2007 11:30:11 +0100 Andreas Jung <lists@zopyx.com> wrote:
--On 21. Februar 2007 02:05:36 -0800 Jostein Leira <jleira@yahoo.com> wrote:
header_present = 'HTTP_ACCEPT_CHARSET' in self.request to
header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys()
I assume that the request implementation of Zope 3 and Zope 2 differ a bit when it comes to the 'in' operator. If request.keys() works for Zope 3 request as well I would like to see this fixed in Zope 3.
After checking the implements and the unittests: I don't see any difference in the behavior of both statements. They behave identical. -aj
Andreas Jung <lists@zopyx.com> wrote: --On 21. Februar 2007 11:30:11 +0100 Andreas Jung wrote:
--On 21. Februar 2007 02:05:36 -0800 Jostein Leira wrote:
header_present = 'HTTP_ACCEPT_CHARSET' in self.request to
header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys()
I assume that the request implementation of Zope 3 and Zope 2 differ a bit when it comes to the 'in' operator. If request.keys() works for Zope 3 request as well I would like to see this fixed in Zope 3.
After checking the implements and the unittests: I don't see any difference in the behavior of both statements. They behave identical. -aj In my Zope 2.10.2 installation the two statements really do behave different. -Jost --------------------------------- Looking for earth-friendly autos? Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
On Wed, February 21, 2007 2:05 am, Jostein Leira wrote:
How about changing the following line 996 in /lib/python/zope/publisher/http.py ( as described in http://www.zope.org/Collectors/Zope/2280 )
header_present = 'HTTP_ACCEPT_CHARSET' in self.request to
header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys()
I think this is a bug. After doing that change, IE6 and IE7 behaved consistently.
After making this change, Firefox behaviour does not change but I get a UnicodeDecodeError in IE6. Here is the error_log entry: Time 2007/02/21 10:05:31.895 US/Pacific User Name (User Id) Anonymous User (None) Request URL http://192.168.45.20:8080/test/test_form Exception Type UnicodeDecodeError Exception Value 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128) Traceback (innermost last): * Module ZPublisher.Publish, line 119, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 42, in call_object * Module Shared.DC.Scripts.Bindings, line 313, in __call__ * Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec * Module Products.PageTemplates.ZopePageTemplate, line 331, in _exec * Module Products.PageTemplates.ZopePageTemplate, line 427, in pt_render * Module Products.PageTemplates.PageTemplate, line 89, in pt_render * Module zope.pagetemplate.pagetemplate, line 117, in pt_render * Module zope.tal.talinterpreter, line 271, in __call__ * Module zope.tal.talinterpreter, line 346, in interpret * Module zope.tal.talinterpreter, line 408, in do_startTag * Module zope.tal.talinterpreter, line 505, in attrAction_tal UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128) Display traceback as text REQUEST form -C '' cookies lazy items SESSION <bound method SessionDataManager.getSessionData of <SessionDataManager at /session_data_manager>> other TraversalRequestNameStack [] AUTHENTICATED_USER <SpecialUser 'Anonymous User'> URL 'http://192.168.45.20:8080/test/test_form' URL2 'http://192.168.45.20:8080' SERVER_URL 'http://192.168.45.20:8080' AUTHENTICATION_PATH '' traverse_subpath [] BASE1 'http://192.168.45.20:8080' BASE2 'http://192.168.45.20:8080/test' BASE3 'http://192.168.45.20:8080/test/test_form' PUBLISHED <ZopePageTemplate at /test/test_form> URL1 'http://192.168.45.20:8080/test' ACTUAL_URL 'http://192.168.45.20:8080/test/test_form' URL0 http://192.168.45.20:8080/test/test_form URL1 http://192.168.45.20:8080/test URL2 http://192.168.45.20:8080 BASE0 http://192.168.45.20:8080 BASE1 http://192.168.45.20:8080 BASE2 http://192.168.45.20:8080/test BASE3 http://192.168.45.20:8080/test/test_form environ HTTP_ACCEPT '*/*' CONNECTION_TYPE 'Keep-Alive' HTTP_USER_AGENT 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)' SERVER_NAME '0.0.0.0' GATEWAY_INTERFACE 'CGI/1.1' SERVER_SOFTWARE 'Zope/(Zope 2.10.2-final, python 2.4.4, linux2) ZServer/1.1' REMOTE_ADDR '192.168.45.151' HTTP_ACCEPT_LANGUAGE 'en-us' SCRIPT_NAME '' REQUEST_METHOD 'GET' HTTP_HOST '192.168.45.20:8080' PATH_INFO '/test/test_form' SERVER_PORT '8080' SERVER_PROTOCOL 'HTTP/1.1' channel.creation_time 1172081131 HTTP_ACCEPT_ENCODING 'gzip, deflate' PATH_TRANSLATED '/test/test_form'
Jostein Leira wrote at 2007-2-21 02:05 -0800:
... header_present = 'HTTP_ACCEPT_CHARSET' in self.request to
header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys()
I think this is a bug. After doing that change, IE6 and IE7 behaved consistently.
"HTTPRequest.keys" is a very costly method. In the case, that "in" has a bug (and does not work reliably), then "self.request.has_key('HTTP_ACCEPT_CHARSET')" should be used (even better would be to implement "in" by calling "has_key"). -- Dieter
participants (4)
-
Andreas Jung -
Daryl Daly -
Dieter Maurer -
Jostein Leira