Dynamic Loading Module

action_triggers.dynamic_loading.get_path_result(path: str) Any[source]

Get the result of a path.

Parameters:

path – The path to import from in the format module.submodule.attr.

Returns:

The imported object.

action_triggers.dynamic_loading.replace_dict_values_with_results(dictionary: dict, opener: str = '{{', closer: str = '}}') dict[source]

Recursively all instances of {{ path }} in the values of a dictionary with the result of the path.

Parameters:
  • dictionary – The dictionary to replace the paths in.

  • opener – The opener of the path.

  • closer – The closer of the path.

Returns:

The dictionary with the paths replaced.

action_triggers.dynamic_loading.replace_string_with_result(string: str, opener: str = '{{', closer: str = '}}') str[source]

Replace all instances of {{ path }} in a string with the result of the path.

Parameters:
  • string – The string to replace the paths in.

  • opener – The opener of the path.

  • closer – The closer of the path.

Returns:

The string with the paths replaced.

action_triggers.dynamic_loading.restricted_import_string(path: str) Any[source]

A restricted version of import_string that only allows importing from any path that has been defined in settings.ACTION_TRIGGER_SETTINGS.ALLOWED_DYNAMIC_IMPORT_PATHS.

This is to prevent arbitrary code execution via dynamic imports.

Parameters:

path – The path to import from in the format module.submodule.attr.

Raises:
  • RuntimeError – If no allowed paths are defined in settings.

  • ValueError – If the path is not allowed.

Returns:

The imported object.