# eric7.Utilities.ModuleParser

Parse a Python module file.

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.

### Global Attributes

PTL_SOURCE
PY_SOURCE
RB_SOURCE
SEARCH_ERROR
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
  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 first attribute assignment (integer)
isSignal
  flag indicating a signal definition (boolean)

#### Attribute.addAssignment

addAssignment(lineno)

Public method to add another assignment line number.

lineno
  linenumber of the additional attribute assignment (integer)

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
  name of module containing this class (string)
name
  name of the class (string)
superClasses
  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, attr)

Public method to add information about attributes.

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

#### Class.addDescription

addDescription(description)

Public method to store the class docstring.

description
  the docstring to be stored (string)

#### Class.addGlobal

addGlobal(name, attr)

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

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

#### 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.getAttribute

getAttribute(name)

Public method to retrieve an attribute by name.

name
  name of the attribute (string)

Return:
  the named attribute or None

#### Class.getMethod

getMethod(name)

Public method to retrieve a method by name.

name
  name of the method (string)

Return:
  the named method or None

#### Class.setEndLine

setEndLine(endLineNo)

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

endLineNo
  number of the last line (integer)

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
  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)
modifierType
  type of the function
annotation
  return annotation

#### Function.addDescription

addDescription(description)

Public method to store the functions docstring.

description
  the docstring to be stored (string)

#### Function.setEndLine

setEndLine(endLineNo)

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

endLineNo
  number of the last line (integer)

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
  name of this module (string)
file
  filename of file containing this module (string)
moduleType
  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
  the source text to be scanned (string)

#### Module.__py_setVisibility

__py_setVisibility(objectRef)

Private method to set the visibility of an object.

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

#### 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
  name of class to be added (string)
_class
  Class object to be added

#### Module.addDescription

addDescription(description)

Public 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.addGlobal

addGlobal(name, attr)

Public method to add information about global variables.

name
  name of the global to add (string)
attr
  Attribute 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.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.

#### Module.getFileName

getFileName()

Public method to retrieve the modules filename.

Return:
  module filename (string)

#### Module.getName

getName()

Public method to retrieve the modules name.

Return:
  module name (string)

#### Module.getType

getType()

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

Return:
  type of the modules's source (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)

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
  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

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 (boolean)

#### VisibilityBase.isProtected

isProtected()

Public method to check, if the visibility is Protected.

Return:
  flag indicating Protected visibility (boolean)

#### VisibilityBase.isPublic

isPublic()

Public method to check, if the visibility is Public.

Return:
  flag indicating Public visibility (boolean)

#### 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
  The whitespace string to be cheked. (string)

Return:
  Length of the whitespace string after tab expansion.

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
  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)

Return:
  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.

Up

## getTypeFromTypeName

getTypeFromTypeName(name)

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

name
  module type name (string)

Return:
  module type or -1 for failure (integer)

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
  name of the module to be parsed (string)
path
  search path for the module (list of strings)
inpackage
  flag indicating that module is inside a package (boolean)
basename
  a path basename that 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)
ignoreBuiltinModules
  flag indicating to ignore the builtin modules (boolean)

Return:
  reference to a Module object containing the parsed module information (Module)

Up

## 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)

Up

## resetParsedModules

resetParsedModules()

Module function to reset the list of modules already parsed.

Up