diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-09-21 14:29:20 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-09-21 14:29:20 (GMT) |
commit | f82b9371f5234e9ce671f7ee7fe1debbe2f48b05 (patch) | |
tree | c82b3b98a6ba36a9a87db59e4eb88221a18139de /Lib | |
parent | 050a61f838dcbf4b6fad6eb83404a7eb1ffb9b9b (diff) | |
parent | 85710a40e7e9eab86060bedc3762ccf9ca8d26ca (diff) | |
download | cpython-f82b9371f5234e9ce671f7ee7fe1debbe2f48b05.zip cpython-f82b9371f5234e9ce671f7ee7fe1debbe2f48b05.tar.gz cpython-f82b9371f5234e9ce671f7ee7fe1debbe2f48b05.tar.bz2 |
#15421: merge with 3.2.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/calendar.py | 6 | ||||
-rw-r--r-- | Lib/test/test_calendar.py | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py index 0301d6b..3bbf399 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -161,7 +161,11 @@ class Calendar(object): oneday = datetime.timedelta(days=1) while True: yield date - date += oneday + try: + date += oneday + except OverflowError: + # Adding one day could fail after datetime.MAXYEAR + break if date.month != month and date.weekday() == self.firstweekday: break diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index e0f6399..e594e01 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -6,6 +6,7 @@ from test.script_helper import assert_python_ok import time import locale import sys +import datetime result_2004_01_text = """ January 2004 @@ -464,6 +465,11 @@ class CalendarTestCase(unittest.TestCase): new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october) + def test_itermonthdates(self): + # ensure itermonthdates doesn't overflow after datetime.MAXYEAR + # see #15421 + list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) + class MonthCalendarTestCase(unittest.TestCase): def setUp(self): |