mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
bpo-46659: calendar uses locale.getlocale() (GH-31166)
The calendar.LocaleTextCalendar and calendar.LocaleHTMLCalendar classes module now use locale.getlocale(), instead of using locale.getdefaultlocale(), if no locale is specified.
This commit is contained in:
parent
7ba1cc8049
commit
7a0486eaa9
5 changed files with 15 additions and 4 deletions
|
|
@ -290,7 +290,7 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
|
|||
.. 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.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -591,6 +591,12 @@ Changes in the Python API
|
|||
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
|
||||
=============
|
||||
|
|
|
|||
|
|
@ -566,7 +566,7 @@ class LocaleTextCalendar(TextCalendar):
|
|||
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):
|
||||
|
|
@ -586,7 +586,7 @@ class LocaleHTMLCalendar(HTMLCalendar):
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -859,7 +859,8 @@ class CommandLineTestCase(unittest.TestCase):
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue