diff options
Diffstat (limited to 'Lib/calendar.py')
-rw-r--r-- | Lib/calendar.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py index 84aa3a429b..3bbf399649 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 @@ -636,7 +640,7 @@ def main(args): parser.add_option( "-e", "--encoding", dest="encoding", default=None, - help="Encoding to use for output" + help="Encoding to use for output." ) parser.add_option( "-t", "--type", @@ -662,10 +666,11 @@ def main(args): if encoding is None: encoding = sys.getdefaultencoding() optdict = dict(encoding=encoding, css=options.css) + write = sys.stdout.buffer.write if len(args) == 1: - print(cal.formatyearpage(datetime.date.today().year, **optdict)) + write(cal.formatyearpage(datetime.date.today().year, **optdict)) elif len(args) == 2: - print(cal.formatyearpage(int(args[1]), **optdict)) + write(cal.formatyearpage(int(args[1]), **optdict)) else: parser.error("incorrect number of arguments") sys.exit(1) @@ -687,9 +692,11 @@ def main(args): else: parser.error("incorrect number of arguments") sys.exit(1) + write = sys.stdout.write if options.encoding: result = result.encode(options.encoding) - print(result) + write = sys.stdout.buffer.write + write(result) if __name__ == "__main__": |