[pypy-svn] r50054 - pypy/branch/ghop-ropes-classes/pypy/rlib
vinogradov at codespeak.net
vinogradov at codespeak.net
Sun Dec 23 21:54:53 CET 2007
Author: vinogradov
Date: Sun Dec 23 21:54:53 2007
New Revision: 50054
Modified:
pypy/branch/ghop-ropes-classes/pypy/rlib/ropewrapper.py
Log:
Move some functions from Rope[Unicode|String] to RopeBaseString
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 Dec 23 21:54:53 2007
@@ -1,34 +1,38 @@
from pypy.rlib import rope
-class RopeString(object):
+class RopeBaseString(object):
+ def __init__(self):
+ self._node = None
+
+ def __len__(self):
+ return self._node.length()
+
+ def __rmul__(self, n):
+ return self * n
+
+ def __hash__(self):
+ return rope.hash_rope(self._node)
+
+class RopeString(RopeBaseString):
def __init__(self, s):
if isinstance(s, str):
self._node = rope.LiteralStringNode(s)
if isinstance(s, rope.LiteralStringNode):
self._node = s
- def __len__(self):
- return self._node.length()
-
def __getitem__(self, index):
return self._node.getchar(index)
- def __eq__(self, other):
- return rope.eq(self._node, rope.LiteralStringNode(other))
-
def __add__(self, other):
return RopeString(self._node + other._node)
def __mul__(self, n):
return RopeString(rope.multiply(self._node, n))
- def __rmul__(self, n):
- return self * n
-
- def __hash__(self):
- return rope.hash_rope(self._node)
+ def __eq__(self, other):
+ return rope.eq(self._node, rope.LiteralStringNode(other))
-class RopeUnicode(object):
+class RopeUnicode(RopeBaseString):
def __init__(self, s):
if isinstance(s, str):
self._node = rope.LiteralUnicodeNode(unicode(s))
@@ -37,9 +41,6 @@
if isinstance(s, rope.LiteralUnicodeNode):
self._node = s
- def __len__(self):
- return self._node.length()
-
def __getitem__(self, index):
return self._node.getunichar(index)
@@ -51,9 +52,3 @@
def __mul__(self, n):
return RopeUnicode(rope.multiply(self._node, n))
-
- def __rmul__(self, n):
- return self * n
-
- def __hash__(self):
- return rope.hash_rope(self._node)
More information about the Pypy-commit
mailing list