eric3.Utilities.ModuleParser
Parse a Python module file.
This module is based on pyclbr.py as of Python 2.2.2
BUGS (from pyclbr.py)
- Code that doesn't pass tabnanny or python -t will confuse it, unless
you set the module TABWIDTH variable (default 8) to the correct tab width
for the file.
Classes
Class |
Class to represent a Python class. |
Function |
Class to represent a Python function or method. |
Module |
Class to represent a Python module. |
Functions
_indent |
Function to determine the indent width of a whitespace string. |
find_module |
Module function to extend the Python module finding mechanism. |
readModule |
Function to read a module file and parse it. |
resetParsedModule |
Module function to clear one module from the list of parsed modules. |
resetParsedModules |
Module function to reset the list of modules already parsed. |
Class
Class to represent a Python class.
Derived from
Methods
Class (Constructor)
Class(module, name, super, file, lineno)
Constructor
- file
-
name of file containing this class (string)
- lineno
-
linenumber of the class definition (integer)
- module
-
name of module containing this class (string)
- name
-
name of the class (string)
- super
-
list of classnames this class is inherited from
(list of strings)
Class._addattribute
_addattribute(name)
Method to add information about attributes.
- name
-
name of the attribute to add (string)
Class._adddescription
_adddescription(description)
Method to store the class docstring.
- description
-
the docstring to be stored (string)
Class._addmethod
_addmethod(name, function)
Method to add information about a method.
- function
-
Function object to be added
- name
-
name of method to be added (string)
Function
Class to represent a Python function or method.
Derived from
Methods
Function (Constructor)
Function(module, name, file, lineno, signature = '')
Constructor
- file
-
name of file containing this function (string)
- lineno
-
linenumber of the function definition (integer)
- module
-
name of module containing this function (string)
- name
-
name of the function (string)
- signature
-
the functions call signature (string)
Function._adddescription
_adddescription(description)
Method to store the functions docstring.
- description
-
the docstring to be stored (string)
Module
Class to represent a Python module.
Derived from
Methods
Module |
Constructor |
_addclass |
Method to add information about a class. |
_adddescription |
Method to store the modules docstring. |
_addfunction |
Method to add information about a function. |
addPathToHierarchy |
Method to put the exhausted path into the result dictionary. |
assembleHierarchy |
Method to assemble the inheritance hierarchy. |
createHierarchy |
Method to build the inheritance hierarchy for all classes of this module. |
getFileName |
Method to retrieve the modules filename. |
getName |
Method to retrieve the modules name. |
scan |
Method to scan the source text and retrieve the relevant information. |
Module (Constructor)
Module(name, file=None)
Constructor
- file
-
filename of file containing this module (string)
- name
-
name of this module (string)
Module._addclass
_addclass(name, _class)
Method to add information about a class.
- _class
-
Class object to be added
- name
-
name of class to be added (string)
Module._adddescription
_adddescription(description)
Method to store the modules docstring.
- description
-
the docstring to be stored (string)
Module._addfunction
_addfunction(name, function)
Method to add information about a function.
- function
-
Function object to be added
- name
-
name of function to be added (string)
Module.addPathToHierarchy
addPathToHierarchy(path, result, fn)
Method to put the exhausted path into the result dictionary.
- fn
-
function to call for classe that are already part of the
result dictionary
- path
-
the exhausted path of classes
- result
-
the result dictionary
Module.assembleHierarchy
assembleHierarchy(name, classes, path, result)
Method to assemble the inheritance hierarchy.
This method will traverse the class hierarchy, from a given class
and build up a nested dictionary of super-classes. The result is
intended to be inverted, i.e. the highest level are the super classes.
This code is borrowed from Boa Constructor.
- classes
-
A dictionary of classes to look in.
- name
-
name of class to assemble hierarchy (string)
- path
-
- result
-
The resultant hierarchy
Module.createHierarchy
createHierarchy()
Method to build the inheritance hierarchy for all classes of this module.
- Returns:
-
A dictionary with inheritance hierarchies.
Module.getFileName
getFileName()
Method to retrieve the modules filename.
- Returns:
-
module filename (string)
Module.getName
getName()
Method to retrieve the modules name.
- Returns:
-
module name (string)
Module.scan
scan(src)
Method to scan the source text and retrieve the relevant information.
- src
-
the source text to be scanned (string)
_indent
_indent(ws, _expandtabs=string.expandtabs)
Function to determine the indent width of a whitespace string.
- _expandtabs
-
Function to be used to expand tab characters.
- ws
-
The whitespace string to be cheked. (string)
- Returns:
-
Length of the whitespace string after tab expansion.
find_module
find_module(name, path)
Module function to extend the Python module finding mechanism.
This function searches for files in the given path. If the filename
doesn't have an extension or an extension of .py, the normal search
implemented in the imp module is used. For all other supported files
only path is searched.
- name
-
filename or modulename to search for (string)
- path
-
search path (list of strings)
- Returns:
-
tuple of the open file, pathname and description. Description
is a tuple of file suffix, file mode and file type)
- Raises ImportError:
-
The file or module wasn't found.
readModule
readModule(module, path=[], inpackage=0, basename="")
Function to read a module file and parse it.
The module is searched in path and sys.path, read and parsed.
If the module was parsed before, the information is taken
from a cache in order to speed up processing.
- basename
-
a path basename. This basename is deleted from
the filename of the module file to be read. (string)
- inpackage
-
Flag indicating that module is inside a
package (boolean)
- module
-
Name of the module to be parsed (string)
- path
-
Searchpath for the module (list of strings)
- Returns:
-
reference to a Module object containing the parsed
module information (Module)
resetParsedModule
resetParsedModule(module, basename="")
Module function to clear one module from the list of parsed modules.
- basename
-
a path basename. This basename is deleted from
the filename of the module file to be cleared. (string)
- module
-
Name of the module to be parsed (string)
resetParsedModules
resetParsedModules()
Module function to reset the list of modules already parsed.