.. note::
The :meth:`formatweekday` and :meth:`formatmonthname` methods of these two
- classes temporarily change the current locale to the given *locale*. Because
+ classes temporarily change the ``LC_TIME`` locale to the given *locale*. Because
the current locale is a process-wide setting, they are not thread-safe.
of sorting simply isn't well-defined in the absence of a total ordering
on list elements.
+* :mod:`calendar`: The :class:`calendar.LocaleTextCalendar` and
+ :class:`calendar.LocaleHTMLCalendar` classes now use
+ :func:`locale.getlocale`, instead of using :func:`locale.getdefaultlocale`,
+ if no locale is specified.
+ (Contributed by Victor Stinner in :issue:`46659`.)
+
Build Changes
=============
def __init__(self, firstweekday=0, locale=None):
TextCalendar.__init__(self, firstweekday)
if locale is None:
- locale = _locale.getdefaultlocale()
+ locale = _locale.getlocale(_locale.LC_TIME)
self.locale = locale
def formatweekday(self, day, width):
def __init__(self, firstweekday=0, locale=None):
HTMLCalendar.__init__(self, firstweekday)
if locale is None:
- locale = _locale.getdefaultlocale()
+ locale = _locale.getlocale(_locale.LC_TIME)
self.locale = locale
def formatweekday(self, day):
self.assertFailure('-L')
self.assertFailure('--locale')
self.assertFailure('-L', 'en')
- lang, enc = locale.getdefaultlocale()
+
+ lang, enc = locale.getlocale()
lang = lang or 'C'
enc = enc or 'UTF-8'
try:
--- /dev/null
+The :class:`calendar.LocaleTextCalendar` and
+:class:`calendar.LocaleHTMLCalendar` classes now use :func:`locale.getlocale`,
+instead of using :func:`locale.getdefaultlocale`, if no locale is specified.
+Patch by Victor Stinner.