\n'
html += ''.join([self.__indent_style * (self.__indent_level + 3) + line + '\n' for line in cell.splitlines()])
html += self.__indent_style * (self.__indent_level + 2) + '\n'
html += self.__indent_style * (self.__indent_level + 1) + '\n'
return html + self.__indent_style * self.__indent_level + ''
class HTML_Month:
'HTML_Month(month, year, indent_level, indent_style) -> new HTML_Month'
def __init__(self, month, year, indent_level, indent_style):
'x.__init__(...) initializes x'
calendar.setfirstweekday(calendar.SUNDAY)
matrix = calendar.monthcalendar(year, month)
self.__table = HTML_Table(len(matrix) + 1, 7, indent_level, indent_style)
for column, text in enumerate(calendar.day_name[-1:] + calendar.day_name[:-1]):
self.__table.mutate(0, column, '%s' % text)
for row, week in enumerate(matrix):
for column, day in enumerate(week):
if day:
self.__table.mutate(row + 1, column, '%02d\n \n' % day) self.__weekday, self.__alldays = calendar.monthrange(year, month) self.__weekday = ((self.__weekday + 1) % 7) + 6 def mutate(self, day, text): 'Mutates a day in the HTML month.' row, column = self.__row_column(day) self.__table.mutate(row, column, '%02d\n \n%s' % (day, text)) return self def access(self, day): 'Accesses a day in the HTML month.' row, column = self.__row_column(day) return self.__table.access(row, column)[15:] def __row_column(self, day): 'Calculates the row and column of day.' assert 1 <= day <= self.__alldays index = day + self.__weekday return index / 7, index % 7 def set_month(self, *attributes): 'Set the attributes for the month.' self.__table.set_table(*attributes) return self def set_week(self, *attributes): 'Set the attributes for each week.' self.__table.set_row(*attributes) return self def set_day(self, *attributes): 'Set the attributes for each day.' self.__table.set_cell(*attributes) return self def html(self): 'Returns the HTML code for the current month.' return self.__table.html() ################################################################################ if __name__ == '__main__': import sys print 'Content-Type: text/plain' print print file(sys.argv[0]).read() |