snakeoil.struct_compat module

Minor struct enhancements, and python version compatibility implementations

In usage, instead of importing struct you should just import this module instead. It’s designed to be a drop in replacement.

class snakeoil.struct_compat.Struct[source]

Bases: Struct

Struct extension class adding read and write methods for handling files

read(fd)[source]

given file like object fd, unpack a record from it

write(fd, *args)[source]

given file like object fd, write a record from it

args must match the number of required values for this instances format; see pack() for details.

snakeoil.struct_compat.calcsize(format, /)

Return size in bytes of the struct described by the format string.

exception snakeoil.struct_compat.error

Bases: Exception

snakeoil.struct_compat.pack(format, v1, v2, ...) bytes

Return a bytes object containing the values v1, v2, … packed according to the format string. See help(struct) for more on format strings.