picop.buffers#

Category facade: bytes / bytearray / array / memoryview / buffer / slice.

Typed buffer-adjacent Core helpers. Prefer bytes_len / bytes_contains / bytes_eq from picop.hot for the common bytes hot path. See Safety for borrowed C-string footguns.

picop.buffers.bytes_check(p)#

Return True if p is bytes or a subtype (PyBytes_Check). :type p: object :param p:

Return type:

bool

picop.buffers.bytes_check_exact(p)#

Return True if type(p) is bytes (PyBytes_CheckExact). :type p: object :param p:

Return type:

bool

picop.buffers.bytes_len(b)#

Return len(b) via PyBytes_GET_SIZE. :type b: bytes :param b:

Return type:

int

picop.buffers.bytes_size(b)#

Return len(b) via checked PyBytes_Size.

Notes

Prefer bytes_len on a typed bytes hot path.

Parameters:

b (object)

Return type:

int

picop.buffers.bytes_contains(haystack, needle)#

Return True if needle is in haystack.

Notes

Uses memchr/memmem under 256B, else the builtin in path.

Parameters:
Return type:

bool

picop.buffers.bytes_bytearray_eq(a, b)#

Return True if bytes/bytearray contents match.

Notes

Either argument order is accepted; compares with memcmp after a length gate.

Parameters:
Return type:

bool

picop.buffers.bytes_eq(a, b)#

Return True if a == b.

Notes

Identity/len short-circuit plus memcmp on typed bytes.

Parameters:
Return type:

bool

picop.buffers.bytes_ne(a, b)#

Return True if a != b (inverse of bytes_eq). :type a: bytes :param a: :type b: bytes :param b:

Return type:

bool

picop.buffers.bytes_startswith(s, prefix)#

Return True if typed s begins with prefix.

Notes

Length gate plus memcmp on the typed prefix region.

Parameters:
Return type:

bool

picop.buffers.bytes_endswith(s, suffix)#

Return True if typed s ends with suffix.

Notes

Length gate plus tail memcmp on the typed suffix region.

Parameters:
Return type:

bool

picop.buffers.bytearray_check(p)#

Return True if p is a bytearray or subtype (PyByteArray_Check). :type p: object :param p:

Return type:

bool

picop.buffers.bytearray_check_exact(p)#

Return True if type(p) is bytearray (PyByteArray_CheckExact). :type p: object :param p:

Return type:

bool

picop.buffers.bytearray_eq(a, b)#

Return True if typed bytearray values are equal.

Notes

Identity/len short-circuit plus memcmp.

Parameters:
Return type:

bool

picop.buffers.bytearray_ne(a, b)#

Return True if typed bytearray values differ (not bytearray_eq). :type a: bytearray :param a: :type b: bytearray :param b:

Return type:

bool

picop.buffers.bytearray_contains(haystack, needle)#

Return True if needle is found in typed haystack.

Notes

Mirrors bytes_contains search strategy on a typed bytearray.

Parameters:
Return type:

bool

picop.buffers.bytearray_len(ba)#

Return len(ba) via PyByteArray_GET_SIZE. :type ba: bytearray :param ba:

Return type:

int

picop.buffers.bytearray_size(ba)#

Return len(ba) via checked PyByteArray_Size.

Notes

Prefer bytearray_len on a typed bytearray hot path.

Parameters:

ba (object)

Return type:

int

picop.buffers.array_check(p)#

Return True if p is an array.array (isinstance). :type p: object :param p:

Return type:

bool

picop.buffers.array_check_exact(p)#

Return True if type(p) is array.array. :type p: object :param p:

Return type:

bool

picop.buffers.array_eq(a, b)#

Return True if typed array.array values are equal.

Notes

Compares typecode/len then memcmp.

Parameters:
Return type:

bool

picop.buffers.array_ne(a, b)#

Return True if typed array.array values differ (not array_eq). :type a: array :param a: :type b: array :param b:

Return type:

bool

picop.buffers.array_len(a)#

Return len(a) via Py_SIZE. :type a: array :param a:

Return type:

int

picop.buffers.array_clone(template, length, zero=True)#

Return a new array like template with length items.

Notes

Optionally zero-fills the new buffer when zero is true.

Parameters:
Return type:

array

picop.buffers.array_zero(a)#

Zero all elements of a via memset.

Notes

Returns 0 on success; errors raise. Do not use the status int as a bool.

Parameters:

a (array)

Return type:

int

picop.buffers.memoryview_check(p)#

Return True if p is a memoryview (PyMemoryView_Check). :type p: object :param p:

Return type:

bool

picop.buffers.memoryview_eq(a, b)#

Return True if views are equal.

Notes

C-contiguous buffers use a memcmp fast path; otherwise falls back to richcompare.

Parameters:
Return type:

bool

picop.buffers.memoryview_ne(a, b)#

Return True if views differ.

Notes

Inverse of memoryview_eq; same contig/richcompare rules.

Parameters:
Return type:

bool

picop.buffers.memoryview_from_object(obj)#

Return memoryview(obj) via PyMemoryView_FromObject. :type obj: object :param obj:

Return type:

memoryview

picop.buffers.buf_check(obj)#

Return True if obj supports the buffer protocol (PyObject_CheckBuffer). :type obj: object :param obj:

Return type:

bool

picop.buffers.buf_eq(a, b)#

Return True if buffer-protocol views are equal.

Notes

C-contiguous buffers use memcmp; otherwise memoryview richcompare. Format/size mismatch yields False.

Parameters:
Return type:

bool

picop.buffers.slice_check(p)#

Return True if p is a slice (PySlice_Check). :type p: object :param p:

Return type:

bool

picop.buffers.slice_eq(a, b)#

Return True if slices are equal.

Notes

Identity short-circuit plus richcompare.

Parameters:
Return type:

bool

picop.buffers.slice_new(start=None, stop=None, step=None)#

Return slice(start, stop, step) via PySlice_New. :type start: object, default: None :param start: :type stop: object, default: None :param stop: :type step: object, default: None :param step:

Return type:

slice