Skip to content
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
10 changes: 7 additions & 3 deletions Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@ 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=None)
.. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding='utf-8')

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 the system default encoding).
output (defaulting to ``utf-8``).

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

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

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

The encoding to use for output.
:option:`--encoding` is required if :option:`--locale` is set.
Defaults to utf-8.

.. versionchanged:: next
The default value has been changed to utf-8.

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

Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ Deprecated
Removed
=======

calendar
--------

* The default *encoding* parameter value in :meth:`calendar.HTMLCalendar.formatyearpage`
is now utf-8.
(Contributed by Jiahao Li in :gh:`135001`.)

ctypes
------

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

def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding='utf-8'):
"""
Return a formatted year as a complete HTML page.
"""
if encoding is None:
encoding = sys.getdefaultencoding()
v = []
a = v.append
a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
Expand Down Expand Up @@ -845,8 +843,8 @@ def main(args=None):
)
parser.add_argument(
"-e", "--encoding",
default=None,
help="encoding to use for output"
default="utf-8",
help="encoding to use for output (default utf-8)"
)
parser.add_argument(
"-t", "--type",
Expand All @@ -872,10 +870,6 @@ 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 @@ -889,8 +883,6 @@ def main(args=None):
cal = HTMLCalendar()
cal.setfirstweekday(options.first_weekday)
encoding = options.encoding
if encoding is None:
encoding = sys.getdefaultencoding()
optdict = dict(encoding=encoding, css=options.css)
write = sys.stdout.buffer.write
if options.year is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The default *encoding* parameter value in
:meth:`calendar.HTMLCalendar.formatyearpage` is now utf-8.
Loading