srctools.types

This module contains various shared type definitions used by other modules.

File Protocols

Most operations acting on file objects only need a subset of the possible methods. These protocols indicate the current expected API.

abstract class srctools.types.FileR[AnyStr]

A readable file. Context manager support is expected.

read(self, data: AnyStr, /) bytes
abstract class srctools.types.FileWBinary

A writable binary file.

write(self, data: bytes | bytearray, /) ...
abstract class srctools.types.FileWText

A writable text file.

write(self, data: str, /) ...
abstract class srctools.types.FileSeek

A seekable file.

seek(self, pos: int, whence: 0 | 1 | 2 = 0, /) ...

The whence values correspond to os.SEEK_SET, SEEK_CUR and SEEK_END

tell(self, /) int

These protocols then combine the above with seekability:

abstract class srctools.types.FileRSeek[AnyStr](FileR[AnyStr], FileSeek)

Combination of FileR and FileSeek.

abstract class srctools.types.FileWBinarySeek(FileWBinary, FileSeek)

Combination of FileWBinary and FileSeek.

abstract class srctools.types.FileWTextSeek(FileWText, FileSeek)

Combination of FileWText and FileSeek.