MCPcopy Index your code
hub / github.com/secdev/scapy / load

Method load

scapy/config.py:626–700  ·  view source on GitHub ↗

Load a scapy extension. :param extension: the name of the extension, as installed.

(self, extension: str)

Source from the content-addressed store, hash-verified

624 loader.exec_module(module)
625
626 def load(self, extension: str):
627 """
628 Load a scapy extension.
629
630 :param extension: the name of the extension, as installed.
631 """
632 if extension in self._loaded:
633 return
634
635 try:
636 import importlib.metadata
637 except ImportError:
638 log_loading.warning(
639 "'%s' not loaded. "
640 "Scapy extensions require at least Python 3.8+ !" % extension
641 )
642 return
643
644 # Get extension distribution
645 try:
646 distr = importlib.metadata.distribution(extension)
647 except importlib.metadata.PackageNotFoundError:
648 log_loading.warning("The extension '%s' was not found !" % extension)
649 return
650
651 # Check the classifiers
652 if distr.metadata.get('License-Expression', None) not in self.GPLV2_LICENCES:
653 log_loading.warning(
654 "'%s' has no GPLv2 classifier therefore cannot be loaded." % extension
655 )
656 return
657
658 # Create the extension
659 ext = ScapyExt()
660
661 # Get the top-level declared "import packages"
662 # HACK: not available nicely in importlib :/
663 packages = distr.read_text("top_level.txt").split()
664
665 for package in packages:
666 scapy_ext = importlib.import_module(package)
667
668 # We initialize the plugin by calling it's 'scapy_ext' function
669 try:
670 scapy_ext_func = scapy_ext.scapy_ext
671 except AttributeError:
672 log_loading.warning(
673 "'%s' does not look like a Scapy plugin !" % extension
674 )
675 return
676 try:
677 scapy_ext_func(ext)
678 except Exception as ex:
679 log_loading.warning(
680 "'%s' failed during initialization with %s" % (
681 extension,
682 ex
683 )

Callers 2

loadallMethod · 0.95
loadFunction · 0.45

Calls 7

_register_specMethod · 0.95
_add_bash_autocompletionFunction · 0.90
ScapyExtClass · 0.85
itemsMethod · 0.80
getMethod · 0.45
valuesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected