Skip to content

gh-135001: Explicitly specify the encoding parameter value of calendar.HTMLCalendar as 'utf-8' #135002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
3) specifies the number of months per row. *css* is the name for the
cascading style sheet to be used. :const:`None` can be passed if no style
sheet should be used. *encoding* specifies the encoding to be used for the
output (defaulting to the system default encoding).
output (defaulting to ``'utf-8'``).


.. method:: formatmonthname(theyear, themonth, withyear=True)
Expand Down
6 changes: 3 additions & 3 deletions Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
Return a formatted year as a complete HTML page.
"""
if encoding is None:
encoding = sys.getdefaultencoding()
encoding = 'utf-8'
v = []
a = v.append
a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
Expand Down Expand Up @@ -846,7 +846,7 @@ def main(args=None):
parser.add_argument(
"-e", "--encoding",
default=None,
help="encoding to use for output"
help="encoding to use for output (default utf-8)"
)
parser.add_argument(
"-t", "--type",
Expand Down Expand Up @@ -890,7 +890,7 @@ def main(args=None):
cal.setfirstweekday(options.first_weekday)
encoding = options.encoding
if encoding is None:
encoding = sys.getdefaultencoding()
encoding = 'utf-8'
optdict = dict(encoding=encoding, css=options.css)
write = sys.stdout.buffer.write
if options.year is None:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def test_output_htmlcalendar_encoding_utf8(self):
self.check_htmlcalendar_encoding('utf-8', 'utf-8')

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

def test_yeardatescalendar(self):
def shrink(cal):
Expand Down
Loading