esp_parser.types

Shared base types.

Classes:

BytesArrayRecord([iterable])

An array of bytestrings.

BytesRecordType([cstring])

Base class for bytes subrecord types.

CStringRecord([cstring])

Base class for cstring subrecord types - sequences of bytes prefixed with the size.

Collection()

Base class for collections of subrecords.

FaceGenRecord([iterable])

Sequence of uint8 for FaceGen.

Float32Record(*args, **kwargs)

Base class for float32 subrecords.

FormIDArrayRecord([iterable])

An array of 4-byte long form IDs.

FormIDRecord([cstring])

Base class for 4-byte long form ID subrecord types.

Int16Record(*args, **kwargs)

Base class for int16 subrecords.

Int32Record(*args, **kwargs)

Base class for int32 subrecords.

Int8Record(*args, **kwargs)

Base class for int8 subrecords.

IntEnum(value)

Base class for integer enums.

IntEnumField(value)

Base class for int enum fields.

MarkerRecord(*args, **kwargs)

Zero byte long marker.

RawBytesRecord([cstring])

Used for unknown structures.

Record(flags, id[, revision, version, ...])

Represents a record in an ESP file.

RecordType

Base class for records in ESP files.

StructRecord()

Base class for records in ESP files.

Uint16Record(*args, **kwargs)

Base class for uint16 subrecords.

Uint32Record(*args, **kwargs)

Base class for uint32 subrecords.

Uint8Record(*args, **kwargs)

Base class for uint8 subrecords.

class BytesArrayRecord(iterable=(), /)[source]

Bases: List[bytes], RecordType

An array of bytestrings.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class BytesRecordType(cstring: Union[str, bytes] = b'')[source]

Bases: RecordType, bytes

Base class for bytes subrecord types.

Subclasses are responsible for parsing and unparsing.

class CStringRecord(cstring: Union[str, bytes] = b'')[source]

Bases: BytesRecordType

Base class for cstring subrecord types - sequences of bytes prefixed with the size.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Collection[source]

Bases: object

Base class for collections of subrecords.

Attributes:

members

Names of subrecords in this collection.

Methods:

parse_member(record_type, raw_bytes)

Parse subrecords in this collection.

members

Type:    Set[bytes]

Names of subrecords in this collection.

classmethod parse_member(record_type, raw_bytes)[source]

Parse subrecords in this collection.

Parameters
  • record_type (bytes)

  • raw_bytes (BytesIO) – Raw bytes for this record’s subrecords

Return type

RecordType

class FaceGenRecord(iterable=(), /)[source]

Bases: List

Sequence of uint8 for FaceGen.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Float32Record(*args, **kwargs)[source]

Bases: RecordType, float

Base class for float32 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class FormIDArrayRecord(iterable=(), /)[source]

Bases: BytesArrayRecord

An array of 4-byte long form IDs.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class FormIDRecord(cstring: Union[str, bytes] = b'')[source]

Bases: BytesRecordType

Base class for 4-byte long form ID subrecord types.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Int16Record(*args, **kwargs)[source]

Bases: RecordType, int

Base class for int16 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Int32Record(*args, **kwargs)[source]

Bases: RecordType, int

Base class for int32 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Int8Record(*args, **kwargs)[source]

Bases: RecordType, int

Base class for int8 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class IntEnum(value)[source]

Bases: IntEnum

Base class for integer enums.

class IntEnumField(value)[source]

Bases: IntEnum

Base class for int enum fields.

class MarkerRecord(*args, **kwargs)[source]

Bases: RecordType

Zero byte long marker.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class RawBytesRecord(cstring: Union[str, bytes] = b'')[source]

Bases: BytesRecordType

Used for unknown structures.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Record(flags, id, revision=0, version=15, unknown=b'\x00\x00', data=[])[source]

Bases: RecordType

Represents a record in an ESP file.

Parameters
  • flags (int) – Record flags

  • id (bytes) – 4-byte form ID

  • revision (int) – Used for revision control by the Creation Kit, if enabled. Default 0.

  • version (int) – Form version . Default 15.

  • unknown (bytes) – Default b'\x00\x00'.

  • data (List[RecordType]) – Subrecords of this record. Default [].

Attributes:

data

Subrecords of this record.

flags

Record flags

id

4-byte form ID

revision

Used for revision control by the Creation Kit, if enabled.

unknown

version

Form version

Methods:

parse(raw_bytes)

Parse this record.

parse_subrecords(raw_bytes)

Parse this record's subrecords.

unparse()

Turn this record back into raw bytes for an ESP file.

data

Type:    List[RecordType]

Subrecords of this record.

flags

Type:    int

Record flags

id

Type:    bytes

4-byte form ID

classmethod parse(raw_bytes)[source]

Parse this record.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

static parse_subrecords(raw_bytes)[source]

Parse this record’s subrecords.

Must be implemented in subclasses.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record’s subrecords

Return type

Iterator[RecordType]

revision

Type:    int

Used for revision control by the Creation Kit, if enabled.

unknown

Type:    bytes

unparse()[source]

Turn this record back into raw bytes for an ESP file.

Return type

bytes

version

Type:    int

Form version

protocol RecordType[source]

Bases: Protocol

Base class for records in ESP files.

Classes that implement this protocol must have the following methods / attributes:

__attrs_post_init__()[source]
__repr__()[source]

Return repr(self).

Return type

str

abstract unparse()[source]

Turn this record back into raw bytes for an ESP file.

Return type

bytes

class StructRecord[source]

Bases: RecordType

Base class for records in ESP files.

Methods:

get_field_names()

Returns a list of attributes on this class in the order they should be packed.

get_struct_and_size()

Returns the pack/unpack struct string and the corresponding size.

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this record back into raw bytes for an ESP file.

abstract static get_field_names()[source]

Returns a list of attributes on this class in the order they should be packed.

Return type

Tuple[str, …]

abstract static get_struct_and_size()[source]

Returns the pack/unpack struct string and the corresponding size.

Return type

Tuple[str, int]

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this record back into raw bytes for an ESP file.

Return type

bytes

class Uint16Record(*args, **kwargs)[source]

Bases: RecordType, int

Base class for uint16 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Uint32Record(*args, **kwargs)[source]

Bases: RecordType, int

Base class for uint32 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes

class Uint8Record(*args, **kwargs)[source]

Bases: RecordType, int

Base class for uint8 subrecords.

Methods:

parse(raw_bytes)

Parse this subrecord.

unparse()

Turn this subrecord back into raw bytes for an ESP file.

classmethod parse(raw_bytes)[source]

Parse this subrecord.

Parameters

raw_bytes (BytesIO) – Raw bytes for this record

Return type

Self

unparse()[source]

Turn this subrecord back into raw bytes for an ESP file.

Return type

bytes