Home | Trees | Index | Help |
|
---|
|
Extract API documentation about python objects by parsing their source code.
DocParser
is a processing class that reads
the Python source code for one or more modules, and uses it to create APIDoc objects
containing the API documentation for the variables and values defined in
those modules.
DocParser
can be subclassed to extend the set of source
code constructions that it supports.
|
|||
ParseError | An exception that is used to signify that docparser
encountered syntactically invalid Python code while processing a
Python source file. |
|
|||
Module parser | |||
---|---|---|---|
ValueDoc |
parse_docs(filename=None,
name=None,
context=None,
is_script=False)
Generate the API documentation for a specified object by parsing Python source files, and return it as a ValueDoc. |
||
_parse_package(package_dir)
If the given directory is a package directory, then parse its __init__.py file (and the __init__.py files of all ancestor packages); and return its ModuleDoc .
|
|||
handle_special_module_vars(module_doc) | |||
_module_var_toktree(module_doc, name) | |||
Module Lookup | |||
_find(name,
package_doc=None)
Return the API documentaiton for the object whose name is name .
|
|||
_is_submodule_import_var(module_doc,
var_name)
Return true if var_name is the name of a variable in
module_doc that just contains an
imported_from link to a submodule of the same name.
|
|||
_find_in_namespace(name, namespace_doc) | |||
_get_filename(identifier, path=None) | |||
File tokenization loop | |||
process_file(module_doc)
Read the given ModuleDoc 's file, and add variables
corresponding to any objects defined in that file.
|
|||
add_to_group(container, api_doc, group_name) | |||
Shallow parser | |||
shallow_parse(line_toks)
Given a flat list of tokens, return a nested tree structure (called a token tree), whose leaves are identical to the original list, but whose structure reflects the structure implied by the grouping tokens (i.e., parenthases, braces, and brackets). |
|||
Line processing | |||
process_line(line, parent_docs, prev_line_doc, lineno, comments, decorators, encoding) | |||
process_control_flow_line(line, parent_docs, prev_line_doc, lineno, comments, decorators, encoding) | |||
process_import(line, parent_docs, prev_line_doc, lineno, comments, decorators, encoding) | |||
process_from_import(line, parent_docs, prev_line_doc, lineno, comments, decorators, encoding) | |||
_process_fromstar_import(src,
parent_docs)
Handle a statement of the form: |
|||
_import_var(name,
parent_docs)
Handle a statement of the form: |
|||
_import_var_as(src,
name,
parent_docs)
Handle a statement of the form: |
|||
_add_import_var(src,
name,
container)
Add a new imported variable named name to
container , with imported_from=src .
|
|||
_global_name(name,
parent_docs)
If the given name is package-local (relative to the current context, as determined by parent_docs ), then convert it
to a global name.
|
|||
process_assignment(line, parent_docs, prev_line_doc, lineno, comments, decorators, encoding) | |||
lhs_is_instvar(lhs_pieces, parent_docs) | |||
rhs_to_valuedoc(rhs, parent_docs) | |||
get_lhs_parent(lhs_name, parent_docs) | |||
process_one_line_block(line,
parent_docs,
prev_line_doc,
lineno,
comments,
decorators,
encoding)
The line handler for single-line blocks, such as: |
|||
process_multi_stmt(line,
parent_docs,
prev_line_doc,
lineno,
comments,
decorators,
encoding)
The line handler for semicolon-separated statements, such as: |
|||
process_del(line,
parent_docs,
prev_line_doc,
lineno,
comments,
decorators,
encoding)
The line handler for delete statements, such as: |
|||
process_docstring(line,
parent_docs,
prev_line_doc,
lineno,
comments,
decorators,
encoding)
The line handler for bare string literals. |
|||
process_funcdef(line,
parent_docs,
prev_line_doc,
lineno,
comments,
decorators,
encoding)
The line handler for function declaration lines, such as: |
|||
apply_decorator(decorator_name, func_doc) | |||
init_arglist(func_doc, arglist) | |||
process_classdef(line,
parent_docs,
prev_line_doc,
lineno,
comments,
decorators,
encoding)
The line handler for class declaration lines, such as: |
|||
find_base(name, parent_docs) | |||
Parsing | |||
dotted_names_in(elt_list)
Return a list of all simple dotted names in the given expression. |
|||
parse_name(elt,
strip_parens=False)
If the given token tree element is a name token, then return that name as a string. |
|||
parse_dotted_name(elt_list, strip_parens=True) | |||
split_on(elt_list, split_tok) | |||
parse_funcdef_arg(elt)
If the given tree token element contains a valid function definition argument (i.e., an identifier token or nested list of identifiers), then return a corresponding string identifier or nested list of string identifiers. |
|||
parse_classdef_bases(elt)
If the given tree token element contains a valid base list (that contains only dotted names), then return a corresponding list of DottedNames. |
|||
parse_dotted_name_list(elt_list)
If the given list of tree token elements contains a comma-separated list of dotted names, then return a corresponding list of DottedName objects. |
|||
parse_string(elt_list) | |||
parse_string_list(elt_list) | |||
Variable Manipulation | |||
set_variable(namespace,
var_doc,
preserve_docstring=False)
Add var_doc to namespace. |
|||
del_variable(namespace, name) | |||
Name Lookup | |||
VariableDoc or None
|
lookup_name(identifier,
parent_docs)
Find and return the documentation for the variable named by the given identifier. |
||
lookup_variable(dotted_name, parent_docs) | |||
lookup_value(dotted_name,
parent_docs)
Find and return the documentation for the value contained in the variable with the given name in the current namespace. |
|||
Docstring Comments | |||
add_docstring_from_comments(api_doc, comments) | |||
Tree tokens | |||
pp_toktree(elts, spacing='normal', indent=0) | |||
Helper Functions | |||
get_module_encoding(filename) | |||
_get_module_name(filename,
package_doc)
Return (dotted_name, is_package) |
|||
flatten(lst, out=None) |
|
|||
_moduledoc_cache | A cache of ModuleDoc s that we've already created. |
||
Configuration Constants: Control Flow | |||
---|---|---|---|
PARSE_TRY_BLOCKS | Should the contents of try blocks be examined? |
||
PARSE_EXCEPT_BLOCKS | Should the contents of except blocks be examined? |
||
PARSE_FINALLY_BLOCKS | Should the contents of finally blocks be
examined? |
||
PARSE_IF_BLOCKS | Should the contents of if blocks be examined? |
||
PARSE_ELSE_BLOCKS | Should the contents of else and elif
blocks be examined? |
||
PARSE_WHILE_BLOCKS | Should the contents of while blocks be examined? |
||
PARSE_FOR_BLOCKS | Should the contents of for blocks be examined? |
||
Configuration Constants: Imports | |||
IMPORT_HANDLING | What should docparser do when it encounters an import
statement? |
||
IMPORT_STAR_HANDLING | When docparser encounters a 'from m import *' statement, and is unable to parse
m (either because
IMPORT_HANDLING='link' , or because parsing failed), how
should it determine the list of identifiers expored by m ? |
||
DEFAULT_DECORATOR_BEHAVIOR | When DocParse encounters an unknown decorator, what
should it do to the documentation of the decorated function? |
||
BASE_HANDLING | What should docparser do when it encounters a base
class that was imported from another module? |
||
Configuration Constants: Comment docstrings | |||
COMMENT_DOCSTRING_MARKER | The prefix used to mark comments that contain attribute docstrings for variables. | ||
Configuration Constants: Grouping | |||
START_GROUP_MARKER | The prefix used to mark a comment that starts a group. | ||
END_GROUP_MARKER | The prefix used to mark a comment that ends a group. | ||
Line processing | |||
CONTROL_FLOW_KEYWORDS | A list of the control flow keywords. |
|
filename parameter or the name
parameter. (It is an error to specify both a filename and a name; or to
specify neither a filename nor a name).
|
ModuleDoc .
|
|
|
name . package_doc , if specified, is the API
documentation for the package containing the named object.
|
var_name is the name of a variable in
module_doc that just contains an imported_from
link to a submodule of the same name. (I.e., is a variable created when
a package imports one of its own submodules.)
|
|
|
ModuleDoc 's file, and add variables
corresponding to any objects defined in that file. In particular, read
and tokenize module_doc.filename , and process each logical
line using process_line().
|
|
Given a flat list of tokens, return a nested tree structure (called a token tree), whose leaves are identical to the original list, but whose structure reflects the structure implied by the grouping tokens (i.e., parenthases, braces, and brackets). If the parenthases, braces, and brackets do not match, or are not balanced, then raise a ParseError. Assign some structure to a sequence of structure (group parens). |
|
|
|
|
>>> from <src> import *
If IMPORT_HANDLING is <src> , and create a new variable
for each export. If IMPORT_STAR_HANDLING is 'parse' , then
the list of exports if found by parsing <src> ; if it is 'introspect' ,
then the list of exports is found by importing and introspecting <src> .
|
>>> import <name>
If IMPORT_HANDLING is 'import a.b' , where
we need to create a variable 'a' in parentdoc containing a
proxy module; and a variable 'b' in the proxy module.
|
>>> import src as name
If IMPORT_HANDLING is imported_from
attribute pointing to the imported object.
|
name to
container , with imported_from=src .
|
parent_docs ), then convert it to a global
name.
|
|
|
|
|
>>> def f(x): return x*2
This handler calls process_line twice: once for the tokens up to and
including the colon, and once for the remaining tokens. The comment
docstring is applied to the first line only.
|
>>> x=1; y=2; z=3
This handler calls process_line once for each statement. The comment
docstring is not passed on to any of the sub-statements.
|
>>> del x, y.z
This handler calls del_variable for each dotted variable in the variable
list. The variable list may be nested. Complex expressions in the
variable list (such as x[3] ) are ignored.
|
prev_line_doc is not None , then the string
literal is added to that APIDoc as a docstring. If it
already has a docstring (from comment docstrings), then the new docstring
will be appended to the old one.
|
>>> def f(a, b=22, (c,d)):
This handler creates and initializes a new VariableDoc
containing a RoutineDoc , adds the VariableDoc
to the containing namespace, and returns the RoutineDoc .
|
|
|
>>> class Foo(Bar, Baz):
This handler creates and initializes a new VariableDoc
containing a ClassDoc , adds the VariableDoc to
the containing namespace, and returns the ClassDoc .
|
|
|
|
|
|
|
|
|
|
|
preserve_docstring is true, then keep the old variable's
docstring when overwriting a variable.
|
|
|
|
|
|
|
|
|
|
|
_moduledoc_cacheA cache ofModuleDoc s that we've already created.
_moduledoc_cache is a dictionary mapping from filenames to
ValueDoc objects.
|
PARSE_TRY_BLOCKSShould the contents oftry blocks be examined?
|
PARSE_EXCEPT_BLOCKSShould the contents ofexcept blocks be examined?
|
PARSE_FINALLY_BLOCKSShould the contents offinally blocks be examined?
|
PARSE_IF_BLOCKSShould the contents ofif blocks be examined?
|
PARSE_ELSE_BLOCKSShould the contents ofelse and elif blocks
be examined?
|
PARSE_WHILE_BLOCKSShould the contents ofwhile blocks be examined?
|
PARSE_FOR_BLOCKSShould the contents offor blocks be examined?
|
IMPORT_HANDLINGWhat shoulddocparser do when it encounters an import
statement?
|
IMPORT_STAR_HANDLINGWhendocparser encounters a 'from m import *' statement, and is unable to parse
m (either because
IMPORT_HANDLING='link' , or because parsing failed), how
should it determine the list of identifiers expored by m ?
|
DEFAULT_DECORATOR_BEHAVIORWhenDocParse encounters an unknown decorator, what
should it do to the documentation of the decorated function?
|
BASE_HANDLINGWhat shoulddocparser do when it encounters a base class
that was imported from another module?
|
COMMENT_DOCSTRING_MARKERThe prefix used to mark comments that contain attribute docstrings for variables.
|
START_GROUP_MARKERThe prefix used to mark a comment that starts a group. This marker should be followed (on the same line) by the name of the group. Following a start-group comment, all variables defined at the same indentation level will be assigned to this group name, until the parser reaches the end of the file, a matching end-group comment, or another start-group comment at the same indentation level.
|
END_GROUP_MARKERThe prefix used to mark a comment that ends a group. See START_GROUP_MARKER.
|
CONTROL_FLOW_KEYWORDSA list of the control flow keywords. If a line begins with one of these keywords, then it should be handled byprocess_control_flow_line .
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 3.0alpha2 on Tue Apr 11 17:30:51 2006 | http://epydoc.sf.net |