Skip to content

Commit f90483e

Browse files
authored
gh-135001: Explicitly specify the encoding parameter value of calendar.HTMLCalendar as 'utf-8' (#135002)
1 parent aaad2e8 commit f90483e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Doc/library/calendar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
251251
3) specifies the number of months per row. *css* is the name for the
252252
cascading style sheet to be used. :const:`None` can be passed if no style
253253
sheet should be used. *encoding* specifies the encoding to be used for the
254-
output (defaulting to the system default encoding).
254+
output (defaulting to ``'utf-8'``).
255255

256256

257257
.. method:: formatmonthname(theyear, themonth, withyear=True)

Lib/calendar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
565565
Return a formatted year as a complete HTML page.
566566
"""
567567
if encoding is None:
568-
encoding = sys.getdefaultencoding()
568+
encoding = 'utf-8'
569569
v = []
570570
a = v.append
571571
a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
@@ -846,7 +846,7 @@ def main(args=None):
846846
parser.add_argument(
847847
"-e", "--encoding",
848848
default=None,
849-
help="encoding to use for output"
849+
help="encoding to use for output (default utf-8)"
850850
)
851851
parser.add_argument(
852852
"-t", "--type",
@@ -890,7 +890,7 @@ def main(args=None):
890890
cal.setfirstweekday(options.first_weekday)
891891
encoding = options.encoding
892892
if encoding is None:
893-
encoding = sys.getdefaultencoding()
893+
encoding = 'utf-8'
894894
optdict = dict(encoding=encoding, css=options.css)
895895
write = sys.stdout.buffer.write
896896
if options.year is None:

Lib/test/test_calendar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_output_htmlcalendar_encoding_utf8(self):
417417
self.check_htmlcalendar_encoding('utf-8', 'utf-8')
418418

419419
def test_output_htmlcalendar_encoding_default(self):
420-
self.check_htmlcalendar_encoding(None, sys.getdefaultencoding())
420+
self.check_htmlcalendar_encoding(None, 'utf-8')
421421

422422
def test_yeardatescalendar(self):
423423
def shrink(cal):

0 commit comments

Comments
 (0)