class documentation

class twisted.python.modules.PythonPath: (source)

View In Hierarchy

I represent the very top of the Python object-space, the module list in sys.path and the modules list in sys.modules.

Property sysPath Retrieve the current value of the module search path list.
Instance Variable moduleDict A dictionary mapping string module names to module objects, like sys.modules.
Instance Variable sysPathHooks A list of PEP-302 path hooks, like sys.path_hooks.
Instance Variable moduleLoader A function that takes a fully-qualified python name and returns a module, like twisted.python.reflect.namedAny.
Method __init__ Create a PythonPath. You almost certainly want to use modules.theSystemPath, or its aliased methods, rather than creating a new instance yourself, though.
Instance Variable importerCache Undocumented
Method iterEntries Iterate the entries on my sysPath.
Method __getitem__ Get a python module by its given fully-qualified name.
Method __contains__ Check to see whether or not a module exists on my import path.
Method __repr__ Display my sysPath and moduleDict in a string representation.
Method iterModules Yield all top-level modules on my sysPath.
Method walkModules Similar to iterModules, this yields every module on the path, then every submodule in each package or entry.
Instance Variable _sysPath A sequence of strings like sys.path. This attribute is read-only.
Instance Variable _sysPathFactory Undocumented
Method _findEntryPathString Determine where a given Python module object came from by looking at path entries.
Method _smartPath Given a path entry from sys.path which may refer to an importer, return the appropriate FilePath-like instance.
_sysPath = (source)
A sequence of strings like sys.path. This attribute is read-only.
@property
sysPath = (source)

Retrieve the current value of the module search path list.

moduleDict = (source)
A dictionary mapping string module names to module objects, like sys.modules.
sysPathHooks = (source)
A list of PEP-302 path hooks, like sys.path_hooks.
moduleLoader = (source)
A function that takes a fully-qualified python name and returns a module, like twisted.python.reflect.namedAny.
def __init__(self, sysPath=None, moduleDict=sys.modules, sysPathHooks=sys.path_hooks, importerCache=sys.path_importer_cache, moduleLoader=namedAny, sysPathFactory=None): (source)

Create a PythonPath. You almost certainly want to use modules.theSystemPath, or its aliased methods, rather than creating a new instance yourself, though.

All parameters are optional, and if unspecified, will use 'system' equivalents that makes this PythonPath like the global theSystemPath instance.

ParameterssysPatha sys.path-like list to use for this PythonPath, to specify where to load modules from.
moduleDicta sys.modules-like dictionary to use for keeping track of what modules this PythonPath has loaded.
sysPathHookssys.path_hooks-like list of PEP-302 path hooks to be used for this PythonPath, to determie which importers should be used.
importerCachea sys.path_importer_cache-like list of PEP-302 importers. This will be used in conjunction with the given sysPathHooks.
moduleLoadera module loader function which takes a string and returns a module. That is to say, it is like namedAny - *not* like __import__.
sysPathFactorya 0-argument callable which returns the current value of a sys.path-like list of strings. Specify either this, or sysPath, not both. This alternative interface is provided because the way the Python import mechanism works, you can re-bind the 'sys.path' name and that is what is used for current imports, so it must be a factory rather than a value to deal with modification by rebinding rather than modification by mutation. Note: it is not recommended to rebind sys.path. Although this mechanism can deal with that, it is a subtle point which some tools that it is easy for tools which interact with sys.path to miss.
_sysPathFactory = (source)

Undocumented

importerCache = (source)

Undocumented

def _findEntryPathString(self, modobj): (source)

Determine where a given Python module object came from by looking at path entries.

def _smartPath(self, pathName): (source)

Given a path entry from sys.path which may refer to an importer, return the appropriate FilePath-like instance.

ParameterspathNamea str describing the path.
Returnsa FilePath-like object.
def iterEntries(self): (source)

Iterate the entries on my sysPath.

Returnsa generator yielding PathEntry objects
def __getitem__(self, modname): (source)

Get a python module by its given fully-qualified name.

ParametersmodnameThe fully-qualified Python module name to load. (type: str)
Returnsan object representing the module identified by modname (type: PythonModule)
RaisesKeyErrorif the module name is not a valid module name, or no such module can be identified as loadable.
def __contains__(self, module): (source)

Check to see whether or not a module exists on my import path.

ParametersmoduleThe name of the module to look for on my import path. (type: str)
def __repr__(self): (source)

Display my sysPath and moduleDict in a string representation.

ReturnsUndocumented (type: str)
def iterModules(self): (source)

Yield all top-level modules on my sysPath.

def walkModules(self, importPackages=False): (source)

Similar to iterModules, this yields every module on the path, then every submodule in each package or entry.

API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.