import calendar
class XmlCal:
def __init__(self, year, month, firstweekday=6):
# default the first weekday to Sunday
# (see docs for the calendar module)
self.year = year
self.month = month
self.firstweekday = firstweekday
calendar.setfirstweekday(firstweekday)
self.weeks = calendar.monthcalendar(year, month)
def toSaxEvents(self, handler):
attr = {}
handler.startElement("year", attr)
handler.characters(str(self.year))
handler.endElement("year")
handler.startElement("month", attr)
handler.characters(str(self.month))
handler.endElement("month")
handler.startElement("firstweekday", attr)
handler.characters(str(self.firstweekday))
handler.endElement("firstweekday")
for week in self.weeks:
handler.startElement("week", attr)
for day in week:
handler.startElement("day", attr)
handler.characters(str(day))
handler.endElement("day")
handler.endElement("week")
|