]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#15421: fix an OverflowError in Calendar.itermonthdates() after datetime.MAXYEAR...
authorEzio Melotti <ezio.melotti@gmail.com>
Fri, 21 Sep 2012 14:26:35 +0000 (17:26 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Fri, 21 Sep 2012 14:26:35 +0000 (17:26 +0300)
Lib/calendar.py
Lib/test/test_calendar.py
Misc/NEWS

index 0301d6b5d6ca51367e30b3a3c6fce67255591fd2..3bbf399649f8fc4df9aab6a571525be411913563 100644 (file)
@@ -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
 
index d3093ac939146e273fe24c6b9c36b86fce510e1b..948a1197b9c28505c1c112e9e99b3af758a0aaf7 100644 (file)
@@ -5,6 +5,7 @@ from test import support
 from test.script_helper import assert_python_ok
 import time
 import locale
+import datetime
 
 result_2004_text = """
                                   2004
@@ -265,6 +266,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):
index bebab93611dc425fdae7c524b2af70fc82776ffb..74782aac68c27a24f0cebce6c25dc0a111ae5d4e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -120,6 +120,9 @@ Core and Builtins
 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'.