Index: UserString.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/UserString.py,v retrieving revision 1.22 diff -c -r1.22 UserString.py *** UserString.py 4 Jun 2004 04:23:29 -0000 1.22 --- UserString.py 20 Jun 2004 10:04:35 -0000 *************** *** 10,23 **** __all__ = ["UserString","MutableString"] ! class UserString: def __init__(self, seq): if isinstance(seq, StringTypes): ! self.data = seq elif isinstance(seq, UserString): ! self.data = seq.data[:] else: ! self.data = str(seq) def __str__(self): return str(self.data) def __repr__(self): return repr(self.data) def __int__(self): return int(self.data) --- 10,45 ---- __all__ = ["UserString","MutableString"] ! class UserString(object): ! components = () ! def dataget(self): ! if self.components: ! self._autojoin() ! return self._data ! data = property(dataget) ! def _autojoin(self): ! parts = [] ! def traverse(self): ! if not hasattr(self, 'components'): ! parts.append(self) ! return ! for s in self.components: ! if hasattr(s, 'components') and s.components: ! traverse(s) ! else: ! parts.append(str(s)) ! traverse(self) ! self.components = () ! self._data = ''.join(parts) ! ! def __init__(self, seq): if isinstance(seq, StringTypes): ! self._data = seq elif isinstance(seq, UserString): ! self._data = seq.data[:] else: ! self._data = str(seq) def __str__(self): return str(self.data) def __repr__(self): return repr(self.data) def __int__(self): return int(self.data) *************** *** 41,52 **** return self.__class__(self.data[start:end]) def __add__(self, other): ! if isinstance(other, UserString): ! return self.__class__(self.data + other.data) ! elif isinstance(other, StringTypes): ! return self.__class__(self.data + other) ! else: ! return self.__class__(self.data + str(other)) def __radd__(self, other): if isinstance(other, StringTypes): return self.__class__(other + self.data) --- 63,71 ---- return self.__class__(self.data[start:end]) def __add__(self, other): ! newone = self.__class__('') ! newone.components = (self, other) ! return newone def __radd__(self, other): if isinstance(other, StringTypes): return self.__class__(other + self.data) *************** *** 181,186 **** --- 200,216 ---- return self if __name__ == "__main__": + S = UserString + + a = S('abc') + print a._data + print a.components, a._data + b = a + a + print b.components, b._data + print len(b), b + + + # execute the regression test to stdout, if called as a script: import os called_in_dir, called_as = os.path.split(sys.argv[0])