diff options
author | Skip Montanaro <skip@pobox.com> | 2002-03-15 13:52:43 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2002-03-15 13:52:43 (GMT) |
commit | 1b9c177c5de0cf0d2d506748209dc840b0eb48d9 (patch) | |
tree | 78f63f3dd6bf4e63c92b70b5d4c807e63a9c480b /Lib/calendar.py | |
parent | 95700f7cde5c0efa1ae7bc956f4ba54ec8508b51 (diff) | |
download | cpython-1b9c177c5de0cf0d2d506748209dc840b0eb48d9.zip cpython-1b9c177c5de0cf0d2d506748209dc840b0eb48d9.tar.gz cpython-1b9c177c5de0cf0d2d506748209dc840b0eb48d9.tar.bz2 |
Corrected _localized_name.__getitem__ based on code in patch 503202 (which I
thought was just a bug report, so didn't notice - doh!). This handles
slicing, which v 1.23 didn't.
Diffstat (limited to 'Lib/calendar.py')
-rw-r--r-- | Lib/calendar.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py index 477f595..9af2c93 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -29,11 +29,13 @@ class _localized_name: self.format = format self.len = len def __getitem__(self, item): - if item > self.len-1 or item < -self.len: - raise IndexError - if item < 0: - item += self.len - return strftime(self.format, (item,)*9).capitalize() + if isinstance(item, int): + if item < 0: item += self.len + if not 0 <= item < self.len: + raise IndexError, "out of range" + return strftime(self.format, (item,)*9).capitalize() + elif isinstance(item, type(slice(0))): + return [self[e] for e in range(self.len)].__getslice__(item.start, item.stop) def __len__(self): return self.len @@ -42,8 +44,8 @@ day_name = _localized_name('%A', 7) day_abbr = _localized_name('%a', 7) # Full and abbreviated names of months (1-based arrays!!!) -month_name = _localized_name('%B', 12) -month_abbr = _localized_name('%b', 12) +month_name = _localized_name('%B', 13) +month_abbr = _localized_name('%b', 13) # Constants for weekdays (MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7) |