eric4.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 |
Protected 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
object
Methods
Class |
Constructor |
addAttribute |
Public method to add information about attributes. |
addDescription |
Public method to store the class docstring. |
addMethod |
Public method to add information about a method. |
setEndLine |
Public method to record the number of the last line of a class. |
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)
Public method to add information about attributes.
- name
-
name of the attribute to add (string)
Class.addDescription
addDescription(description)
Public method to store the class docstring.
- description
-
the docstring to be stored (string)
Class.addMethod
addMethod(name, function)
Public method to add information about a method.
- name
-
name of method to be added (string)
- function
-
Function object to be added
Class.setEndLine
setEndLine(endLineNo)
Public method to record the number of the last line of a class.
- endLineNo
-
number of the last line (integer)
Function
Class to represent a Python function or method.
Derived from
object
Methods
Function (Constructor)
Function(module, name, file, lineno, signature = '', pyqtSignature = None)
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)
- pyqtSignature
-
the functions PyQt signature (string)
Function.addDescription
addDescription(description)
Public method to store the functions docstring.
- description
-
the docstring to be stored (string)
Module
Class to represent a Python module.
Derived from
object
Methods
Module |
Constructor |
__py_scan |
Privaet method to scan the source text of a Python module and retrieve the relevant information. |
__rb_scan |
Private method to scan the source text of a Python module and retrieve the relevant information. |
addClass |
Public method to add information about a class. |
addDescription |
Protected method to store the modules docstring. |
addFunction |
Public method to add information about a function. |
addModule |
Public method to add information about a Ruby module. |
addPathToHierarchy |
Public method to put the exhausted path into the result dictionary. |
assembleHierarchy |
Public method to assemble the inheritance hierarchy. |
createHierarchy |
Public method to build the inheritance hierarchy for all classes of this module. |
getFileName |
Public method to retrieve the modules filename. |
getName |
Public method to retrieve the modules name. |
scan |
Public 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)
Privaet 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)
Private 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)
Public 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)
Protected method to store the modules docstring.
- description
-
the docstring to be stored (string)
Module.addFunction
addFunction(name, function)
Public 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)
Public 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)
Public 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)
Public 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()
Public method to build the inheritance hierarchy for all classes of this module.
- Returns:
-
A dictionary with inheritance hierarchies.
Module.getFileName
getFileName()
Public method to retrieve the modules filename.
- Returns:
-
module filename (string)
Module.getName
getName()
Public method to retrieve the modules name.
- Returns:
-
module name (string)
Module.scan
scan(src)
Public 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)
Public method to add information about a class.
- name
-
name of class to be added (string)
- _class
-
Class object to be added
_indent
_indent(ws)
Protected function to determine the indent width of a whitespace string.
- ws
-
The whitespace string to be cheked. (string)
- 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, caching=True)
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)
- caching
-
flag indicating that the parsed module should be
cached (boolean)
- 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.