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

Merged
merged 7 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
Wulian233 committed Jun 6, 2025
commit a232d70183f1f0c500b5cfc15704f379138b721f
12 changes: 3 additions & 9 deletions Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,13 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
specifies the number of months per row.


.. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding='utf-8')
.. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding=None)

Return a year's calendar as a complete HTML page. *width* (defaulting to
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 ``utf-8``).

.. versionchanged:: next
The default value of the *encoding* has been changed to utf-8.
output (defaulting to ``'utf-8'``).

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

Expand Down Expand Up @@ -653,10 +650,7 @@ The following options are accepted:
.. option:: --encoding ENCODING, -e ENCODING

The encoding to use for output.
Defaults to utf-8.

.. versionchanged:: next
The default value has been changed to utf-8.
:option:`--encoding` is required if :option:`--locale` is set.

.. option:: --type {text,html}, -t {text,html}

Expand Down
12 changes: 10 additions & 2 deletions Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,12 @@ def formatyear(self, theyear, width=3):
a('</table>')
return ''.join(v)

def formatyearpage(self, theyear, width=3, css='calendar.css', encoding='utf-8'):
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 = 'utf-8'
v = []
a = v.append
a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
Expand Down Expand Up @@ -843,7 +845,7 @@ def main(args=None):
)
parser.add_argument(
"-e", "--encoding",
default="utf-8",
default=None,
help="encoding to use for output (default utf-8)"
)
parser.add_argument(
Expand All @@ -870,6 +872,10 @@ def main(args=None):

options = parser.parse_args(args)

if options.locale and not options.encoding:
parser.error("if --locale is specified --encoding is required")
sys.exit(1)

locale = options.locale, options.encoding
today = datetime.date.today()

Expand All @@ -883,6 +889,8 @@ def main(args=None):
cal = HTMLCalendar()
cal.setfirstweekday(options.first_weekday)
encoding = options.encoding
if encoding is None:
encoding = 'utf-8'
optdict = dict(encoding=encoding, css=options.css)
write = sys.stdout.buffer.write
if options.year is None:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Replace *encoding* parameter value in
:meth:`calendar.HTMLCalendar.formatyearpage` from
:func:`sys.getdefaultencoding()` to ``utf-8``.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy