[pypy-svn] r51321 - pypy/branch/ghop-ropes-classes/pypy/rlib
vinogradov at codespeak.net
vinogradov at codespeak.net
Thu Feb 7 19:24:53 CET 2008
Author: vinogradov
Date: Thu Feb 7 19:24:53 2008
New Revision: 51321
Modified:
pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py
Log:
Basic Implementation of index method
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 Thu Feb 7 19:24:53 2008
@@ -64,6 +64,25 @@
else:
raise TypeError("expected a character buffer object")
+ def index(self, sub, start=None, stop=None):
+ data = None
+
+ if isinstance(sub, str):
+ data = RopeString(sub)
+ if isinstance(sub, unicode):
+ data = RopeUnicode(sub)
+ if isinstance(sub, RopeBaseString):
+ data = sub
+
+ if data:
+ result = rope.find(self._node, data._node)
+ if result >= 0:
+ return result
+ else:
+ raise ValueError("substring not found")
+ else:
+ raise TypeError("expected a character buffer object")
+
class RopeStringIterator(object):
def __init__(self, node):
self._iter = rope.ItemIterator(node)
More information about the Pypy-commit
mailing list