diff options
| author | Raymond Hettinger <python@rcn.com> | 2008-02-07 03:25:46 (GMT) |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2008-02-07 03:25:46 (GMT) |
| commit | 882a416900ab24d78f398809d1b1a4a119db91e6 (patch) | |
| tree | 455b742451b9baf6fe0fffe5863f64c921fd7523 /Lib/UserString.py | |
| parent | 017b6a3ad2be5c0e3309fb016234397211d6ffa7 (diff) | |
| download | cpython-882a416900ab24d78f398809d1b1a4a119db91e6.zip cpython-882a416900ab24d78f398809d1b1a4a119db91e6.tar.gz cpython-882a416900ab24d78f398809d1b1a4a119db91e6.tar.bz2 | |
Merge r60628, r60631, and r60633. Register UserList and UserString will the appropriate ABCs.
Diffstat (limited to 'Lib/UserString.py')
| -rwxr-xr-x | Lib/UserString.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/UserString.py b/Lib/UserString.py index 9c58a34..71984a7 100755 --- a/Lib/UserString.py +++ b/Lib/UserString.py @@ -6,10 +6,11 @@ Note: string objects have grown methods in Python 1.6 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 @@ class UserString: 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 @@ class MutableString(UserString): 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: |
