Skip to content

Commit 68bd800

Browse files
committed
Change the default *encoding* of calendar.HTMLCalendar to UTF-8
1 parent b595237 commit 68bd800

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

Doc/library/calendar.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,16 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
245245
specifies the number of months per row.
246246

247247

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

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

256+
.. versionchanged:: next
257+
The default value of the *encoding* has been changed to utf-8.
256258

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

@@ -651,8 +653,10 @@ The following options are accepted:
651653
.. option:: --encoding ENCODING, -e ENCODING
652654

653655
The encoding to use for output.
654-
:option:`--encoding` is required if :option:`--locale` is set.
656+
Defaults to utf-8.
655657

658+
.. versionchanged:: next
659+
The default value has been changed to utf-8.
656660

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

Doc/whatsnew/3.15.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ Deprecated
138138
Removed
139139
=======
140140

141+
calendar
142+
--------
143+
144+
* The default *encoding* parameter value in :meth:`calendar.HTMLCalendar.formatyearpage`
145+
is now utf-8.
146+
(Contributed by Jiahao Li in :gh:`135001`.)
147+
141148
ctypes
142149
------
143150

Lib/calendar.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,10 @@ def formatyear(self, theyear, width=3):
560560
a('</table>')
561561
return ''.join(v)
562562

563-
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
563+
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding='utf-8'):
564564
"""
565565
Return a formatted year as a complete HTML page.
566566
"""
567-
if encoding is None:
568-
encoding = sys.getdefaultencoding()
569567
v = []
570568
a = v.append
571569
a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
@@ -845,8 +843,8 @@ def main(args=None):
845843
)
846844
parser.add_argument(
847845
"-e", "--encoding",
848-
default=None,
849-
help="encoding to use for output"
846+
default="utf-8",
847+
help="encoding to use for output (default utf-8)"
850848
)
851849
parser.add_argument(
852850
"-t", "--type",
@@ -872,10 +870,6 @@ def main(args=None):
872870

873871
options = parser.parse_args(args)
874872

875-
if options.locale and not options.encoding:
876-
parser.error("if --locale is specified --encoding is required")
877-
sys.exit(1)
878-
879873
locale = options.locale, options.encoding
880874
today = datetime.date.today()
881875

@@ -889,8 +883,6 @@ def main(args=None):
889883
cal = HTMLCalendar()
890884
cal.setfirstweekday(options.first_weekday)
891885
encoding = options.encoding
892-
if encoding is None:
893-
encoding = sys.getdefaultencoding()
894886
optdict = dict(encoding=encoding, css=options.css)
895887
write = sys.stdout.buffer.write
896888
if options.year is None:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The default *encoding* parameter value in
2+
:meth:`calendar.HTMLCalendar.formatyearpage` is now utf-8.

0 commit comments

Comments
 (0)