Example #1
0
 def parametric_test(self, filename):
     with codecs.open(filename, encoding="utf-8") as fp:
         testdata = fp.read()
     
     cp = CitationParser(self.parser)
     nodes = cp.parse_string(testdata)
     got = []
     for node in nodes:
         if isinstance(node, str):
             got.append(node.strip())
         else:
             (text, result) = node
             got.append(util.parseresults_as_xml(result).strip())
     
     wantfile = os.path.splitext(filename)[0] + ".result"
     if os.path.exists(wantfile):
         with open(wantfile) as fp:
             want = [x.strip() for x in fp.read().split("\n\n")]
     else:
         print("\nparse_string() returns:")
         print("\n\n".join(compare))
         self.fail("%s not found" % wantfile)
     self.maxDiff = 4096
     self.assertListEqual(want,got)
Example #2
0
    def parametric_test(self, filename):
        with codecs.open(filename, encoding="utf-8") as fp:
            testdata = fp.read()

        cp = CitationParser(self.parser)
        nodes = cp.parse_string(testdata)
        got = []
        for node in nodes:
            if isinstance(node, str):
                got.append(node.strip())
            else:
                (text, result) = node
                got.append(util.parseresults_as_xml(result).strip())

        wantfile = os.path.splitext(filename)[0] + ".result"
        if os.path.exists(wantfile):
            with open(wantfile) as fp:
                want = [x.strip() for x in fp.read().split("\n\n")]
        else:
            print("\nparse_string() returns:")
            print("\n\n".join(compare))
            self.fail("%s not found" % wantfile)
        self.maxDiff = 4096
        self.assertListEqual(want, got)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# begin
from ferenda import CitationParser, URIFormatter, citationpatterns, uriformats
from ferenda.elements import Link

citparser = CitationParser()
citparser.add_grammar(citationpatterns.url)
formatter = URIFormatter(("url", uriformats.url))

res = []
text = "An example: http://example.org/. That is all."

for node in citparser.parse_string(text):
    if isinstance(node,str):
        # non-linked text, add and continue
        res.append(node)
    if isinstance(node, tuple):
        (text, match) = node
        uri = formatter.format(match)
        if uri:
            res.append(Link(uri, text, rel="dcterms:references"))
# end
return_value = True
Example #4
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# begin
from ferenda import CitationParser, URIFormatter, citationpatterns, uriformats
from ferenda.elements import Link

citparser = CitationParser()
citparser.add_grammar(citationpatterns.url)
formatter = URIFormatter(("url", uriformats.url))

res = []
text = "An example: http://example.org/. That is all."

for node in citparser.parse_string(text):
    if isinstance(node, str):
        # non-linked text, add and continue
        res.append(node)
    if isinstance(node, tuple):
        (text, match) = node
        uri = formatter.format(match)
        if uri:
            res.append(Link(uri, text, rel="dcterms:references"))
# end
return_value = True