Skip to content

Commit f54f757

Browse files
pgdrhugovk
andauthored
Refactor out html page
Contributed by hugovk Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent e0f9a9e commit f54f757

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Lib/calendar.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,9 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
603603
return ''.join(v).encode(encoding, "xmlcharrefreplace")
604604

605605

606-
def formatmonthpage(self, theyear, themonth, width=3, css='calendar.css', encoding=None):
606+
def _format_html_page(self, theyear, content, css, encoding):
607607
"""
608-
Return a formatted month as a complete HTML page.
608+
Return a complete HTML page with the given content.
609609
"""
610610
if encoding is None:
611611
encoding = 'utf-8'
@@ -626,11 +626,25 @@ def formatmonthpage(self, theyear, themonth, width=3, css='calendar.css', encodi
626626
a(f'<link rel="stylesheet" href="{css}">\n')
627627
a('</head>\n')
628628
a('<body>\n')
629-
a(self.formatmonth(theyear, themonth, width))
629+
a(content)
630630
a('</body>\n')
631631
a('</html>\n')
632632
return ''.join(v).encode(encoding, "xmlcharrefreplace")
633633

634+
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
635+
"""
636+
Return a formatted year as a complete HTML page.
637+
"""
638+
content = self.formatyear(theyear, width)
639+
return self._format_html_page(theyear, content, css, encoding)
640+
641+
def formatmonthpage(self, theyear, themonth, width=3, css='calendar.css', encoding=None):
642+
"""
643+
Return a formatted month as a complete HTML page.
644+
"""
645+
content = self.formatmonth(theyear, themonth, width)
646+
return self._format_html_page(theyear, content, css, encoding)
647+
634648

635649
class different_locale:
636650
def __init__(self, locale):

0 commit comments

Comments
 (0)