Commit 84d03f6b authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #17049: Localized calendar methods now return unicode if a locale

includes an encoding and the result string contains month or weekday (was
regression from Python 2.6).
parent 8a56c3ff
...@@ -492,6 +492,7 @@ class TimeEncoding: ...@@ -492,6 +492,7 @@ class TimeEncoding:
def __enter__(self): def __enter__(self):
self.oldlocale = _locale.getlocale(_locale.LC_TIME) self.oldlocale = _locale.getlocale(_locale.LC_TIME)
_locale.setlocale(_locale.LC_TIME, self.locale) _locale.setlocale(_locale.LC_TIME, self.locale)
return _locale.getlocale(_locale.LC_TIME)[1]
def __exit__(self, *args): def __exit__(self, *args):
_locale.setlocale(_locale.LC_TIME, self.oldlocale) _locale.setlocale(_locale.LC_TIME, self.oldlocale)
......
...@@ -255,11 +255,23 @@ class CalendarTestCase(unittest.TestCase): ...@@ -255,11 +255,23 @@ class CalendarTestCase(unittest.TestCase):
# (it is still not thread-safe though) # (it is still not thread-safe though)
old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
try: try:
calendar.LocaleTextCalendar(locale='').formatmonthname(2010, 10, 10) cal = calendar.LocaleTextCalendar(locale='')
local_weekday = cal.formatweekday(1, 10)
local_month = cal.formatmonthname(2010, 10, 10)
except locale.Error: except locale.Error:
# cannot set the system default locale -- skip rest of test # cannot set the system default locale -- skip rest of test
return raise unittest.SkipTest('cannot set the system default locale')
calendar.LocaleHTMLCalendar(locale='').formatmonthname(2010, 10) # should be encodable
local_weekday.encode('utf-8')
local_month.encode('utf-8')
self.assertEqual(len(local_weekday), 10)
self.assertGreaterEqual(len(local_month), 10)
cal = calendar.LocaleHTMLCalendar(locale='')
local_weekday = cal.formatweekday(1)
local_month = cal.formatmonthname(2010, 10)
# should be encodable
local_weekday.encode('utf-8')
local_month.encode('utf-8')
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
self.assertEqual(old_october, new_october) self.assertEqual(old_october, new_october)
......
...@@ -202,6 +202,10 @@ Core and Builtins ...@@ -202,6 +202,10 @@ Core and Builtins
Library Library
------- -------
- Issue #17049: Localized calendar methods now return unicode if a locale
includes an encoding and the result string contains month or weekday (was
regression from Python 2.6).
- Issue #4844: ZipFile now raises BadZipfile when opens a ZIP file with an - Issue #4844: ZipFile now raises BadZipfile when opens a ZIP file with an
incomplete "End of Central Directory" record. Original patch by Guilherme incomplete "End of Central Directory" record. Original patch by Guilherme
Polo and Alan McIntyre. Polo and Alan McIntyre.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment