[Python-checkins] cpython (3.2): #15421: fix an OverflowError in Calendar.itermonthdates() after
ezio.melotti
python-checkins at python.org
Fri Sep 21 16:29:42 CEST 2012
http://hg.python.org/cpython/rev/aa73e60f65e9
changeset: 79089:aa73e60f65e9
branch: 3.2
parent: 79086:0b60dcabf7e6
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Fri Sep 21 17:26:35 2012 +0300
summary:
#15421: fix an OverflowError in Calendar.itermonthdates() after datetime.MAXYEAR. Patch by Cédric Krier.
files:
Lib/calendar.py | 6 +++++-
Lib/test/test_calendar.py | 6 ++++++
Misc/NEWS | 3 +++
3 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/Lib/calendar.py b/Lib/calendar.py
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -161,7 +161,11 @@
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
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -5,6 +5,7 @@
from test.script_helper import assert_python_ok
import time
import locale
+import datetime
result_2004_text = """
2004
@@ -265,6 +266,11 @@
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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -120,6 +120,9 @@
Library
-------
+- Issue #15421: fix an OverflowError in Calendar.itermonthdates() after
+ datetime.MAXYEAR. Patch by Cédric Krier.
+
- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML
elements 'meta' and 'param'.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list