[Python-checkins] cpython (merge 3.2 -> default): merge from 3.2

senthil.kumaran python-checkins at python.org
Thu Aug 11 03:25:58 CEST 2011


http://hg.python.org/cpython/rev/fdfd1d67d9fb
changeset:   71808:fdfd1d67d9fb
parent:      71803:1b4fae183da3
parent:      71807:23316468ed4f
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Thu Aug 11 09:25:45 2011 +0800
summary:
  merge from 3.2

files:
  Lib/calendar.py           |  11 +++++++----
  Lib/test/test_calendar.py |   7 +++++++
  Misc/NEWS                 |   2 ++
  3 files changed, 16 insertions(+), 4 deletions(-)


diff --git a/Lib/calendar.py b/Lib/calendar.py
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -636,7 +636,7 @@
     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 +662,11 @@
         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 +688,11 @@
         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__":
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
@@ -2,6 +2,7 @@
 import unittest
 
 from test import support
+from test.script_helper import assert_python_ok
 import time
 import locale
 
@@ -451,6 +452,11 @@
         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,
@@ -460,6 +466,7 @@
         TimegmTestCase,
         MonthRangeTestCase,
         LeapdaysTestCase,
+        ConsoleOutputTestCase
     )
 
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -251,6 +251,8 @@
 Library
 -------
 
+- Issue #10087: Fix the html output format of the calendar module.
+
 - Issue #12540: Prevent zombie IDLE processes on Windows due to changes
   in os.kill().
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list