class documentation

Parser for var file headers

All var files require a header which includes a number of magic bytes, data lengths, and a customizable comment.

Class Raw Raw bytes container for TIHeader
Class Method open Creates a new header from a file given a filename
Method __bytes__ No summary
Method __copy__ No summary
Method __eq__ Determines if two headers have the same bytes
Method __init__ Creates an empty header which targets a specified model
Method __len__ No summary
Method __or__ Constructs a var by concatenating this header with a list of entries
Method bytes No summary
Method comment The comment attached to the var
Method extra Extra export bytes for the var
Method load_bytes Loads a byte string or bytestream into the header
Method load_from_file Loads this header from a file given a file pointer
Method magic The file magic for the var
Method product_id The product ID for the var
Method targets Determines which model(s) this header can target
Instance Variable raw Undocumented
@classmethod
def open(cls, filename: str) -> TIHeader: (source)

Creates a new header from a file given a filename

Parameters
filename:strA filename to open
Returns
TIHeaderThe header stored in the file
def __bytes__(self) -> bytes: (source)
Returns
bytesThe bytes contained in this header
def __copy__(self) -> TIHeader: (source)
Returns
TIHeaderA copy of this header
def __eq__(self, other: TIHeader) -> bool: (source)

Determines if two headers have the same bytes

Parameters
other:TIHeaderThe header to check against
Returns
boolWhether this header is equal to other
def __init__(self, model: TIModel = None, *, magic: str = None, extra: bytes = b'\x1a\n', product_id: int = None, comment: str = 'Created with tivars_lib_py v0.9.2', data: bytes = None): (source)

Creates an empty header which targets a specified model

Parameters
model:TIModelA minimum TIModel to target (defaults to TI_83P)
magic:strFile magic at the start of the header (default to the model's magic)
extra:bytesExtra export bytes for the header (defaults to $1a0a)
product_id:intThe targeted model's product ID (defaults to $00)
comment:strA comment to include in the header (defaults to a simple lib message)
data:bytesThis header's data (defaults to empty)
def __len__(self) -> int: (source)
Returns
intThe total length of this header's bytes
def __or__(self, other: list[TIEntry]) -> TIVar: (source)

Constructs a var by concatenating this header with a list of entries

Parameters
other:list[TIEntry]A list of entries to place into the var
Returns
TIVarA var with this header and other as its entries
def bytes(self) -> bytes: (source)
Returns
bytesThe bytes contained in this header
@Section(42, String)
def comment(self) -> str: (source)

The comment attached to the var

@Section(2)
def extra(self) -> bytes: (source)

Extra export bytes for the var

The exact meaning and interpretation of these bytes is not yet determined. These bytes are set by different export tools and can often be "incorrect" without causing issues.

def load_bytes(self, data: bytes | BytesIO): (source)

Loads a byte string or bytestream into the header

Parameters
data:bytes | BytesIOThe source bytes
def load_from_file(self, file: BinaryIO): (source)

Loads this header from a file given a file pointer

Parameters
file:BinaryIOA binary file to read from
@Section(8, String)
def magic(self) -> str: (source)

The file magic for the var

@Section(1, Bits[:])
def product_id(self) -> int: (source)

The product ID for the var

While used to identify the model the var was created on, it has no actual functional ramifications. Furthermore, it does not constitute a 1-to-1 mapping to distinct models.

def targets(self) -> set[TIModel]: (source)

Determines which model(s) this header can target

The header contains no reference to a model to target, which permits sharing across models where possible. This method derives a set of valid models from the header's file magic and product ID.

If the header contains malformed magic, an error will be raised. If the header contains a malformed product ID, it will be ignored.

Returns
set[TIModel]A set of models that this header can target

Undocumented