[pypy-svn] r73386 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
agaynor at codespeak.net
agaynor at codespeak.net
Sun Apr 4 20:55:42 CEST 2010
Author: agaynor
Date: Sun Apr 4 20:55:40 2010
New Revision: 73386
Added:
pypy/branch/cpython-extension/pypy/module/cpyext/mapping.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_mapping.py
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
Log:
Implemented PyMapping_Keys.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py Sun Apr 4 20:55:40 2010
@@ -48,6 +48,7 @@
import pypy.module.cpyext.eval
import pypy.module.cpyext.getargs
import pypy.module.cpyext.import_
+import pypy.module.cpyext.mapping
import pypy.module.cpyext.iterator
# now that all rffi_platform.Struct types are registered, configure them
Added: pypy/branch/cpython-extension/pypy/module/cpyext/mapping.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/mapping.py Sun Apr 4 20:55:40 2010
@@ -0,0 +1,12 @@
+from pypy.module.cpyext.api import cpython_api
+from pypy.module.cpyext.pyobject import PyObject
+
+
+ at cpython_api([PyObject], PyObject)
+def PyMapping_Keys(space, w_obj):
+ """On success, return a list of the keys in object o. On failure, return NULL.
+ This is equivalent to the Python expression o.keys()."""
+ # XXX: Cpython implements this in terms of PyObject_CallMethod, we should
+ # do that eventually.
+ w_meth = space.getattr(w_obj, space.wrap("keys"))
+ return space.call_function(w_meth)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Sun Apr 4 20:55:40 2010
@@ -3674,12 +3674,6 @@
raise NotImplementedError
@cpython_api([PyObject], PyObject)
-def PyMapping_Keys(space, o):
- """On success, return a list of the keys in object o. On failure, return NULL.
- This is equivalent to the Python expression o.keys()."""
- raise NotImplementedError
-
- at cpython_api([PyObject], PyObject)
def PyMapping_Values(space, o):
"""On success, return a list of the values in object o. On failure, return
NULL. This is equivalent to the Python expression o.values()."""
Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_mapping.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_mapping.py Sun Apr 4 20:55:40 2010
@@ -0,0 +1,8 @@
+from pypy.module.cpyext.test.test_api import BaseApiTest
+
+
+class TestMapping(BaseApiTest):
+ def test_keys(self, space, api):
+ w_d = space.newdict()
+ space.setitem(w_d, space.wrap("a"), space.wrap("a"))
+ assert space.eq_w(api.PyMapping_Keys(w_d), space.wrap(["a"]))
More information about the Pypy-commit
mailing list