Subclass of Calendar that outputs a calendar as a simple plain text similar to the UNIX program cal.
| 347 | |
| 348 | |
| 349 | class TextCalendar(Calendar): |
| 350 | """ |
| 351 | Subclass of Calendar that outputs a calendar as a simple plain text |
| 352 | similar to the UNIX program cal. |
| 353 | """ |
| 354 | |
| 355 | def prweek(self, theweek, width): |
| 356 | """ |
| 357 | Print a single week (no newline). |
| 358 | """ |
| 359 | print(self.formatweek(theweek, width), end='') |
| 360 | |
| 361 | def formatday(self, day, weekday, width): |
| 362 | """ |
| 363 | Returns a formatted day. |
| 364 | """ |
| 365 | if day == 0: |
| 366 | s = '' |
| 367 | else: |
| 368 | s = '%2i' % day # right-align single-digit days |
| 369 | return s.center(width) |
| 370 | |
| 371 | def formatweek(self, theweek, width): |
| 372 | """ |
| 373 | Returns a single week in a string (no newline). |
| 374 | """ |
| 375 | return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek) |
| 376 | |
| 377 | def formatweekday(self, day, width): |
| 378 | """ |
| 379 | Returns a formatted week day name. |
| 380 | """ |
| 381 | if width >= max(map(len, day_name)): |
| 382 | names = day_name |
| 383 | else: |
| 384 | names = day_abbr |
| 385 | return names[day][:width].center(width) |
| 386 | |
| 387 | def formatweekheader(self, width): |
| 388 | """ |
| 389 | Return a header for a week. |
| 390 | """ |
| 391 | return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays()) |
| 392 | |
| 393 | def formatmonthname(self, theyear, themonth, width, withyear=True): |
| 394 | """ |
| 395 | Return a formatted month name. |
| 396 | """ |
| 397 | _validate_month(themonth) |
| 398 | |
| 399 | s = standalone_month_name[themonth] |
| 400 | if withyear: |
| 401 | s = "%s %r" % (s, theyear) |
| 402 | return s.center(width) |
| 403 | |
| 404 | def prmonth(self, theyear, themonth, w=0, l=0): |
| 405 | """ |
| 406 | Print a month's calendar. |
no outgoing calls
no test coverage detected
searching dependent graphs…