From d1e833c256b95461a2d5af437c4ce16b71345c22 Mon Sep 17 00:00:00 2001 From: ianbicking Date: Mon, 22 Mar 2004 15:11:35 +0000 Subject: Added the pynodes file I missed yesterday. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1858 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/readers/python/pynodes.py | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 docutils/readers/python/pynodes.py (limited to 'docutils/readers/python/pynodes.py') diff --git a/docutils/readers/python/pynodes.py b/docutils/readers/python/pynodes.py new file mode 100644 index 000000000..f246a5dc6 --- /dev/null +++ b/docutils/readers/python/pynodes.py @@ -0,0 +1,80 @@ +#! /usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +""" + +from docutils import nodes +from docutils.nodes import Element, TextElement, Structural, Inline, Part + + +# ===================== +# Structural Elements +# ===================== + +class package_section(Structural, Element): pass +class module_section(Structural, Element): pass +class class_section(Structural, Element): pass +class method_section(Structural, Element): pass +class function_section(Structural, Element): pass +class module_attribute_section(Structural, Element): pass +class class_attribute_section(Structural, Element): pass +class instance_attribute_section(Structural, Element): pass + +# Structural Support Elements +# --------------------------- + +class inheritance_list(Part, Element): pass +class parameter_list(Part, Element): pass +class parameter_item(Part, Element): pass +class optional_parameters(Part, Element): pass +class parameter_tuple(Part, Element): pass +class parameter_default(Part, TextElement): pass +class initial_value(Part, TextElement): pass +class import_item(Part, TextElement): pass + +# ================= +# Inline Elements +# ================= + +# These elements cannot become references until the second +# pass. Initially, we'll use "reference" or "name". + +class package(Part, Inline, TextElement): pass +class module(Part, Inline, TextElement): pass + + +class inline_class(Part, Inline, TextElement): + + tagname = 'class' + + +class method(Part, Inline, TextElement): pass +class function(Part, Inline, TextElement): pass +class variable(Inline, TextElement): pass +class parameter(Part, Inline, TextElement): pass +class inline_type(Inline, TextElement): + tagname = 'type' +class class_attribute(Part, Inline, TextElement): pass +class module_attribute(Part, Inline, TextElement): pass +class instance_attribute(Part, Inline, TextElement): pass +class exception_class(Inline, TextElement): pass +class warning_class(Inline, TextElement): pass + +# Collect all the classes we've written above +node_class_names = [] +def build_node_class_names(): + for name, var in globals().items(): + if type(var) is types.ClassType \ + and issubclass(var, nodes.Node) \ + and name.lower() == name: + node_class_names.append(var.tagname or name) + +# Register the new node names with GenericNodeVisitor and +# SpecificNodeVisitor: +nodes._add_node_class_names(node_class_names) -- cgit v1.2.1 From db10b42915077db1a6cbb936145d0d803142b12a Mon Sep 17 00:00:00 2001 From: ianbicking Date: Tue, 23 Mar 2004 19:57:14 +0000 Subject: * Bug fixes to python reader * Getting tests up-to-date * Trimming unused nodes from pynodes git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1876 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/readers/python/pynodes.py | 81 +++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'docutils/readers/python/pynodes.py') diff --git a/docutils/readers/python/pynodes.py b/docutils/readers/python/pynodes.py index f246a5dc6..40db6975e 100644 --- a/docutils/readers/python/pynodes.py +++ b/docutils/readers/python/pynodes.py @@ -10,33 +10,39 @@ """ from docutils import nodes -from docutils.nodes import Element, TextElement, Structural, Inline, Part +from docutils.nodes import Element, TextElement, Structural, Inline, Part, \ + Text +import types +# This is the parent class of all the other pynode classes: +class PythonStructural(Structural): pass # ===================== # Structural Elements # ===================== -class package_section(Structural, Element): pass -class module_section(Structural, Element): pass -class class_section(Structural, Element): pass -class method_section(Structural, Element): pass -class function_section(Structural, Element): pass -class module_attribute_section(Structural, Element): pass -class class_attribute_section(Structural, Element): pass -class instance_attribute_section(Structural, Element): pass +class module_section(PythonStructural, Element): pass +class class_section(PythonStructural, Element): pass +class class_base(PythonStructural, Element): pass +class method_section(PythonStructural, Element): pass +class attribute(PythonStructural, Element): pass +class function_section(PythonStructural, Element): pass +class class_attribute_section(PythonStructural, Element): pass +class class_attribute(PythonStructural, Element): pass +class expression_value(PythonStructural, Element): pass +class attribute(PythonStructural, Element): pass # Structural Support Elements # --------------------------- -class inheritance_list(Part, Element): pass -class parameter_list(Part, Element): pass -class parameter_item(Part, Element): pass -class optional_parameters(Part, Element): pass -class parameter_tuple(Part, Element): pass -class parameter_default(Part, TextElement): pass -class initial_value(Part, TextElement): pass -class import_item(Part, TextElement): pass +class parameter_list(PythonStructural, Element): pass +class parameter_tuple(PythonStructural, Element): pass +class parameter_default(PythonStructural, TextElement): pass +class import_group(PythonStructural, TextElement): pass +class import_from(PythonStructural, TextElement): pass +class import_name(PythonStructural, TextElement): pass +class import_alias(PythonStructural, TextElement): pass +class docstring(PythonStructural, Element): pass # ================= # Inline Elements @@ -45,34 +51,35 @@ class import_item(Part, TextElement): pass # These elements cannot become references until the second # pass. Initially, we'll use "reference" or "name". -class package(Part, Inline, TextElement): pass -class module(Part, Inline, TextElement): pass +class object_name(PythonStructural, TextElement): pass +class parameter_list(PythonStructural, TextElement): pass +class parameter(PythonStructural, TextElement): pass +class parameter_default(PythonStructural, TextElement): pass +class class_attribute(PythonStructural, TextElement): pass +class attribute_tuple(PythonStructural, TextElement): pass +# ================= +# Unused Elements +# ================= -class inline_class(Part, Inline, TextElement): - - tagname = 'class' - +# These were part of the model, and maybe should be in the future, but +# aren't now. +#class package_section(PythonStructural, Element): pass +#class module_attribute_section(PythonStructural, Element): pass +#class instance_attribute_section(PythonStructural, Element): pass +#class module_attribute(PythonStructural, TextElement): pass +#class instance_attribute(PythonStructural, TextElement): pass +#class exception_class(PythonStructural, TextElement): pass +#class warning_class(PythonStructural, TextElement): pass -class method(Part, Inline, TextElement): pass -class function(Part, Inline, TextElement): pass -class variable(Inline, TextElement): pass -class parameter(Part, Inline, TextElement): pass -class inline_type(Inline, TextElement): - tagname = 'type' -class class_attribute(Part, Inline, TextElement): pass -class module_attribute(Part, Inline, TextElement): pass -class instance_attribute(Part, Inline, TextElement): pass -class exception_class(Inline, TextElement): pass -class warning_class(Inline, TextElement): pass # Collect all the classes we've written above node_class_names = [] def build_node_class_names(): for name, var in globals().items(): - if type(var) is types.ClassType \ - and issubclass(var, nodes.Node) \ - and name.lower() == name: + if (type(var) is types.ClassType + and issubclass(var, PythonStructural) \ + and name.lower() == name): node_class_names.append(var.tagname or name) # Register the new node names with GenericNodeVisitor and -- cgit v1.2.1 From c75f5e75d567181ab0267cf4224a3cea59adc53f Mon Sep 17 00:00:00 2001 From: ianbicking Date: Tue, 23 Mar 2004 23:21:11 +0000 Subject: Reader parses docstrings (according to __docformat__) and produces full output. The reader should thus be "done". Run readers/python/__init__.py with a filename argument to get output in the DOM format. A transformer will be necessary to translate this into the standard docutils DOM. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1881 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/readers/python/pynodes.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docutils/readers/python/pynodes.py') diff --git a/docutils/readers/python/pynodes.py b/docutils/readers/python/pynodes.py index 40db6975e..61e21f10e 100644 --- a/docutils/readers/python/pynodes.py +++ b/docutils/readers/python/pynodes.py @@ -74,14 +74,14 @@ class attribute_tuple(PythonStructural, TextElement): pass # Collect all the classes we've written above -node_class_names = [] -def build_node_class_names(): +def install_node_class_names(): + node_class_names = [] for name, var in globals().items(): if (type(var) is types.ClassType and issubclass(var, PythonStructural) \ and name.lower() == name): node_class_names.append(var.tagname or name) - -# Register the new node names with GenericNodeVisitor and -# SpecificNodeVisitor: -nodes._add_node_class_names(node_class_names) + # Register the new node names with GenericNodeVisitor and + # SpecificNodeVisitor: + nodes._add_node_class_names(node_class_names) +install_node_class_names() -- cgit v1.2.1