tzinfo.py should use getdefaultencoding instead of getdefaultlocale
|Reported by:||gthb||Owned by:||mitsuhiko|
|Severity:||Keywords:||locale encoding getdefaultlocale getdefaultencoding mac|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In some locales on Mac OS X, page rendering fails with an error like:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py", line 81, in render_node raise wrapped TemplateSyntaxError: Caught an exception while rendering: unknown encoding: mac-icelandic
(where the encoding varies, could be mac-roman or other Mac-specific encodings)
It turns out that Python does not recognize some Mac-specific encodings, including those that are default in some locales (such as our Icelandic one).
That should be okay, we would just configure Python or Django to use a different default encoding. But the trouble is, we can't. In tzinfo.py the default encoding is determined as locale.getdefaultlocale(), which calls _locale._getdefaultlocale(), which on a Mac calls CFStringGetSystemEncoding. Of this latter function, the Mac documentation says:
In Mac OS X, this encoding is determined by the user's preferred language setting. The preferred language is the first language listed in the International pane of the System Preferences.
So there appears to be no way, in some locales, to get Django to render pages. One is forced to change the user's global language preference in the operating system settings. That's a bit too inflexible.
In contrast, sys.getdefaultencoding is easily controlled by calling sys.setdefaultencoding in sitecustomize.py.
Thus tzinfo.py should obtain the default encoding using sys.getdefaultencoding instead — at least optionally, or perhaps as a special-case exception for the mac-specific encodings, if one wants to take great care to minimize behavior changes in working installations.
Change History (15)
comment:1 Changed 5 years ago by gthb
- Keywords getdefaultencoding mac added
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 5 years ago by jacob
- milestone set to 1.1
- Triage Stage changed from Unreviewed to Accepted