MCPcopy Index your code
hub / github.com/RustPython/RustPython / TextCalendar

Class TextCalendar

Lib/calendar.py:330–447  ·  view source on GitHub ↗

Subclass of Calendar that outputs a calendar as a simple plain text similar to the UNIX program cal.

Source from the content-addressed store, hash-verified

328
329
330class TextCalendar(Calendar):
331 """
332 Subclass of Calendar that outputs a calendar as a simple plain text
333 similar to the UNIX program cal.
334 """
335
336 def prweek(self, theweek, width):
337 """
338 Print a single week (no newline).
339 """
340 print(self.formatweek(theweek, width), end='')
341
342 def formatday(self, day, weekday, width):
343 """
344 Returns a formatted day.
345 """
346 if day == 0:
347 s = ''
348 else:
349 s = '%2i' % day # right-align single-digit days
350 return s.center(width)
351
352 def formatweek(self, theweek, width):
353 """
354 Returns a single week in a string (no newline).
355 """
356 return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek)
357
358 def formatweekday(self, day, width):
359 """
360 Returns a formatted week day name.
361 """
362 if width >= 9:
363 names = day_name
364 else:
365 names = day_abbr
366 return names[day][:width].center(width)
367
368 def formatweekheader(self, width):
369 """
370 Return a header for a week.
371 """
372 return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays())
373
374 def formatmonthname(self, theyear, themonth, width, withyear=True):
375 """
376 Return a formatted month name.
377 """
378 _validate_month(themonth)
379
380 s = month_name[themonth]
381 if withyear:
382 s = "%s %r" % (s, theyear)
383 return s.center(width)
384
385 def prmonth(self, theyear, themonth, w=0, l=0):
386 """
387 Print a month's calendar.

Callers 1

calendar.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected