summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-02-06 20:59:41 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-02-06 20:59:41 (GMT)
commitb8b6d3ef40a355cb7e6256d3e3eb4edd904b05c9 (patch)
tree34c2987c75b0f7e4bc66164be8c42da928467b74
parent8284c4a7fb27efd55323513572e247a895a35ae1 (diff)
downloadcpython-b8b6d3ef40a355cb7e6256d3e3eb4edd904b05c9.zip
cpython-b8b6d3ef40a355cb7e6256d3e3eb4edd904b05c9.tar.gz
cpython-b8b6d3ef40a355cb7e6256d3e3eb4edd904b05c9.tar.bz2
Let the world know that UserList is a MutableSequence.
-rw-r--r--Lib/UserList.py6
-rwxr-xr-xLib/UserString.py9
2 files changed, 12 insertions, 3 deletions
diff --git a/Lib/UserList.py b/Lib/UserList.py
index 116122f..348ea76 100644
--- a/Lib/UserList.py
+++ b/Lib/UserList.py
@@ -1,6 +1,8 @@
"""A more or less complete user-defined wrapper around list objects."""
-class UserList:
+import collections
+
+class UserList(collections.MutableSequence):
def __init__(self, initlist=None):
self.data = []
if initlist is not None:
@@ -69,3 +71,5 @@ class UserList:
self.data.extend(other.data)
else:
self.data.extend(other)
+
+collections.MutableSequence.register(UserList)
diff --git a/Lib/UserString.py b/Lib/UserString.py
index a8b805f..615c135 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, str):
self.data = seq
@@ -161,7 +162,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
@@ -230,6 +233,8 @@ class MutableString(UserString):
self.data *= n
return self
+collections.MutableSequence.register(MutableString)
+
if __name__ == "__main__":
# execute the regression test to stdout, if called as a script:
import os