MCPcopy Index your code
hub / github.com/python/cpython / _CLIDemoCalendar

Class _CLIDemoCalendar

Lib/calendar.py:684–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

682
683
684class _CLIDemoCalendar(TextCalendar):
685 def __init__(self, highlight_day=None, *args, **kwargs):
686 super().__init__(*args, **kwargs)
687 self.highlight_day = highlight_day
688
689 def formatweek(self, theweek, width, *, highlight_day=None):
690 """
691 Returns a single week in a string (no newline).
692 """
693 if highlight_day:
694 from _colorize import get_colors
695
696 ansi = get_colors()
697 highlight = f"{ansi.BLACK}{ansi.BACKGROUND_YELLOW}"
698 reset = ansi.RESET
699 else:
700 highlight = reset = ""
701
702 return ' '.join(
703 (
704 f"{highlight}{self.formatday(d, wd, width)}{reset}"
705 if d == highlight_day
706 else self.formatday(d, wd, width)
707 )
708 for (d, wd) in theweek
709 )
710
711 def formatmonth(self, theyear, themonth, w=0, l=0):
712 """
713 Return a month's calendar string (multi-line).
714 """
715 if (
716 self.highlight_day
717 and self.highlight_day.year == theyear
718 and self.highlight_day.month == themonth
719 ):
720 highlight_day = self.highlight_day.day
721 else:
722 highlight_day = None
723 w = max(2, w)
724 l = max(1, l)
725 s = self.formatmonthname(theyear, themonth, 7 * (w + 1) - 1)
726 s = s.rstrip()
727 s += '\n' * l
728 s += self.formatweekheader(w).rstrip()
729 s += '\n' * l
730 for week in self.monthdays2calendar(theyear, themonth):
731 s += self.formatweek(week, w, highlight_day=highlight_day).rstrip()
732 s += '\n' * l
733 return s
734
735 def formatyear(self, theyear, w=2, l=1, c=6, m=3):
736 """
737 Returns a year's calendar as a multi-line string.
738 """
739 w = max(2, w)
740 l = max(1, l)
741 c = max(2, c)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…