From 3be1afad6f40817f8089656d54a1b215cdd7feba Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Sun, 23 Apr 2017 08:44:04 +0200 Subject: [PATCH 01/24] Add more styling options to HTMLCalendar The HTMLCalendar has now multiple class attributes for styling the calendar. In order to retain backwards compatibility style names are not changed. The new attributes are: weekday_head_styles month_head_styles = ("month",) year_head_styles = ("year",) year_styles = ("year",) This are added to the previously existing styles, which where scattered around the code hard coded or as class attributes: month style day styles noday style The relevant methods have been modified to use these attributes. If you want a calendar where elements has multiple CSS attributes you can now do the following: >>> my_styles = HTMLCalendar.cssclasses[:] >>> my_stelys = " ".join((s, "black text-centered")) for s in my_styles] class MyCalendar(HTMLCalendar): cssclasses = styles month_head_styles = "month-title text-bold" This implementation simply replaces hard coded string with class attributes (which are also single strings albite the attribute names which are in plural). --- Lib/calendar.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Lib/calendar.py b/Lib/calendar.py index 28ac56fdbe858d..35d82b4ff983a1 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -381,13 +381,20 @@ class HTMLCalendar(Calendar): # CSS classes for the day s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] + noday_classes = "noday" + weekday_head_styles = cssclasses + month_head_styles = "month" + month_styles = "month" + year_head_styles = "year" + year_styles = "year" def formatday(self, day, weekday): """ Return a day as a table cell. """ if day == 0: - return ' ' # day outside month + # day outside month + return ' ' % self.noday_classes else: return '%d' % (self.cssclasses[weekday], day) @@ -402,7 +409,8 @@ def formatweekday(self, day): """ Return a weekday name as a table header. """ - return '%s' % (self.cssclasses[day], day_abbr[day]) + return '%s' % ( + self.weekday_head_styles[day], day_abbr[day]) def formatweekheader(self): """ @@ -419,7 +427,8 @@ def formatmonthname(self, theyear, themonth, withyear=True): s = '%s %s' % (month_name[themonth], theyear) else: s = '%s' % month_name[themonth] - return '%s' % s + return '%s' % ( + self.month_head_styles, s) def formatmonth(self, theyear, themonth, withyear=True): """ @@ -427,7 +436,8 @@ def formatmonth(self, theyear, themonth, withyear=True): """ v = [] a = v.append - a('') + a('
' % ( + self.month_styles)) a('\n') a(self.formatmonthname(theyear, themonth, withyear=withyear)) a('\n') @@ -447,9 +457,11 @@ def formatyear(self, theyear, width=3): v = [] a = v.append width = max(width, 1) - a('
') + a('
' % + self.year_head_styles) a('\n') - a('' % (width, theyear)) + a('' % ( + width, self.year_styles, theyear)) for i in range(January, January+12, width): # months in this row months = range(i, min(i+width, 13)) From f2609fb0aebbd02b1f7150a5b379815151013662 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Mon, 24 Apr 2017 20:58:29 +0200 Subject: [PATCH 02/24] Consitent naming --- Lib/calendar.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/calendar.py b/Lib/calendar.py index 35d82b4ff983a1..188ed7a9b90531 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -382,11 +382,11 @@ class HTMLCalendar(Calendar): # CSS classes for the day ' % ( - self.weekday_head_styles[day], day_abbr[day]) + self.weekday_head_classes[day], day_abbr[day]) def formatweekheader(self): """ @@ -428,7 +428,7 @@ def formatmonthname(self, theyear, themonth, withyear=True): else: s = '%s' % month_name[themonth] return '' % ( - self.month_head_styles, s) + self.month_head_classes, s) def formatmonth(self, theyear, themonth, withyear=True): """ @@ -437,7 +437,7 @@ def formatmonth(self, theyear, themonth, withyear=True): v = [] a = v.append a('
%s
%s
s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] noday_classes = "noday" - weekday_head_styles = cssclasses - month_head_styles = "month" - month_styles = "month" - year_head_styles = "year" - year_styles = "year" + weekday_head_classes = cssclasses + month_head_classes = "month" + month_classes = "month" + year_head_classes = "year" + year_classes = "year" def formatday(self, day, weekday): """ @@ -410,7 +410,7 @@ def formatweekday(self, day): Return a weekday name as a table header. """ return '%s
%s
' % ( - self.month_styles)) + self.month_classes)) a('\n') a(self.formatmonthname(theyear, themonth, withyear=withyear)) a('\n') @@ -458,10 +458,10 @@ def formatyear(self, theyear, width=3): a = v.append width = max(width, 1) a('
' % - self.year_head_styles) + self.year_head_classes) a('\n') a('' % ( - width, self.year_styles, theyear)) + width, self.year_classes, theyear)) for i in range(January, January+12, width): # months in this row months = range(i, min(i+width, 13)) From fe05aaccadd5587d2a3bf64eafc7db7878c85715 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Mon, 1 May 2017 22:50:38 +0200 Subject: [PATCH 03/24] Add test case for subclassing --- Lib/test/test_calendar.py | 91 ++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index bd57653ffadc16..4ef1ef88a3fe2e 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -57,19 +57,22 @@ 25 26 27 28 29 30 31 29 30 27 28 29 30 31 """ + +default_format = dict(year="year", month="month", encoding="ascii") + result_2004_html = """\ - + - + Calendar for 2004 -
%s
-
2004
- +
January
+
2004
+ @@ -77,8 +80,8 @@
January
MonTueWedThuFriSatSun
   1234
567891011
19202122232425
262728293031 
-
- +
February
+ @@ -86,8 +89,8 @@
February
MonTueWedThuFriSatSun
      1
2345678
16171819202122
23242526272829
-
- +
March
+ @@ -95,8 +98,8 @@
March
MonTueWedThuFriSatSun
1234567
891011121314
22232425262728
293031    
-
- +
April
+ @@ -104,8 +107,8 @@
April
MonTueWedThuFriSatSun
   1234
567891011
19202122232425
2627282930  
-
- +
May
+ @@ -114,8 +117,8 @@
May
MonTueWedThuFriSatSun
     12
3456789
24252627282930
31      
-
- +
June
+ @@ -123,8 +126,8 @@
June
MonTueWedThuFriSatSun
 123456
78910111213
21222324252627
282930    
-
- +
July
+ @@ -132,8 +135,8 @@
July
MonTueWedThuFriSatSun
   1234
567891011
19202122232425
262728293031 
-
- +
August
+ @@ -142,8 +145,8 @@
August
MonTueWedThuFriSatSun
      1
2345678
23242526272829
3031     
-
- +
September
+ @@ -151,8 +154,8 @@
September
MonTueWedThuFriSatSun
  12345
6789101112
20212223242526
27282930   
-
- +
October
+ @@ -160,8 +163,8 @@
October
MonTueWedThuFriSatSun
    123
45678910
18192021222324
25262728293031
-
- +
November
+ @@ -169,8 +172,8 @@
November
MonTueWedThuFriSatSun
1234567
891011121314
22232425262728
2930     
-
- +
December
+ @@ -327,9 +330,12 @@ def neitherspacenordigit(c): def check_htmlcalendar_encoding(self, req, res): cal = calendar.HTMLCalendar() + format_ = default_format.copy() + format_["encoding"] = req or 'utf-8' + output = cal.formatyearpage(2004, encoding=req) self.assertEqual( - cal.formatyearpage(2004, encoding=req), - (result_2004_html % {'e': res}).encode(res) + output, + result_2004_html.format(**format_).encode(res) ) def test_output(self): @@ -825,7 +831,7 @@ def test_html_output_current_year(self): def test_html_output_year_encoding(self): stdout = self.run_ok('-t', 'html', '--encoding', 'ascii', '2004') self.assertEqual(stdout, - (result_2004_html % {'e': 'ascii'}).encode('ascii')) + result_2004_html.format(**default_format).encode('ascii')) def test_html_output_year_css(self): self.assertFailure('-t', 'html', '-c') @@ -844,5 +850,30 @@ def test__all__(self): support.check__all__(self, calendar, blacklist=blacklist) +class TestSubClassingCase(unittest.TestCase): + + def setUp(self): + + class CustomHTMLCal(calendar.HTMLCalendar): + cssclasses = [style + " text-nowrap" for style in + calendar.HTMLCalendar.cssclasses] + month_head_classes = "text-center month-head" + month_classes = "text-center month" + year_classes = "lead " + + self.cal = CustomHTMLCal() + + def test_formatmonthname(self): + self.assertIn('class="text-center month-head"', self.cal.formatmonthname(2017, 5)) + + def test_formatmonth(self): + self.assertIn('class="text-center month"', self.cal.formatmonth(2017, 5)) + + def test_formatweek(self): + weeks = self.cal.monthdays2calendar(2017,5) + self.assertIn('class="wed text-nowrap"', self.cal.formatweek(weeks[0])) + def test_format_year(self): + self.assertIn('' % (3, self.cal.year_classes, 2017), self.cal.formatyear(2017)) + if __name__ == "__main__": unittest.main() From 363e3738c414ca095e5d62dc95cd6166965cc4a5 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Wed, 3 May 2017 21:09:08 +0200 Subject: [PATCH 04/24] Add documentation for customizing HTMLCalendar --- Doc/library/calendar.rst | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 41e9e28e0c0b25..642cd253db4a04 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -170,6 +170,44 @@ it's the base calendar for all computations. sheet should be used. *encoding* specifies the encoding to be used for the output (defaulting to the system default encoding). + :class:`HTMLCalendar` has the following attribute you can override to customize the style of your calender: + + .. attribute:: cssclasses + + By default it is a list with containing a style for each name:: + + cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] + + But you can add more styles for each day if you want:: + + cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] + + Note, the the lenght of this list must be 7 items. + + .. attribute:: noday_classes + + .. attribute:: weekday_head_classes + + This by default the same as ``HTMLCalendar.cssclassess``. + + .. attribute:: month_head_classes + + .. attribute:: month_classes + + .. attribute:: year_head_classes + + .. attribute:: year_classes + +Here is an example how you can customize ``HTMLCalendar``:: + + class CustomHTMLCal(calendar.HTMLCalendar): + cssclasses = [style + " text-nowrap" for style in + calendar.HTMLCalendar.cssclasses] + month_head_classes = "text-center month-head" + month_classes = "text-center month" + year_classes = "lead" + + .. class:: LocaleTextCalendar(firstweekday=0, locale=None) From 4ae2a2813b1342f6903142412d9073f19c7513d2 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Mon, 8 May 2017 23:17:19 +0200 Subject: [PATCH 05/24] Documentation updates Fix typos, and more class attributes documentation --- Doc/library/calendar.rst | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 642cd253db4a04..7c9d6cfa88020d 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -174,30 +174,53 @@ it's the base calendar for all computations. .. attribute:: cssclasses - By default it is a list with containing a style for each name:: + Is a list of CSS styles used for each weekday. The default style list is:: cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] - But you can add more styles for each day if you want:: + But you can add more styles for each day if you want:: cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] - Note, the the lenght of this list must be 7 items. + Note, that the length of this list must be 7 items. .. attribute:: noday_classes + The CSS class for a week day occuring in previous or the coming month. + .. attribute:: weekday_head_classes - This by default the same as ``HTMLCalendar.cssclassess``. + Is a list of CSS styles used for each weekday. The default style list is + + the same as ``HTMLCalendar.cssclassess``. .. attribute:: month_head_classes + A space separted list of styles for the month head, for example:: + + "text-bold text-red" + + The default value is ``"month"``. + .. attribute:: month_classes - .. attribute:: year_head_classes + a space separted list of styles for the whole table. + + the default value is ``"month"``. .. attribute:: year_classes + a space separted list of styles for the table when formatting the year + as a table of tables (see: ``HTMLCalendar.formatyear``). + + the default value is ``"year"``. + + .. attribute:: year_head_classes + + a space separted list of styles for the table head when formatting the year as a table of tables (see: ``HTMLCalendar.formatyear``). + + the default value is ``"year"``. + Here is an example how you can customize ``HTMLCalendar``:: class CustomHTMLCal(calendar.HTMLCalendar): From 28cfb91cca7845d6f45ee55c8d1bd7d361835856 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Wed, 10 May 2017 21:12:38 +0200 Subject: [PATCH 06/24] Correct spelling and fix styling Thanks @csabllea --- Doc/library/calendar.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 7c9d6cfa88020d..d6a1e8ac8c1645 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -174,7 +174,7 @@ it's the base calendar for all computations. .. attribute:: cssclasses - Is a list of CSS styles used for each weekday. The default style list is:: + A list of CSS styles used for each weekday. The default style list is:: cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] @@ -182,42 +182,42 @@ it's the base calendar for all computations. cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] - Note, that the length of this list must be 7 items. + Note that the length of this list must be 7 items. .. attribute:: noday_classes - The CSS class for a week day occuring in previous or the coming month. + The CSS class for a week day occurring in previous or the coming month. .. attribute:: weekday_head_classes - Is a list of CSS styles used for each weekday. The default style list is - - the same as ``HTMLCalendar.cssclassess``. + A list of CSS styles used for each weekday. The default style list is + the same as ``HTMLCalendar.cssclasses``. .. attribute:: month_head_classes - A space separted list of styles for the month head, for example:: - + A space separated list of styles for the month head, for example:: + "text-bold text-red" The default value is ``"month"``. .. attribute:: month_classes - a space separted list of styles for the whole table. + A space separated list of styles for the whole table. the default value is ``"month"``. .. attribute:: year_classes - a space separted list of styles for the table when formatting the year + A space separated list of styles for the table when formatting the year as a table of tables (see: ``HTMLCalendar.formatyear``). the default value is ``"year"``. .. attribute:: year_head_classes - a space separted list of styles for the table head when formatting the year as a table of tables (see: ``HTMLCalendar.formatyear``). + A space separated list of styles for the table head when formatting the year as a + table of tables (see: ``HTMLCalendar.formatyear``). the default value is ``"year"``. From 02ebee9c05e3c0531e30ee4629ad084fab9e02b7 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Wed, 10 May 2017 21:53:40 +0200 Subject: [PATCH 07/24] Format white space to comply with the style guide --- Doc/library/calendar.rst | 59 +++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index d6a1e8ac8c1645..097e6f26c8629c 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -170,56 +170,54 @@ it's the base calendar for all computations. sheet should be used. *encoding* specifies the encoding to be used for the output (defaulting to the system default encoding). - :class:`HTMLCalendar` has the following attribute you can override to customize the style of your calender: + :class:`HTMLCalendar` has the following attributes you can override to + customize the style of your calender: - .. attribute:: cssclasses + .. attribute:: cssclasses - A list of CSS styles used for each weekday. The default style list is:: + A list of CSS styles used for each weekday. The default style list is:: - cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] + cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] - But you can add more styles for each day if you want:: + But you can add more styles for each day if you want:: - cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] + cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] - Note that the length of this list must be 7 items. + Note that the length of this list must be 7 items. - .. attribute:: noday_classes + .. attribute:: noday_classes - The CSS class for a week day occurring in previous or the coming month. + The CSS class for a week day occurring in previous or the coming month. - .. attribute:: weekday_head_classes + .. attribute:: weekday_head_classes - A list of CSS styles used for each weekday. The default style list is - the same as ``HTMLCalendar.cssclasses``. + A list of CSS styles used for each weekday. The default style list is + the same as ``HTMLCalendar.cssclasses``. - .. attribute:: month_head_classes + .. attribute:: month_head_classes - A space separated list of styles for the month head, for example:: - - "text-bold text-red" + A space separated list of styles for the month head, for example:: - The default value is ``"month"``. + "text-bold text-red" - .. attribute:: month_classes + The default value is ``"month"``. - A space separated list of styles for the whole table. + .. attribute:: month_classes - the default value is ``"month"``. + A space separated list of styles for the whole table. + The default value is ``"month"``. - .. attribute:: year_classes + .. attribute:: year_classes - A space separated list of styles for the table when formatting the year - as a table of tables (see: ``HTMLCalendar.formatyear``). + A space separated list of styles for the table when formatting the year + as a table of tables (see: ``HTMLCalendar.formatyear``). + The default value is ``"year"``. - the default value is ``"year"``. + .. attribute:: year_head_classes - .. attribute:: year_head_classes - - A space separated list of styles for the table head when formatting the year as a - table of tables (see: ``HTMLCalendar.formatyear``). - - the default value is ``"year"``. + A space separated list of styles for the table head when formatting the + year as a table of tables (see: ``HTMLCalendar.formatyear``). + The default value is ``"year"``. Here is an example how you can customize ``HTMLCalendar``:: @@ -231,7 +229,6 @@ Here is an example how you can customize ``HTMLCalendar``:: year_classes = "lead" - .. class:: LocaleTextCalendar(firstweekday=0, locale=None) This subclass of :class:`TextCalendar` can be passed a locale name in the From 0cffae609fb629ef0a6fce324d81fb3a285d50c3 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 11 May 2017 07:08:59 +0200 Subject: [PATCH 08/24] Rewording and addition of sphinx directives * change `you` and `your` to more 3 person * added sphnix directives instead of unformatted text. --- Doc/library/calendar.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 097e6f26c8629c..087302c4bcc582 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -171,7 +171,7 @@ it's the base calendar for all computations. output (defaulting to the system default encoding). :class:`HTMLCalendar` has the following attributes you can override to - customize the style of your calender: + customize the style of the calendar: .. attribute:: cssclasses @@ -179,20 +179,20 @@ it's the base calendar for all computations. cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] - But you can add more styles for each day if you want:: + more styles can be added for each day:: cssclasses = ["mon text-bold", "tue", "wed", "thu", "fri", "sat", "sun red"] - Note that the length of this list must be 7 items. + Note that the length of this list must be seven items. .. attribute:: noday_classes - The CSS class for a week day occurring in previous or the coming month. + The CSS class for a weekday occurring in the previous or coming month. .. attribute:: weekday_head_classes A list of CSS styles used for each weekday. The default style list is - the same as ``HTMLCalendar.cssclasses``. + the same as :attr:`cssclasses`. .. attribute:: month_head_classes @@ -210,16 +210,16 @@ it's the base calendar for all computations. .. attribute:: year_classes A space separated list of styles for the table when formatting the year - as a table of tables (see: ``HTMLCalendar.formatyear``). + as a table of tables (see: :meth:`formatyear`). The default value is ``"year"``. .. attribute:: year_head_classes A space separated list of styles for the table head when formatting the - year as a table of tables (see: ``HTMLCalendar.formatyear``). + year as a table of tables (see: :meth:`formatyear`). The default value is ``"year"``. -Here is an example how you can customize ``HTMLCalendar``:: +Here is an example how one can customize ``HTMLCalendar``:: class CustomHTMLCal(calendar.HTMLCalendar): cssclasses = [style + " text-nowrap" for style in From 4752eb6f5287334a2c0258344167444249de50af Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Mon, 22 May 2017 07:34:06 +0200 Subject: [PATCH 09/24] Refactor Styles -> CSS Classes Also re-word again the name of the class attributes. Instead of "classe" use "class" where the attribute is not a list. Add a note how to override the attributes easily. --- Doc/library/calendar.rst | 41 +++++++++++++++++++++------------------- Lib/calendar.py | 20 ++++++++++---------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 087302c4bcc582..a5bedeba78d92a 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -175,7 +175,7 @@ it's the base calendar for all computations. .. attribute:: cssclasses - A list of CSS styles used for each weekday. The default style list is:: + A list of CSS classes used for each weekday. The default style list is:: cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] @@ -185,48 +185,51 @@ it's the base calendar for all computations. Note that the length of this list must be seven items. - .. attribute:: noday_classes + .. attribute:: noday_class The CSS class for a weekday occurring in the previous or coming month. .. attribute:: weekday_head_classes - A list of CSS styles used for each weekday. The default style list is - the same as :attr:`cssclasses`. + A list of CSS classes used for weekday names in the header row. + The default the same as :attr:`cssclasses`. - .. attribute:: month_head_classes + .. attribute:: month_head_class - A space separated list of styles for the month head, for example:: + The month's head CSS class. + The default value is ``"month"``. - "text-bold text-red" - The default value is ``"month"``. + .. attribute:: month_class - .. attribute:: month_classes + The CSS class for the whole month's table. - A space separated list of styles for the whole table. The default value is ``"month"``. - .. attribute:: year_classes + .. attribute:: year_class - A space separated list of styles for the table when formatting the year - as a table of tables (see: :meth:`formatyear`). + The CSS class for the whole year's table of tables (see: :meth:`formatyear`). The default value is ``"year"``. - .. attribute:: year_head_classes + .. attribute:: year_head_class - A space separated list of styles for the table head when formatting the - year as a table of tables (see: :meth:`formatyear`). + The CSS class for the whole year's table of tables (see: :meth:`formatyear`). The default value is ``"year"``. +Note that although the the naming for the above described class attributes is +singular (e.g. ``month_class`` ``noday_class``, one can replace the single CSS +class with a space separated list of CSS classes, for example:: + + "text-bold text-red" + Here is an example how one can customize ``HTMLCalendar``:: class CustomHTMLCal(calendar.HTMLCalendar): cssclasses = [style + " text-nowrap" for style in calendar.HTMLCalendar.cssclasses] - month_head_classes = "text-center month-head" - month_classes = "text-center month" - year_classes = "lead" + month_head_class = "text-center month-head" + month_class = "text-center month" + year_class = "text-italic lead" .. class:: LocaleTextCalendar(firstweekday=0, locale=None) diff --git a/Lib/calendar.py b/Lib/calendar.py index 188ed7a9b90531..44971ef5f159ab 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -381,12 +381,12 @@ class HTMLCalendar(Calendar): # CSS classes for the day ' % self.noday_classes + return '' % self.noday_class else: return '' % (self.cssclasses[weekday], day) @@ -428,7 +428,7 @@ def formatmonthname(self, theyear, themonth, withyear=True): else: s = '%s' % month_name[themonth] return '' % ( - self.month_head_classes, s) + self.month_head_class, s) def formatmonth(self, theyear, themonth, withyear=True): """ @@ -437,7 +437,7 @@ def formatmonth(self, theyear, themonth, withyear=True): v = [] a = v.append a('
December
MonTueWedThuFriSatSun
  12345
6789101112
%s
s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] - noday_classes = "noday" weekday_head_classes = cssclasses - month_head_classes = "month" - month_classes = "month" - year_head_classes = "year" - year_classes = "year" + noday_class = "noday" + month_head_class = "month" + month_class = "month" + year_head_class = "year" + year_class = "year" def formatday(self, day, weekday): """ @@ -394,7 +394,7 @@ def formatday(self, day, weekday): """ if day == 0: # day outside month - return '  %d
%s
' % ( - self.month_classes)) + self.month_class)) a('\n') a(self.formatmonthname(theyear, themonth, withyear=withyear)) a('\n') @@ -458,10 +458,10 @@ def formatyear(self, theyear, width=3): a = v.append width = max(width, 1) a('
' % - self.year_head_classes) + self.year_head_class) a('\n') a('' % ( - width, self.year_classes, theyear)) + width, self.year_class, theyear)) for i in range(January, January+12, width): # months in this row months = range(i, min(i+width, 13)) From d44470899244668df27f10ab44ac84a3b4bcf33e Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Tue, 30 May 2017 23:07:38 +0200 Subject: [PATCH 10/24] Rename class atrribute again and fix test * Prefix class attribute with cssclass_ This avoids confusion, since it makes it clear, that these are CSS classes, not Python classes. Furthermore by putting the cssclass in front it makes it clear that those attributes belong to the same "group" of class attributes. --- Doc/library/calendar.rst | 35 ++++++++++++++++------------------- Lib/calendar.py | 24 ++++++++++++------------ Lib/test/test_calendar.py | 8 ++++---- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index a5bedeba78d92a..000898c245215b 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -175,7 +175,7 @@ it's the base calendar for all computations. .. attribute:: cssclasses - A list of CSS classes used for each weekday. The default style list is:: + A list of CSS classes used for each weekday. The default class list is:: cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] @@ -185,39 +185,36 @@ it's the base calendar for all computations. Note that the length of this list must be seven items. - .. attribute:: noday_class + .. attribute:: cssclass_noday The CSS class for a weekday occurring in the previous or coming month. - .. attribute:: weekday_head_classes + .. attribute:: cssclass_weekday_head A list of CSS classes used for weekday names in the header row. - The default the same as :attr:`cssclasses`. + The default is the same as :attr:`cssclasses`. - .. attribute:: month_head_class + .. attribute:: cssclass_month_head - The month's head CSS class. - The default value is ``"month"``. + The month's head CSS class. The default value is ``"month"``. - .. attribute:: month_class + .. attribute:: cssclass_month - The CSS class for the whole month's table. + The CSS class for the whole month's table. The default value is ``"month"``. - The default value is ``"month"``. - - .. attribute:: year_class + .. attribute:: cssclass_year The CSS class for the whole year's table of tables (see: :meth:`formatyear`). The default value is ``"year"``. - .. attribute:: year_head_class + .. attribute:: cssclass_year_head - The CSS class for the whole year's table of tables (see: :meth:`formatyear`). + The CSS class for the table head for the whole year (see: :meth:`formatyear`). The default value is ``"year"``. -Note that although the the naming for the above described class attributes is -singular (e.g. ``month_class`` ``noday_class``, one can replace the single CSS +Note that although the naming for the above described class attributes is +singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the single CSS class with a space separated list of CSS classes, for example:: "text-bold text-red" @@ -227,9 +224,9 @@ Here is an example how one can customize ``HTMLCalendar``:: class CustomHTMLCal(calendar.HTMLCalendar): cssclasses = [style + " text-nowrap" for style in calendar.HTMLCalendar.cssclasses] - month_head_class = "text-center month-head" - month_class = "text-center month" - year_class = "text-italic lead" + cssclass_month_head = "text-center month-head" + cssclass_month = "text-center month" + cssclass_year = "text-italic lead" .. class:: LocaleTextCalendar(firstweekday=0, locale=None) diff --git a/Lib/calendar.py b/Lib/calendar.py index 44971ef5f159ab..3dc3f138f420a2 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -381,12 +381,12 @@ class HTMLCalendar(Calendar): # CSS classes for the day ' % self.noday_class + return '' % self.cssclass_noday else: return '' % (self.cssclasses[weekday], day) @@ -410,7 +410,7 @@ def formatweekday(self, day): Return a weekday name as a table header. """ return '' % ( - self.weekday_head_classes[day], day_abbr[day]) + self.cssclass_weekday_head[day], day_abbr[day]) def formatweekheader(self): """ @@ -428,7 +428,7 @@ def formatmonthname(self, theyear, themonth, withyear=True): else: s = '%s' % month_name[themonth] return '' % ( - self.month_head_class, s) + self.cssclass_month_head, s) def formatmonth(self, theyear, themonth, withyear=True): """ @@ -437,7 +437,7 @@ def formatmonth(self, theyear, themonth, withyear=True): v = [] a = v.append a('
%s
s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] - weekday_head_classes = cssclasses - noday_class = "noday" - month_head_class = "month" - month_class = "month" - year_head_class = "year" - year_class = "year" + cssclass_weekday_head = cssclasses + cssclass_noday = "noday" + cssclass_month_head = "month" + cssclass_month = "month" + cssclass_year_head = "year" + cssclass_year = "year" def formatday(self, day, weekday): """ @@ -394,7 +394,7 @@ def formatday(self, day, weekday): """ if day == 0: # day outside month - return '  %d%s
%s
' % ( - self.month_class)) + self.cssclass_month)) a('\n') a(self.formatmonthname(theyear, themonth, withyear=withyear)) a('\n') @@ -458,10 +458,10 @@ def formatyear(self, theyear, width=3): a = v.append width = max(width, 1) a('
' % - self.year_head_class) + self.cssclass_year_head) a('\n') a('' % ( - width, self.year_class, theyear)) + width, self.cssclass_year, theyear)) for i in range(January, January+12, width): # months in this row months = range(i, min(i+width, 13)) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 4ef1ef88a3fe2e..a42c83da36ec33 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -857,9 +857,9 @@ def setUp(self): class CustomHTMLCal(calendar.HTMLCalendar): cssclasses = [style + " text-nowrap" for style in calendar.HTMLCalendar.cssclasses] - month_head_classes = "text-center month-head" - month_classes = "text-center month" - year_classes = "lead " + cssclass_month_head = "text-center month-head" + cssclass_month = "text-center month" + cssclass_year = "lead " self.cal = CustomHTMLCal() @@ -873,7 +873,7 @@ def test_formatweek(self): weeks = self.cal.monthdays2calendar(2017,5) self.assertIn('class="wed text-nowrap"', self.cal.formatweek(weeks[0])) def test_format_year(self): - self.assertIn('' % (3, self.cal.year_classes, 2017), self.cal.formatyear(2017)) + self.assertIn('' % (3, self.cal.cssclass_year, 2017), self.cal.formatyear(2017)) if __name__ == "__main__": unittest.main() From 075d86c184e80d874c57a138ada0d87631c29fd2 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 06:34:29 +0200 Subject: [PATCH 11/24] Fix wrong usage of CSS classes --- Lib/calendar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/calendar.py b/Lib/calendar.py index 3dc3f138f420a2..7cd42ab8097b5c 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -458,10 +458,10 @@ def formatyear(self, theyear, width=3): a = v.append width = max(width, 1) a('
%s
%s
%s
' % - self.cssclass_year_head) + self.cssclass_year) a('\n') a('' % ( - width, self.cssclass_year, theyear)) + width, self.cssclass_year_head, theyear)) for i in range(January, January+12, width): # months in this row months = range(i, min(i+width, 13)) From fd2bda3c00196b6feb7cdf41500273f5189e55a3 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 06:35:08 +0200 Subject: [PATCH 12/24] Add documation strings for the HTMLCalendar class attributes --- Lib/calendar.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/calendar.py b/Lib/calendar.py index 7cd42ab8097b5c..48f21aa48a5f52 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -380,12 +380,18 @@ class HTMLCalendar(Calendar): """ # CSS classes for the day ' % (3, self.cal.cssclass_year, 2017), self.cal.formatyear(2017)) + self.assertIn('' % (3, self.cal.cssclass_year_head, 2017), self.cal.formatyear(2017)) if __name__ == "__main__": unittest.main() From 2efe925e0113f50b286e3471476866699ae5562e Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 06:51:59 +0200 Subject: [PATCH 15/24] Update NEWS and ACKS --- Doc/whatsnew/3.7.rst | 7 +++++++ Misc/ACKS | 1 + 2 files changed, 8 insertions(+) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 875fc556912cae..1e678143ab2cfa 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -95,6 +95,13 @@ New Modules Improved Modules ================ +calendar +-------- +The :class:`~calendar.HTMLCalendar` has added new class attribute which ease the +customisation the CSS classes in the produced HTML calendar. +(Contributed by Oz Tiram in :issue:`30095`.) + + distutils --------- diff --git a/Misc/ACKS b/Misc/ACKS index ab41431add0fa5..87ca37bd5188ff 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1540,6 +1540,7 @@ Jeremy Thurgood Eric Tiedemann July Tikhonov Tracy Tims +Oz Tiram Oren Tirosh Tim Tisdall Jason Tishler From 712cf537cc37122d6490da5d27547d06b9af617a Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 07:39:50 +0200 Subject: [PATCH 16/24] Merge upstream changes for what is new in 3.7 --- Doc/whatsnew/3.7.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 1e678143ab2cfa..d525bd83e82154 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -85,6 +85,14 @@ Other Language Changes * :exc:`ImportError` now displays module name and module ``__file__`` path when ``from ... import ...`` fails. (Contributed by Matthias Bussonnier in :issue:`29546`.) +* Circular imports involving absolute imports with binding a submodule to + a name are now supported. + (Contributed by Serhiy Storchaka in :issue:`30024`.) + +* ``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather than + ``format(str(self), '')``. + (Contributed by Serhiy Storchaka in :issue:`28974`.) + New Modules =========== @@ -95,13 +103,34 @@ New Modules Improved Modules ================ +binascii +-------- + +The :func:`~binascii.b2a_uu` function now accepts an optional *backtick* +keyword argument. When it's true, zeros are represented by ``'`'`` +instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) + + calendar -------- + The :class:`~calendar.HTMLCalendar` has added new class attribute which ease the customisation the CSS classes in the produced HTML calendar. (Contributed by Oz Tiram in :issue:`30095`.) +cgi +--- + +:func:`~cgi.parse_multipart` returns the same results as +:class:`~FieldStorage` : for non-file fields, the value associated to a key +is a list of strings, not bytes. +(Contributed by Pierre Quentel in :issue:`29979`.) + +contextlib +---------- +:func:`contextlib.asynccontextmanager` has been added. (Contributed by +Jelle Zijlstra in :issue:`29679`.) distutils --------- @@ -117,6 +146,11 @@ If-Modified-Since header. The server returns the 304 response status if the target file was not modified after the time specified in the header. (Contributed by Pierre Quentel in :issue:`29654`.) +Add the parameter ``directory`` to the :class:`~http.server.SimpleHTTPRequestHandler` +and the ``--directory`` to the command line of the module :mod:`~http.server`. +With this parameter, the server serves the specified directory, by default it uses the current working directory. +(Contributed by Stéphane Wirtel and Julien Palard in :issue:`28707`.) + locale ------ @@ -139,6 +173,10 @@ Serhiy Storchaka in :issue:`28682`.) Added support for :ref:`file descriptors ` in :func:`~os.scandir` on Unix. (Contributed by Serhiy Storchaka in :issue:`25996`.) +New function :func:`os.register_at_fork` allows registering Python callbacks +to be executed on a process fork. (Contributed by Antoine Pitrou in +:issue:`16500`.) + unittest.mock ------------- @@ -160,6 +198,13 @@ urllib.parse adding `~` to the set of characters that is never quoted by default. (Contributed by Christian Theune and Ratnadeep Debnath in :issue:`16285`.) +uu +-- + +Function :func:`~uu.encode` now accepts an optional *backtick* +keyword argument. When it's true, zeros are represented by ``'`'`` +instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) + Optimizations ============= @@ -183,6 +228,10 @@ Optimizations using the :func:`os.scandir` function. (Contributed by Serhiy Storchaka in :issue:`25996`.) +* Optimized case-insensitive matching and searching of :mod:`regular + expressions `. Searching some patterns can now be up to 20 times faster. + (Contributed by Serhiy Storchaka in :issue:`30285`.) + Build and C API Changes ======================= @@ -205,6 +254,11 @@ Build and C API Changes * Added functions :c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices`. (Contributed by Serhiy Storchaka in :issue:`27867`.) +* :c:func:`PyOS_AfterFork` is deprecated in favour of the new functions + :c:func:`PyOS_BeforeFork`, :c:func:`PyOS_AfterFork_Parent` and + :c:func:`PyOS_AfterFork_Child`. (Contributed by Antoine Pitrou in + :issue:`16500`.) + Deprecated ========== @@ -232,6 +286,8 @@ Deprecated now deprecated. It never correctly worked. (Contributed by Serhiy Storchaka in :issue:`28692`.) +- The :mod:`macpath` is now deprecated and will be removed in Python 3.8. + Changes in the C API -------------------- @@ -264,6 +320,12 @@ API and Feature Removals longer take keyword arguments. The first argument of :func:`int` can now be passes only as positional argument. +* Removed previously deprecated in Python 2.4 classes ``Plist``, ``Dict`` and + ``_InternalDict`` in the :mod:`plistlib` module. Dict values in the result + of functions :func:`~plistlib.readPlist` and + :func:`~plistlib.readPlistFromBytes` are now normal dicts. You no longer + can use attribute access to access items of these dictionaries. + Porting to Python 3.7 ===================== From c54116e471796f8506f05fb67cdd4679f66d563d Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 17:40:33 +0200 Subject: [PATCH 17/24] Fix versionadded directives --- Doc/library/calendar.rst | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index ebfcb1c321bb4b..412bfd9c993ae9 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -185,39 +185,45 @@ it's the base calendar for all computations. Note that the length of this list must be seven items. - .. versionadded:: 3.7 .. attribute:: cssclass_noday The CSS class for a weekday occurring in the previous or coming month. - .. versionadded:: 3.7 + .. versionadded:: 3.7 + .. attribute:: cssclass_weekday_head A list of CSS classes used for weekday names in the header row. The default is the same as :attr:`cssclasses`. - .. versionadded:: 3.7 + .. versionadded:: 3.7 + .. attribute:: cssclass_month_head The month's head CSS class. The default value is ``"month"``. - .. versionadded:: 3.7 + .. versionadded:: 3.7 + .. attribute:: cssclass_month The CSS class for the whole month's table. The default value is ``"month"``. - .. versionadded:: 3.7 + .. versionadded:: 3.7 + .. attribute:: cssclass_year The CSS class for the whole year's table of tables (see: :meth:`formatyear`). The default value is ``"year"``. - .. versionadded:: 3.7 + .. versionadded:: 3.7 + .. attribute:: cssclass_year_head The CSS class for the table head for the whole year (see: :meth:`formatyear`). The default value is ``"year"``. + .. versionadded:: 3.7 + Note that although the naming for the above described class attributes is singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the single CSS class with a space separated list of CSS classes, for example:: From 45d68c2dd0ef5b85581afbdfd3f89c2213bd648e Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 17:48:14 +0200 Subject: [PATCH 18/24] pep8 white space fixes --- Lib/test/test_calendar.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 237d9d5d9496bf..8f6c609218fa66 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -864,16 +864,20 @@ class CustomHTMLCal(calendar.HTMLCalendar): self.cal = CustomHTMLCal() def test_formatmonthname(self): - self.assertIn('class="text-center month-head"', self.cal.formatmonthname(2017, 5)) + self.assertIn('class="text-center month-head"', + self.cal.formatmonthname(2017, 5)) def test_formatmonth(self): - self.assertIn('class="text-center month"', self.cal.formatmonth(2017, 5)) + self.assertIn('class="text-center month"', + self.cal.formatmonth(2017, 5)) def test_formatweek(self): - weeks = self.cal.monthdays2calendar(2017,5) + weeks = self.cal.monthdays2calendar(2017, 5) self.assertIn('class="wed text-nowrap"', self.cal.formatweek(weeks[0])) + def test_format_year(self): - self.assertIn('' % (3, self.cal.cssclass_year_head, 2017), self.cal.formatyear(2017)) + self.assertIn('' % ( + 3, self.cal.cssclass_year_head, 2017), self.cal.formatyear(2017)) if __name__ == "__main__": unittest.main() From 6571d3f5b485e589ac7114429a9a45edccfb401a Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Thu, 1 Jun 2017 17:59:46 +0200 Subject: [PATCH 19/24] Move HTMLCalendar example into class description block. --- Doc/library/calendar.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 412bfd9c993ae9..39bcb39df3d6a7 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -224,20 +224,20 @@ it's the base calendar for all computations. .. versionadded:: 3.7 -Note that although the naming for the above described class attributes is -singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the -single CSS class with a space separated list of CSS classes, for example:: + Note that although the naming for the above described class attributes is + singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the + single CSS class with a space separated list of CSS classes, for example:: - "text-bold text-red" + "text-bold text-red" -Here is an example how one can customize ``HTMLCalendar``:: + Here is an example how one can customize ``HTMLCalendar``:: - class CustomHTMLCal(calendar.HTMLCalendar): - cssclasses = [style + " text-nowrap" for style in - calendar.HTMLCalendar.cssclasses] - cssclass_month_head = "text-center month-head" - cssclass_month = "text-center month" - cssclass_year = "text-italic lead" + class CustomHTMLCal(calendar.HTMLCalendar): + cssclasses = [style + " text-nowrap" for style in + calendar.HTMLCalendar.cssclasses] + cssclass_month_head = "text-center month-head" + cssclass_month = "text-center month" + cssclass_year = "text-italic lead" .. class:: LocaleTextCalendar(firstweekday=0, locale=None) From 496c19437c3c00bbc281787d348194e7f94af36c Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Fri, 2 Jun 2017 16:42:11 +0200 Subject: [PATCH 20/24] Whitespace. --- Doc/library/calendar.rst | 8 ++++++++ Lib/calendar.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 39bcb39df3d6a7..8e65ad543e5cc8 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -170,6 +170,7 @@ it's the base calendar for all computations. sheet should be used. *encoding* specifies the encoding to be used for the output (defaulting to the system default encoding). + :class:`HTMLCalendar` has the following attributes you can override to customize the style of the calendar: @@ -185,12 +186,14 @@ it's the base calendar for all computations. Note that the length of this list must be seven items. + .. attribute:: cssclass_noday The CSS class for a weekday occurring in the previous or coming month. .. versionadded:: 3.7 + .. attribute:: cssclass_weekday_head A list of CSS classes used for weekday names in the header row. @@ -198,18 +201,21 @@ it's the base calendar for all computations. .. versionadded:: 3.7 + .. attribute:: cssclass_month_head The month's head CSS class. The default value is ``"month"``. .. versionadded:: 3.7 + .. attribute:: cssclass_month The CSS class for the whole month's table. The default value is ``"month"``. .. versionadded:: 3.7 + .. attribute:: cssclass_year The CSS class for the whole year's table of tables (see: :meth:`formatyear`). @@ -217,6 +223,7 @@ it's the base calendar for all computations. .. versionadded:: 3.7 + .. attribute:: cssclass_year_head The CSS class for the table head for the whole year (see: :meth:`formatyear`). @@ -224,6 +231,7 @@ it's the base calendar for all computations. .. versionadded:: 3.7 + Note that although the naming for the above described class attributes is singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the single CSS class with a space separated list of CSS classes, for example:: diff --git a/Lib/calendar.py b/Lib/calendar.py index 1a7b3a8a690ab6..ae04fe4abda95f 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -381,16 +381,22 @@ class HTMLCalendar(Calendar): # CSS classes for the day ' % ( - self.cssclass_weekday_head[day], day_abbr[day]) + self.cssclasses_weekday_head[day], day_abbr[day]) def formatweekheader(self): """ From 7ffa9ccecf9095e9c687668af835bfb6c9b095f5 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Fri, 2 Jun 2017 17:10:03 +0200 Subject: [PATCH 22/24] Avoid link to the start of the class description. --- Doc/library/calendar.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 198f315530aabd..828eb0993ea169 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -147,7 +147,7 @@ it's the base calendar for all computations. This class can be used to generate HTML calendars. - :class:`HTMLCalendar` instances have the following methods: + :class:`!HTMLCalendar` instances have the following methods: .. method:: formatmonth(theyear, themonth, withyear=True) @@ -171,8 +171,8 @@ it's the base calendar for all computations. output (defaulting to the system default encoding). - :class:`HTMLCalendar` has the following attributes you can override to - customize the style of the calendar: + :class:`!HTMLCalendar` has the following attributes you can override to + customize the CSS classes used by the calendar: .. attribute:: cssclasses @@ -238,7 +238,7 @@ it's the base calendar for all computations. "text-bold text-red" - Here is an example how one can customize ``HTMLCalendar``:: + Here is an example how :class:`!HTMLCalendar` can be customized:: class CustomHTMLCal(calendar.HTMLCalendar): cssclasses = [style + " text-nowrap" for style in From f0f6100c8521b8ade2183db69f7810654aeacf45 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Fri, 2 Jun 2017 17:46:29 +0200 Subject: [PATCH 23/24] In the attribute description refer to the method that uses the attribute. --- Doc/library/calendar.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 828eb0993ea169..a415b4792a6bd6 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -204,30 +204,32 @@ it's the base calendar for all computations. .. attribute:: cssclass_month_head - The month's head CSS class. The default value is ``"month"``. + The month's head CSS class (used by :meth:`formatmonthname`). + The default value is ``"month"``. .. versionadded:: 3.7 .. attribute:: cssclass_month - The CSS class for the whole month's table. The default value is ``"month"``. + The CSS class for the whole month's table (used by :meth:`formatmonth`). + The default value is ``"month"``. .. versionadded:: 3.7 .. attribute:: cssclass_year - The CSS class for the whole year's table of tables (see: :meth:`formatyear`). - The default value is ``"year"``. + The CSS class for the whole year's table of tables (used by + :meth:`formatyear`). The default value is ``"year"``. .. versionadded:: 3.7 .. attribute:: cssclass_year_head - The CSS class for the table head for the whole year (see: :meth:`formatyear`). - The default value is ``"year"``. + The CSS class for the table head for the whole year (used by + :meth:`formatyear`). The default value is ``"year"``. .. versionadded:: 3.7 From 3b4529da5a060547f39d043efbf8015f9ad17323 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Mon, 5 Jun 2017 17:06:41 +0200 Subject: [PATCH 24/24] Complete all tests for HTMLCalendar class attributes --- Lib/test/test_calendar.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 8f6c609218fa66..c777f6483567dd 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -857,8 +857,11 @@ def setUp(self): class CustomHTMLCal(calendar.HTMLCalendar): cssclasses = [style + " text-nowrap" for style in calendar.HTMLCalendar.cssclasses] + cssclasses_weekday_head = ["red", "blue", "green", "lilac", + "yellow", "orange", "pink"] cssclass_month_head = "text-center month-head" cssclass_month = "text-center month" + cssclass_year = "text-italic " cssclass_year_head = "lead " self.cal = CustomHTMLCal() @@ -875,7 +878,17 @@ def test_formatweek(self): weeks = self.cal.monthdays2calendar(2017, 5) self.assertIn('class="wed text-nowrap"', self.cal.formatweek(weeks[0])) + def test_formatweek_head(self): + header = self.cal.formatweekheader() + for color in self.cal.cssclasses_weekday_head: + self.assertIn('
%s
s - cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] + cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun + # CSS classes for the day s cssclass_weekday_head = cssclasses + # CSS class for the days before and after current month cssclass_noday = "noday" + # CSS class for the month's head cssclass_month_head = "month" + # CSS class for the month cssclass_month = "month" + # CSS class for the year's table head cssclass_year_head = "year" + # CSS class for the whole year table cssclass_year = "year" def formatday(self, day, weekday): From 1c63cfa45b0e29883d712395a69a954c53667fcb Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 06:35:33 +0200 Subject: [PATCH 13/24] Mention in which version class attributes were added --- Doc/library/calendar.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 000898c245215b..ebfcb1c321bb4b 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -185,37 +185,42 @@ it's the base calendar for all computations. Note that the length of this list must be seven items. + .. versionadded:: 3.7 .. attribute:: cssclass_noday The CSS class for a weekday occurring in the previous or coming month. + .. versionadded:: 3.7 .. attribute:: cssclass_weekday_head A list of CSS classes used for weekday names in the header row. The default is the same as :attr:`cssclasses`. + .. versionadded:: 3.7 .. attribute:: cssclass_month_head The month's head CSS class. The default value is ``"month"``. - + .. versionadded:: 3.7 .. attribute:: cssclass_month The CSS class for the whole month's table. The default value is ``"month"``. + .. versionadded:: 3.7 .. attribute:: cssclass_year The CSS class for the whole year's table of tables (see: :meth:`formatyear`). The default value is ``"year"``. + .. versionadded:: 3.7 .. attribute:: cssclass_year_head The CSS class for the table head for the whole year (see: :meth:`formatyear`). The default value is ``"year"``. Note that although the naming for the above described class attributes is -singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the single CSS -class with a space separated list of CSS classes, for example:: +singular (e.g. ``cssclass_month`` ``cssclass_noday``), one can replace the +single CSS class with a space separated list of CSS classes, for example:: "text-bold text-red" From e4b95a0ac590d7a6d15af78c7054ef92a9d1ff30 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 1 Jun 2017 06:43:11 +0200 Subject: [PATCH 14/24] Fix failing test --- Lib/calendar.py | 2 +- Lib/test/test_calendar.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/calendar.py b/Lib/calendar.py index 48f21aa48a5f52..1a7b3a8a690ab6 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -380,7 +380,7 @@ class HTMLCalendar(Calendar): """ # CSS classes for the day s - cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun + cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] # CSS classes for the day s cssclass_weekday_head = cssclasses # CSS class for the days before and after current month diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index a42c83da36ec33..237d9d5d9496bf 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -859,7 +859,7 @@ class CustomHTMLCal(calendar.HTMLCalendar): calendar.HTMLCalendar.cssclasses] cssclass_month_head = "text-center month-head" cssclass_month = "text-center month" - cssclass_year = "lead " + cssclass_year_head = "lead " self.cal = CustomHTMLCal() @@ -873,7 +873,7 @@ def test_formatweek(self): weeks = self.cal.monthdays2calendar(2017,5) self.assertIn('class="wed text-nowrap"', self.cal.formatweek(weeks[0])) def test_format_year(self): - self.assertIn('
%s
%s
%s
%s
s cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] + # CSS classes for the day s cssclass_weekday_head = cssclasses + # CSS class for the days before and after current month cssclass_noday = "noday" + # CSS class for the month's head cssclass_month_head = "month" + # CSS class for the month cssclass_month = "month" + # CSS class for the year's table head cssclass_year_head = "year" + # CSS class for the whole year table cssclass_year = "year" From 2eae99d74eaaa81f64421e904f87c541014f65f4 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Fri, 2 Jun 2017 16:45:25 +0200 Subject: [PATCH 21/24] Update variable name that contains a list of CSS classes to be plural. --- Doc/library/calendar.rst | 2 +- Lib/calendar.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst index 8e65ad543e5cc8..198f315530aabd 100644 --- a/Doc/library/calendar.rst +++ b/Doc/library/calendar.rst @@ -194,7 +194,7 @@ it's the base calendar for all computations. .. versionadded:: 3.7 - .. attribute:: cssclass_weekday_head + .. attribute:: cssclasses_weekday_head A list of CSS classes used for weekday names in the header row. The default is the same as :attr:`cssclasses`. diff --git a/Lib/calendar.py b/Lib/calendar.py index ae04fe4abda95f..0218e2d39770fa 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -383,7 +383,7 @@ class HTMLCalendar(Calendar): cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] # CSS classes for the day s - cssclass_weekday_head = cssclasses + cssclasses_weekday_head = cssclasses # CSS class for the days before and after current month cssclass_noday = "noday" @@ -422,7 +422,7 @@ def formatweekday(self, day): Return a weekday name as a table header. """ return '%s' % color, header) + def test_format_year(self): + self.assertIn( + ('' % + self.cal.cssclass_year), self.cal.formatyear(2017)) + + def test_format_year_head(self): self.assertIn('' % ( 3, self.cal.cssclass_year_head, 2017), self.cal.formatyear(2017))
%s