Message119194
>>> import calendar
>>> calendar.LocaleTextCalendar(locale='fr_FR').formatmonthname(2010,10,10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\calendar.py", line 522, in formatmonthname
with TimeEncoding(self.locale) as encoding:
File "C:\Python27\lib\calendar.py", line 489, in __enter__
self.oldlocale = _locale.setlocale(_locale.LC_TIME, self.locale)
File "C:\Python27\lib\locale.py", line 531, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
Is it just my machine or is this a common thing on most machines? If I do a test and I try to set a locale with the setlocale() method, I get this "locale.Error: unsupported locale setting". So I gather that the method setlocale() is broken and we should fix it before fixing the Locale{Text,HTML}Calendar ones.
The way setlocale() is implemented, is this:
def setlocale(category, value=None):
""" setlocale(integer,string=None) -> string.
Activates/queries locale processing.
"""
if value not in (None, '', 'C'):
raise Error, '_locale emulation only supports "C" locale'
return 'C'
Please note that the online documentation documents its API like this:
locale.setlocale(category[, locale]) See http://docs.python.org/library/locale.html#locale.setlocale
So you can see that the implementation differs from the documentation in that it documents the 2nd argument as 'locale' where in the implementation there is 'value'. If that's a bug, I don't know.
Anyway, please fix the implementation. I found out some very interesting thing... Note the line "if value not in (None, '', 'C')" in the implementation. This is the faulty thing in the function because NoneType is not iterable.
Test it for yourself in the interpreter:
>>> value = None
>>> value not in None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument of type 'NoneType' is not iterable
So this setlocale() always raises an error. Please fix this.
Of course, this is valid:
>>> value = None
>>> value is not None
False
No error here. So try to combine this into a workable patch. Thanks. |
|
Date |
User |
Action |
Args |
2010-10-20 08:52:52 | Retro | set | recipients:
+ Retro, twouters, georg.brandl, ixokai, belopolsky, christian.heimes, eric.araujo, JJeffries |
2010-10-20 08:52:52 | Retro | set | messageid: <1287564772.67.0.552174528839.issue10092@psf.upfronthosting.co.za> |
2010-10-20 08:52:51 | Retro | link | issue10092 messages |
2010-10-20 08:52:50 | Retro | create | |
|