15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)from cpython.ref cimport PyObject, PyTypeObject
25f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)from libc.stdio cimport FILE
35f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
45f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)cdef extern from "Python.h":
55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    #####################################################################
75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # 6.1 Object Protocol
85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    #####################################################################
95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_Print(object o, FILE *fp, int flags) except -1
105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Print an object o, on file fp. Returns -1 on error. The flags
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # argument is used to enable certain printing options. The only
125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # option currently supported is Py_PRINT_RAW; if given, the str()
135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # of the object is written instead of the repr().
145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_HasAttrString(object o, char *attr_name)
165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Returns 1 if o has the attribute attr_name, and 0
175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # otherwise. This is equivalent to the Python expression
185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "hasattr(o, attr_name)". This function always succeeds.
195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_GetAttrString(object o, char *attr_name)
215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.  Retrieve an attribute named
225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # attr_name from object o. Returns the attribute value on success,
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # or NULL on failure. This is the equivalent of the Python
245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # expression "o.attr_name".
255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_HasAttr(object o, object attr_name)
275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Returns 1 if o has the attribute attr_name, and 0
285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # otherwise. This is equivalent to the Python expression
295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "hasattr(o, attr_name)". This function always succeeds.
305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_GetAttr(object o, object attr_name)
325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.  Retrieve an attribute named
335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # attr_name from object o. Returns the attribute value on success,
345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # or NULL on failure. This is the equivalent of the Python
355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # expression "o.attr_name".
365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_SetAttrString(object o, char *attr_name, object v) except -1
385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Set the value of the attribute named attr_name, for object o, to
395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the value v. Returns -1 on failure. This is the equivalent of
405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the Python statement "o.attr_name = v".
415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_SetAttr(object o, object attr_name, object v) except -1
435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Set the value of the attribute named attr_name, for object o, to
445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the value v. Returns -1 on failure. This is the equivalent of
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the Python statement "o.attr_name = v".
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_DelAttrString(object o, char *attr_name) except -1
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Delete attribute named attr_name, for object o. Returns -1 on
495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure. This is the equivalent of the Python statement: "del
505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # o.attr_name".
515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_DelAttr(object o, object attr_name) except -1
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Delete attribute named attr_name, for object o. Returns -1 on
545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure. This is the equivalent of the Python statement "del
555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # o.attr_name".
565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_RichCompare(object o1, object o2, int opid)
605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compare the values of o1 and o2 using the operation specified by
625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # opid, which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or
635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Py_GE, corresponding to <, <=, ==, !=, >, or >=
645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # respectively. This is the equivalent of the Python expression
655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "o1 op o2", where op is the operator corresponding to
665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # opid. Returns the value of the comparison on success, or NULL on
675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure.
685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_RichCompareBool(object o1, object o2, int opid) except -1
705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compare the values of o1 and o2 using the operation specified by
715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # opid, which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or
725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Py_GE, corresponding to <, <=, ==, !=, >, or >=
735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # respectively. Returns -1 on error, 0 if the result is false, 1
745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # otherwise. This is the equivalent of the Python expression "o1
755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # op o2", where op is the operator corresponding to opid.
765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_Cmp(object o1, object o2, int *result) except -1
785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compare the values of o1 and o2 using a routine provided by o1,
795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # if one exists, otherwise with a routine provided by o2. The
805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # result of the comparison is returned in result. Returns -1 on
815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure. This is the equivalent of the Python statement "result
825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # = cmp(o1, o2)".
835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_Compare(object o1, object o2) except *
855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compare the values of o1 and o2 using a routine provided by o1,
865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # if one exists, otherwise with a routine provided by o2. Returns
875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the result of the comparison on success. On error, the value
885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # returned is undefined; use PyErr_Occurred() to detect an
895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # error. This is equivalent to the Python expression "cmp(o1,
905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # o2)".
915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Repr(object o)
935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compute a string representation of object o. Returns the string
955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # representation on success, NULL on failure. This is the
965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # equivalent of the Python expression "repr(o)". Called by the
975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # repr() built-in function and by reverse quotes.
985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Str(object o)
1005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compute a string representation of object o. Returns the string
1025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # representation on success, NULL on failure. This is the
1035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # equivalent of the Python expression "str(o)". Called by the
1045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # str() built-in function and by the print statement.
1055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Unicode(object o)
1075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compute a Unicode string representation of object o. Returns the
1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Unicode string representation on success, NULL on failure. This
1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # is the equivalent of the Python expression "unicode(o)". Called
1115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # by the unicode() built-in function.
1125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_IsInstance(object inst, object cls) except -1
1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Returns 1 if inst is an instance of the class cls or a subclass
1155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # of cls, or 0 if not. On error, returns -1 and sets an
1165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # exception. If cls is a type object rather than a class object,
1175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # PyObject_IsInstance() returns 1 if inst is of type cls. If cls
1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # is a tuple, the check will be done against every entry in
1195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # cls. The result will be 1 when at least one of the checks
1205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # returns 1, otherwise it will be 0. If inst is not a class
1215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # instance and cls is neither a type object, nor a class object,
1225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # nor a tuple, inst must have a __class__ attribute -- the class
1235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # relationship of the value of that attribute with cls will be
1245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # used to determine the result of this function.
1255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Subclass determination is done in a fairly straightforward way,
1275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # but includes a wrinkle that implementors of extensions to the
1285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # class system may want to be aware of. If A and B are class
1295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # objects, B is a subclass of A if it inherits from A either
1305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # directly or indirectly. If either is not a class object, a more
1315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # general mechanism is used to determine the class relationship of
1325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the two objects. When testing if B is a subclass of A, if A is
1335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # B, PyObject_IsSubclass() returns true. If A and B are different
1345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # objects, B's __bases__ attribute is searched in a depth-first
1355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # fashion for A -- the presence of the __bases__ attribute is
1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # considered sufficient for this determination.
1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_IsSubclass(object derived, object cls) except -1
1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Returns 1 if the class derived is identical to or derived from
1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the class cls, otherwise returns 0. In case of an error, returns
1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # -1. If cls is a tuple, the check will be done against every
1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # entry in cls. The result will be 1 when at least one of the
1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # checks returns 1, otherwise it will be 0. If either derived or
1445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # cls is not an actual class object (or tuple), this function uses
1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the generic algorithm described above. New in version
1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # 2.1. Changed in version 2.3: Older versions of Python did not
1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # support a tuple as the second argument.
1485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyCallable_Check(object o)
1505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Determine if the object o is callable. Return 1 if the object is
1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # callable and 0 otherwise. This function always succeeds.
1525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Call(object callable_object, object args, object kw)
1545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Call a callable Python object callable_object, with arguments
1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # given by the tuple args, and named arguments given by the
1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # dictionary kw. If no named arguments are needed, kw may be
1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # NULL. args must not be NULL, use an empty tuple if no arguments
1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # are needed. Returns the result of the call on success, or NULL
1605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # on failure. This is the equivalent of the Python expression
1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "apply(callable_object, args, kw)" or "callable_object(*args,
1625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # **kw)".
1635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_CallObject(object callable_object, object args)
1655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Call a callable Python object callable_object, with arguments
1675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # given by the tuple args. If no arguments are needed, then args
1685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # may be NULL. Returns the result of the call on success, or NULL
1695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # on failure. This is the equivalent of the Python expression
1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "apply(callable_object, args)" or "callable_object(*args)".
1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_CallFunction(object callable, char *format, ...)
1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Call a callable Python object callable, with a variable number
1755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # of C arguments. The C arguments are described using a
1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Py_BuildValue() style format string. The format may be NULL,
1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # indicating that no arguments are provided. Returns the result of
1785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the call on success, or NULL on failure. This is the equivalent
1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # of the Python expression "apply(callable, args)" or
1805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "callable(*args)". Note that if you only pass object  args,
1815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # PyObject_CallFunctionObjArgs is a faster alternative.
1825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_CallMethod(object o, char *method, char *format, ...)
1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Call the method named method of object o with a variable number
1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # of C arguments. The C arguments are described by a
1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Py_BuildValue() format string that should produce a tuple. The
1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # format may be NULL, indicating that no arguments are
1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # provided. Returns the result of the call on success, or NULL on
1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure. This is the equivalent of the Python expression
1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "o.method(args)". Note that if you only pass object  args,
1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # PyObject_CallMethodObjArgs is a faster alternative.
1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    #object PyObject_CallFunctionObjArgs(object callable, ..., NULL)
1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_CallFunctionObjArgs(object callable, ...)
1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Call a callable Python object callable, with a variable number
1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # of PyObject* arguments. The arguments are provided as a variable
1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # number of parameters followed by NULL. Returns the result of the
2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # call on success, or NULL on failure.
2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    #PyObject* PyObject_CallMethodObjArgs(object o, object name, ..., NULL)
2035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_CallMethodObjArgs(object o, object name, ...)
2045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Calls a method of the object o, where the name of the method is
2065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # given as a Python string object in name. It is called with a
2075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # variable number of PyObject* arguments. The arguments are
2085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # provided as a variable number of parameters followed by
2095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # NULL. Returns the result of the call on success, or NULL on
2105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure.
2115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    long PyObject_Hash(object o) except? -1
2135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Compute and return the hash value of an object o. On failure,
2145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # return -1. This is the equivalent of the Python expression
2155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "hash(o)".
2165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_IsTrue(object o) except -1
2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Returns 1 if the object o is considered to be true, and 0
2195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # otherwise. This is equivalent to the Python expression "not not
2205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # o". On failure, return -1.
2215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_Not(object o) except -1
2235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Returns 0 if the object o is considered to be true, and 1
2245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # otherwise. This is equivalent to the Python expression "not
2255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # o". On failure, return -1.
2265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Type(object o)
2285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
2295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # When o is non-NULL, returns a type object corresponding to the
2305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # object type of object o. On failure, raises SystemError and
2315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # returns NULL. This is equivalent to the Python expression
2325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # type(o). This function increments the reference count of the
2335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # return value. There's really no reason to use this function
2345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # instead of the common expression o->ob_type, which returns a
2355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # pointer of type PyTypeObject*, except when the incremented
2365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # reference count is needed.
2375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bint PyObject_TypeCheck(object o, PyTypeObject *type)
2395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return true if the object o is of type type or a subtype of
2405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # type. Both parameters must be non-NULL.
2415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    Py_ssize_t PyObject_Length(object o) except -1
2435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    Py_ssize_t PyObject_Size(object o) except -1
2445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return the length of object o. If the object o provides either
2455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the sequence and mapping protocols, the sequence length is
2465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # returned. On error, -1 is returned. This is the equivalent to
2475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the Python expression "len(o)".
2485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_GetItem(object o, object key)
2505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
2515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return element of o corresponding to the object key or NULL on
2525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # failure. This is the equivalent of the Python expression
2535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # "o[key]".
2545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_SetItem(object o, object key, object v) except -1
2565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Map the object key to the value v. Returns -1 on failure. This
2575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # is the equivalent of the Python statement "o[key] = v".
2585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_DelItem(object o, object key) except -1
2605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Delete the mapping for key from o. Returns -1 on failure. This
2615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # is the equivalent of the Python statement "del o[key]".
2625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    int PyObject_AsFileDescriptor(object o) except -1
2645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Derives a file-descriptor from a Python object. If the object is
2655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # an integer or long integer, its value is returned. If not, the
2665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # object's fileno() method is called if it exists; the method must
2675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # return an integer or long integer, which is returned as the file
2685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # descriptor value. Returns -1 on failure.
2695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Dir(object o)
2715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
2725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # This is equivalent to the Python expression "dir(o)", returning
2735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # a (possibly empty) list of strings appropriate for the object
2745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # argument, or NULL if there was an error. If the argument is
2755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # NULL, this is like the Python "dir()", returning the names of
2765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # the current locals; in this case, if no execution frame is
2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # active then NULL is returned but PyErr_Occurred() will return
2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # false.
2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_GetIter(object o)
2815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Return value: New reference.
2825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # This is equivalent to the Python expression "iter(o)". It
2835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # returns a new iterator for the object argument, or the object
2845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # itself if the object is already an iterator. Raises TypeError
2855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # and returns NULL if the object cannot be iterated.
2865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    Py_ssize_t Py_SIZE(object o)
2885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    object PyObject_Format(object obj, object format_spec)
2905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Takes an arbitrary object and returns the result of calling
2915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # obj.__format__(format_spec).
2925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    # Added in Py2.6
293