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