MCPcopy Create free account
hub / github.com/twisted/twisted / __getitem__

Method __getitem__

src/twisted/python/modules.py:689–725  ·  view source on GitHub ↗

Get a python module by its given fully-qualified name. @param modname: The fully-qualified Python module name to load. @type modname: C{str} @return: an object representing the module identified by C{modname} @rtype: L{PythonModule} @raise KeyErr

(self, modname)

Source from the content-addressed store, hash-verified

687 yield PathEntry(fp, self)
688
689 def __getitem__(self, modname):
690 """
691 Get a python module by its given fully-qualified name.
692
693 @param modname: The fully-qualified Python module name to load.
694
695 @type modname: C{str}
696
697 @return: an object representing the module identified by C{modname}
698
699 @rtype: L{PythonModule}
700
701 @raise KeyError: if the module name is not a valid module name, or no
702 such module can be identified as loadable.
703 """
704 # See if the module is already somewhere in Python-land.
705 moduleObject = self.moduleDict.get(modname)
706 if moduleObject is not None:
707 # we need 2 paths; one of the path entry and one for the module.
708 pe = PathEntry(
709 self._smartPath(self._findEntryPathString(moduleObject)), self
710 )
711 mp = self._smartPath(moduleObject.__file__)
712 return PythonModule(modname, mp, pe)
713
714 # Recurse if we're trying to get a submodule.
715 if "." in modname:
716 pkg = self
717 for name in modname.split("."):
718 pkg = pkg[name]
719 return pkg
720
721 # Finally do the slowest possible thing and iterate
722 for module in self.iterModules():
723 if module.name == modname:
724 return module
725 raise KeyError(modname)
726
727 def __contains__(self, module):
728 """

Callers 1

__contains__Method · 0.95

Calls 6

_smartPathMethod · 0.95
_findEntryPathStringMethod · 0.95
iterModulesMethod · 0.95
PathEntryClass · 0.85
PythonModuleClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected