diff Lib/UserString.py @ 45212:feb6dd36d53f legacy-trunk

Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
author Raymond Hettinger <python@rcn.com>
date Thu, 07 Feb 2008 03:25:46 +0000
parents 9620134010a5
children c0aa6d8f5cdb
line wrap: on
line diff
--- a/Lib/UserString.py	Thu Feb 07 03:10:33 2008 +0000
+++ b/Lib/UserString.py	Thu Feb 07 03:25:46 2008 +0000
@@ -6,10 +6,11 @@
 This module requires Python 1.6 or later.
 """
 import sys
+import collections
 
 __all__ = ["UserString","MutableString"]
 
-class UserString:
+class UserString(collections.Sequence):
     def __init__(self, seq):
         if isinstance(seq, basestring):
             self.data = seq
@@ -129,7 +130,9 @@
     def upper(self): return self.__class__(self.data.upper())
     def zfill(self, width): return self.__class__(self.data.zfill(width))
 
-class MutableString(UserString):
+collections.Sequence.register(UserString)
+
+class MutableString(UserString, collections.MutableSequence):
     """mutable string objects
 
     Python strings are immutable objects.  This has the advantage, that
@@ -208,6 +211,10 @@
     def __imul__(self, n):
         self.data *= n
         return self
+    def insert(self, index, value):
+        self[index:index] = value
+
+collections.MutableSequence.register(MutableString)
 
 if __name__ == "__main__":
     # execute the regression test to stdout, if called as a script: