summaryrefslogtreecommitdiff
path: root/Lib/UserString.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-08-09 01:37:06 +0000
committerRaymond Hettinger <python@rcn.com>2002-08-09 01:37:06 +0000
commita5e21afc6ac558d3bd1c2e40fd01e6cfaf632efb (patch)
treefdf533a6e81a3898327172fdcc809a4a19898388 /Lib/UserString.py
parent3ddcf025b28a8bc96ccc1e54e59a25f6925f33a0 (diff)
downloadcpython-a5e21afc6ac558d3bd1c2e40fd01e6cfaf632efb.tar.gz
Moved inplace add and multiply methods from UserString to MutableString.
Closes SF Bug #592573 where inplace add mutated a UserString. Added unittests to verify the bug is cleared.
Diffstat (limited to 'Lib/UserString.py')
-rwxr-xr-xLib/UserString.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/Lib/UserString.py b/Lib/UserString.py
index 8209820aeb..8bd2c422ab 100755
--- a/Lib/UserString.py
+++ b/Lib/UserString.py
@@ -52,20 +52,9 @@ class UserString:
return self.__class__(other + self.data)
else:
return self.__class__(str(other) + self.data)
- def __iadd__(self, other):
- if isinstance(other, UserString):
- self.data += other.data
- elif isinstance(other, StringTypes):
- self.data += other
- else:
- self.data += str(other)
- return self
def __mul__(self, n):
return self.__class__(self.data*n)
__rmul__ = __mul__
- def __imul__(self, n):
- self.data *= n
- return self
# the following methods are defined in alphabetical order:
def capitalize(self): return self.__class__(self.data.capitalize())
@@ -168,6 +157,17 @@ class MutableString(UserString):
self.data = self.data[:start] + self.data[end:]
def immutable(self):
return UserString(self.data)
+ def __iadd__(self, other):
+ if isinstance(other, UserString):
+ self.data += other.data
+ elif isinstance(other, StringTypes):
+ self.data += other
+ else:
+ self.data += str(other)
+ return self
+ def __imul__(self, n):
+ self.data *= n
+ return self
if __name__ == "__main__":
# execute the regression test to stdout, if called as a script: