[Python-checkins] r86769 - in python/branches/release27-maint: Doc/library/calendar.rst Lib/calendar.py Lib/test/test_calendar.py Misc/NEWS
georg.brandl
python-checkins at python.org
Fri Nov 26 08:57:57 CET 2010
Author: georg.brandl
Date: Fri Nov 26 08:57:57 2010
New Revision: 86769
Log:
Merged revisions 85728 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85728 | georg.brandl | 2010-10-19 20:54:25 +0200 (Di, 19 Okt 2010) | 1 line
#10092: Properly reset locale in Locale*Calendar classes. The context manager was buggy because setlocale() returns the *new* locale, not the old. Also add a test for this.
........
Modified:
python/branches/release27-maint/ (props changed)
python/branches/release27-maint/Doc/library/calendar.rst
python/branches/release27-maint/Lib/calendar.py
python/branches/release27-maint/Lib/test/test_calendar.py
python/branches/release27-maint/Misc/NEWS
Modified: python/branches/release27-maint/Doc/library/calendar.rst
==============================================================================
--- python/branches/release27-maint/Doc/library/calendar.rst (original)
+++ python/branches/release27-maint/Doc/library/calendar.rst Fri Nov 26 08:57:57 2010
@@ -182,9 +182,9 @@
.. class:: LocaleTextCalendar([firstweekday[, locale]])
This subclass of :class:`TextCalendar` can be passed a locale name in the
- constructor and will return month and weekday names in the specified
- locale. If this locale includes an encoding all strings containing month and
- weekday names will be returned as unicode.
+ constructor and will return month and weekday names in the specified locale.
+ If this locale includes an encoding all strings containing month and weekday
+ names will be returned as unicode.
.. versionadded:: 2.5
@@ -198,6 +198,13 @@
.. versionadded:: 2.5
+.. note::
+
+ The :meth:`formatweekday` and :meth:`formatmonthname` methods of these two
+ classes temporarily change the current locale to the given *locale*. Because
+ the current locale is a process-wide setting, they are not thread-safe.
+
+
For simple text calendars this module provides the following functions.
Modified: python/branches/release27-maint/Lib/calendar.py
==============================================================================
--- python/branches/release27-maint/Lib/calendar.py (original)
+++ python/branches/release27-maint/Lib/calendar.py Fri Nov 26 08:57:57 2010
@@ -486,8 +486,8 @@
self.locale = locale
def __enter__(self):
- self.oldlocale = _locale.setlocale(_locale.LC_TIME, self.locale)
- return _locale.getlocale(_locale.LC_TIME)[1]
+ self.oldlocale = _locale.getlocale(_locale.LC_TIME)
+ _locale.setlocale(_locale.LC_TIME, self.locale)
def __exit__(self, *args):
_locale.setlocale(_locale.LC_TIME, self.oldlocale)
Modified: python/branches/release27-maint/Lib/test/test_calendar.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_calendar.py (original)
+++ python/branches/release27-maint/Lib/test/test_calendar.py Fri Nov 26 08:57:57 2010
@@ -2,6 +2,7 @@
import unittest
from test import test_support
+import locale
result_2004_text = """
@@ -248,6 +249,22 @@
# verify it "acts like a sequence" in two forms of iteration
self.assertEqual(value[::-1], list(reversed(value)))
+ def test_localecalendars(self):
+ # ensure that Locale{Text,HTML}Calendar resets the locale properly
+ # (it is still not thread-safe though)
+ try:
+ def_locale = locale.getdefaultlocale()
+ except locale.Error:
+ # cannot determine a default locale -- skip test
+ return
+ old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
+ calendar.LocaleTextCalendar(
+ locale=def_locale).formatmonthname(2010, 10, 10)
+ calendar.LocaleHTMLCalendar(
+ locale=def_locale).formatmonthname(2010, 10)
+ new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
+ self.assertEquals(old_october, new_october)
+
class MonthCalendarTestCase(unittest.TestCase):
def setUp(self):
Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS (original)
+++ python/branches/release27-maint/Misc/NEWS Fri Nov 26 08:57:57 2010
@@ -13,6 +13,8 @@
Library
-------
+- Issue #10092: Properly reset locale in calendar.Locale*Calendar classes.
+
- Issue #10459: Update CJK character names to Unicode 5.2.
- Issue #6098: Don't claim DOM level 3 conformance in minidom.
More information about the Python-checkins
mailing list