@@ -574,9 +574,9 @@ def formatyear(self, theyear, width=3):
574574 a ('</table>' )
575575 return '' .join (v )
576576
577- def formatyearpage (self , theyear , width = 3 , css = 'calendar.css' , encoding = None ):
577+ def _format_html_page (self , theyear , content , css , encoding ):
578578 """
579- Return a formatted year as a complete HTML page .
579+ Return a complete HTML page with the given content .
580580 """
581581 if encoding is None :
582582 encoding = 'utf-8'
@@ -597,11 +597,25 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
597597 a (f'<link rel="stylesheet" href="{ css } ">\n ' )
598598 a ('</head>\n ' )
599599 a ('<body>\n ' )
600- a (self . formatyear ( theyear , width ) )
600+ a (content )
601601 a ('</body>\n ' )
602602 a ('</html>\n ' )
603603 return '' .join (v ).encode (encoding , "xmlcharrefreplace" )
604604
605+ def formatyearpage (self , theyear , width = 3 , css = 'calendar.css' , encoding = None ):
606+ """
607+ Return a formatted year as a complete HTML page.
608+ """
609+ content = self .formatyear (theyear , width )
610+ return self ._format_html_page (theyear , content , css , encoding )
611+
612+ def formatmonthpage (self , theyear , themonth , width = 3 , css = 'calendar.css' , encoding = None ):
613+ """
614+ Return a formatted month as a complete HTML page.
615+ """
616+ content = self .formatmonth (theyear , themonth , width )
617+ return self ._format_html_page (theyear , content , css , encoding )
618+
605619
606620class different_locale :
607621 def __init__ (self , locale ):
@@ -886,7 +900,7 @@ def main(args=None):
886900 parser .add_argument (
887901 "month" ,
888902 nargs = '?' , type = int ,
889- help = "month number (1-12, text only )"
903+ help = "month number (1-12)"
890904 )
891905
892906 options = parser .parse_args (args )
@@ -899,9 +913,6 @@ def main(args=None):
899913 today = datetime .date .today ()
900914
901915 if options .type == "html" :
902- if options .month :
903- parser .error ("incorrect number of arguments" )
904- sys .exit (1 )
905916 if options .locale :
906917 cal = LocaleHTMLCalendar (locale = locale )
907918 else :
@@ -912,10 +923,14 @@ def main(args=None):
912923 encoding = 'utf-8'
913924 optdict = dict (encoding = encoding , css = options .css )
914925 write = sys .stdout .buffer .write
926+
915927 if options .year is None :
916928 write (cal .formatyearpage (today .year , ** optdict ))
917929 else :
918- write (cal .formatyearpage (options .year , ** optdict ))
930+ if options .month :
931+ write (cal .formatmonthpage (options .year , options .month , ** optdict ))
932+ else :
933+ write (cal .formatyearpage (options .year , ** optdict ))
919934 else :
920935 if options .locale :
921936 cal = _CLIDemoLocaleCalendar (highlight_day = today , locale = locale )
0 commit comments