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

Commitce0f854

Browse files
serhiy-storchakamiss-islington
authored andcommitted
pythongh-136028: Fix parsing month names containing "İ" (U+0130) in strptime() (pythonGH-136029)
This affects locales az_AZ, ber_DZ, ber_MA and crh_UA.(cherry picked from commit731f5b8)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent1e972c7 commitce0f854

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

‎Lib/_strptime.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def _findall(haystack, needle):
4242
yieldi
4343
i+=len(needle)
4444

45+
def_fixmonths(months):
46+
yieldfrommonths
47+
# The lower case of 'İ' ('\u0130') is 'i\u0307'.
48+
# The re module only supports 1-to-1 character matching in
49+
# case-insensitive mode.
50+
forsinmonths:
51+
if'i\u0307'ins:
52+
yields.replace('i\u0307','\u0130')
4553

4654
lzh_TW_alt_digits= (
4755
# 〇:一:二:三:四:五:六:七:八:九
@@ -366,8 +374,8 @@ def __init__(self, locale_time=None):
366374
'z':r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|(?-i:Z))",
367375
'A':self.__seqToRE(self.locale_time.f_weekday,'A'),
368376
'a':self.__seqToRE(self.locale_time.a_weekday,'a'),
369-
'B':self.__seqToRE(self.locale_time.f_month[1:],'B'),
370-
'b':self.__seqToRE(self.locale_time.a_month[1:],'b'),
377+
'B':self.__seqToRE(_fixmonths(self.locale_time.f_month[1:]),'B'),
378+
'b':self.__seqToRE(_fixmonths(self.locale_time.a_month[1:]),'b'),
371379
'p':self.__seqToRE(self.locale_time.am_pm,'p'),
372380
'Z':self.__seqToRE((tzfortz_namesinself.locale_time.timezone
373381
fortzintz_names),

‎Lib/test/test_strptime.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ def test_month_locale(self):
340340
self.roundtrip('%B',1, (1900,m,1,0,0,0,0,1,0))
341341
self.roundtrip('%b',1, (1900,m,1,0,0,0,0,1,0))
342342

343+
@run_with_locales('LC_TIME','az_AZ','ber_DZ','ber_MA','crh_UA')
344+
deftest_month_locale2(self):
345+
# Test for month directives
346+
# Month name contains 'İ' ('\u0130')
347+
self.roundtrip('%B',1, (2025,6,1,0,0,0,6,152,0))
348+
self.roundtrip('%b',1, (2025,6,1,0,0,0,6,152,0))
349+
self.roundtrip('%B',1, (2025,7,1,0,0,0,1,182,0))
350+
self.roundtrip('%b',1, (2025,7,1,0,0,0,1,182,0))
351+
343352
deftest_day(self):
344353
# Test for day directives
345354
self.roundtrip('%d %Y',2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix parsing month names containing "İ" (U+0130, LATIN CAPITAL LETTER I WITH
2+
DOT ABOVE) in:func:`time.strptime`. This affects locales az_AZ, ber_DZ,
3+
ber_MA and crh_UA.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp