[pypy-svn] r50111 - pypy/branch/ghop-ropes-classes/pypy/rlib

vinogradov at codespeak.net vinogradov at codespeak.net
Tue Dec 25 20:45:02 CET 2007


Author: vinogradov
Date: Tue Dec 25 20:45:01 2007
New Revision: 50111

Modified:
   pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py
Log:
Implement methods of RopeUnicode and RopeString to pass iteration test

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	Tue Dec 25 20:45:01 2007
@@ -19,6 +19,15 @@
     def __ne__(self, other):
         return not self == other
     
+class RopeStringIterator(object):
+    def __init__(self, node):
+        self._iter = rope.ItemIterator(node)
+    
+    def next(self):
+        return self._iter.nextchar()
+    
+    def __iter__():
+        return self
 
 class RopeString(RopeBaseString):
     def __init__(self, s):
@@ -41,6 +50,19 @@
             return (rope.eq(self._node, other._node))
         else:
             return rope.eq(self._node, rope.LiteralStringNode(other))    
+    
+    def __iter__(self):
+        return RopeStringIterator(self._node)
+
+class RopeUnicodeIterator(object):
+    def __init__(self, node):
+        self._iter = rope.ItemIterator(node)
+    
+    def next(self):
+        return self._iter.nextunichar()
+    
+    def __iter__():
+        return self
 
 class RopeUnicode(RopeBaseString):
     def __init__(self, s):
@@ -65,3 +87,6 @@
    
     def __mul__(self, n):
         return RopeUnicode(rope.multiply(self._node, n))
+    
+    def __iter__(self):
+        return RopeUnicodeIterator(self._node)



More information about the Pypy-commit mailing list