#2971: Unicode encoding error w/ Windows & defined locale
---------------------+------------------------------------------------------
Reporter: eblot | Owner: jonas
Type: defect | Status: new
Priority: normal | Milestone:
Component: general | Version: devel
Severity: major | Keywords: unicode windows
---------------------+------------------------------------------------------
The following piece of code:
{{{
#!py
encoding = locale.getlocale(locale.LC_TIME)[1] or \
locale.getpreferredencoding()
}}}
in [source:/trunk/trac/util/[EMAIL PROTECTED] /trac/util/__init__.py]
breaks w/ Windows & ActiveState Python 2.3:
{{{
ActivePython 2.3.5 Build 236 (ActiveState Corp.) based on
Python 2.3.5 (#62, Feb 9 2005, 16:17:08) [MSC v.1200 32 bit (Intel)] on
win32
}}}
with the following Python stack trace
{{{
Traceback (most recent call last):
File "trac\web\main.py", line 308, in dispatch_request
dispatcher.dispatch(req)
File "trac\web\main.py", line 153, in dispatch
populate_hdf(req.hdf, self.env, req)
File "trac\web\main.py", line 69, in populate_hdf
hdf['trac'] = {
File "trac\util\__init__.py", line 198, in format_datetime
return unicode(text, encoding, 'replace')
LookupError: unknown encoding: 1252
}}}
when locale is defined.
It seems the trouble comes from the Python encoding:
{{{
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'French_France')
'French_France.1252'
>>> locale.setlocale(locale.LC_ALL, 'English_United-Kingdom')
'English_United Kingdom.1252'
>>> locale.getlocale(locale.LC_TIME)[1]
'1252'
}}}
The expected code page was `cp1252`, '''not''' `1252`:
{{{
>>> locale.getpreferredencoding()
'cp1252'
>>> unicode('test', 'cp1252', 'replace')
u'test'
>>> unicode('test', '1252', 'replace')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
LookupError: unknown encoding: 1252
}}}
--
Ticket URL: <http://projects.edgewall.com/trac/ticket/2971>
The Trac Project <http://trac.edgewall.com/>
_______________________________________________
Trac-Tickets mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac-tickets