]> granicus.if.org Git - python/commitdiff
Issue #17049: Localized calendar methods now return unicode if a locale
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 31 Jan 2013 13:57:51 +0000 (15:57 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 31 Jan 2013 13:57:51 +0000 (15:57 +0200)
includes an encoding and the result string contains month or weekday (was
regression from Python 2.6).

Lib/calendar.py
Lib/test/test_calendar.py
Misc/NEWS

index 232957829f093b9aa0c57b349f1ed2e6b66c37c1..441b2f576bc31097a03f10b4897b7f77c545ee32 100644 (file)
@@ -492,6 +492,7 @@ class TimeEncoding:
     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)
index 0f91d29590362377a7937bb4d3b1b4fe8a3e70be..40fb76ddd61974e37f3eadfe6d47a0bbcf4e71f1 100644 (file)
@@ -255,11 +255,23 @@ class CalendarTestCase(unittest.TestCase):
         # (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)
 
index 34e4bda9c230ccd7dec49944d78fb1c7b12d6ca9..e4d429fa911224fd96f16e7a5fc3e9d7fa9f69c5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -202,6 +202,10 @@ Core and Builtins
 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.