This commit is contained in:
Brian Curtin 2011-08-10 20:34:20 -05:00
commit c29966f392
3 changed files with 16 additions and 4 deletions

View File

@ -636,7 +636,7 @@ def main(args):
parser.add_option( parser.add_option(
"-e", "--encoding", "-e", "--encoding",
dest="encoding", default=None, dest="encoding", default=None,
help="Encoding to use for output" help="Encoding to use for output."
) )
parser.add_option( parser.add_option(
"-t", "--type", "-t", "--type",
@ -662,10 +662,11 @@ def main(args):
if encoding is None: if encoding is None:
encoding = sys.getdefaultencoding() encoding = sys.getdefaultencoding()
optdict = dict(encoding=encoding, css=options.css) optdict = dict(encoding=encoding, css=options.css)
write = sys.stdout.buffer.write
if len(args) == 1: if len(args) == 1:
print(cal.formatyearpage(datetime.date.today().year, **optdict)) write(cal.formatyearpage(datetime.date.today().year, **optdict))
elif len(args) == 2: elif len(args) == 2:
print(cal.formatyearpage(int(args[1]), **optdict)) write(cal.formatyearpage(int(args[1]), **optdict))
else: else:
parser.error("incorrect number of arguments") parser.error("incorrect number of arguments")
sys.exit(1) sys.exit(1)
@ -687,9 +688,11 @@ def main(args):
else: else:
parser.error("incorrect number of arguments") parser.error("incorrect number of arguments")
sys.exit(1) sys.exit(1)
write = sys.stdout.write
if options.encoding: if options.encoding:
result = result.encode(options.encoding) result = result.encode(options.encoding)
print(result) write = sys.stdout.buffer.write
write(result)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -2,6 +2,7 @@ import calendar
import unittest import unittest
from test import support from test import support
from test.script_helper import assert_python_ok
import time import time
import locale import locale
@ -451,6 +452,11 @@ class LeapdaysTestCase(unittest.TestCase):
self.assertEqual(calendar.leapdays(1997,2020), 5) 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(): def test_main():
support.run_unittest( support.run_unittest(
OutputTestCase, OutputTestCase,
@ -460,6 +466,7 @@ def test_main():
TimegmTestCase, TimegmTestCase,
MonthRangeTestCase, MonthRangeTestCase,
LeapdaysTestCase, LeapdaysTestCase,
ConsoleOutputTestCase
) )

View File

@ -251,6 +251,8 @@ Core and Builtins
Library Library
------- -------
- Issue #10087: Fix the html output format of the calendar module.
- Issue #12540: Prevent zombie IDLE processes on Windows due to changes - Issue #12540: Prevent zombie IDLE processes on Windows due to changes
in os.kill(). in os.kill().