2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
6 This package contains Docutils parser modules.
9 __docformat__
= 'reStructuredText'
12 from docutils
import Component
13 if sys
.version_info
< (2,5):
14 from docutils
._compat
import __import__
17 class Parser(Component
):
19 component_type
= 'parser'
20 config_section
= 'parsers'
22 def parse(self
, inputstring
, document
):
23 """Override to parse `inputstring` into document tree `document`."""
24 raise NotImplementedError('subclass must override this method')
26 def setup_parse(self
, inputstring
, document
):
27 """Initial parse setup. Call at start of `self.parse()`."""
28 self
.inputstring
= inputstring
29 self
.document
= document
30 document
.reporter
.attach_observer(document
.note_parse_message
)
32 def finish_parse(self
):
33 """Finalize parse details. Call at end of `self.parse()`."""
34 self
.document
.reporter
.detach_observer(
35 self
.document
.note_parse_message
)
39 'restructuredtext': 'rst',
44 def get_parser_class(parser_name
):
45 """Return the Parser class from the `parser_name` module."""
46 parser_name
= parser_name
.lower()
47 if parser_name
in _parser_aliases
:
48 parser_name
= _parser_aliases
[parser_name
]
50 module
= __import__(parser_name
, globals(), locals(), level
=1)
52 module
= __import__(parser_name
, globals(), locals(), level
=0)