sequence.pxd 5.9 KB

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