3.6. State Objects#
-
PyTypeObject CpState_Type#
The type object for the
CpStateObject
class.
-
type CpStateObject#
A special class that conforms to the Context protocol used in C packing and unpacking functions.
It is meant to be a replacement to the Python Context class as it solves a few problems. For instance, there may be global variables passed to the unpack function. Instead of copying them into every parsing layer, we just store them in the state object. The state is meant to be accessible from any layer in the parsing process.
-
int CpState_CheckExact(PyObject *op)#
Checks if the given object is an
CpStateObject
.
-
int CpState_Check(PyObject *op)#
Checks if the given object is instance of an
CpStateObject
-
CpStateObject *CpState_New(PyObject *io)#
- Return value: Always NULL.
Creates a new state and returns it. Returns NULL if an error occurs.
-
PyObject *CpState_Tell(CpStateObject *state)#
- Return value: New reference.
Returns the current position of the state. Returns NULL if an error occurs.
-
PyObject *CpState_Seek(CpStateObject *state, Py_ssize_t pos, PyObject whence)#
- Return value: New reference.
Seeks to the given position. Returns
0
if successful. Returns-1
if an error occurs.
-
PyObject *CpState_Read(CpStateObject *state, Py_ssize_t size)#
- Return value: New reference.
Reads the given number of bytes. Returns NULL if an error occurs. This function will verify the amount of bytes read from the stream.
-
PyObject *CpState_ReadFully(CpStateObject *state)#
- Return value: New reference.
Reads the entire stream. Returns NULL if an error occurs.
-
PyObject *CpState_Write(CpStateObject *state, PyObject *bytes)#
- Return value: New reference.
Writes the given bytes to the stream. Returns NULL if an error occurs.
-
int CpState_SetGlobals(CpStateObject *state, PyObject *globals)#
Sets the global namespace for pre-defined context variables. Returns
0
if successful and-1
if an error occurs.