Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: calendar.py
"""Calendar printing functions
[0] Fix | Delete
[1] Fix | Delete
Note when comparing these calendars to the ones printed by cal(1): By
[2] Fix | Delete
default, these calendars have Monday as the first day of the week, and
[3] Fix | Delete
Sunday as the last (the European convention). Use setfirstweekday() to
[4] Fix | Delete
set the first day of the week (0=Monday, 6=Sunday)."""
[5] Fix | Delete
[6] Fix | Delete
import sys
[7] Fix | Delete
import datetime
[8] Fix | Delete
import locale as _locale
[9] Fix | Delete
from itertools import repeat
[10] Fix | Delete
[11] Fix | Delete
__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
[12] Fix | Delete
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
[13] Fix | Delete
"monthcalendar", "prmonth", "month", "prcal", "calendar",
[14] Fix | Delete
"timegm", "month_name", "month_abbr", "day_name", "day_abbr",
[15] Fix | Delete
"Calendar", "TextCalendar", "HTMLCalendar", "LocaleTextCalendar",
[16] Fix | Delete
"LocaleHTMLCalendar", "weekheader"]
[17] Fix | Delete
[18] Fix | Delete
# Exception raised for bad input (with string parameter for details)
[19] Fix | Delete
error = ValueError
[20] Fix | Delete
[21] Fix | Delete
# Exceptions raised for bad input
[22] Fix | Delete
class IllegalMonthError(ValueError):
[23] Fix | Delete
def __init__(self, month):
[24] Fix | Delete
self.month = month
[25] Fix | Delete
def __str__(self):
[26] Fix | Delete
return "bad month number %r; must be 1-12" % self.month
[27] Fix | Delete
[28] Fix | Delete
[29] Fix | Delete
class IllegalWeekdayError(ValueError):
[30] Fix | Delete
def __init__(self, weekday):
[31] Fix | Delete
self.weekday = weekday
[32] Fix | Delete
def __str__(self):
[33] Fix | Delete
return "bad weekday number %r; must be 0 (Monday) to 6 (Sunday)" % self.weekday
[34] Fix | Delete
[35] Fix | Delete
[36] Fix | Delete
# Constants for months referenced later
[37] Fix | Delete
January = 1
[38] Fix | Delete
February = 2
[39] Fix | Delete
[40] Fix | Delete
# Number of days per month (except for February in leap years)
[41] Fix | Delete
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
[42] Fix | Delete
[43] Fix | Delete
# This module used to have hard-coded lists of day and month names, as
[44] Fix | Delete
# English strings. The classes following emulate a read-only version of
[45] Fix | Delete
# that, but supply localized names. Note that the values are computed
[46] Fix | Delete
# fresh on each call, in case the user changes locale between calls.
[47] Fix | Delete
[48] Fix | Delete
class _localized_month:
[49] Fix | Delete
[50] Fix | Delete
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
[51] Fix | Delete
_months.insert(0, lambda x: "")
[52] Fix | Delete
[53] Fix | Delete
def __init__(self, format):
[54] Fix | Delete
self.format = format
[55] Fix | Delete
[56] Fix | Delete
def __getitem__(self, i):
[57] Fix | Delete
funcs = self._months[i]
[58] Fix | Delete
if isinstance(i, slice):
[59] Fix | Delete
return [f(self.format) for f in funcs]
[60] Fix | Delete
else:
[61] Fix | Delete
return funcs(self.format)
[62] Fix | Delete
[63] Fix | Delete
def __len__(self):
[64] Fix | Delete
return 13
[65] Fix | Delete
[66] Fix | Delete
[67] Fix | Delete
class _localized_day:
[68] Fix | Delete
[69] Fix | Delete
# January 1, 2001, was a Monday.
[70] Fix | Delete
_days = [datetime.date(2001, 1, i+1).strftime for i in range(7)]
[71] Fix | Delete
[72] Fix | Delete
def __init__(self, format):
[73] Fix | Delete
self.format = format
[74] Fix | Delete
[75] Fix | Delete
def __getitem__(self, i):
[76] Fix | Delete
funcs = self._days[i]
[77] Fix | Delete
if isinstance(i, slice):
[78] Fix | Delete
return [f(self.format) for f in funcs]
[79] Fix | Delete
else:
[80] Fix | Delete
return funcs(self.format)
[81] Fix | Delete
[82] Fix | Delete
def __len__(self):
[83] Fix | Delete
return 7
[84] Fix | Delete
[85] Fix | Delete
[86] Fix | Delete
# Full and abbreviated names of weekdays
[87] Fix | Delete
day_name = _localized_day('%A')
[88] Fix | Delete
day_abbr = _localized_day('%a')
[89] Fix | Delete
[90] Fix | Delete
# Full and abbreviated names of months (1-based arrays!!!)
[91] Fix | Delete
month_name = _localized_month('%B')
[92] Fix | Delete
month_abbr = _localized_month('%b')
[93] Fix | Delete
[94] Fix | Delete
# Constants for weekdays
[95] Fix | Delete
(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)
[96] Fix | Delete
[97] Fix | Delete
[98] Fix | Delete
def isleap(year):
[99] Fix | Delete
"""Return True for leap years, False for non-leap years."""
[100] Fix | Delete
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
[101] Fix | Delete
[102] Fix | Delete
[103] Fix | Delete
def leapdays(y1, y2):
[104] Fix | Delete
"""Return number of leap years in range [y1, y2).
[105] Fix | Delete
Assume y1 <= y2."""
[106] Fix | Delete
y1 -= 1
[107] Fix | Delete
y2 -= 1
[108] Fix | Delete
return (y2//4 - y1//4) - (y2//100 - y1//100) + (y2//400 - y1//400)
[109] Fix | Delete
[110] Fix | Delete
[111] Fix | Delete
def weekday(year, month, day):
[112] Fix | Delete
"""Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31)."""
[113] Fix | Delete
if not datetime.MINYEAR <= year <= datetime.MAXYEAR:
[114] Fix | Delete
year = 2000 + year % 400
[115] Fix | Delete
return datetime.date(year, month, day).weekday()
[116] Fix | Delete
[117] Fix | Delete
[118] Fix | Delete
def monthrange(year, month):
[119] Fix | Delete
"""Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for
[120] Fix | Delete
year, month."""
[121] Fix | Delete
if not 1 <= month <= 12:
[122] Fix | Delete
raise IllegalMonthError(month)
[123] Fix | Delete
day1 = weekday(year, month, 1)
[124] Fix | Delete
ndays = mdays[month] + (month == February and isleap(year))
[125] Fix | Delete
return day1, ndays
[126] Fix | Delete
[127] Fix | Delete
[128] Fix | Delete
def _monthlen(year, month):
[129] Fix | Delete
return mdays[month] + (month == February and isleap(year))
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
def _prevmonth(year, month):
[133] Fix | Delete
if month == 1:
[134] Fix | Delete
return year-1, 12
[135] Fix | Delete
else:
[136] Fix | Delete
return year, month-1
[137] Fix | Delete
[138] Fix | Delete
[139] Fix | Delete
def _nextmonth(year, month):
[140] Fix | Delete
if month == 12:
[141] Fix | Delete
return year+1, 1
[142] Fix | Delete
else:
[143] Fix | Delete
return year, month+1
[144] Fix | Delete
[145] Fix | Delete
[146] Fix | Delete
class Calendar(object):
[147] Fix | Delete
"""
[148] Fix | Delete
Base calendar class. This class doesn't do any formatting. It simply
[149] Fix | Delete
provides data to subclasses.
[150] Fix | Delete
"""
[151] Fix | Delete
[152] Fix | Delete
def __init__(self, firstweekday=0):
[153] Fix | Delete
self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday
[154] Fix | Delete
[155] Fix | Delete
def getfirstweekday(self):
[156] Fix | Delete
return self._firstweekday % 7
[157] Fix | Delete
[158] Fix | Delete
def setfirstweekday(self, firstweekday):
[159] Fix | Delete
self._firstweekday = firstweekday
[160] Fix | Delete
[161] Fix | Delete
firstweekday = property(getfirstweekday, setfirstweekday)
[162] Fix | Delete
[163] Fix | Delete
def iterweekdays(self):
[164] Fix | Delete
"""
[165] Fix | Delete
Return an iterator for one week of weekday numbers starting with the
[166] Fix | Delete
configured first one.
[167] Fix | Delete
"""
[168] Fix | Delete
for i in range(self.firstweekday, self.firstweekday + 7):
[169] Fix | Delete
yield i%7
[170] Fix | Delete
[171] Fix | Delete
def itermonthdates(self, year, month):
[172] Fix | Delete
"""
[173] Fix | Delete
Return an iterator for one month. The iterator will yield datetime.date
[174] Fix | Delete
values and will always iterate through complete weeks, so it will yield
[175] Fix | Delete
dates outside the specified month.
[176] Fix | Delete
"""
[177] Fix | Delete
for y, m, d in self.itermonthdays3(year, month):
[178] Fix | Delete
yield datetime.date(y, m, d)
[179] Fix | Delete
[180] Fix | Delete
def itermonthdays(self, year, month):
[181] Fix | Delete
"""
[182] Fix | Delete
Like itermonthdates(), but will yield day numbers. For days outside
[183] Fix | Delete
the specified month the day number is 0.
[184] Fix | Delete
"""
[185] Fix | Delete
day1, ndays = monthrange(year, month)
[186] Fix | Delete
days_before = (day1 - self.firstweekday) % 7
[187] Fix | Delete
yield from repeat(0, days_before)
[188] Fix | Delete
yield from range(1, ndays + 1)
[189] Fix | Delete
days_after = (self.firstweekday - day1 - ndays) % 7
[190] Fix | Delete
yield from repeat(0, days_after)
[191] Fix | Delete
[192] Fix | Delete
def itermonthdays2(self, year, month):
[193] Fix | Delete
"""
[194] Fix | Delete
Like itermonthdates(), but will yield (day number, weekday number)
[195] Fix | Delete
tuples. For days outside the specified month the day number is 0.
[196] Fix | Delete
"""
[197] Fix | Delete
for i, d in enumerate(self.itermonthdays(year, month), self.firstweekday):
[198] Fix | Delete
yield d, i % 7
[199] Fix | Delete
[200] Fix | Delete
def itermonthdays3(self, year, month):
[201] Fix | Delete
"""
[202] Fix | Delete
Like itermonthdates(), but will yield (year, month, day) tuples. Can be
[203] Fix | Delete
used for dates outside of datetime.date range.
[204] Fix | Delete
"""
[205] Fix | Delete
day1, ndays = monthrange(year, month)
[206] Fix | Delete
days_before = (day1 - self.firstweekday) % 7
[207] Fix | Delete
days_after = (self.firstweekday - day1 - ndays) % 7
[208] Fix | Delete
y, m = _prevmonth(year, month)
[209] Fix | Delete
end = _monthlen(y, m) + 1
[210] Fix | Delete
for d in range(end-days_before, end):
[211] Fix | Delete
yield y, m, d
[212] Fix | Delete
for d in range(1, ndays + 1):
[213] Fix | Delete
yield year, month, d
[214] Fix | Delete
y, m = _nextmonth(year, month)
[215] Fix | Delete
for d in range(1, days_after + 1):
[216] Fix | Delete
yield y, m, d
[217] Fix | Delete
[218] Fix | Delete
def itermonthdays4(self, year, month):
[219] Fix | Delete
"""
[220] Fix | Delete
Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
[221] Fix | Delete
Can be used for dates outside of datetime.date range.
[222] Fix | Delete
"""
[223] Fix | Delete
for i, (y, m, d) in enumerate(self.itermonthdays3(year, month)):
[224] Fix | Delete
yield y, m, d, (self.firstweekday + i) % 7
[225] Fix | Delete
[226] Fix | Delete
def monthdatescalendar(self, year, month):
[227] Fix | Delete
"""
[228] Fix | Delete
Return a matrix (list of lists) representing a month's calendar.
[229] Fix | Delete
Each row represents a week; week entries are datetime.date values.
[230] Fix | Delete
"""
[231] Fix | Delete
dates = list(self.itermonthdates(year, month))
[232] Fix | Delete
return [ dates[i:i+7] for i in range(0, len(dates), 7) ]
[233] Fix | Delete
[234] Fix | Delete
def monthdays2calendar(self, year, month):
[235] Fix | Delete
"""
[236] Fix | Delete
Return a matrix representing a month's calendar.
[237] Fix | Delete
Each row represents a week; week entries are
[238] Fix | Delete
(day number, weekday number) tuples. Day numbers outside this month
[239] Fix | Delete
are zero.
[240] Fix | Delete
"""
[241] Fix | Delete
days = list(self.itermonthdays2(year, month))
[242] Fix | Delete
return [ days[i:i+7] for i in range(0, len(days), 7) ]
[243] Fix | Delete
[244] Fix | Delete
def monthdayscalendar(self, year, month):
[245] Fix | Delete
"""
[246] Fix | Delete
Return a matrix representing a month's calendar.
[247] Fix | Delete
Each row represents a week; days outside this month are zero.
[248] Fix | Delete
"""
[249] Fix | Delete
days = list(self.itermonthdays(year, month))
[250] Fix | Delete
return [ days[i:i+7] for i in range(0, len(days), 7) ]
[251] Fix | Delete
[252] Fix | Delete
def yeardatescalendar(self, year, width=3):
[253] Fix | Delete
"""
[254] Fix | Delete
Return the data for the specified year ready for formatting. The return
[255] Fix | Delete
value is a list of month rows. Each month row contains up to width months.
[256] Fix | Delete
Each month contains between 4 and 6 weeks and each week contains 1-7
[257] Fix | Delete
days. Days are datetime.date objects.
[258] Fix | Delete
"""
[259] Fix | Delete
months = [
[260] Fix | Delete
self.monthdatescalendar(year, i)
[261] Fix | Delete
for i in range(January, January+12)
[262] Fix | Delete
]
[263] Fix | Delete
return [months[i:i+width] for i in range(0, len(months), width) ]
[264] Fix | Delete
[265] Fix | Delete
def yeardays2calendar(self, year, width=3):
[266] Fix | Delete
"""
[267] Fix | Delete
Return the data for the specified year ready for formatting (similar to
[268] Fix | Delete
yeardatescalendar()). Entries in the week lists are
[269] Fix | Delete
(day number, weekday number) tuples. Day numbers outside this month are
[270] Fix | Delete
zero.
[271] Fix | Delete
"""
[272] Fix | Delete
months = [
[273] Fix | Delete
self.monthdays2calendar(year, i)
[274] Fix | Delete
for i in range(January, January+12)
[275] Fix | Delete
]
[276] Fix | Delete
return [months[i:i+width] for i in range(0, len(months), width) ]
[277] Fix | Delete
[278] Fix | Delete
def yeardayscalendar(self, year, width=3):
[279] Fix | Delete
"""
[280] Fix | Delete
Return the data for the specified year ready for formatting (similar to
[281] Fix | Delete
yeardatescalendar()). Entries in the week lists are day numbers.
[282] Fix | Delete
Day numbers outside this month are zero.
[283] Fix | Delete
"""
[284] Fix | Delete
months = [
[285] Fix | Delete
self.monthdayscalendar(year, i)
[286] Fix | Delete
for i in range(January, January+12)
[287] Fix | Delete
]
[288] Fix | Delete
return [months[i:i+width] for i in range(0, len(months), width) ]
[289] Fix | Delete
[290] Fix | Delete
[291] Fix | Delete
class TextCalendar(Calendar):
[292] Fix | Delete
"""
[293] Fix | Delete
Subclass of Calendar that outputs a calendar as a simple plain text
[294] Fix | Delete
similar to the UNIX program cal.
[295] Fix | Delete
"""
[296] Fix | Delete
[297] Fix | Delete
def prweek(self, theweek, width):
[298] Fix | Delete
"""
[299] Fix | Delete
Print a single week (no newline).
[300] Fix | Delete
"""
[301] Fix | Delete
print(self.formatweek(theweek, width), end='')
[302] Fix | Delete
[303] Fix | Delete
def formatday(self, day, weekday, width):
[304] Fix | Delete
"""
[305] Fix | Delete
Returns a formatted day.
[306] Fix | Delete
"""
[307] Fix | Delete
if day == 0:
[308] Fix | Delete
s = ''
[309] Fix | Delete
else:
[310] Fix | Delete
s = '%2i' % day # right-align single-digit days
[311] Fix | Delete
return s.center(width)
[312] Fix | Delete
[313] Fix | Delete
def formatweek(self, theweek, width):
[314] Fix | Delete
"""
[315] Fix | Delete
Returns a single week in a string (no newline).
[316] Fix | Delete
"""
[317] Fix | Delete
return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek)
[318] Fix | Delete
[319] Fix | Delete
def formatweekday(self, day, width):
[320] Fix | Delete
"""
[321] Fix | Delete
Returns a formatted week day name.
[322] Fix | Delete
"""
[323] Fix | Delete
if width >= 9:
[324] Fix | Delete
names = day_name
[325] Fix | Delete
else:
[326] Fix | Delete
names = day_abbr
[327] Fix | Delete
return names[day][:width].center(width)
[328] Fix | Delete
[329] Fix | Delete
def formatweekheader(self, width):
[330] Fix | Delete
"""
[331] Fix | Delete
Return a header for a week.
[332] Fix | Delete
"""
[333] Fix | Delete
return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays())
[334] Fix | Delete
[335] Fix | Delete
def formatmonthname(self, theyear, themonth, width, withyear=True):
[336] Fix | Delete
"""
[337] Fix | Delete
Return a formatted month name.
[338] Fix | Delete
"""
[339] Fix | Delete
s = month_name[themonth]
[340] Fix | Delete
if withyear:
[341] Fix | Delete
s = "%s %r" % (s, theyear)
[342] Fix | Delete
return s.center(width)
[343] Fix | Delete
[344] Fix | Delete
def prmonth(self, theyear, themonth, w=0, l=0):
[345] Fix | Delete
"""
[346] Fix | Delete
Print a month's calendar.
[347] Fix | Delete
"""
[348] Fix | Delete
print(self.formatmonth(theyear, themonth, w, l), end='')
[349] Fix | Delete
[350] Fix | Delete
def formatmonth(self, theyear, themonth, w=0, l=0):
[351] Fix | Delete
"""
[352] Fix | Delete
Return a month's calendar string (multi-line).
[353] Fix | Delete
"""
[354] Fix | Delete
w = max(2, w)
[355] Fix | Delete
l = max(1, l)
[356] Fix | Delete
s = self.formatmonthname(theyear, themonth, 7 * (w + 1) - 1)
[357] Fix | Delete
s = s.rstrip()
[358] Fix | Delete
s += '\n' * l
[359] Fix | Delete
s += self.formatweekheader(w).rstrip()
[360] Fix | Delete
s += '\n' * l
[361] Fix | Delete
for week in self.monthdays2calendar(theyear, themonth):
[362] Fix | Delete
s += self.formatweek(week, w).rstrip()
[363] Fix | Delete
s += '\n' * l
[364] Fix | Delete
return s
[365] Fix | Delete
[366] Fix | Delete
def formatyear(self, theyear, w=2, l=1, c=6, m=3):
[367] Fix | Delete
"""
[368] Fix | Delete
Returns a year's calendar as a multi-line string.
[369] Fix | Delete
"""
[370] Fix | Delete
w = max(2, w)
[371] Fix | Delete
l = max(1, l)
[372] Fix | Delete
c = max(2, c)
[373] Fix | Delete
colwidth = (w + 1) * 7 - 1
[374] Fix | Delete
v = []
[375] Fix | Delete
a = v.append
[376] Fix | Delete
a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip())
[377] Fix | Delete
a('\n'*l)
[378] Fix | Delete
header = self.formatweekheader(w)
[379] Fix | Delete
for (i, row) in enumerate(self.yeardays2calendar(theyear, m)):
[380] Fix | Delete
# months in this row
[381] Fix | Delete
months = range(m*i+1, min(m*(i+1)+1, 13))
[382] Fix | Delete
a('\n'*l)
[383] Fix | Delete
names = (self.formatmonthname(theyear, k, colwidth, False)
[384] Fix | Delete
for k in months)
[385] Fix | Delete
a(formatstring(names, colwidth, c).rstrip())
[386] Fix | Delete
a('\n'*l)
[387] Fix | Delete
headers = (header for k in months)
[388] Fix | Delete
a(formatstring(headers, colwidth, c).rstrip())
[389] Fix | Delete
a('\n'*l)
[390] Fix | Delete
# max number of weeks for this row
[391] Fix | Delete
height = max(len(cal) for cal in row)
[392] Fix | Delete
for j in range(height):
[393] Fix | Delete
weeks = []
[394] Fix | Delete
for cal in row:
[395] Fix | Delete
if j >= len(cal):
[396] Fix | Delete
weeks.append('')
[397] Fix | Delete
else:
[398] Fix | Delete
weeks.append(self.formatweek(cal[j], w))
[399] Fix | Delete
a(formatstring(weeks, colwidth, c).rstrip())
[400] Fix | Delete
a('\n' * l)
[401] Fix | Delete
return ''.join(v)
[402] Fix | Delete
[403] Fix | Delete
def pryear(self, theyear, w=0, l=0, c=6, m=3):
[404] Fix | Delete
"""Print a year's calendar."""
[405] Fix | Delete
print(self.formatyear(theyear, w, l, c, m), end='')
[406] Fix | Delete
[407] Fix | Delete
[408] Fix | Delete
class HTMLCalendar(Calendar):
[409] Fix | Delete
"""
[410] Fix | Delete
This calendar returns complete HTML pages.
[411] Fix | Delete
"""
[412] Fix | Delete
[413] Fix | Delete
# CSS classes for the day <td>s
[414] Fix | Delete
cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
[415] Fix | Delete
[416] Fix | Delete
# CSS classes for the day <th>s
[417] Fix | Delete
cssclasses_weekday_head = cssclasses
[418] Fix | Delete
[419] Fix | Delete
# CSS class for the days before and after current month
[420] Fix | Delete
cssclass_noday = "noday"
[421] Fix | Delete
[422] Fix | Delete
# CSS class for the month's head
[423] Fix | Delete
cssclass_month_head = "month"
[424] Fix | Delete
[425] Fix | Delete
# CSS class for the month
[426] Fix | Delete
cssclass_month = "month"
[427] Fix | Delete
[428] Fix | Delete
# CSS class for the year's table head
[429] Fix | Delete
cssclass_year_head = "year"
[430] Fix | Delete
[431] Fix | Delete
# CSS class for the whole year table
[432] Fix | Delete
cssclass_year = "year"
[433] Fix | Delete
[434] Fix | Delete
def formatday(self, day, weekday):
[435] Fix | Delete
"""
[436] Fix | Delete
Return a day as a table cell.
[437] Fix | Delete
"""
[438] Fix | Delete
if day == 0:
[439] Fix | Delete
# day outside month
[440] Fix | Delete
return '<td class="%s">&nbsp;</td>' % self.cssclass_noday
[441] Fix | Delete
else:
[442] Fix | Delete
return '<td class="%s">%d</td>' % (self.cssclasses[weekday], day)
[443] Fix | Delete
[444] Fix | Delete
def formatweek(self, theweek):
[445] Fix | Delete
"""
[446] Fix | Delete
Return a complete week as a table row.
[447] Fix | Delete
"""
[448] Fix | Delete
s = ''.join(self.formatday(d, wd) for (d, wd) in theweek)
[449] Fix | Delete
return '<tr>%s</tr>' % s
[450] Fix | Delete
[451] Fix | Delete
def formatweekday(self, day):
[452] Fix | Delete
"""
[453] Fix | Delete
Return a weekday name as a table header.
[454] Fix | Delete
"""
[455] Fix | Delete
return '<th class="%s">%s</th>' % (
[456] Fix | Delete
self.cssclasses_weekday_head[day], day_abbr[day])
[457] Fix | Delete
[458] Fix | Delete
def formatweekheader(self):
[459] Fix | Delete
"""
[460] Fix | Delete
Return a header for a week as a table row.
[461] Fix | Delete
"""
[462] Fix | Delete
s = ''.join(self.formatweekday(i) for i in self.iterweekdays())
[463] Fix | Delete
return '<tr>%s</tr>' % s
[464] Fix | Delete
[465] Fix | Delete
def formatmonthname(self, theyear, themonth, withyear=True):
[466] Fix | Delete
"""
[467] Fix | Delete
Return a month name as a table row.
[468] Fix | Delete
"""
[469] Fix | Delete
if withyear:
[470] Fix | Delete
s = '%s %s' % (month_name[themonth], theyear)
[471] Fix | Delete
else:
[472] Fix | Delete
s = '%s' % month_name[themonth]
[473] Fix | Delete
return '<tr><th colspan="7" class="%s">%s</th></tr>' % (
[474] Fix | Delete
self.cssclass_month_head, s)
[475] Fix | Delete
[476] Fix | Delete
def formatmonth(self, theyear, themonth, withyear=True):
[477] Fix | Delete
"""
[478] Fix | Delete
Return a formatted month as a table.
[479] Fix | Delete
"""
[480] Fix | Delete
v = []
[481] Fix | Delete
a = v.append
[482] Fix | Delete
a('<table border="0" cellpadding="0" cellspacing="0" class="%s">' % (
[483] Fix | Delete
self.cssclass_month))
[484] Fix | Delete
a('\n')
[485] Fix | Delete
a(self.formatmonthname(theyear, themonth, withyear=withyear))
[486] Fix | Delete
a('\n')
[487] Fix | Delete
a(self.formatweekheader())
[488] Fix | Delete
a('\n')
[489] Fix | Delete
for week in self.monthdays2calendar(theyear, themonth):
[490] Fix | Delete
a(self.formatweek(week))
[491] Fix | Delete
a('\n')
[492] Fix | Delete
a('</table>')
[493] Fix | Delete
a('\n')
[494] Fix | Delete
return ''.join(v)
[495] Fix | Delete
[496] Fix | Delete
def formatyear(self, theyear, width=3):
[497] Fix | Delete
"""
[498] Fix | Delete
Return a formatted year as a table of tables.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function