[Zope-Checkins] CVS: Zope/lib/python/docutils/readers - __init__.py:1.2.10.3 pep.py:1.2.10.3 standalone.py:1.2.10.3

Andreas Jung cvs-admin at zope.org
Sun Nov 30 11:05:55 EST 2003


Update of /cvs-repository/Zope/lib/python/docutils/readers
In directory cvs.zope.org:/tmp/cvs-serv9303/readers

Added Files:
      Tag: Zope-2_7-branch
	__init__.py pep.py standalone.py 
Log Message:
updated



=== Zope/lib/python/docutils/readers/__init__.py 1.2.10.2 => 1.2.10.3 ===
--- /dev/null	Sun Nov 30 11:05:55 2003
+++ Zope/lib/python/docutils/readers/__init__.py	Sun Nov 30 11:05:25 2003
@@ -0,0 +1,89 @@
+# Authors: David Goodger; Ueli Schlaepfer
+# Contact: goodger at users.sourceforge.net
+# Revision: $Revision$
+# Date: $Date$
+# Copyright: This module has been placed in the public domain.
+
+"""
+This package contains Docutils Reader modules.
+"""
+
+__docformat__ = 'reStructuredText'
+
+
+import sys
+from docutils import utils, parsers, Component
+from docutils.transforms import universal
+
+
+class Reader(Component):
+
+    """
+    Abstract base class for docutils Readers.
+
+    Each reader module or package must export a subclass also called 'Reader'.
+
+    The three steps of a Reader's responsibility are defined: `scan()`,
+    `parse()`, and `transform()`. Call `read()` to process a document.
+    """
+
+    component_type = 'reader'
+    config_section = 'readers'
+
+    def __init__(self, parser=None, parser_name='restructuredtext'):
+        """
+        Initialize the Reader instance.
+
+        Several instance attributes are defined with dummy initial values.
+        Subclasses may use these attributes as they wish.
+        """
+
+        self.parser = parser
+        """A `parsers.Parser` instance shared by all doctrees.  May be left
+        unspecified if the document source determines the parser."""
+
+        if parser is None and parser_name:
+            self.set_parser(parser_name)
+
+        self.source = None
+        """`docutils.io` IO object, source of input data."""
+
+        self.input = None
+        """Raw text input; either a single string or, for more complex cases,
+        a collection of strings."""
+
+    def set_parser(self, parser_name):
+        """Set `self.parser` by name."""
+        parser_class = parsers.get_parser_class(parser_name)
+        self.parser = parser_class()
+
+    def read(self, source, parser, settings):
+        self.source = source
+        if not self.parser:
+            self.parser = parser
+        self.settings = settings
+        self.input = self.source.read()
+        self.parse()
+        return self.document
+
+    def parse(self):
+        """Parse `self.input` into a document tree."""
+        self.document = document = self.new_document()
+        self.parser.parse(self.input, document)
+        document.current_source = document.current_line = None
+
+    def new_document(self):
+        """Create and return a new empty document tree (root node)."""
+        document = utils.new_document(self.source.source_path, self.settings)
+        return document
+
+
+_reader_aliases = {}
+
+def get_reader_class(reader_name):
+    """Return the Reader class from the `reader_name` module."""
+    reader_name = reader_name.lower()
+    if _reader_aliases.has_key(reader_name):
+        reader_name = _reader_aliases[reader_name]
+    module = __import__(reader_name, globals(), locals())
+    return module.Reader


=== Zope/lib/python/docutils/readers/pep.py 1.2.10.2 => 1.2.10.3 ===
--- /dev/null	Sun Nov 30 11:05:55 2003
+++ Zope/lib/python/docutils/readers/pep.py	Sun Nov 30 11:05:25 2003
@@ -0,0 +1,61 @@
+# Author: David Goodger
+# Contact: goodger at users.sourceforge.net
+# Revision: $Revision$
+# Date: $Date$
+# Copyright: This module has been placed in the public domain.
+
+"""
+Python Enhancement Proposal (PEP) Reader.
+"""
+
+__docformat__ = 'reStructuredText'
+
+
+from docutils.readers import standalone
+from docutils.transforms import peps, references
+from docutils.parsers import rst
+
+
+class Inliner(rst.states.Inliner):
+
+    """
+    Extend `rst.Inliner` for local PEP references.
+    """
+
+    pep_url = rst.states.Inliner.pep_url_local
+
+
+class Reader(standalone.Reader):
+
+    supported = ('pep',)
+    """Contexts this reader supports."""
+
+    settings_spec = (
+        'PEP Reader Option Defaults',
+        'The --pep-references and --rfc-references options (for the '
+        'reStructuredText parser) are on by default.',
+        ())
+
+    config_section = 'pep reader'
+    config_section_dependencies = ('readers', 'standalone reader')
+
+    default_transforms = (references.Substitutions,
+                          peps.Headers,
+                          peps.Contents,
+                          references.ChainedTargets,
+                          references.AnonymousHyperlinks,
+                          references.IndirectHyperlinks,
+                          peps.TargetNotes,
+                          references.Footnotes,
+                          references.ExternalTargets,
+                          references.InternalTargets,)
+
+    settings_default_overrides = {'pep_references': 1, 'rfc_references': 1}
+
+    inliner_class = Inliner
+
+    def __init__(self, parser=None, parser_name=None):
+        """`parser` should be ``None``."""
+        if parser is None:
+            parser = rst.Parser(rfc2822=1, inliner=self.inliner_class())
+        standalone.Reader.__init__(self, parser, '')


=== Zope/lib/python/docutils/readers/standalone.py 1.2.10.2 => 1.2.10.3 ===
--- /dev/null	Sun Nov 30 11:05:55 2003
+++ Zope/lib/python/docutils/readers/standalone.py	Sun Nov 30 11:05:25 2003
@@ -0,0 +1,54 @@
+# Author: David Goodger
+# Contact: goodger at users.sourceforge.net
+# Revision: $Revision$
+# Date: $Date$
+# Copyright: This module has been placed in the public domain.
+
+"""
+Standalone file Reader for the reStructuredText markup syntax.
+"""
+
+__docformat__ = 'reStructuredText'
+
+
+import sys
+from docutils import frontend, readers
+from docutils.transforms import frontmatter, references
+from docutils.parsers.rst import Parser
+
+
+class Reader(readers.Reader):
+
+    supported = ('standalone',)
+    """Contexts this reader supports."""
+
+    document = None
+    """A single document tree."""
+
+    settings_spec = (
+        'Standalone Reader',
+        None,
+        (('Disable the promotion of a lone top-level section title to '
+          'document title (and subsequent section title to document '
+          'subtitle promotion; enabled by default).',
+          ['--no-doc-title'],
+          {'dest': 'doctitle_xform', 'action': 'store_false', 'default': 1,
+           'validator': frontend.validate_boolean}),
+         ('Disable the bibliographic field list transform (enabled by '
+          'default).',
+          ['--no-doc-info'],
+          {'dest': 'docinfo_xform', 'action': 'store_false', 'default': 1,
+           'validator': frontend.validate_boolean}),))
+
+    config_section = 'standalone reader'
+    config_section_dependencies = ('readers',)
+
+    default_transforms = (references.Substitutions,
+                          frontmatter.DocTitle,
+                          frontmatter.DocInfo,
+                          references.ChainedTargets,
+                          references.AnonymousHyperlinks,
+                          references.IndirectHyperlinks,
+                          references.Footnotes,
+                          references.ExternalTargets,
+                          references.InternalTargets,)




More information about the Zope-Checkins mailing list