[Python-checkins] CVS: python/dist/src/Lib calendar.py,1.22,1.22.18.1

Michael Hudson mwh@users.sourceforge.net
Sat, 16 Mar 2002 10:01:07 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv23250

Modified Files:
      Tag: release22-maint
	calendar.py 
Log Message:
This checkin backport two checkins by Skip.

backport montanaro's checkin of
    revision 1.24 of calendar.py

make _localized_name instances work more like the tuples they replaced.  In
particular, negative indexes work and they are limited by the actual length
of the names they represent (weekday and month names).  This closes bug
#503202.

[and then]

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.


Index: calendar.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/calendar.py,v
retrieving revision 1.22
retrieving revision 1.22.18.1
diff -C2 -d -r1.22 -r1.22.18.1
*** calendar.py	22 May 2001 15:58:30 -0000	1.22
--- calendar.py	16 Mar 2002 18:01:05 -0000	1.22.18.1
***************
*** 26,41 ****
  
  class _localized_name:
!     def __init__(self, format):
          self.format = format
      def __getitem__(self, item):
!         return strftime(self.format, (item,)*9).capitalize()
  
  # Full and abbreviated names of weekdays
! day_name = _localized_name('%A')
! day_abbr = _localized_name('%a')
  
  # Full and abbreviated names of months (1-based arrays!!!)
! month_name = _localized_name('%B')
! month_abbr = _localized_name('%b')
  
  # Constants for weekdays
--- 26,50 ----
  
  class _localized_name:
!     def __init__(self, format, len):
          self.format = format
+         self.len = len
      def __getitem__(self, item):
!         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
  
  # Full and abbreviated names of weekdays
! 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', 13)
! month_abbr = _localized_name('%b', 13)
  
  # Constants for weekdays