]> granicus.if.org Git - python/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 3106ef273e86e9541d96552615632ffa61e9de70..232957829f093b9aa0c57b349f1ed2e6b66c37c1 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 2a562688109fa5085bfff97b75d533054919782a..5d6549c6cd8fda222cb48437a508b05362dc9144 100644 (file)
@@ -3,6 +3,7 @@ import unittest
 
 from test import test_support
 import locale
+import datetime
 
 
 result_2004_text = """
@@ -262,6 +263,11 @@ class CalendarTestCase(unittest.TestCase):
         new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
         self.assertEquals(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 e73499810427f6c9d30af1bc68bb875823ae42e7..84d4bd1910cca5301dfb274c02b9590dbf48c4e5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,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'.