UTF Tables

class PyCriCodecsEx.utf.UTF(stream: str | BinaryIO, recursive=False)[source]

Bases: object

Use this class to unpack @UTF table binary payload.

__init__(stream: str | BinaryIO, recursive=False)[source]

Unpacks UTF table binary payload

Parameters:
  • stream (Union[str | BinaryIO]) – The input stream or file path to read the UTF table from.

  • recursive (bool) – Whether to recursively unpack nested UTF tables.

property dictarray: list[dict]

Returns a list representation of the UTF table.

property table: dict

Returns a dictionary representation of the UTF table.

Effectively, this retrieves a transposed version of the dictarray. Whilst discarding type info.

This is mostly here for cpk.py compatibility.

class PyCriCodecsEx.utf.UTFBuilder(dictarray_src: list[dict], encrypt: bool = False, encoding: str = 'utf-8', table_name: str = 'PyCriCodecs_table', ignore_recursion: bool = False)[source]

Bases: object

Use this class to build UTF table binary payloads from a dictarray.

__init__(dictarray_src: list[dict], encrypt: bool = False, encoding: str = 'utf-8', table_name: str = 'PyCriCodecs_table', ignore_recursion: bool = False) None[source]

Packs UTF payload back into their binary form

Parameters:
  • dictarray_src – list[dict]: A list of dictionaries representing the UTF table.

  • encrypt – Whether to encrypt the table (default: False).

  • encoding – The character encoding to use (default: “utf-8”).

  • table_name – The name of the table (default: “PyCriCodecs_table”).

  • ignore_recursion – Whether to ignore recursion when packing (default: False).

bytes() bytearray[source]

Returns a @UTF bytearray Table from the provided payload dict.

class PyCriCodecsEx.utf.UTFViewer(payload: list | dict, **args)[source]

Bases: object

Use this class to create dataclass-like access to `dictarray`s.

class ListView(clazz: Type[Ty], payload: list[Ty])[source]

Bases: list

__init__(clazz: Type[Ty], payload: list[Ty])[source]
append(o: UTFViewer)[source]

Append object to the end of the list.

clear()[source]

Remove all items from list.

count(value)[source]

Return number of occurrences of value.

extend(iterable)[source]

Extend list by appending elements from the iterable.

insert(index, o: UTFViewer)[source]

Insert object before index.

pop(index=-1)[source]

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value)[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

sort(key: callable)[source]

Sort the list in ascending order and return None.

The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).

If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.

The reverse flag can be set to sort in descending order.

__init__(payload)[source]

Construct a non-owning read-write, deletable view of a UTF table dictarray.

Nested classes are supported.

Sorting (using .sort()) is done in-place and affects the original payload.