Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/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 date in self.itermonthdates(year, month):
[176] Fix | Delete
if date.month != month:
[177] Fix | Delete
yield (0, date.weekday())
[178] Fix | Delete
else:
[179] Fix | Delete
yield (date.day, date.weekday())
[180] Fix | Delete
[181] Fix | Delete
def itermonthdays(self, year, month):
[182] Fix | Delete
"""
[183] Fix | Delete
Like itermonthdates(), but will yield day numbers. For days outside
[184] Fix | Delete
the specified month the day number is 0.
[185] Fix | Delete
"""
[186] Fix | Delete
for date in self.itermonthdates(year, month):
[187] Fix | Delete
if date.month != month:
[188] Fix | Delete
yield 0
[189] Fix | Delete
else:
[190] Fix | Delete
yield date.day
[191] Fix | Delete
[192] Fix | Delete
def monthdatescalendar(self, year, month):
[193] Fix | Delete
"""
[194] Fix | Delete
Return a matrix (list of lists) representing a month's calendar.
[195] Fix | Delete
Each row represents a week; week entries are datetime.date values.
[196] Fix | Delete
"""
[197] Fix | Delete
dates = list(self.itermonthdates(year, month))
[198] Fix | Delete
return [ dates[i:i+7] for i in range(0, len(dates), 7) ]
[199] Fix | Delete
[200] Fix | Delete
def monthdays2calendar(self, year, month):
[201] Fix | Delete
"""
[202] Fix | Delete
Return a matrix representing a month's calendar.
[203] Fix | Delete
Each row represents a week; week entries are
[204] Fix | Delete
(day number, weekday number) tuples. Day numbers outside this month
[205] Fix | Delete
are zero.
[206] Fix | Delete
"""
[207] Fix | Delete
days = list(self.itermonthdays2(year, month))
[208] Fix | Delete
return [ days[i:i+7] for i in range(0, len(days), 7) ]
[209] Fix | Delete
[210] Fix | Delete
def monthdayscalendar(self, year, month):
[211] Fix | Delete
"""
[212] Fix | Delete
Return a matrix representing a month's calendar.
[213] Fix | Delete
Each row represents a week; days outside this month are zero.
[214] Fix | Delete
"""
[215] Fix | Delete
days = list(self.itermonthdays(year, month))
[216] Fix | Delete
return [ days[i:i+7] for i in range(0, len(days), 7) ]
[217] Fix | Delete
[218] Fix | Delete
def yeardatescalendar(self, year, width=3):
[219] Fix | Delete
"""
[220] Fix | Delete
Return the data for the specified year ready for formatting. The return
[221] Fix | Delete
value is a list of month rows. Each month row contains up to width months.
[222] Fix | Delete
Each month contains between 4 and 6 weeks and each week contains 1-7
[223] Fix | Delete
days. Days are datetime.date objects.
[224] Fix | Delete
"""
[225] Fix | Delete
months = [
[226] Fix | Delete
self.monthdatescalendar(year, i)
[227] Fix | Delete
for i in range(January, January+12)
[228] Fix | Delete
]
[229] Fix | Delete
return [months[i:i+width] for i in range(0, len(months), width) ]
[230] Fix | Delete
[231] Fix | Delete
def yeardays2calendar(self, year, width=3):
[232] Fix | Delete
"""
[233] Fix | Delete
Return the data for the specified year ready for formatting (similar to
[234] Fix | Delete
yeardatescalendar()). Entries in the week lists are
[235] Fix | Delete
(day number, weekday number) tuples. Day numbers outside this month are
[236] Fix | Delete
zero.
[237] Fix | Delete
"""
[238] Fix | Delete
months = [
[239] Fix | Delete
self.monthdays2calendar(year, i)
[240] Fix | Delete
for i in range(January, January+12)
[241] Fix | Delete
]
[242] Fix | Delete
return [months[i:i+width] for i in range(0, len(months), width) ]
[243] Fix | Delete
[244] Fix | Delete
def yeardayscalendar(self, year, width=3):
[245] Fix | Delete
"""
[246] Fix | Delete
Return the data for the specified year ready for formatting (similar to
[247] Fix | Delete
yeardatescalendar()). Entries in the week lists are day numbers.
[248] Fix | Delete
Day numbers outside this month are zero.
[249] Fix | Delete
"""
[250] Fix | Delete
months = [
[251] Fix | Delete
self.monthdayscalendar(year, i)
[252] Fix | Delete
for i in range(January, January+12)
[253] Fix | Delete
]
[254] Fix | Delete
return [months[i:i+width] for i in range(0, len(months), width) ]
[255] Fix | Delete
[256] Fix | Delete
[257] Fix | Delete
class TextCalendar(Calendar):
[258] Fix | Delete
"""
[259] Fix | Delete
Subclass of Calendar that outputs a calendar as a simple plain text
[260] Fix | Delete
similar to the UNIX program cal.
[261] Fix | Delete
"""
[262] Fix | Delete
[263] Fix | Delete
def prweek(self, theweek, width):
[264] Fix | Delete
"""
[265] Fix | Delete
Print a single week (no newline).
[266] Fix | Delete
"""
[267] Fix | Delete
print self.formatweek(theweek, width),
[268] Fix | Delete
[269] Fix | Delete
def formatday(self, day, weekday, width):
[270] Fix | Delete
"""
[271] Fix | Delete
Returns a formatted day.
[272] Fix | Delete
"""
[273] Fix | Delete
if day == 0:
[274] Fix | Delete
s = ''
[275] Fix | Delete
else:
[276] Fix | Delete
s = '%2i' % day # right-align single-digit days
[277] Fix | Delete
return s.center(width)
[278] Fix | Delete
[279] Fix | Delete
def formatweek(self, theweek, width):
[280] Fix | Delete
"""
[281] Fix | Delete
Returns a single week in a string (no newline).
[282] Fix | Delete
"""
[283] Fix | Delete
return ' '.join(self.formatday(d, wd, width) for (d, wd) in theweek)
[284] Fix | Delete
[285] Fix | Delete
def formatweekday(self, day, width):
[286] Fix | Delete
"""
[287] Fix | Delete
Returns a formatted week day name.
[288] Fix | Delete
"""
[289] Fix | Delete
if width >= 9:
[290] Fix | Delete
names = day_name
[291] Fix | Delete
else:
[292] Fix | Delete
names = day_abbr
[293] Fix | Delete
return names[day][:width].center(width)
[294] Fix | Delete
[295] Fix | Delete
def formatweekheader(self, width):
[296] Fix | Delete
"""
[297] Fix | Delete
Return a header for a week.
[298] Fix | Delete
"""
[299] Fix | Delete
return ' '.join(self.formatweekday(i, width) for i in self.iterweekdays())
[300] Fix | Delete
[301] Fix | Delete
def formatmonthname(self, theyear, themonth, width, withyear=True):
[302] Fix | Delete
"""
[303] Fix | Delete
Return a formatted month name.
[304] Fix | Delete
"""
[305] Fix | Delete
s = month_name[themonth]
[306] Fix | Delete
if withyear:
[307] Fix | Delete
s = "%s %r" % (s, theyear)
[308] Fix | Delete
return s.center(width)
[309] Fix | Delete
[310] Fix | Delete
def prmonth(self, theyear, themonth, w=0, l=0):
[311] Fix | Delete
"""
[312] Fix | Delete
Print a month's calendar.
[313] Fix | Delete
"""
[314] Fix | Delete
print self.formatmonth(theyear, themonth, w, l),
[315] Fix | Delete
[316] Fix | Delete
def formatmonth(self, theyear, themonth, w=0, l=0):
[317] Fix | Delete
"""
[318] Fix | Delete
Return a month's calendar string (multi-line).
[319] Fix | Delete
"""
[320] Fix | Delete
w = max(2, w)
[321] Fix | Delete
l = max(1, l)
[322] Fix | Delete
s = self.formatmonthname(theyear, themonth, 7 * (w + 1) - 1)
[323] Fix | Delete
s = s.rstrip()
[324] Fix | Delete
s += '\n' * l
[325] Fix | Delete
s += self.formatweekheader(w).rstrip()
[326] Fix | Delete
s += '\n' * l
[327] Fix | Delete
for week in self.monthdays2calendar(theyear, themonth):
[328] Fix | Delete
s += self.formatweek(week, w).rstrip()
[329] Fix | Delete
s += '\n' * l
[330] Fix | Delete
return s
[331] Fix | Delete
[332] Fix | Delete
def formatyear(self, theyear, w=2, l=1, c=6, m=3):
[333] Fix | Delete
"""
[334] Fix | Delete
Returns a year's calendar as a multi-line string.
[335] Fix | Delete
"""
[336] Fix | Delete
w = max(2, w)
[337] Fix | Delete
l = max(1, l)
[338] Fix | Delete
c = max(2, c)
[339] Fix | Delete
colwidth = (w + 1) * 7 - 1
[340] Fix | Delete
v = []
[341] Fix | Delete
a = v.append
[342] Fix | Delete
a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip())
[343] Fix | Delete
a('\n'*l)
[344] Fix | Delete
header = self.formatweekheader(w)
[345] Fix | Delete
for (i, row) in enumerate(self.yeardays2calendar(theyear, m)):
[346] Fix | Delete
# months in this row
[347] Fix | Delete
months = range(m*i+1, min(m*(i+1)+1, 13))
[348] Fix | Delete
a('\n'*l)
[349] Fix | Delete
names = (self.formatmonthname(theyear, k, colwidth, False)
[350] Fix | Delete
for k in months)
[351] Fix | Delete
a(formatstring(names, colwidth, c).rstrip())
[352] Fix | Delete
a('\n'*l)
[353] Fix | Delete
headers = (header for k in months)
[354] Fix | Delete
a(formatstring(headers, colwidth, c).rstrip())
[355] Fix | Delete
a('\n'*l)
[356] Fix | Delete
# max number of weeks for this row
[357] Fix | Delete
height = max(len(cal) for cal in row)
[358] Fix | Delete
for j in range(height):
[359] Fix | Delete
weeks = []
[360] Fix | Delete
for cal in row:
[361] Fix | Delete
if j >= len(cal):
[362] Fix | Delete
weeks.append('')
[363] Fix | Delete
else:
[364] Fix | Delete
weeks.append(self.formatweek(cal[j], w))
[365] Fix | Delete
a(formatstring(weeks, colwidth, c).rstrip())
[366] Fix | Delete
a('\n' * l)
[367] Fix | Delete
return ''.join(v)
[368] Fix | Delete
[369] Fix | Delete
def pryear(self, theyear, w=0, l=0, c=6, m=3):
[370] Fix | Delete
"""Print a year's calendar."""
[371] Fix | Delete
print self.formatyear(theyear, w, l, c, m)
[372] Fix | Delete
[373] Fix | Delete
[374] Fix | Delete
class HTMLCalendar(Calendar):
[375] Fix | Delete
"""
[376] Fix | Delete
This calendar returns complete HTML pages.
[377] Fix | Delete
"""
[378] Fix | Delete
[379] Fix | Delete
# CSS classes for the day <td>s
[380] Fix | Delete
cssclasses = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
[381] Fix | Delete
[382] Fix | Delete
def formatday(self, day, weekday):
[383] Fix | Delete
"""
[384] Fix | Delete
Return a day as a table cell.
[385] Fix | Delete
"""
[386] Fix | Delete
if day == 0:
[387] Fix | Delete
return '<td class="noday">&nbsp;</td>' # day outside month
[388] Fix | Delete
else:
[389] Fix | Delete
return '<td class="%s">%d</td>' % (self.cssclasses[weekday], day)
[390] Fix | Delete
[391] Fix | Delete
def formatweek(self, theweek):
[392] Fix | Delete
"""
[393] Fix | Delete
Return a complete week as a table row.
[394] Fix | Delete
"""
[395] Fix | Delete
s = ''.join(self.formatday(d, wd) for (d, wd) in theweek)
[396] Fix | Delete
return '<tr>%s</tr>' % s
[397] Fix | Delete
[398] Fix | Delete
def formatweekday(self, day):
[399] Fix | Delete
"""
[400] Fix | Delete
Return a weekday name as a table header.
[401] Fix | Delete
"""
[402] Fix | Delete
return '<th class="%s">%s</th>' % (self.cssclasses[day], day_abbr[day])
[403] Fix | Delete
[404] Fix | Delete
def formatweekheader(self):
[405] Fix | Delete
"""
[406] Fix | Delete
Return a header for a week as a table row.
[407] Fix | Delete
"""
[408] Fix | Delete
s = ''.join(self.formatweekday(i) for i in self.iterweekdays())
[409] Fix | Delete
return '<tr>%s</tr>' % s
[410] Fix | Delete
[411] Fix | Delete
def formatmonthname(self, theyear, themonth, withyear=True):
[412] Fix | Delete
"""
[413] Fix | Delete
Return a month name as a table row.
[414] Fix | Delete
"""
[415] Fix | Delete
if withyear:
[416] Fix | Delete
s = '%s %s' % (month_name[themonth], theyear)
[417] Fix | Delete
else:
[418] Fix | Delete
s = '%s' % month_name[themonth]
[419] Fix | Delete
return '<tr><th colspan="7" class="month">%s</th></tr>' % s
[420] Fix | Delete
[421] Fix | Delete
def formatmonth(self, theyear, themonth, withyear=True):
[422] Fix | Delete
"""
[423] Fix | Delete
Return a formatted month as a table.
[424] Fix | Delete
"""
[425] Fix | Delete
v = []
[426] Fix | Delete
a = v.append
[427] Fix | Delete
a('<table border="0" cellpadding="0" cellspacing="0" class="month">')
[428] Fix | Delete
a('\n')
[429] Fix | Delete
a(self.formatmonthname(theyear, themonth, withyear=withyear))
[430] Fix | Delete
a('\n')
[431] Fix | Delete
a(self.formatweekheader())
[432] Fix | Delete
a('\n')
[433] Fix | Delete
for week in self.monthdays2calendar(theyear, themonth):
[434] Fix | Delete
a(self.formatweek(week))
[435] Fix | Delete
a('\n')
[436] Fix | Delete
a('</table>')
[437] Fix | Delete
a('\n')
[438] Fix | Delete
return ''.join(v)
[439] Fix | Delete
[440] Fix | Delete
def formatyear(self, theyear, width=3):
[441] Fix | Delete
"""
[442] Fix | Delete
Return a formatted year as a table of tables.
[443] Fix | Delete
"""
[444] Fix | Delete
v = []
[445] Fix | Delete
a = v.append
[446] Fix | Delete
width = max(width, 1)
[447] Fix | Delete
a('<table border="0" cellpadding="0" cellspacing="0" class="year">')
[448] Fix | Delete
a('\n')
[449] Fix | Delete
a('<tr><th colspan="%d" class="year">%s</th></tr>' % (width, theyear))
[450] Fix | Delete
for i in range(January, January+12, width):
[451] Fix | Delete
# months in this row
[452] Fix | Delete
months = range(i, min(i+width, 13))
[453] Fix | Delete
a('<tr>')
[454] Fix | Delete
for m in months:
[455] Fix | Delete
a('<td>')
[456] Fix | Delete
a(self.formatmonth(theyear, m, withyear=False))
[457] Fix | Delete
a('</td>')
[458] Fix | Delete
a('</tr>')
[459] Fix | Delete
a('</table>')
[460] Fix | Delete
return ''.join(v)
[461] Fix | Delete
[462] Fix | Delete
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
[463] Fix | Delete
"""
[464] Fix | Delete
Return a formatted year as a complete HTML page.
[465] Fix | Delete
"""
[466] Fix | Delete
if encoding is None:
[467] Fix | Delete
encoding = sys.getdefaultencoding()
[468] Fix | Delete
v = []
[469] Fix | Delete
a = v.append
[470] Fix | Delete
a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
[471] Fix | Delete
a('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n')
[472] Fix | Delete
a('<html>\n')
[473] Fix | Delete
a('<head>\n')
[474] Fix | Delete
a('<meta http-equiv="Content-Type" content="text/html; charset=%s" />\n' % encoding)
[475] Fix | Delete
if css is not None:
[476] Fix | Delete
a('<link rel="stylesheet" type="text/css" href="%s" />\n' % css)
[477] Fix | Delete
a('<title>Calendar for %d</title>\n' % theyear)
[478] Fix | Delete
a('</head>\n')
[479] Fix | Delete
a('<body>\n')
[480] Fix | Delete
a(self.formatyear(theyear, width))
[481] Fix | Delete
a('</body>\n')
[482] Fix | Delete
a('</html>\n')
[483] Fix | Delete
return ''.join(v).encode(encoding, "xmlcharrefreplace")
[484] Fix | Delete
[485] Fix | Delete
[486] Fix | Delete
class TimeEncoding:
[487] Fix | Delete
def __init__(self, locale):
[488] Fix | Delete
self.locale = locale
[489] Fix | Delete
[490] Fix | Delete
def __enter__(self):
[491] Fix | Delete
self.oldlocale = _locale.getlocale(_locale.LC_TIME)
[492] Fix | Delete
_locale.setlocale(_locale.LC_TIME, self.locale)
[493] Fix | Delete
return _locale.getlocale(_locale.LC_TIME)[1]
[494] Fix | Delete
[495] Fix | Delete
def __exit__(self, *args):
[496] Fix | Delete
_locale.setlocale(_locale.LC_TIME, self.oldlocale)
[497] Fix | Delete
[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