Revert "io.FileInput/io.FileOutput: No system-exit on IOError."
[docutils.git] / docutils / parsers / __init__.py
blob2683376f991bf497eed8d780ed6d53c09ef32775
1 # $Id$
2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
5 """
6 This package contains Docutils parser modules.
7 """
9 __docformat__ = 'reStructuredText'
11 from docutils import Component
14 class Parser(Component):
16 component_type = 'parser'
17 config_section = 'parsers'
19 def parse(self, inputstring, document):
20 """Override to parse `inputstring` into document tree `document`."""
21 raise NotImplementedError('subclass must override this method')
23 def setup_parse(self, inputstring, document):
24 """Initial parse setup. Call at start of `self.parse()`."""
25 self.inputstring = inputstring
26 self.document = document
27 document.reporter.attach_observer(document.note_parse_message)
29 def finish_parse(self):
30 """Finalize parse details. Call at end of `self.parse()`."""
31 self.document.reporter.detach_observer(
32 self.document.note_parse_message)
35 _parser_aliases = {
36 'restructuredtext': 'rst',
37 'rest': 'rst',
38 'restx': 'rst',
39 'rtxt': 'rst',}
41 def get_parser_class(parser_name):
42 """Return the Parser class from the `parser_name` module."""
43 parser_name = parser_name.lower()
44 if parser_name in _parser_aliases:
45 parser_name = _parser_aliases[parser_name]
46 module = __import__(parser_name, globals(), locals())
47 return module.Parser