[Python-checkins] cpython (2.7): Issue #17049: Localized calendar methods now return unicode if a locale
serhiy.storchaka
python-checkins at python.org
Thu Jan 31 14:58:36 CET 2013
http://hg.python.org/cpython/rev/af41eca1959e
changeset: 81851:af41eca1959e
branch: 2.7
parent: 81847:32de35f0f877
user: Serhiy Storchaka <storchaka at gmail.com>
date: Thu Jan 31 15:57:51 2013 +0200
summary:
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).
files:
Lib/calendar.py | 1 +
Lib/test/test_calendar.py | 18 +++++++++++++++---
Misc/NEWS | 4 ++++
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/Lib/calendar.py b/Lib/calendar.py
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -492,6 +492,7 @@
def __enter__(self):
self.oldlocale = _locale.getlocale(_locale.LC_TIME)
_locale.setlocale(_locale.LC_TIME, self.locale)
+ return _locale.getlocale(_locale.LC_TIME)[1]
def __exit__(self, *args):
_locale.setlocale(_locale.LC_TIME, self.oldlocale)
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -255,11 +255,23 @@
# (it is still not thread-safe though)
old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
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:
# cannot set the system default locale -- skip rest of test
- return
- calendar.LocaleHTMLCalendar(locale='').formatmonthname(2010, 10)
+ raise unittest.SkipTest('cannot set the system default locale')
+ # 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)
self.assertEqual(old_october, new_october)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -202,6 +202,10 @@
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
incomplete "End of Central Directory" record. Original patch by Guilherme
Polo and Alan McIntyre.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list