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. |
RbModule |
Class to represent a Ruby 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
None
Methods
Class (Constructor)
Class(module, name, super, file, lineno)
Constructor
- 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)
- file
-
name of file containing this class (string)
- lineno
-
linenumber of the class definition (integer)
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.
- name
-
name of method to be added (string)
- function
-
Function object to be added
Function
Class to represent a Python function or method.
Derived from
None
Methods
Function (Constructor)
Function(module, name, file, lineno, signature = '')
Constructor
- module
-
name of module containing this function (string)
- name
-
name of the function (string)
- file
-
name of file containing this function (string)
- lineno
-
linenumber of the function definition (integer)
- 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
None
Methods
Module |
Constructor |
__py_scan |
Method to scan the source text of a Python module and retrieve the relevant information. |
__rb_scan |
Method to scan the source text of a Python module and retrieve the relevant information. |
_addclass |
Method to add information about a class. |
_adddescription |
Method to store the modules docstring. |
_addfunction |
Method to add information about a function. |
_addmodule |
Method to add information about a Ruby module. |
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, type=None)
Constructor
- name
-
name of this module (string)
- file
-
filename of file containing this module (string)
- type
-
type of this module
Module.__py_scan
__py_scan(src)
Method to scan the source text of a Python module and retrieve the relevant information.
- src
-
the source text to be scanned (string)
Module.__rb_scan
__rb_scan(src)
Method to scan the source text of a Python module and retrieve the relevant information.
- src
-
the source text to be scanned (string)
Module._addclass
_addclass(name, _class)
Method to add information about a class.
- name
-
name of class to be added (string)
- _class
-
Class object to be added
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.
- name
-
name of function to be added (string)
- function
-
Function object to be added
Module._addmodule
_addmodule(name, module)
Method to add information about a Ruby module.
- name
-
name of module to be added (string)
- module
-
Module object to be added
Module.addPathToHierarchy
addPathToHierarchy(path, result, fn)
Method to put the exhausted path into the result dictionary.
- path
-
the exhausted path of classes
- result
-
the result dictionary
- fn
-
function to call for classe that are already part of 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.
- name
-
name of class to assemble hierarchy (string)
- classes
-
A dictionary of classes to look in.
- 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)
RbModule
Class to represent a Ruby module.
Derived from
Class
Methods
RbModule (Constructor)
RbModule(module, name, file, lineno)
Constructor
- module
-
name of module containing this class (string)
- name
-
name of the class (string)
- file
-
name of file containing this class (string)
- lineno
-
linenumber of the class definition (integer)
RbModule._addclass
_addclass(name, _class)
Method to add information about a class.
- name
-
name of class to be added (string)
- _class
-
Class object to be added
_indent
_indent(ws, _expandtabs=string.expandtabs)
Function to determine the indent width of a whitespace string.
- ws
-
The whitespace string to be cheked. (string)
- _expandtabs
-
Function to be used to expand tab characters.
- Returns:
-
Length of the whitespace string after tab expansion.
find_module
find_module(name, path, extensions)
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)
- extensions
-
list of extensions, which should be considered valid
source file extensions (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="", extensions=None)
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.
- module
-
Name of the module to be parsed (string)
- path
-
Searchpath for the module (list of strings)
- inpackage
-
Flag indicating that module is inside a
package (boolean)
- basename
-
a path basename. This basename is deleted from
the filename of the module file to be read. (string)
- extensions
-
list of extensions, which should be considered valid
source file extensions (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.
- module
-
Name of the module to be parsed (string)
- basename
-
a path basename. This basename is deleted from
the filename of the module file to be cleared. (string)
resetParsedModules
resetParsedModules()
Module function to reset the list of modules already parsed.