1. Armin Rigo
  2. cpython-withatomic

Commits

Senthil Kumaran  committed 9fc7ef6

Fix closes Issue10087 - fixing the output of calendar display in the html format. Patch by Chris Lambacher. Test Contributed by catherine.

  • Participants
  • Parent commits 6ef6551
  • Branches 3.2

Comments (0)

Files changed (2)

File Lib/calendar.py

View file
     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",
         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)
         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__":

File Lib/test/test_calendar.py

View file
 import unittest
 
 from test import support
+from test.script_helper import assert_python_ok
 import time
 import locale
 
         self.assertEqual(calendar.leapdays(1997,2020), 5)
 
 
+class ConsoleOutputTestCase(unittest.TestCase):
+    def test_outputs_bytes(self):
+        (return_code, stdout, stderr) = assert_python_ok('-m', 'calendar', '--type=html', '2010')
+        self.assertEqual(stdout[:6], b'<?xml ')
+
 def test_main():
     support.run_unittest(
         OutputTestCase,
         TimegmTestCase,
         MonthRangeTestCase,
         LeapdaysTestCase,
+        ConsoleOutputTestCase
     )