/Doc/c-api/mapping.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 83 lines · 46 code · 37 blank · 0 comment · 0 complexity · 11916896a9eb346f99dd5f59091f1bb7 MD5 · raw file

  1. .. highlightlang:: c
  2. .. _mapping:
  3. Mapping Protocol
  4. ================
  5. .. cfunction:: int PyMapping_Check(PyObject *o)
  6. Return ``1`` if the object provides mapping protocol, and ``0`` otherwise. This
  7. function always succeeds.
  8. .. cfunction:: Py_ssize_t PyMapping_Size(PyObject *o)
  9. Py_ssize_t PyMapping_Length(PyObject *o)
  10. .. index:: builtin: len
  11. Returns the number of keys in object *o* on success, and ``-1`` on failure. For
  12. objects that do not provide mapping protocol, this is equivalent to the Python
  13. expression ``len(o)``.
  14. .. versionchanged:: 2.5
  15. These functions returned an :ctype:`int` type. This might require
  16. changes in your code for properly supporting 64-bit systems.
  17. .. cfunction:: int PyMapping_DelItemString(PyObject *o, char *key)
  18. Remove the mapping for object *key* from the object *o*. Return ``-1`` on
  19. failure. This is equivalent to the Python statement ``del o[key]``.
  20. .. cfunction:: int PyMapping_DelItem(PyObject *o, PyObject *key)
  21. Remove the mapping for object *key* from the object *o*. Return ``-1`` on
  22. failure. This is equivalent to the Python statement ``del o[key]``.
  23. .. cfunction:: int PyMapping_HasKeyString(PyObject *o, char *key)
  24. On success, return ``1`` if the mapping object has the key *key* and ``0``
  25. otherwise. This is equivalent to ``o[key]``, returning ``True`` on success
  26. and ``False`` on an exception. This function always succeeds.
  27. .. cfunction:: int PyMapping_HasKey(PyObject *o, PyObject *key)
  28. Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
  29. This is equivalent to ``o[key]``, returning ``True`` on success and ``False``
  30. on an exception. This function always succeeds.
  31. .. cfunction:: PyObject* PyMapping_Keys(PyObject *o)
  32. On success, return a list of the keys in object *o*. On failure, return *NULL*.
  33. This is equivalent to the Python expression ``o.keys()``.
  34. .. cfunction:: PyObject* PyMapping_Values(PyObject *o)
  35. On success, return a list of the values in object *o*. On failure, return
  36. *NULL*. This is equivalent to the Python expression ``o.values()``.
  37. .. cfunction:: PyObject* PyMapping_Items(PyObject *o)
  38. On success, return a list of the items in object *o*, where each item is a tuple
  39. containing a key-value pair. On failure, return *NULL*. This is equivalent to
  40. the Python expression ``o.items()``.
  41. .. cfunction:: PyObject* PyMapping_GetItemString(PyObject *o, char *key)
  42. Return element of *o* corresponding to the object *key* or *NULL* on failure.
  43. This is the equivalent of the Python expression ``o[key]``.
  44. .. cfunction:: int PyMapping_SetItemString(PyObject *o, char *key, PyObject *v)
  45. Map the object *key* to the value *v* in object *o*. Returns ``-1`` on failure.
  46. This is the equivalent of the Python statement ``o[key] = v``.