1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | :Author: David Goodger |
---|
5 | :Contact: goodger@users.sourceforge.net |
---|
6 | :Revision: $Revision: 1881 $ |
---|
7 | :Date: $Date: 2004-03-24 00:21:11 +0100 (Wed, 24 Mar 2004) $ |
---|
8 | :Copyright: This module has been placed in the public domain. |
---|
9 | |
---|
10 | """ |
---|
11 | |
---|
12 | from docutils import nodes |
---|
13 | from docutils.nodes import Element, TextElement, Structural, Inline, Part, \ |
---|
14 | Text |
---|
15 | import types |
---|
16 | |
---|
17 | # This is the parent class of all the other pynode classes: |
---|
18 | class PythonStructural(Structural): pass |
---|
19 | |
---|
20 | # ===================== |
---|
21 | # Structural Elements |
---|
22 | # ===================== |
---|
23 | |
---|
24 | class module_section(PythonStructural, Element): pass |
---|
25 | class class_section(PythonStructural, Element): pass |
---|
26 | class class_base(PythonStructural, Element): pass |
---|
27 | class method_section(PythonStructural, Element): pass |
---|
28 | class attribute(PythonStructural, Element): pass |
---|
29 | class function_section(PythonStructural, Element): pass |
---|
30 | class class_attribute_section(PythonStructural, Element): pass |
---|
31 | class class_attribute(PythonStructural, Element): pass |
---|
32 | class expression_value(PythonStructural, Element): pass |
---|
33 | class attribute(PythonStructural, Element): pass |
---|
34 | |
---|
35 | # Structural Support Elements |
---|
36 | # --------------------------- |
---|
37 | |
---|
38 | class parameter_list(PythonStructural, Element): pass |
---|
39 | class parameter_tuple(PythonStructural, Element): pass |
---|
40 | class parameter_default(PythonStructural, TextElement): pass |
---|
41 | class import_group(PythonStructural, TextElement): pass |
---|
42 | class import_from(PythonStructural, TextElement): pass |
---|
43 | class import_name(PythonStructural, TextElement): pass |
---|
44 | class import_alias(PythonStructural, TextElement): pass |
---|
45 | class docstring(PythonStructural, Element): pass |
---|
46 | |
---|
47 | # ================= |
---|
48 | # Inline Elements |
---|
49 | # ================= |
---|
50 | |
---|
51 | # These elements cannot become references until the second |
---|
52 | # pass. Initially, we'll use "reference" or "name". |
---|
53 | |
---|
54 | class object_name(PythonStructural, TextElement): pass |
---|
55 | class parameter_list(PythonStructural, TextElement): pass |
---|
56 | class parameter(PythonStructural, TextElement): pass |
---|
57 | class parameter_default(PythonStructural, TextElement): pass |
---|
58 | class class_attribute(PythonStructural, TextElement): pass |
---|
59 | class attribute_tuple(PythonStructural, TextElement): pass |
---|
60 | |
---|
61 | # ================= |
---|
62 | # Unused Elements |
---|
63 | # ================= |
---|
64 | |
---|
65 | # These were part of the model, and maybe should be in the future, but |
---|
66 | # aren't now. |
---|
67 | #class package_section(PythonStructural, Element): pass |
---|
68 | #class module_attribute_section(PythonStructural, Element): pass |
---|
69 | #class instance_attribute_section(PythonStructural, Element): pass |
---|
70 | #class module_attribute(PythonStructural, TextElement): pass |
---|
71 | #class instance_attribute(PythonStructural, TextElement): pass |
---|
72 | #class exception_class(PythonStructural, TextElement): pass |
---|
73 | #class warning_class(PythonStructural, TextElement): pass |
---|
74 | |
---|
75 | |
---|
76 | # Collect all the classes we've written above |
---|
77 | def install_node_class_names(): |
---|
78 | node_class_names = [] |
---|
79 | for name, var in globals().items(): |
---|
80 | if (type(var) is types.ClassType |
---|
81 | and issubclass(var, PythonStructural) \ |
---|
82 | and name.lower() == name): |
---|
83 | node_class_names.append(var.tagname or name) |
---|
84 | # Register the new node names with GenericNodeVisitor and |
---|
85 | # SpecificNodeVisitor: |
---|
86 | nodes._add_node_class_names(node_class_names) |
---|
87 | install_node_class_names() |
---|