オブジェクトプロトコル (object protocol)
****************************************

int PyObject_Print(PyObject *o, FILE *fp, int flags)

   オブジェクト *o* をファイル *fp* に出力します。失敗すると "-1" を返
   します。 *flags* 引数は何らかの出力オプションを有効にする際に使いま
   す。現在サポートされている唯一のオプションは "Py_PRINT_RAW" です;
   このオプションを指定すると、 "repr()" の代わりに "str()" を使ってオ
   ブジェクトを書き込みます。

int PyObject_HasAttr(PyObject *o, PyObject *attr_name)

   *o* が属性 *attr_name* を持つときに "1" を、それ以外のときに "0" を
   返します。この関数は Python の式 "hasattr(o, attr_name)" と同じです
   。この関数は常に成功します。

int PyObject_HasAttrString(PyObject *o, const char *attr_name)

   *o* が属性 *attr_name* を持つときに "1" を、それ以外のときに "0" を
   返します。この関数は Python の式 "hasattr(o, attr_name)" と同じです
   。この関数は常に成功します。

PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)
    *Return value: New reference.*

   オブジェクト *o* から、名前 *attr_name* の属性を取得します。成功す
   ると属性値を返し失敗すると *NULL* を返します。この関数は Python の
   式 "o.attr_name" と同じです。

PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)
    *Return value: New reference.*

   オブジェクト *o* から、名前 *attr_name* の属性を取得します。成功す
   ると属性値を返し失敗すると *NULL* を返します。この関数は Python の
   式 "o.attr_name" と同じです。

PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name)

   型オブジェクトの "tp_getattro" スロットに置かれる、属性を取得する総
   称的な関数です。この関数は、 (もし存在すれば) オブジェクトの属性
   "__dict__" に加え、オブジェクトの MRO にあるクラスの辞書にあるデス
   クリプタを探します。 デスクリプタ (descriptor) の実装 で概要が述べ
   られている通り、データのデスクリプタはインスタンスの属性より優先さ
   れ、非データデスクリプタは後回しにされます。見付からなかった場合は
   "AttributeError" を送出します。

int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)

   オブジェクト *o* の *attr_name* という名の属性に、値 *v* を設定しま
   す。 失敗すると例外を送出し "-1" を返します; 成功すると "0" を返し
   ます。 この関数は Python の式 "o.attr_name = v" と同じです。

   *v* が *NULL* の場合は属性が削除されますが、この機能は非推奨であり
   "PyObject_DelAttr()" を使うのが望ましいです。

int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)

   オブジェクト *o* の *attr_name* という名の属性に、値 *v* を設定しま
   す。 失敗すると例外を送出し "-1" を返します; 成功すると "0" を返し
   ます。 この関数は Python の式 "o.attr_name = v" と同じです。

   *v* が *NULL* の場合は属性が削除されますが、この機能は非推奨であり
   "PyObject_DelAttrString()" を使うのが望ましいです。

int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)

   属性の設定と削除を行う汎用的な関数で、型オブジェクトの
   "tp_setattro" スロットに置かれます。 オブジェクトの MRO にあるクラ
   スの辞書からデータディスクリプタを探し、見付かった場合はインスタン
   スの辞書にある属性の設定や削除よりも優先されます。 そうでない場合は
   、(もし存在すれば) オブジェクトの "__dict__" に属性を設定もしくは削
   除します。 成功すると "0" が返され、そうでない場合は
   "AttributeError" が送出され "-1" が返されます。

int PyObject_DelAttr(PyObject *o, PyObject *attr_name)

   オブジェクト *o* の *attr_name* という名の属性を削除します。失敗す
   ると "-1" を返します。この関数は Python の文 "del o.attr_name" と同
   じです。

int PyObject_DelAttrString(PyObject *o, const char *attr_name)

   オブジェクト *o* の *attr_name* という名の属性を削除します。失敗す
   ると "-1" を返します。この関数は Python の文 "del o.attr_name" と同
   じです。

PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)
    *Return value: New reference.*

   *o1* と *o2* を *opid* に指定した演算によって比較します。 *opid* は
   "Py_LT", "Py_LE", "Py_EQ", "Py_NE", "Py_GT", または "Py_GE", のいず
   れかでなければならず、それぞれ "<", "<=", "==", "!=", ">", および
   ">=" に対応します。この関数は Python の式 "o1 op o2" と同じで、
   "op" が *opid* に対応する演算子です。成功すると比較結果の値を返し失
   敗すると *NULL* を返します。

int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid)

   *o1* と *o2* を *opid* に指定した演算によって比較します。 *opid* は
   "Py_LT", "Py_LE", "Py_EQ", "Py_NE", "Py_GT", または "Py_GE", のいず
   れかでなければならず、それぞれ "<", "<=", "==", "!=", ">", および
   ">=" に対応します。比較結果が真ならば "1" を、偽ならば "0" を、エラ
   ーが発生すると "-1" を返します。この関数は Python の式 "o1 op o2"
   と同じで、 "op" が *opid* に対応する演算子です。

注釈: *o1* と *o2* が同一のオブジェクトである場合、
  "PyObject_RichCompareBool()" は "Py_EQ" に対して常に "1" を返し、
  "Py_NE" に対して常に "0" を返します。

int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)

   Compare the values of *o1* and *o2* using a routine provided by
   *o1*, if one exists, otherwise with a routine provided by *o2*.
   The result of the comparison is returned in *result*.  Returns "-1"
   on failure.  This is the equivalent of the Python statement "result
   = cmp(o1, o2)".

int PyObject_Compare(PyObject *o1, PyObject *o2)

   Compare the values of *o1* and *o2* using a routine provided by
   *o1*, if one exists, otherwise with a routine provided by *o2*.
   Returns the result of the comparison on success.  On error, the
   value returned is undefined; use "PyErr_Occurred()" to detect an
   error.  This is equivalent to the Python expression "cmp(o1, o2)".

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

   Compute a string representation of object *o*.  Returns the string
   representation on success, *NULL* on failure.  This is the
   equivalent of the Python expression "repr(o)".  Called by the
   "repr()" built-in function and by reverse quotes.

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

   Compute a string representation of object *o*.  Returns the string
   representation on success, *NULL* on failure.  This is the
   equivalent of the Python expression "str(o)".  Called by the
   "str()" built-in function and by the "print" statement.

PyObject* PyObject_Bytes(PyObject *o)

   Compute a bytes representation of object *o*.  In 2.x, this is just
   an alias for "PyObject_Str()".

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

   Compute a Unicode string representation of object *o*.  Returns the
   Unicode string representation on success, *NULL* on failure. This
   is the equivalent of the Python expression "unicode(o)".  Called by
   the "unicode()" built-in function.

int PyObject_IsInstance(PyObject *inst, PyObject *cls)

   Returns "1" if *inst* is an instance of the class *cls* or a
   subclass of *cls*, or "0" if not.  On error, returns "-1" and sets
   an exception.  If *cls* is a type object rather than a class
   object, "PyObject_IsInstance()" returns "1" if *inst* is of type
   *cls*.  If *cls* is a tuple, the check will be done against every
   entry in *cls*. The result will be "1" when at least one of the
   checks returns "1", otherwise it will be "0". If *inst* is not a
   class instance and *cls* is neither a type object, nor a class
   object, nor a tuple, *inst* must have a "__class__" attribute — the
   class relationship of the value of that attribute with *cls* will
   be used to determine the result of this function.

   バージョン 2.1 で追加.

   バージョン 2.2 で変更: Support for a tuple as the second argument
   added.

Subclass determination is done in a fairly straightforward way, but
includes a wrinkle that implementors of extensions to the class system
may want to be aware of.  If "A" and "B" are class objects, "B" is a
subclass of "A" if it inherits from "A" either directly or indirectly.
If either is not a class object, a more general mechanism is used to
determine the class relationship of the two objects.  When testing if
*B* is a subclass of *A*, if *A* is *B*, "PyObject_IsSubclass()"
returns true.  If *A* and *B* are different objects, *B*’s "__bases__"
attribute is searched in a depth-first fashion for *A* — the presence
of the "__bases__" attribute is considered sufficient for this
determination.

int PyObject_IsSubclass(PyObject *derived, PyObject *cls)

   Returns "1" if the class *derived* is identical to or derived from
   the class *cls*, otherwise returns "0".  In case of an error,
   returns "-1". If *cls* is a tuple, the check will be done against
   every entry in *cls*. The result will be "1" when at least one of
   the checks returns "1", otherwise it will be "0". If either
   *derived* or *cls* is not an actual class object (or tuple), this
   function uses the generic algorithm described above.

   バージョン 2.1 で追加.

   バージョン 2.3 で変更: Older versions of Python did not support a
   tuple as the second argument.

int PyCallable_Check(PyObject *o)

   オブジェクト *o* が呼び出し可能オブジェクトかどうか調べます。オブジ
   ェクトが呼び出し可能であるときに "1" を返し、そうでないときには "0"
   を返します。この関数呼び出しは常に成功します。

PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw)
    *Return value: New reference.*

   Call a callable Python object *callable_object*, with arguments
   given by the tuple *args*, and named arguments given by the
   dictionary *kw*. If no named arguments are needed, *kw* may be
   *NULL*. *args* must not be *NULL*, use an empty tuple if no
   arguments are needed. Returns the result of the call on success, or
   *NULL* on failure.  This is the equivalent of the Python expression
   "apply(callable_object, args, kw)" or "callable_object(*args,
   **kw)".

   バージョン 2.2 で追加.

PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)
    *Return value: New reference.*

   Call a callable Python object *callable_object*, with arguments
   given by the tuple *args*.  If no arguments are needed, then *args*
   may be *NULL*.  Returns the result of the call on success, or
   *NULL* on failure.  This is the equivalent of the Python expression
   "apply(callable_object, args)" or "callable_object(*args)".

PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...)
    *Return value: New reference.*

   Call a callable Python object *callable*, with a variable number of
   C arguments. The C arguments are described using a
   "Py_BuildValue()" style format string.  The format may be *NULL*,
   indicating that no arguments are provided. Returns the result of
   the call on success, or *NULL* on failure.  This is the equivalent
   of the Python expression "apply(callable, args)" or
   "callable(*args)". Note that if you only pass "PyObject *" args,
   "PyObject_CallFunctionObjArgs()" is a faster alternative.

PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)
    *Return value: New reference.*

   オブジェクト *o* の *method* という名前のメソッドを、可変数個の C
   引数とともに呼び出します。C 引数はタプルを生成するような
   "Py_BuildValue()" 形式のフォーマット文字列を使って記述します。
   *format* は *NULL* にしてもよく、与える引数がないことを表します。成
   功すると呼び出し結果として得られたオブジェクトを返し、失敗すると
   *NULL* を返します。 Python の式 "o.method(args)" と同じです。もしも
   、 "PyObject *" args だけを引数に渡す場合は、
   "PyObject_CallMethodObjArgs()" がより速い方法であることを覚えておい
   てください。

PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL)
    *Return value: New reference.*

   呼び出し可能な Python オブジェクト *callable* を可変数個の
   "PyObject*" 引数とともに呼び出します。引数列は末尾に *NULL* がつい
   た可変数個のパラメタとして与えます。成功すると呼び出し結果として得
   られたオブジェクトを返し失敗すると *NULL* を返します。

   バージョン 2.2 で追加.

PyObject* PyObject_CallMethodObjArgs(PyObject *o, PyObject *name, ..., NULL)
    *Return value: New reference.*

   オブジェクト *o* のメソッドを呼び出します、メソッド名は Python 文字
   列オブジェクト *name* で与えます。可変数個の "PyObject*" 引数と共に
   呼び出されます. 引数列は末尾に *NULL* がついた可変数個のパラメタと
   して与えます。成功すると呼び出し結果として得られたオブジェクトを返
   し失敗すると *NULL* を返します。

   バージョン 2.2 で追加.

long PyObject_Hash(PyObject *o)

   オブジェクト *o* のハッシュ値を計算して返します。失敗すると "-1" を
   返します。 Python の式 "hash(o)" と同じです。

long PyObject_HashNotImplemented(PyObject *o)

   "type(o)" がハッシュ不可能であることを示す "TypeError" を設定し、
   "-1" を返します。この関数は "tp_hash" スロットに格納されたときには
   特別な扱いを受け、その type がハッシュ不可能であることをインタプリ
   タに明示的に示します。

   バージョン 2.6 で追加.

int PyObject_IsTrue(PyObject *o)

   *o* が真を表すとみなせる場合には "1" を、そうでないときには "0" を
   返します。   Python の式 "not not o" と同じです。失敗すると "-1" を
   返します。

int PyObject_Not(PyObject *o)

   *o* が真を表すとみなせる場合には "0" を、そうでないときには "1" を
   返します。   Python の式 "not o" と同じです。失敗すると "-1" を返し
   ます。

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

   *o* が *NULL* でない場合、オブジェクト *o* のオブジェクト型に相当す
   る型オブジェクトを返します。失敗すると "SystemError" を送出して
   *NULL* を返します。 Python の式 "type(o)" と同じです。  この関数は
   戻り値の参照カウントをインクリメントします。参照カウントのインクリ
   メントが必要でない限り、広く使われていて "PyTypeObject*" 型のポイン
   タを返す表記法 "o->ob_type" の代わりに使う理由は全くありません。

int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)

   オブジェクト *o* が、 *type* か *type* のサブタイプであるときに真を
   返します。どちらのパラメタも *NULL* であってはなりません。

   バージョン 2.2 で追加.

Py_ssize_t PyObject_Length(PyObject *o)
Py_ssize_t PyObject_Size(PyObject *o)

   *o* の長さを返します。ただしオブジェクト *o* がシーケンス型プロトコ
   ルとマップ型プロトコルの両方を提供している場合、シーケンスとしての
   長さを返します。エラーが生じると "-1" を返します。 Python の式
   "len(o)" と同じです。

   バージョン 2.5 で変更: These functions returned an "int" type. This
   might require changes in your code for properly supporting 64-bit
   systems.

PyObject* PyObject_GetItem(PyObject *o, PyObject *key)
    *Return value: New reference.*

   オブジェクト *key* に対応する *o* の要素を返します。失敗すると
   *NULL* を返します。Python の式 "o[key]" と同じです。

int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)

   オブジェクト *key* を値 *v* に対応付けます。 失敗すると例外を送出し
   "-1" を返します; 成功すると "0" を返します。 Python の文 "o[key] =
   v" と同じです。

int PyObject_DelItem(PyObject *o, PyObject *key)

   オブジェクト *o* から *key* に関する対応付けを削除します。失敗する
   と "-1" を返します。 Python の文 "del o[key]" と同じです。

int PyObject_AsFileDescriptor(PyObject *o)

   Derives a file descriptor from a Python object.  If the object is
   an integer or long integer, its value is returned.  If not, the
   object’s "fileno()" method is called if it exists; the method must
   return an integer or long integer, which is returned as the file
   descriptor value.  Returns "-1" on failure.

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

   この関数は Python の式 "dir(o)" と同じで、オブジェクトの変数名に割
   り当てている文字列からなるリスト (空の場合もあります) を返します。
   エラーの場合には *NULL* を返します。引数を *NULL* にすると、Python
   における "dir()" と同様に、現在のローカルな名前を返します; この場合
   、アクティブな実行フレームがなければ *NULL* を返しますが、
   "PyErr_Occurred()" は偽を返します。

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

   Python の式 "iter(o)" と同じです。引数にとったオブジェクトに対する
   新たなイテレータか、オブジェクトがすでにイテレータの場合にはオブジ
   ェクト自身を返します。オブジェクトが反復処理不可能であった場合には
   "TypeError" を送出して *NULL* を返します。
