OLD | NEW |
(Empty) | |
| 1 from cpython.ref cimport PyObject |
| 2 |
| 3 cdef extern from "Python.h": |
| 4 |
| 5 ############################################################################ |
| 6 # 6.3 Sequence Protocol |
| 7 ############################################################################ |
| 8 |
| 9 bint PySequence_Check(object o) |
| 10 # Return 1 if the object provides sequence protocol, and 0 |
| 11 # otherwise. This function always succeeds. |
| 12 |
| 13 Py_ssize_t PySequence_Size(object o) except -1 |
| 14 # Returns the number of objects in sequence o on success, and -1 |
| 15 # on failure. For objects that do not provide sequence protocol, |
| 16 # this is equivalent to the Python expression "len(o)". |
| 17 |
| 18 Py_ssize_t PySequence_Length(object o) except -1 |
| 19 # Alternate name for PySequence_Size(). |
| 20 |
| 21 object PySequence_Concat(object o1, object o2) |
| 22 # Return value: New reference. |
| 23 # Return the concatenation of o1 and o2 on success, and NULL on |
| 24 # failure. This is the equivalent of the Python expression "o1 + |
| 25 # o2". |
| 26 |
| 27 object PySequence_Repeat(object o, Py_ssize_t count) |
| 28 # Return value: New reference. |
| 29 # Return the result of repeating sequence object o count times, or |
| 30 # NULL on failure. This is the equivalent of the Python expression |
| 31 # "o * count". |
| 32 |
| 33 object PySequence_InPlaceConcat(object o1, object o2) |
| 34 # Return value: New reference. |
| 35 # Return the concatenation of o1 and o2 on success, and NULL on |
| 36 # failure. The operation is done in-place when o1 supports |
| 37 # it. This is the equivalent of the Python expression "o1 += o2". |
| 38 |
| 39 object PySequence_InPlaceRepeat(object o, Py_ssize_t count) |
| 40 # Return value: New reference. |
| 41 # Return the result of repeating sequence object o count times, or |
| 42 # NULL on failure. The operation is done in-place when o supports |
| 43 # it. This is the equivalent of the Python expression "o *= |
| 44 # count". |
| 45 |
| 46 object PySequence_GetItem(object o, Py_ssize_t i) |
| 47 # Return value: New reference. |
| 48 # Return the ith element of o, or NULL on failure. This is the |
| 49 # equivalent of the Python expression "o[i]". |
| 50 |
| 51 object PySequence_GetSlice(object o, Py_ssize_t i1, Py_ssize_t i2) |
| 52 # Return value: New reference. |
| 53 # Return the slice of sequence object o between i1 and i2, or NULL |
| 54 # on failure. This is the equivalent of the Python expression |
| 55 # "o[i1:i2]". |
| 56 |
| 57 int PySequence_SetItem(object o, Py_ssize_t i, object v) except -1 |
| 58 # Assign object v to the ith element of o. Returns -1 on |
| 59 # failure. This is the equivalent of the Python statement "o[i] = |
| 60 # v". This function does not steal a reference to v. |
| 61 |
| 62 int PySequence_DelItem(object o, Py_ssize_t i) except -1 |
| 63 # Delete the ith element of object o. Returns -1 on failure. This |
| 64 # is the equivalent of the Python statement "del o[i]". |
| 65 |
| 66 int PySequence_SetSlice(object o, Py_ssize_t i1, Py_ssize_t i2, object v) ex
cept -1 |
| 67 # Assign the sequence object v to the slice in sequence object o |
| 68 # from i1 to i2. This is the equivalent of the Python statement |
| 69 # "o[i1:i2] = v". |
| 70 |
| 71 int PySequence_DelSlice(object o, Py_ssize_t i1, Py_ssize_t i2) except -1 |
| 72 # Delete the slice in sequence object o from i1 to i2. Returns -1 |
| 73 # on failure. This is the equivalent of the Python statement "del |
| 74 # o[i1:i2]". |
| 75 |
| 76 int PySequence_Count(object o, object value) except -1 |
| 77 # Return the number of occurrences of value in o, that is, return |
| 78 # the number of keys for which o[key] == value. On failure, return |
| 79 # -1. This is equivalent to the Python expression |
| 80 # "o.count(value)". |
| 81 |
| 82 int PySequence_Contains(object o, object value) except -1 |
| 83 # Determine if o contains value. If an item in o is equal to |
| 84 # value, return 1, otherwise return 0. On error, return -1. This |
| 85 # is equivalent to the Python expression "value in o". |
| 86 |
| 87 Py_ssize_t PySequence_Index(object o, object value) except -1 |
| 88 # Return the first index i for which o[i] == value. On error, |
| 89 # return -1. This is equivalent to the Python expression |
| 90 # "o.index(value)". |
| 91 |
| 92 object PySequence_List(object o) |
| 93 # Return value: New reference. |
| 94 # Return a list object with the same contents as the arbitrary |
| 95 # sequence o. The returned list is guaranteed to be new. |
| 96 |
| 97 object PySequence_Tuple(object o) |
| 98 # Return value: New reference. |
| 99 # Return a tuple object with the same contents as the arbitrary |
| 100 # sequence o or NULL on failure. If o is a tuple, a new reference |
| 101 # will be returned, otherwise a tuple will be constructed with the |
| 102 # appropriate contents. This is equivalent to the Python |
| 103 # expression "tuple(o)". |
| 104 |
| 105 object PySequence_Fast(object o, char *m) |
| 106 # Return value: New reference. |
| 107 # Returns the sequence o as a tuple, unless it is already a tuple |
| 108 # or list, in which case o is returned. Use |
| 109 # PySequence_Fast_GET_ITEM() to access the members of the |
| 110 # result. Returns NULL on failure. If the object is not a |
| 111 # sequence, raises TypeError with m as the message text. |
| 112 |
| 113 PyObject* PySequence_Fast_GET_ITEM(object o, Py_ssize_t i) |
| 114 # Return value: Borrowed reference. |
| 115 # Return the ith element of o, assuming that o was returned by |
| 116 # PySequence_Fast(), o is not NULL, and that i is within bounds. |
| 117 |
| 118 PyObject** PySequence_Fast_ITEMS(object o) |
| 119 # Return the underlying array of PyObject pointers. Assumes that o |
| 120 # was returned by PySequence_Fast() and o is not NULL. |
| 121 |
| 122 object PySequence_ITEM(object o, Py_ssize_t i) |
| 123 # Return value: New reference. |
| 124 # Return the ith element of o or NULL on failure. Macro form of |
| 125 # PySequence_GetItem() but without checking that |
| 126 # PySequence_Check(o) is true and without adjustment for negative |
| 127 # indices. |
| 128 |
| 129 Py_ssize_t PySequence_Fast_GET_SIZE(object o) |
| 130 # Returns the length of o, assuming that o was returned by |
| 131 # PySequence_Fast() and that o is not NULL. The size can also be |
| 132 # gotten by calling PySequence_Size() on o, but |
| 133 # PySequence_Fast_GET_SIZE() is faster because it can assume o is |
| 134 # a list or tuple. |
| 135 |
| 136 |
OLD | NEW |