eric3.Utilities.pyclbr

Parse a Python file and retrieve classes and methods.

Parse enough of a Python file to recognize class and method definitions and to find out the superclasses of a class.

The interface consists of a single function:
readmodule(module, path)
module is the name of a Python module, path is an optional list of directories where the module is to be searched. If present, path is prepended to the system search path sys.path. The return value is a dictionary. The keys of the dictionary are the names of the classes defined in the module (including classes that are defined via the from XXX import YYY construct). The values are class instances of the class Class defined here.

A class is described by the class Class in this module. Instances of this class have the following instance variables:

The dictionary of methods uses the method names as keys and a tuple consisting of the line numbers on which the method was defined and a list of the methods parameters as values. If the name of a super class is not recognized, the corresponding entry in the list of super classes is not a class instance but a string giving the name of the super class. Since import statements are recognized and imported modules are scanned as well, this shouldn't happen often.

BUGS

PACKAGE RELATED BUGS

This is a modified version of the one found in the Python 2.2.2 distribution.

Classes

Class Class to represent a Python class.
Function Class to represent a top-level Python function

Functions

_indent Module function to return the indentation depth.
find_module Module function to extend the Python module finding mechanism.
readmodule Backwards compatible interface.
readmodule_ex Read a module file and return a dictionary of classes.

Class

Class to represent a Python class.

Derived from

Methods

Class Constructor
_addclass Protected method to add a nested class to this class.
_addmethod Method to add information about a method.

Class (Constructor)

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

Constructor

file
filename containing this class
lineno
linenumber of the class definition
module
name of the module containing this class
name
name of this class
super
list of class names this class is inherited from

Class._addclass

_addclass(name, _class)

Protected method to add a nested class to this class.

_class
Class object to be added
name
name of the class

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)

Up

Function

Class to represent a top-level Python function

Derived from

Class

Methods

Function Constructor

Function (Constructor)

Function(module, name, file, lineno, signature = '')

Constructor

file
filename containing this class
lineno
linenumber of the class definition
module
name of the module containing this function
name
name of this function
signature
parameterlist of the method

Up

_indent

_indent(ws, _expandtabs=string.expandtabs)

Module function to return the indentation depth.

_expandtabs
callable object used to expand tab characters
ws
the whitespace to be checked (string)
Returns:
length of the whitespace string (integer)
Up

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

readmodule

readmodule(module, path=[], inpackage=0)

Backwards compatible interface.

Like readmodule_ex() but strips Function objects from the resulting dictionary.

inpackage
flag indicating a module inside a package is scanned
path
path the module should be searched in (list of strings)
Returns:
the resulting dictionary
Up

readmodule_ex

readmodule_ex(module, path=[], inpackage=0)

Read a module file and return a dictionary of classes.

Search for MODULE in PATH and sys.path, read and parse the module and return a dictionary with one entry for each class found in the module.

inpackage
flag indicating a module inside a package is scanned
path
path the module should be searched in (list of strings)
Returns:
the resulting dictionary
Up