]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-135001: Explicitly specify the encoding parameter value of `calendar.HTMLCalendar...
authorWulian233 <1055917385@qq.com>
Mon, 9 Jun 2025 13:40:09 +0000 (21:40 +0800)
committerGitHub <noreply@github.com>
Mon, 9 Jun 2025 13:40:09 +0000 (15:40 +0200)
Doc/library/calendar.rst
Lib/calendar.py
Lib/test/test_calendar.py

index 39090e36ed9c0d994b51e28032a9a4574f350f8a..b292d828841f2f34ae77ab441edc1a24085e72e7 100644 (file)
@@ -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)
index 18f76d52ff858199f606a35273b47606d5f3937d..3be1b50500eb070f8f0e272865e9f0d3e2fbbc37 100644 (file)
@@ -565,7 +565,7 @@ class HTMLCalendar(Calendar):
         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)
@@ -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",
@@ -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:
index 7ade4271b7a1564f8b963020cb07db63fa224e77..bc39c86b8cf62dbddbd03a6f7eaea8b46faa531e 100644 (file)
@@ -417,7 +417,7 @@ class OutputTestCase(unittest.TestCase):
         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):