﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10335	tzinfo.py should use getdefaultencoding instead of getdefaultlocale[1]	Gunnlaugur Þór Briem	Armin Ronacher	"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()[1], 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."		closed	Core (Other)	1.0		fixed	locale encoding getdefaultlocale getdefaultencoding mac		Ready for checkin	1	0	0	0	0	0
