映射协议
********

参见 "PyObject_GetItem()"、"PyObject_SetItem()" 与
"PyObject_DelItem()"。

int PyMapping_Check(PyObject *o)

   Return "1" if the object provides mapping protocol or supports
   slicing, and "0" otherwise.  Note that it returns "1" for Python
   classes with a "__getitem__()" method since in general case it is
   impossible to determine what the type of keys it supports.  This
   function always succeeds.

Py_ssize_t PyMapping_Size(PyObject *o)
Py_ssize_t PyMapping_Length(PyObject *o)

   成功时返回对象 *o* 中键的数量，失败时返回 "-1"。 这相当于 Python 表
   达式 "len(o)"。

PyObject* PyMapping_GetItemString(PyObject *o, const char *key)
    *Return value: New reference.*

   Return element of *o* corresponding to the string *key* or *NULL*
   on failure. This is the equivalent of the Python expression
   "o[key]". See also "PyObject_GetItem()".

int PyMapping_SetItemString(PyObject *o, const char *key, PyObject *v)

   在对象 *o* 中将字符串 *key* 映射到值 *v*。 失败时返回 "-1"。 这相当
   于 Python 语句 "o[key] = v"。 另请参见 "PyObject_SetItem()"。

int PyMapping_DelItem(PyObject *o, PyObject *key)

   从对象 *o* 中移除对象 *key* 的映射。 失败时返回 "-1"。 这相当于
   Python 语句 "del o[key]"。 这是 "PyObject_DelItem()" 的一个别名。

int PyMapping_DelItemString(PyObject *o, const char *key)

   从对象 *o* 中移除字符串 *key* 的映射。 失败时返回 "-1"。 这相当于
   Python 语句 "del o[key]"。

int PyMapping_HasKey(PyObject *o, PyObject *key)

   如果映射对象具有键 *key* 则返回 "1"，否则返回 "0"。 这相当于 Python
   表达式 "key in o"。 此函数总是会成功执行。

   请注意在调用 "__getitem__()" 方法期间发生的异常将会被屏蔽。 要获取
   错误报告请改用 "PyObject_GetItem()"。

int PyMapping_HasKeyString(PyObject *o, const char *key)

   如果映射对象具有键 *key* 则返回 "1"，否则返回 "0"。 这相当于 Python
   表达式 "key in o"。 此函数总是会成功执行。

   请注意在调用 "__getitem__()" 方法期间发生的异常将会被屏蔽。 要获取
   错误报告请改用 "PyMapping_GetItemString()"。

PyObject* PyMapping_Keys(PyObject *o)
    *Return value: New reference.*

   On success, return a list or tuple of the keys in object *o*.  On
   failure, return *NULL*.

PyObject* PyMapping_Values(PyObject *o)
    *Return value: New reference.*

   On success, return a list or tuple of the values in object *o*.  On
   failure, return *NULL*.

PyObject* PyMapping_Items(PyObject *o)
    *Return value: New reference.*

   On success, return a list or tuple of the items in object *o*,
   where each item is a tuple containing a key-value pair.  On
   failure, return *NULL*.
