[pypy-svn] r74206 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Thu Apr 29 00:01:43 CEST 2010
Author: afa
Date: Thu Apr 29 00:01:41 2010
New Revision: 74206
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
Log:
PyDict_Values, PyDict_Keys, PyDict_Items
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py Thu Apr 29 00:01:41 2010
@@ -72,6 +72,24 @@
"""Empty an existing dictionary of all key-value pairs."""
space.call_method(w_obj, "clear")
+ at cpython_api([PyObject], PyObject)
+def PyDict_Keys(space, w_obj):
+ """Return a PyListObject containing all the keys from the dictionary,
+ as in the dictionary method dict.keys()."""
+ return space.call_method(w_obj, "keys")
+
+ at cpython_api([PyObject], PyObject)
+def PyDict_Values(space, w_obj):
+ """Return a PyListObject containing all the values from the
+ dictionary p, as in the dictionary method dict.values()."""
+ return space.call_method(w_obj, "values")
+
+ at cpython_api([PyObject], PyObject)
+def PyDict_Items(space, w_obj):
+ """Return a PyListObject containing all the items from the
+ dictionary, as in the dictionary method dict.items()."""
+ return space.call_method(w_obj, "items")
+
@cpython_api([PyObject, Py_ssize_t, PyObjectP, PyObjectP], rffi.INT_real, error=CANNOT_FAIL)
def PyDict_Next(space, w_obj, ppos, pkey, pvalue):
"""Iterate over all key-value pairs in the dictionary p. The
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 Thu Apr 29 00:01:41 2010
@@ -811,24 +811,6 @@
key. Return 0 on success or -1 on failure."""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PyDict_Items(space, p):
- """Return a PyListObject containing all the items from the
- dictionary, as in the dictionary method dict.items()."""
- raise NotImplementedError
-
- at cpython_api([PyObject], PyObject)
-def PyDict_Keys(space, p):
- """Return a PyListObject containing all the keys from the dictionary,
- as in the dictionary method dict.keys()."""
- raise NotImplementedError
-
- at cpython_api([PyObject], PyObject)
-def PyDict_Values(space, p):
- """Return a PyListObject containing all the values from the
- dictionary p, as in the dictionary method dict.values()."""
- raise NotImplementedError
-
@cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
def PyDict_Merge(space, a, b, override):
"""Iterate over mapping object b adding key-value pairs to dictionary a.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py Thu Apr 29 00:01:41 2010
@@ -51,3 +51,12 @@
i = space.wrap(2)
assert not api.PyDict_Check(i)
assert not api.PyDict_CheckExact(i)
+
+ def test_keys(self, space, api):
+ w_d = space.newdict()
+ space.setitem(w_d, space.wrap("a"), space.wrap("b"))
+
+ assert space.eq_w(api.PyDict_Keys(w_d), space.wrap(["a"]))
+ assert space.eq_w(api.PyDict_Values(w_d), space.wrap(["b"]))
+ assert space.eq_w(api.PyDict_Items(w_d), space.wrap([("a", "b")]))
+
More information about the Pypy-commit
mailing list