Exemple #1
0
 def document(self):
     if self._doc is None:
         # Use the rst parsers document output to do as much of the
         # validation as we can without resorting to custom logic (this
         # parser is what sphinx and others use anyway so it's hopefully
         # mature).
         parser_cls = docutils_parser.get_parser_class("rst")
         parser = parser_cls()
         defaults = {
             'halt_level': 5,
             'report_level': 5,
             'quiet': True,
             'file_insertion_enabled': False,
             'traceback': True,
             # Development use only.
             'dump_settings': False,
             'dump_internals': False,
             'dump_transforms': False,
         }
         opt = frontend.OptionParser(components=[parser], defaults=defaults)
         doc = utils.new_document(source_path=self.filename,
                                  settings=opt.get_default_values())
         parser.parse(self.contents, doc)
         self._doc = doc
     return self._doc
Exemple #2
0
    def test_inputrestrictions(self):
        parser_class = parsers.get_parser_class('rst')
        parser = parser_class()
        document = utils.new_document('test data', frontend.OptionParser(
                    components=(parser, )).get_default_values())

        self.assertRaises(UnicodeError, # UnicodeDecodeError since py2.3
                          parser.parse, 'hol%s' % chr(224), document)
Exemple #3
0
 def get_parser(self, parser_name):
     """
     Get a parser based on its name.  We reuse parsers during this
     visitation, so parser instances are cached.
     """
     parser_name = parsers._parser_aliases.get(parser_name, parser_name)
     if not self.parsers.has_key(parser_name):
         cls = parsers.get_parser_class(parser_name)
         self.parsers[parser_name] = cls()
     return self.parsers[parser_name]
Exemple #4
0
 def get_parser(self, parser_name):
     """
     Get a parser based on its name.  We reuse parsers during this
     visitation, so parser instances are cached.
     """
     parser_name = parsers._parser_aliases.get(parser_name, parser_name)
     if not self.parsers.has_key(parser_name):
         cls = parsers.get_parser_class(parser_name)
         self.parsers[parser_name] = cls()
     return self.parsers[parser_name]
Exemple #5
0
def getTree(rstTxt):
    """From a given RST string, parses into an abstract document tree, which is
       then returned.
    """
    RstParser = parsers.get_parser_class("rst")
    settings = frontend.OptionParser(
        components=(RstParser, )).get_default_values()
    doc = utils.new_document("", settings)
    psr = RstParser()
    psr.parse(rstTxt, doc)
    return doc
    def test_inputrestrictions(self):
        parser_class = parsers.get_parser_class('rst')
        parser = parser_class()
        document = utils.new_document('test data', frontend.OptionParser(
                    components=(parser, )).get_default_values())

        if sys.version_info < (3,):
            # supplying string input is supported, but only if ascii-decodable
            self.assertRaises(UnicodeDecodeError,
                              parser.parse, b'hol%s' % chr(224), document)
        else:
            # input must be unicode at all times
            self.assertRaises(TypeError, parser.parse, b'hol', document)
Exemple #7
0
    def test_inputrestrictions(self):
        parser_class = parsers.get_parser_class('rst')
        parser = parser_class()
        document = utils.new_document('test data', frontend.OptionParser(
                    components=(parser, )).get_default_values())

        if sys.version_info < (3,):
            # supplying string input is supported, but only if ascii-decodable
            self.assertRaises(UnicodeError, # UnicodeDecodeError since py2.3
                              parser.parse, b('hol%s' % chr(224)), document)
        else:
            # input must be unicode at all times
            self.assertRaises(TypeError, parser.parse, b('hol'), document)
Exemple #8
0
def parser_name(argument):
    """
    Return a docutils parser whose name matches the argument.
    (Directive option conversion function.)

    Return `None`, if the argument evaluates to `False`.
    """
    if not argument:
        return None
    try:
        return parsers.get_parser_class(argument)
    except ImportError:
        raise ValueError('Unknown parser name "%s".'%argument)
def aFunction(string):
    source  = StringInput(string, encoding='utf-8')
    docname = "fake"
    __app.env.temp_data['docname'] = docname

    settings = frontend.OptionParser((Writer,)).get_default_values()
    settings.tab_width = 8
    settings.pep_references = False
    settings.rfc_references = False
    settings.env = __app.env

    reader = DoctreeReader()
    parser = parsers.get_parser_class("rst")()

    docu   = utils.new_document(source.source_path, settings)
    parser.parse(source.read(), docu)
    __app.builder.prepare_writing((docname,))
    return __app.builder.write_doc(docname, docu).destination
Exemple #10
0
def aFunction(string):
    source = StringInput(string, encoding='utf-8')
    docname = "fake"
    __app.env.temp_data['docname'] = docname

    settings = frontend.OptionParser((Writer, )).get_default_values()
    settings.tab_width = 8
    settings.pep_references = False
    settings.rfc_references = False
    settings.env = __app.env

    reader = DoctreeReader()
    parser = parsers.get_parser_class("rst")()

    docu = utils.new_document(source.source_path, settings)
    parser.parse(source.read(), docu)
    __app.builder.prepare_writing((docname, ))
    return __app.builder.write_doc(docname, docu).destination
Exemple #11
0
 def set_parser(self, parser_name):
     """Set `self.parser` by name."""
     parser_class = parsers.get_parser_class(parser_name)
     self.parser = parser_class()
 def test_local_parser(self):
     # requires local-parser.py in test directory (testroot)
     wr = get_parser_class('local-parser')
 def test_registered_parser(self):
     rdr = get_parser_class('rst')
 def set_parser(self, parser_name):
     """Set `self.parser` by name."""
     parser_class = parsers.get_parser_class(parser_name)
     self.parser = parser_class()