summaryrefslogtreecommitdiffstats
path: root/Lib/UserString.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2005-02-18 13:22:43 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2005-02-18 13:22:43 (GMT)
commitaf3b39a1823d57eca4034ce6879ab926f175595e (patch)
tree6f66deffcd98a72aa66e5ebf3da44b3fbb4155e0 /Lib/UserString.py
parent612df8e21ded5a6d7c0f6641f16422883c61b4d9 (diff)
downloadcpython-af3b39a1823d57eca4034ce6879ab926f175595e.zip
cpython-af3b39a1823d57eca4034ce6879ab926f175595e.tar.gz
cpython-af3b39a1823d57eca4034ce6879ab926f175595e.tar.bz2
Add support for negative indices in UserString.MutableString.__setitem__
and UserString.MutableString.__delitem__.
Diffstat (limited to 'Lib/UserString.py')
-rwxr-xr-xLib/UserString.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/UserString.py b/Lib/UserString.py
index e8e0fed..3251139 100755
--- a/Lib/UserString.py
+++ b/Lib/UserString.py
@@ -146,9 +146,13 @@ class MutableString(UserString):
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):