[ZCM] [ZC] 2280/ 5 Comment "getPreferredCharsets() returns iso-8859-1 and not utf-8 when HTTP_ACCEPT_CHARSET not present in request"

"Collector: Zope Bugs, Features, and Patches ..." <[email protected]> Mon, 19 Feb 2007 05:29:09 -0500
Newsgroups gmane.comp.web.zope.devel.collector-monitor
Message-ID <[email protected]>
Issue #2280 Update (Comment) "getPreferredCharsets() returns iso-8859-1 and not utf-8 when HTTP_ACCEPT_CHARSET not present in request"
 Status Rejected, Zope/bug+solution medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2280

==============================================================
= Comment - Entry #5 by jost on Feb 19, 2007 5:29 am

> = Comment - Entry #4 by jost on Feb 19, 2007 4:52 am
> 
> > * sys.setdefaultencoding() is evil evil evil. Don't use that.
> If I don't change the default encoding I can't save any page templates
>   containing non-ascii characters. 

Correction: I can save page templates containing non-ascii characters, but not like this:

<tal:block tal:content="python:'æøå'"/>

________________________________________
= Comment - Entry #4 by jost on Feb 19, 2007 4:52 am

> = Comment - Entry #3 by philikon on Feb 16, 2007 11:52 am
> This might be a problem local to Zope 2, or it may not be a problem at
>   all at this point. Hard to say. Point is:
> 
> * str(self.request) is not really a solution. In fact, it's pretty weird and wrong.

How about chaning the line 

    header_present = 'HTTP_ACCEPT_CHARSET' in self.request

to

    header_present = 'HTTP_ACCEPT_CHARSET' in self.request.keys()

This seems to work correct.

> * sys.setdefaultencoding() is evil evil evil. Don't use that.
If I don't change the default encoding I can't save any page templates containing non-ascii characters. 

> We need more info to reproduce this issue. Ideally, an HTTP transcript
>   (e.g. using tcpwatch) would be best. Until then the issue remains
>   rejected.
What is it you want to look at. The request? I am pretty sure it does not contain any HTTP_ACCEPT_CHARSET statement in the header. At least it is not present when I print it out from the method in question.

Regard Jost
________________________________________
= Comment - Entry #3 by philikon on Feb 16, 2007 11:52 am

This might be a problem local to Zope 2, or it may not be a problem at all at this point. Hard to say. Point is:

* str(self.request) is not really a solution. In fact, it's pretty weird and wrong.

* type(self.request) returning <type 'instance'> is normal.

* sys.setdefaultencoding() is evil evil evil. Don't use that.

We need more info to reproduce this issue. Ideally, an HTTP transcript (e.g. using tcpwatch) would be best. Until then the issue remains rejected.

________________________________________
= Reject - Entry #2 by ajung on Feb 16, 2007 11:38 am

 Status: Pending => Rejected

This belongs into the Zope 3 bugtracker since it addresses an issues in the Zope 3 core
________________________________________
= Request - Entry #1 by jost on Feb 16, 2007 11:30 am

I'm not sure if I'm sumitting this the right place or if this is just a local problem not affecting any other, but I have the following problem:

While using Internet Explorer 7 (IE7), the method getPreferredCharsets() in the class HTTPCharsets (http.py) returns 'iso-8859-1' and not 'utf-8' as expected. As far as I know, IE7 does not set the HTTP_ACCEPT_CHARSET in the request. Reading the source I would expect that no HTTP_ACCEPT_CHARSET should result in a return value of 'utf-8'.

At least on my system the line 996 of /lib/python/zope/publisher/http.py

   header_present = 'HTTP_ACCEPT_CHARSET' in self.request

sets header_present = True, even if self.request does not contain 'HTTP_ACCEPT_CHARSET'!

Suspecting a problem with the line, not understanding why, I changed it to:

   header_present = 'HTTP_ACCEPT_CHARSET' in str(self.request)

This resolves my problem.


###################
Other charset related settings I have changed:

Have set sys.setdefaultencoding('utf-8') in /usr/local/lib/python2.4/site.py.
Have set management_page_charset='utf-8' as property of / in ZMI.
Have set default-zpublisher-encoding utf-8 in etc/zope.conf.

Adding for debug in /lib/python/zope/publisher/http.py (around line 1000):

    print type(self.request)

returns:

    <type 'instance'>




==============================================================