Ticket #2971 (reopened defect)
Unicode encoding error w/ Windows & defined locale
| Reported by: | eblot | Owned by: | cboos |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.11.3 |
| Component: | general | Version: | devel |
| Severity: | major | Keywords: | unicode windows python23 |
| Cc: |
Description
The following piece of code:
encoding = locale.getlocale(locale.LC_TIME)[1] or \ locale.getpreferredencoding()
in /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
Attachments
Change History
Note: See
TracTickets for help on using
tickets.


