include.inhibit module

include.inhibit.DISABLED_TYPES = <include.inhibit.DisabledIncludeTypes for '', children ''>

Default interface to disabled types, see DisabledIncludeTypes

exception include.inhibit.DisabledIncludeError

Bases: exceptions.ImportError

An import operation failed due to its include type being disabled

class include.inhibit.DisabledIncludeTypes

Bases: object

Interface for disabling include types

Meta-container to control disabled include types. The methods disable() and enable() allow to control which include types can be used.

Disabled types cannot be used to import code, be it explicitly or implicitly via bootstrapping. Once a type is disabled, attempts to import code with it raise DisabledIncludeError.

This is provided as a two-level filter: each type can be disabled either for both the current and any child process, or only for child processes. It is not possible to enable an include type for child processes but not the current process. Note that child processes inherit disabled types only on startup.

Note:This is a singleton, as it controls interpreter state.
disable(identifier, children_only=False)

Disable an include type

Parameters:
  • identifier – module or name of the include type
  • children_only – disable the include type only for child processes, not the current process

The identifier can be specified in multiple ways to disable an include type:

module (include.files or include.mount.files)
The base module implementing the include type. These modules have a module.IMPORT_PATH attribute.
implementation path ("include.files")
Import path of the module implementing the include type.
mount path ("include.mount.files")
Mount path of the module implementing the include type.
short path ("files")
Relative path of the module implementing the include type.
enable(identifier, exclude_children=False)

Enable a previously disabled include type

Parameters:
  • identifier – module or name of the include type
  • exclude_children – disable the include type only for child processes, not the current process

The identifier can be specified in multiple ways to disable an include type. See disable() for details.

environment_key = 'PY_INCLUDE_DISABLE'

Key of the environment storing include types disabled for child processes

class include.inhibit.DisabledTypeLoader(module_prefix)

Bases: include.base.import_hook.BaseIncludeLoader

load_module(name)

Load and return a module

If the module is already loaded, the existing module is returned. Otherwise, raises DisabledIncludeError.

uri2module(uri)

Convert an unencoded source uri to an encoded module name

Always raises DisabledIncludeError.