Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-46659: Enhance LocaleTextCalendar for C locale#31214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:calendar_c_locale
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletionsDoc/library/calendar.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -289,9 +289,10 @@ 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 ``LC_TIME`` locale to the given *locale*. Because
the current locale is a process-wide setting, they are not thread-safe.
The constructor, :meth:`formatweekday` and :meth:`formatmonthname` methods
of these two 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.


For simple text calendars this module provides the following functions.
Expand Down
19 changes: 16 additions & 3 deletionsLib/calendar.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -548,15 +548,28 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
class different_locale:
def __init__(self, locale):
self.locale = locale
self.oldlocale = None

def __enter__(self):
self.oldlocale = _locale.getlocale(_locale.LC_TIME)
self.oldlocale = _locale.setlocale(_locale.LC_TIME, None)
_locale.setlocale(_locale.LC_TIME, self.locale)

def __exit__(self, *args):
if self.oldlocale is None:
return
_locale.setlocale(_locale.LC_TIME, self.oldlocale)


def _get_default_locale():
locale = _locale.setlocale(_locale.LC_TIME, None)
if locale == "C":
with different_locale(""):
# The LC_TIME locale does not seem to be configured:
# get the user preferred locale.
locale = _locale.setlocale(_locale.LC_TIME, None)
return locale


class LocaleTextCalendar(TextCalendar):
"""
This class can be passed a locale name in the constructor and will return
Expand All@@ -566,7 +579,7 @@ class LocaleTextCalendar(TextCalendar):
def __init__(self, firstweekday=0, locale=None):
TextCalendar.__init__(self, firstweekday)
if locale is None:
locale =_locale.getlocale(_locale.LC_TIME)
locale =_get_default_locale()
self.locale = locale

def formatweekday(self, day, width):
Expand All@@ -586,7 +599,7 @@ class LocaleHTMLCalendar(HTMLCalendar):
def __init__(self, firstweekday=0, locale=None):
HTMLCalendar.__init__(self, firstweekday)
if locale is None:
locale =_locale.getlocale(_locale.LC_TIME)
locale =_get_default_locale()
self.locale = locale

def formatweekday(self, day):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp