pyctr.type.base.typereader module

pyctr.type.base.typereader.raise_if_closed(method)[source]

Wraps a method that raises an exception if the reader object is closed.

Parameters:

method – The method to call if the file is not closed.

Returns:

The wrapper method.

exception pyctr.type.base.typereader.ReaderError[source]

Bases: PyCTRError

Generic error for TypeReaderBase operations.

exception pyctr.type.base.typereader.ReaderClosedError[source]

Bases: ReaderError

The reader object is closed.

class pyctr.type.base.typereader.TypeReaderBase(file, *, fs=None, closefd=None, mode='rb')[source]

Bases: object

Base class for all reader classes.

This handles types that are based in a single file. Therefore not every class will use this, such as SDFilesystem.

Parameters:
  • file (FilePathOrObject) – A file path or a file-like object with the type’s data.

  • closefd (bool | None) – Close the underlying file object when closed. Defaults to True for file paths, and False for file-like objects.

  • mode (str) – Mode to open the file with, passed to open. This is set by type readers internally. Only used if a file path was given.

  • fs (FS | None)

closed: bool

True if the reader is closed.

close()[source]

Close the reader. If closefd is True, the underlying file is also closed.

class pyctr.type.base.typereader.TypeReaderCryptoBase(file, *, fs=None, closefd=None, mode='rb', crypto=None, dev=False)[source]

Bases: TypeReaderBase

Base class for reader classes that use a CryptoEngine object..

Parameters:
  • file (FilePathOrObject) – A file path or a file-like object with the type’s data.

  • closefd (bool) – Close the underlying file object when closed. Defaults to True for file paths, and False for file-like objects.

  • crypto (CryptoEngine) – A custom crypto.CryptoEngine object to be used. Defaults to None, which causes a new one to be created. This typically only works directly on the type, not any subtypes that might be created (e.g. CIAReader creates NCCHReader).

  • dev (bool) – Use devunit keys.

  • mode (str) – Mode to open the file with, passed to open. This is set by type readers internally. Only used if a file path was given.

  • fs (FS | None)