[pypy-svn] r73082 - in pypy/branch/cpython-extension/pypy: module/cpyext rlib
xoraxax at codespeak.net
xoraxax at codespeak.net
Mon Mar 29 17:04:27 CEST 2010
Author: xoraxax
Date: Mon Mar 29 17:04:26 2010
New Revision: 73082
Added:
pypy/branch/cpython-extension/pypy/rlib/string.py
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
Log:
Add split function and use it in typeobject.py
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py Mon Mar 29 17:04:26 2010
@@ -21,6 +21,7 @@
from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr, PyTypeObject, \
PyGetSetDef
from pypy.module.cpyext.slotdefs import slotdefs
+from pypy.rlib.string import split
class W_GetSetPropertyEx(GetSetProperty):
@@ -97,7 +98,7 @@
# XXX missing: convert_member_defs
full_name = rffi.charp2str(pto.c_tp_name)
- module_name, extension_name = full_name.split(".", 1)
+ module_name, extension_name = split(full_name, ".", 1)
dict_w["__module__"] = space.wrap(module_name)
W_TypeObject.__init__(self, space, extension_name,
Added: pypy/branch/cpython-extension/pypy/rlib/string.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/rlib/string.py Mon Mar 29 17:04:26 2010
@@ -0,0 +1,17 @@
+def split(value, by, maxsplit):
+ bylen = len(by)
+ if bylen == 0:
+ raise ValueError("empty separator")
+
+ res = []
+ start = 0
+ while maxsplit != 0:
+ next = value.find(by, start)
+ if next < 0:
+ break
+ res.append(value[start:next])
+ start = next + bylen
+ maxsplit -= 1 # NB. if it's already < 0, it stays < 0
+
+ res.append(value[start:len(value)])
+ return res
More information about the Pypy-commit
mailing list