[Python-checkins] python/dist/src/Lib UserString.py,1.23,1.24

doerwalter at users.sourceforge.net doerwalter at users.sourceforge.net
Fri Feb 18 14:23:19 CET 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23548/Lib

Modified Files:
	UserString.py 
Log Message:
Add support for negative indices in UserString.MutableString.__setitem__
and UserString.MutableString.__delitem__.


Index: UserString.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserString.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- UserString.py	4 Aug 2004 08:01:06 -0000	1.23
+++ UserString.py	18 Feb 2005 13:22:43 -0000	1.24
@@ -146,9 +146,13 @@
     def __hash__(self):
         raise TypeError, "unhashable type (it is mutable)"
     def __setitem__(self, index, sub):
+        if index < 0:
+           index += len(self.data)
         if index < 0 or index >= len(self.data): raise IndexError
         self.data = self.data[:index] + sub + self.data[index+1:]
     def __delitem__(self, index):
+        if index < 0:
+           index += len(self.data)
         if index < 0 or index >= len(self.data): raise IndexError
         self.data = self.data[:index] + self.data[index+1:]
     def __setslice__(self, start, end, sub):



More information about the Python-checkins mailing list