Index: Lib/calendar.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/calendar.py,v retrieving revision 1.34 diff -u -r1.34 calendar.py --- Lib/calendar.py 7 Jun 2004 03:47:06 -0000 1.34 +++ Lib/calendar.py 12 Nov 2004 19:52:02 -0000 @@ -22,6 +22,12 @@ # Number of days per month (except for February in leap years) mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] +_proto_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)] +_proto_months.insert(0, lambda x: "") + +# January 1, 2001, was a Monday. +_proto_days = [datetime.date(2001, 1, i+1).strftime for i in range(7)] + # This module used to have hard-coded lists of day and month names, as # English strings. The classes following emulate a read-only version of # that, but supply localized names. Note that the values are computed @@ -32,10 +38,10 @@ self.format = format def __getitem__(self, i): - data = [datetime.date(2001, j, 1).strftime(self.format) - for j in range(1, 13)] - data.insert(0, "") - return data[i] + if isinstance(i, slice): + return [f(self.format) for f in _proto_months[i]] + else: + return _proto_months[i](self.format) def __len__(self): return 13 @@ -45,10 +51,10 @@ self.format = format def __getitem__(self, i): - # January 1, 2001, was a Monday. - data = [datetime.date(2001, 1, j+1).strftime(self.format) - for j in range(7)] - return data[i] + if isinstance(i, slice): + return [f(self.format) for f in _proto_days[i]] + else: + return _proto_days[i](self.format) def __len__(self): return 7