[pypy-svn] r39747 - in pypy/branch/rope-branch/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Mar 2 20:19:20 CET 2007


Author: cfbolz
Date: Fri Mar  2 20:19:19 2007
New Revision: 39747

Modified:
   pypy/branch/rope-branch/pypy/objspace/std/rope.py
   pypy/branch/rope-branch/pypy/objspace/std/ropeobject.py
   pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py
Log:
fix rope bug -- indeed some sort of normalization problem


Modified: pypy/branch/rope-branch/pypy/objspace/std/rope.py
==============================================================================
--- pypy/branch/rope-branch/pypy/objspace/std/rope.py	(original)
+++ pypy/branch/rope-branch/pypy/objspace/std/rope.py	Fri Mar  2 20:19:19 2007
@@ -198,9 +198,8 @@
     return result
 
 def getslice(node, start, stop, step, slicelength):
-    start, stop, node = find_straddling(node, start, stop)
     if step != 1:
-        # XXX optimize later using SeekableCharIterator
+        start, stop, node = find_straddling(node, start, stop)
         iter = SeekableCharIterator(node)
         iter.seekforward(start)
         result = [iter.next()]
@@ -211,6 +210,7 @@
     return getslice_one(node, start, stop)
 
 def getslice_one(node, start, stop):
+    start, stop, node = find_straddling(node, start, stop)
     if isinstance(node, BinaryConcatNode):
         if start == 0:
             if stop == node.length():

Modified: pypy/branch/rope-branch/pypy/objspace/std/ropeobject.py
==============================================================================
--- pypy/branch/rope-branch/pypy/objspace/std/ropeobject.py	(original)
+++ pypy/branch/rope-branch/pypy/objspace/std/ropeobject.py	Fri Mar  2 20:19:19 2007
@@ -268,11 +268,11 @@
     start = 0
     selfnode = w_self._node
     bynode = w_by._node
-    iter = rope.FindIterator(selfnode, bynode)
     bylen = bynode.length()
     if bylen == 0:
         raise OperationError(space.w_ValueError, space.wrap("empty separator"))
 
+    iter = rope.FindIterator(selfnode, bynode)
     while maxsplit != 0:
         try:
             next = iter.next()

Modified: pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py
==============================================================================
--- pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py	(original)
+++ pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py	Fri Mar  2 20:19:19 2007
@@ -90,6 +90,14 @@
             for stop in range(start, len(result)):
                 assert s[start:stop].flatten() == result[start:stop]
 
+def test_getslice_bug():
+    s1 = LiteralStringNode("/home/arigo/svn/pypy/branch/rope-branch/pypy/bin")
+    s2 = LiteralStringNode("/pypy")
+    s = s1 + s2
+    r = getslice_one(s, 1, 5)
+    assert r.flatten() == "home"
+
+
 def test_getslice_step():
     s1 = (LiteralStringNode("abcde") + LiteralStringNode("fghijklm") +
           LiteralStringNode("nopqrstu") + LiteralStringNode("vwxyz") + 



More information about the Pypy-commit mailing list