[pypy-svn] r50375 - in pypy/branch/ghop-ropes-classes/pypy/rlib: . test
vinogradov at codespeak.net
vinogradov at codespeak.net
Sun Jan 6 15:11:59 CET 2008
Author: vinogradov
Date: Sun Jan 6 15:11:57 2008
New Revision: 50375
Modified:
pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py
pypy/branch/ghop-ropes-classes/pypy/rlib/test/test_ropewrapper.py
Log:
Rewrite Rope __add__ algorithm
Modified: pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py
==============================================================================
--- pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py (original)
+++ pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py Sun Jan 6 15:11:57 2008
@@ -23,10 +23,20 @@
return self.__class__(rope.multiply(self._node, n))
def __add__(self, other):
+
if isinstance(self, RopeUnicode) or isinstance(other, RopeUnicode):
- return RopeUnicode(self._node + other._node)
+ if isinstance(self, RopeUnicode):
+ result = self._node.flatten_unicode()
+ else:
+ result = self.decode('utf-8')._node.flatten_unicode()
+
+ if isinstance(other, RopeUnicode):
+ result += other._node.flatten_unicode()
+ else:
+ result += other.decode('utf-8')._node.flatten_unicode()
+ return RopeUnicode(result)
else:
- return self.__class__(self._node + other._node)
+ return RopeString(self._node.flatten_string() + other._node.flatten_string())
def __getitem__(self, index):
if isinstance(index, int):
@@ -66,7 +76,7 @@
def encode(self, encoding, errors='strict'):
s = self._node.flatten_string()
result = s.encode(encoding, errors)
- return RopeUnicode(result)
+ return RopeString(result)
def decode(self, codepage, errors='strict'):
s = self._node.flatten_string()
Modified: pypy/branch/ghop-ropes-classes/pypy/rlib/test/test_ropewrapper.py
==============================================================================
--- pypy/branch/ghop-ropes-classes/pypy/rlib/test/test_ropewrapper.py (original)
+++ pypy/branch/ghop-ropes-classes/pypy/rlib/test/test_ropewrapper.py Sun Jan 6 15:11:57 2008
@@ -127,6 +127,7 @@
s1 = self.conststr("\xff")
s2 = self.constunicode("a")
py.test.raises(UnicodeDecodeError, "s1 + s2")
+ py.test.raises(UnicodeDecodeError, "s2 + s1")
class TestPythonCoercion(AbstractTestCoercion):
conststr = str
More information about the pypy-svn
mailing list