Teks sumber — English
Terjemahan — Bahasa Indonesia
These functions raise :exc:`TypeError` when expecting a bytes parameter and called with a non-bytes parameter.
The internal buffer of :c:type:`PyBytesObject` always includes an extra trailing null byte for compatibility with null terminated C strings. This extra byte is not counted in :c:func:`PyBytes_Size` nor in the various *length* and *size* arguments of the functions below.
This subtype of :c:type:`PyObject` represents a Python bytes object.
This instance of :c:type:`PyTypeObject` represents the Python bytes type; it is the same object as :class:`bytes` in the Python layer.
Return true if the object *o* is a bytes object or an instance of a subtype of the bytes type. This function always succeeds.
Return true if the object *o* is a bytes object, but not an instance of a subtype of the bytes type. This function always succeeds.
Use the :c:type:`PyBytesWriter` API instead of ``PyBytes_FromStringAndSize(NULL, len)``.
Take a C :c:func:`printf`\ -style *format* string and a variable number of arguments, calculate the size of the resulting Python bytes object and return a bytes object with the values formatted into it. The variable arguments must be C types and must correspond exactly to the format characters in the *format* string. The following format characters are allowed:
Type
Typ
:c:type:` Py_ssize_t`
Return a pointer to the contents of *o*. The pointer refers to the internal buffer of *o*, which consists of ``len(o) + 1`` bytes. The last byte in the buffer is always null, regardless of whether there are any other null bytes. The data must not be modified in any way, unless the object was just created using ``PyBytes_FromStringAndSize(NULL, size)``. It must not be deallocated. If *o* is not a bytes object at all, :c:func:`PyBytes_AsString` returns ``NULL`` and raises :exc:`TypeError`.
The buffer refers to an internal buffer of *obj*, which includes an additional null byte at the end (not counted in *length*). The data must not be modified in any way, unless the object was just created using ``PyBytes_FromStringAndSize(NULL, size)``. It must not be deallocated. If *obj* is not a bytes object at all, :c:func:`PyBytes_AsStringAndSize` returns ``-1`` and raises :exc:`TypeError`.
Previously, :exc:`TypeError` was raised when embedded null bytes were encountered in the bytes object.
Use the :c:type:`PyBytesWriter` API instead.
This function does not do type checking; it is undefined behavior to pass *bytes* as a non-bytes object or ``NULL``.
The :c:type:`PyBytesWriter` API can be used to create a Python :class:`bytes` object.
Create a :c:type:`PyBytesWriter` to write *size* bytes.
Finish a :c:type:`PyBytesWriter` created by :c:func:`PyBytesWriter_Create`.
Discard a :c:type:`PyBytesWriter` created by :c:func:`PyBytesWriter_Create`.
The pointer remains valid until a :c:type:`PyBytesWriter` function other than :c:func:`PyBytesWriter_GetData` or :c:func:`PyBytesWriter_GetSize` is called on *writer*.