mex.common.assets package

Submodules

mex.common.assets.base module

class mex.common.assets.base.BaseAssetsConnector

Bases: BaseConnector

Base class for assets connectors that handle file loading.

abstractmethod glob(path: str, pattern: str) list[str]

Return the list of file names from a given path.

Parameters:
  • path – The path pointing to the file to read

  • pattern – pattern to match

Returns:

List of file names

Raises:

PermissionError – For file access permission issues

abstractmethod read(path: str) bytes

Read a file from the given path and return bytes.

Parameters:

path – The path pointing to the file to read

Returns:

The file contents as bytes

Raises:

PermissionError – For file access permission issues

mex.common.assets.filesystem module

class mex.common.assets.filesystem.FilesystemAssetsConnector

Bases: BaseAssetsConnector

Filesystem-based implementation of assets connector.

__init__() None

Create a new connector instance.

_resolve_path_and_check_permission(path: str) Path

Resolve a path and check whether path is permitted.

Parameters:

path – The path pointing to the file to load

Returns:

resolved path

Raises:

PermissionError – For file access permission issues

close() None

Nothing to close for filesystem access.

glob(path: str, pattern: str) list[str]

Return the list of file names from a given path from the file system.

Parameters:
  • path – The path pointing to the file to read

  • pattern – pattern to match

Returns:

List of file names

Raises:

PermissionError – For file access permission issues

read(path: str) bytes

Read a file from the filesystem.

Parameters:

path – The path pointing to the file to load

Returns:

The file contents as bytes

Raises:

PermissionError – For file access permission issues

mex.common.assets.registry module

mex.common.assets.registry.get_assets_connector() BaseAssetsConnector

Get an instance of the assets connector as configured by assets_connector.

Raises:

RuntimeError – When the configured connector is not registered

Returns:

An instance of a subclass of BaseAssetsConnector

mex.common.assets.registry.register_assets_connector(key: AssetsConnectorType, connector_cls: type[BaseAssetsConnector]) None

Register an implementation of an assets connector to a settings key.

Parameters:
  • key – Possible value of BaseSettings.assets_connector

  • connector_cls – Implementation of an assets connector

Raises:

RuntimeError – When the key is already registered

Module contents

class mex.common.assets.BaseAssetsConnector

Bases: BaseConnector

Base class for assets connectors that handle file loading.

abstractmethod glob(path: str, pattern: str) list[str]

Return the list of file names from a given path.

Parameters:
  • path – The path pointing to the file to read

  • pattern – pattern to match

Returns:

List of file names

Raises:

PermissionError – For file access permission issues

abstractmethod read(path: str) bytes

Read a file from the given path and return bytes.

Parameters:

path – The path pointing to the file to read

Returns:

The file contents as bytes

Raises:

PermissionError – For file access permission issues

class mex.common.assets.FilesystemAssetsConnector

Bases: BaseAssetsConnector

Filesystem-based implementation of assets connector.

__init__() None

Create a new connector instance.

_resolve_path_and_check_permission(path: str) Path

Resolve a path and check whether path is permitted.

Parameters:

path – The path pointing to the file to load

Returns:

resolved path

Raises:

PermissionError – For file access permission issues

close() None

Nothing to close for filesystem access.

glob(path: str, pattern: str) list[str]

Return the list of file names from a given path from the file system.

Parameters:
  • path – The path pointing to the file to read

  • pattern – pattern to match

Returns:

List of file names

Raises:

PermissionError – For file access permission issues

read(path: str) bytes

Read a file from the filesystem.

Parameters:

path – The path pointing to the file to load

Returns:

The file contents as bytes

Raises:

PermissionError – For file access permission issues

mex.common.assets.get_assets_connector() BaseAssetsConnector

Get an instance of the assets connector as configured by assets_connector.

Raises:

RuntimeError – When the configured connector is not registered

Returns:

An instance of a subclass of BaseAssetsConnector

mex.common.assets.register_assets_connector(key: AssetsConnectorType, connector_cls: type[BaseAssetsConnector]) None

Register an implementation of an assets connector to a settings key.

Parameters:
  • key – Possible value of BaseSettings.assets_connector

  • connector_cls – Implementation of an assets connector

Raises:

RuntimeError – When the key is already registered