buildframework/helium/external/python/lib/common/docutils-0.5-py2.5.egg/docutils/parsers/__init__.py
changeset 179 d8ac696cc51f
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
       
     1 # $Id: __init__.py 4564 2006-05-21 20:44:42Z wiemann $
       
     2 # Author: David Goodger <goodger@python.org>
       
     3 # Copyright: This module has been placed in the public domain.
       
     4 
       
     5 """
       
     6 This package contains Docutils parser modules.
       
     7 """
       
     8 
       
     9 __docformat__ = 'reStructuredText'
       
    10 
       
    11 from docutils import Component
       
    12 
       
    13 
       
    14 class Parser(Component):
       
    15 
       
    16     component_type = 'parser'
       
    17     config_section = 'parsers'
       
    18 
       
    19     def parse(self, inputstring, document):
       
    20         """Override to parse `inputstring` into document tree `document`."""
       
    21         raise NotImplementedError('subclass must override this method')
       
    22 
       
    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)
       
    28 
       
    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)
       
    33 
       
    34 
       
    35 _parser_aliases = {
       
    36       'restructuredtext': 'rst',
       
    37       'rest': 'rst',
       
    38       'restx': 'rst',
       
    39       'rtxt': 'rst',}
       
    40 
       
    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_aliases.has_key(parser_name):
       
    45         parser_name = _parser_aliases[parser_name]
       
    46     module = __import__(parser_name, globals(), locals())
       
    47     return module.Parser