eric7.Utilities.ModuleParser

Parse a Python module file.

BUGS (from pyclbr.py)

Global Attributes

PTL_SOURCE
PY_SOURCE
RB_SOURCE
SUPPORTED_TYPES
TABWIDTH
TYPE_MAPPING
__all__
_commentsub
_hashsub
_modules
_py_getnext
_rb_getnext

Classes

Attribute Class to represent a Python function or method.
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.
VisibilityBase Class implementing the visibility aspect of all objects.

Functions

_indent Protected function to determine the indent width of a whitespace string.
find_module Module function to extend the Python module finding mechanism.
getTypeFromTypeName Module function to determine the module type given the module type name.
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.


Attribute

Class to represent a Python function or method.

Derived from

VisibilityBase

Class Attributes

None

Class Methods

None

Methods

Attribute Constructor
addAssignment Public method to add another assignment line number.

Static Methods

None

Attribute (Constructor)

Attribute(module, name, file, lineno, isSignal=False)

Constructor

module (str)
name of module containing this function
name (str)
name of the function
file (str)
name of file containing this function
lineno (int)
linenumber of the first attribute assignment
isSignal (bool)
flag indicating a signal definition

Attribute.addAssignment

addAssignment(lineno)

Public method to add another assignment line number.

lineno (int)
linenumber of the additional attribute assignment
Up


Class

Class to represent a Python class.

Derived from

VisibilityBase

Class Attributes

None

Class Methods

None

Methods

Class Constructor
addAttribute Public method to add information about attributes.
addDescription Public method to store the class docstring.
addGlobal Public method to add information about global (class) variables.
addMethod Public method to add information about a method.
getAttribute Public method to retrieve an attribute by name.
getMethod Public method to retrieve a method by name.
setEndLine Public method to record the number of the last line of a class.

Static Methods

None

Class (Constructor)

Class(module, name, superClasses, file, lineno)

Constructor

module (str)
name of module containing this class
name (str)
name of the class
superClasses (list of str)
list of classnames this class is inherited from
file (str)
name of file containing this class
lineno (int)
linenumber of the class definition

Class.addAttribute

addAttribute(name, attr)

Public method to add information about attributes.

name (str)
name of the attribute to add
attr (Attribute)
Attribute object to be added

Class.addDescription

addDescription(description)

Public method to store the class docstring.

description (str)
the docstring to be stored

Class.addGlobal

addGlobal(name, attr)

Public method to add information about global (class) variables.

name (str)
name of the global to add
attr (Attribute)
Attribute object to be added

Class.addMethod

addMethod(name, function)

Public method to add information about a method.

name (str)
name of method to be added
function (Function)
Function object to be added

Class.getAttribute

getAttribute(name)

Public method to retrieve an attribute by name.

name (str)
name of the attribute
Return:
the named attribute or None
Return Type:
Attribute

Class.getMethod

getMethod(name)

Public method to retrieve a method by name.

name (str)
name of the method
Return:
the named method or None
Return Type:
Function

Class.setEndLine

setEndLine(endLineNo)

Public method to record the number of the last line of a class.

endLineNo (int)
number of the last line
Up


Function

Class to represent a Python function or method.

Derived from

VisibilityBase

Class Attributes

Class
General
Static

Class Methods

None

Methods

Function Constructor
addDescription Public method to store the functions docstring.
setEndLine Public method to record the number of the last line of a class.

Static Methods

None

Function (Constructor)

Function(module, name, file, lineno, signature="", pyqtSignature=None, modifierType=General, annotation="", )

Constructor

module (str)
name of module containing this function
name (str)
name of the function
file (str)
name of file containing this function
lineno (int)
linenumber of the function definition
signature (str)
the functions call signature
pyqtSignature (str)
the functions PyQt signature
modifierType (int)
type of the function
annotation (str)
return annotation

Function.addDescription

addDescription(description)

Public method to store the functions docstring.

description (str)
the docstring to be stored

Function.setEndLine

setEndLine(endLineNo)

Public method to record the number of the last line of a class.

endLineNo (int)
number of the last line
Up


Module

Class to represent a Python module.

Derived from

None

Class Attributes

None

Class Methods

None

Methods

Module Constructor
__py_scan Private method to scan the source text of a Python module and retrieve the relevant information.
__py_setVisibility Private method to set the visibility of an object.
__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 Public method to store the modules docstring.
addFunction Public method to add information about a function.
addGlobal Public method to add information about global variables.
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.
calculateEndline Function to calculate the end line of a class or method/function.
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.
getType Public method to get the type of the module's source.
scan Public method to scan the source text and retrieve the relevant information.

Static Methods

None

Module (Constructor)

Module(name, file=None, moduleType=None)

Constructor

name (str)
name of this module
file (str)
filename of file containing this module
moduleType (int)
type of this module

Module.__py_scan

__py_scan(src)

Private method to scan the source text of a Python module and retrieve the relevant information.

src (str)
the source text to be scanned

Module.__py_setVisibility

__py_setVisibility(objectRef)

Private method to set the visibility of an object.

objectRef (Attribute, Class or Function)
reference to the object

Module.__rb_scan

__rb_scan(src)

Private method to scan the source text of a Python module and retrieve the relevant information.

src (str)
the source text to be scanned

Module.addClass

addClass(name, _class)

Public method to add information about a class.

name (str)
name of class to be added
_class (Class)
Class object to be added

Module.addDescription

addDescription(description)

Public method to store the modules docstring.

description (str)
the docstring to be stored

Module.addFunction

addFunction(name, function)

Public method to add information about a function.

name (str)
name of function to be added
function (Function)
Function object to be added

Module.addGlobal

addGlobal(name, attr)

Public method to add information about global variables.

name (str)
name of the global to add
attr (Attribute)
Attribute object to be added

Module.addModule

addModule(name, module)

Public method to add information about a Ruby module.

name (str)
name of module to be added
module (Module)
Module object to be added

Module.addPathToHierarchy

addPathToHierarchy(path, result, fn)

Public method to put the exhausted path into the result dictionary.

path (list of str)
the exhausted path of classes
result (dict)
the result dictionary
fn (function)
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 (str)
name of class to assemble hierarchy
classes (dict)
A dictionary of classes to look in.
path (list of str)
path of classes
result (dict)
The resultant hierarchy

Module.calculateEndline

calculateEndline(lines, indent)

Function to calculate the end line of a class or method/function.

lineno (int)
line number to start at (one based)
lines (list of str)
list of source lines
indent (int)
indent length the class/method/function definition
Return:
end line of the class/method/function (one based)
Return Type:
int

Module.createHierarchy

createHierarchy()

Public method to build the inheritance hierarchy for all classes of this module.

Return:
A dictionary with inheritance hierarchies.
Return Type:
dict

Module.getFileName

getFileName()

Public method to retrieve the modules filename.

Return:
module filename
Return Type:
str

Module.getName

getName()

Public method to retrieve the modules name.

Return:
module name
Return Type:
str

Module.getType

getType()

Public method to get the type of the module's source.

Return:
type of the modules's source
Return Type:
str

Module.scan

scan(src)

Public method to scan the source text and retrieve the relevant information.

src (str)
the source text to be scanned
Up


RbModule

Class to represent a Ruby module.

Derived from

Class

Class Attributes

None

Class Methods

None

Methods

RbModule Constructor
addClass Public method to add information about a class.

Static Methods

None

RbModule (Constructor)

RbModule(module, name, file, lineno)

Constructor

module (str)
name of module containing this class
name (str)
name of the class
file (str)
name of file containing this class
lineno (int)
linenumber of the class definition

RbModule.addClass

addClass(name, _class)

Public method to add information about a class.

name (str)
name of class to be added
_class (Class)
Class object to be added
Up


VisibilityBase

Class implementing the visibility aspect of all objects.

Derived from

None

Class Attributes

None

Class Methods

None

Methods

isPrivate Public method to check, if the visibility is Private.
isProtected Public method to check, if the visibility is Protected.
isPublic Public method to check, if the visibility is Public.
setPrivate Public method to set the visibility to Private.
setProtected Public method to set the visibility to Protected.
setPublic Public method to set the visibility to Public.

Static Methods

None

VisibilityBase.isPrivate

isPrivate()

Public method to check, if the visibility is Private.

Return:
flag indicating Private visibility
Return Type:
bool

VisibilityBase.isProtected

isProtected()

Public method to check, if the visibility is Protected.

Return:
flag indicating Protected visibility
Return Type:
bool

VisibilityBase.isPublic

isPublic()

Public method to check, if the visibility is Public.

Return:
flag indicating Public visibility
Return Type:
bool

VisibilityBase.setPrivate

setPrivate()

Public method to set the visibility to Private.

VisibilityBase.setProtected

setProtected()

Public method to set the visibility to Protected.

VisibilityBase.setPublic

setPublic()

Public method to set the visibility to Public.

Up


_indent

_indent(ws)

Protected function to determine the indent width of a whitespace string.

ws (str)
The whitespace string to be cheked.
Return:
length of the whitespace string after tab expansion
Return Type:
int
Up


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 (str)
filename or modulename to search for
path (list of str)
search path
extensions (list of str)
list of extensions, which should be considered valid source file extensions
Return:
tuple of the open file, pathname and description. Description is a tuple of file suffix, file mode and file type)
Return Type:
tuple
Raises ImportError:
The file or module wasn't found.
Up


getTypeFromTypeName

getTypeFromTypeName(name)

Module function to determine the module type given the module type name.

name (str)
module type name
Return:
module type or -1 for failure
Return Type:
int
Up


readModule

readModule(module, path=None, inpackage=False, basename="", extensions=None, caching=True, ignoreBuiltinModules=False, )

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 (str)
name of the module to be parsed
path (list of str)
search path for the module
inpackage (bool)
flag indicating that module is inside a package
basename (str)
a path basename that is deleted from the filename of the module file to be read
extensions (list of str)
list of extensions, which should be considered valid source file extensions
caching (bool)
flag indicating that the parsed module should be cached
ignoreBuiltinModules (bool)
flag indicating to ignore the builtin modules
Return:
reference to a Module object containing the parsed module information
Return Type:
Module
Up


resetParsedModule

resetParsedModule(module, basename="")

Module function to clear one module from the list of parsed modules.

module (str)
Name of the module to be parsed
basename (str)
a path basename. This basename is deleted from the filename of the module file to be cleared.
Up


resetParsedModules

resetParsedModules()

Module function to reset the list of modules already parsed.

Up