Subclass of Calendar that outputs a calendar as a simple plain text similar to the UNIX program cal.
| 293 | |
| 294 | |
| 295 | class TextCalendar(Calendar): |
| 296 | """ |
| 297 | Subclass of Calendar that outputs a calendar as a simple plain text |
| 298 | similar to the UNIX program cal. |
| 299 | """ |
| 300 | |
| 301 | def prweek(self, theweek, width): |
| 302 | """ |
| 303 | Print a single week (no newline). |
| 304 | """ |
| 305 | print(self.formatweek(theweek, width), end='') |
| 306 | |
| 307 | def formatday(self, day, weekday, width): |
| 308 | """ |
| 309 | Returns a formatted day. |
| 310 | """ |
| 311 | if day == 0: |
| 312 | s = '' |
| 313 | else: |
| 314 | s = '%2i' % day # right-align single-digit days |
| 315 | return s.center(width) |
| 316 | |
| 317 | def formatweek(self, theweek, width): |
| 318 | """ |
| 319 | Returns a single week in a string (no newline). |
| 320 | """ |
| 321 | return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek) |
| 322 | |
| 323 | def formatweekday(self, day, width): |
| 324 | """ |
| 325 | Returns a formatted week day name. |
| 326 | """ |
| 327 | if width >= 9: |
| 328 | names = day_name |
| 329 | else: |
| 330 | names = day_abbr |
| 331 | return names[day][:width].center(width) |
| 332 | |
| 333 | def formatweekheader(self, width): |
| 334 | """ |
| 335 | Return a header for a week. |
| 336 | """ |
| 337 | return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays()) |
| 338 | |
| 339 | def formatmonthname(self, theyear, themonth, width, withyear=True): |
| 340 | """ |
| 341 | Return a formatted month name. |
| 342 | """ |
| 343 | s = month_name[themonth] |
| 344 | if withyear: |
| 345 | s = "%s %r" % (s, theyear) |
| 346 | return s.center(width) |
| 347 | |
| 348 | def prmonth(self, theyear, themonth, w=0, l=0): |
| 349 | """ |
| 350 | Print a month's calendar. |
| 351 | """ |
| 352 | print(self.formatmonth(theyear, themonth, w, l), end='') |
no outgoing calls
no test coverage detected