[Zope-Checkins] CVS: Zope/lib/python/docutils/parsers - __init__.py:1.2

Andreas Jung andreas@andreas-jung.com
Sat, 1 Feb 2003 04:26:38 -0500


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

Added Files:
	__init__.py 
Log Message:
merge from ajung-restructuredtext-integration-branch


=== Zope/lib/python/docutils/parsers/__init__.py 1.1 => 1.2 ===
--- /dev/null	Sat Feb  1 04:26:38 2003
+++ Zope/lib/python/docutils/parsers/__init__.py	Sat Feb  1 04:26:05 2003
@@ -0,0 +1,48 @@
+# Author: David Goodger
+# Contact: goodger@users.sourceforge.net
+# Revision: $Revision$
+# Date: $Date$
+# Copyright: This module has been placed in the public domain.
+
+"""
+This package contains Docutils parser modules.
+"""
+
+__docformat__ = 'reStructuredText'
+
+from docutils import Component
+
+
+class Parser(Component):
+
+    component_type = 'parser'
+
+    def parse(self, inputstring, document):
+        """Override to parse `inputstring` into document tree `document`."""
+        raise NotImplementedError('subclass must override this method')
+
+    def setup_parse(self, inputstring, document):
+        """Initial parse setup.  Call at start of `self.parse()`."""
+        self.inputstring = inputstring
+        self.document = document
+        document.reporter.attach_observer(document.note_parse_message)
+
+    def finish_parse(self):
+        """Finalize parse details.  Call at end of `self.parse()`."""
+        self.document.reporter.detach_observer(
+            self.document.note_parse_message)
+
+
+_parser_aliases = {
+      'restructuredtext': 'rst',
+      'rest': 'rst',
+      'restx': 'rst',
+      'rtxt': 'rst',}
+
+def get_parser_class(parser_name):
+    """Return the Parser class from the `parser_name` module."""
+    parser_name = parser_name.lower()
+    if _parser_aliases.has_key(parser_name):
+        parser_name = _parser_aliases[parser_name]
+    module = __import__(parser_name, globals(), locals())
+    return module.Parser