[2] | 1 | .. highlightlang:: c
|
---|
| 2 |
|
---|
| 3 | .. _bytearrayobjects:
|
---|
| 4 |
|
---|
| 5 | Byte Array Objects
|
---|
| 6 | ------------------
|
---|
| 7 |
|
---|
| 8 | .. index:: object: bytearray
|
---|
| 9 |
|
---|
| 10 | .. versionadded:: 2.6
|
---|
| 11 |
|
---|
| 12 |
|
---|
[391] | 13 | .. c:type:: PyByteArrayObject
|
---|
[2] | 14 |
|
---|
[391] | 15 | This subtype of :c:type:`PyObject` represents a Python bytearray object.
|
---|
[2] | 16 |
|
---|
| 17 |
|
---|
[391] | 18 | .. c:var:: PyTypeObject PyByteArray_Type
|
---|
[2] | 19 |
|
---|
[391] | 20 | This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
|
---|
[2] | 21 | it is the same object as ``bytearray`` in the Python layer.
|
---|
| 22 |
|
---|
| 23 | Type check macros
|
---|
| 24 | ^^^^^^^^^^^^^^^^^
|
---|
| 25 |
|
---|
[391] | 26 | .. c:function:: int PyByteArray_Check(PyObject *o)
|
---|
[2] | 27 |
|
---|
| 28 | Return true if the object *o* is a bytearray object or an instance of a
|
---|
| 29 | subtype of the bytearray type.
|
---|
| 30 |
|
---|
| 31 |
|
---|
[391] | 32 | .. c:function:: int PyByteArray_CheckExact(PyObject *o)
|
---|
[2] | 33 |
|
---|
| 34 | Return true if the object *o* is a bytearray object, but not an instance of a
|
---|
| 35 | subtype of the bytearray type.
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | Direct API functions
|
---|
| 39 | ^^^^^^^^^^^^^^^^^^^^
|
---|
| 40 |
|
---|
[391] | 41 | .. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
|
---|
[2] | 42 |
|
---|
| 43 | Return a new bytearray object from any object, *o*, that implements the
|
---|
| 44 | buffer protocol.
|
---|
| 45 |
|
---|
| 46 | .. XXX expand about the buffer protocol, at least somewhere
|
---|
| 47 |
|
---|
| 48 |
|
---|
[391] | 49 | .. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
|
---|
[2] | 50 |
|
---|
| 51 | Create a new bytearray object from *string* and its length, *len*. On
|
---|
| 52 | failure, *NULL* is returned.
|
---|
| 53 |
|
---|
| 54 |
|
---|
[391] | 55 | .. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
|
---|
[2] | 56 |
|
---|
| 57 | Concat bytearrays *a* and *b* and return a new bytearray with the result.
|
---|
| 58 |
|
---|
| 59 |
|
---|
[391] | 60 | .. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
|
---|
[2] | 61 |
|
---|
| 62 | Return the size of *bytearray* after checking for a *NULL* pointer.
|
---|
| 63 |
|
---|
| 64 |
|
---|
[391] | 65 | .. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
|
---|
[2] | 66 |
|
---|
| 67 | Return the contents of *bytearray* as a char array after checking for a
|
---|
| 68 | *NULL* pointer.
|
---|
| 69 |
|
---|
| 70 |
|
---|
[391] | 71 | .. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
|
---|
[2] | 72 |
|
---|
| 73 | Resize the internal buffer of *bytearray* to *len*.
|
---|
| 74 |
|
---|
| 75 | Macros
|
---|
| 76 | ^^^^^^
|
---|
| 77 |
|
---|
| 78 | These macros trade safety for speed and they don't check pointers.
|
---|
| 79 |
|
---|
[391] | 80 | .. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
|
---|
[2] | 81 |
|
---|
[391] | 82 | Macro version of :c:func:`PyByteArray_AsString`.
|
---|
[2] | 83 |
|
---|
| 84 |
|
---|
[391] | 85 | .. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
|
---|
[2] | 86 |
|
---|
[391] | 87 | Macro version of :c:func:`PyByteArray_Size`.
|
---|