latest.ipv8.messaging.interfaces.lan_addresses.importshield

Module Contents

Classes

Platform

Platform identifier to select where providers should be run.

conditional_import_shield

Protect against imports in a context that could segfault when imported in the wrong OS.

class latest.ipv8.messaging.interfaces.lan_addresses.importshield.Platform(*args, **kwds)

Bases: enum.Enum

Platform identifier to select where providers should be run.

ANY
NONE = 0
WINDOWS = 'Windows'
LINUX = 'Linux'
class latest.ipv8.messaging.interfaces.lan_addresses.importshield.conditional_import_shield(platf: Platform = Platform.ANY, verbose: bool = False)

Bases: contextlib.AbstractContextManager

Protect against imports in a context that could segfault when imported in the wrong OS.

This context manager provides two things:

  1. Conditional imports based on platform (platform.system()).

  2. Exception handling and logging.

__enter__() conditional_import_shield

When we enter the context, check if we are running on the right platform.

If we are not on the right platform, we temporarily sabotage the module’s import system.

__exit__(exctype: type[BaseException] | None, excinst: BaseException | None, exctb: types.TracebackType | None) bool

When we exit the context, unsabotage the import system and log any exceptions.