Beispiel #1
0
    def test_iri_escape(self):
        obj = RdfXmlObject()
        with open(join(dirname(testing.__file__),
                'data', '0', 'injection.rdf')) as fd:
            rawstr = fd.read()
        obj.parse(rawstr)

        result = sparql.insert(obj.graph,
            'http://store.example.com/metadata.rdf')

        # all < and > needs to be escaped
        self.assertNotIn('<ha> <ha> <ha>', result)
        # all whitespaces escaped in iri
        self.assertNotIn('\nCLEAR GRAPH <http', result)
        self.assertIn('%0ACLEAR%20GRAPH%20%3Chttp', result)
Beispiel #2
0
 def test_n3_insert_base_uri_object(self):
     obj = RdfXmlObject()
     with open(join(dirname(testing.__file__),
             'data', '0', 'nested_object.rdf')) as fd:
         rawstr = fd.read()
     obj.parse(rawstr)
     graph = sorted(sparql.n3_insert(obj.graph, 'some/data.xml'))
     self.assertEqual(graph, [
         u'<some/data.xml#inner> <http://ns.example.com/target> '
             '<http://site.example.com/target> .',
         u'<some/data.xml#inner> <http://ns.example.com/title> '
             '"Inner Title" .',
         u'<some/data.xml#root> <http://ns.example.com/is> '
             '<some/data.xml#inner> .',
     ])
Beispiel #3
0
    def render(self):
        super(RdfPage, self).update()

        contents = self.data['contents']()
        s = StringIO(contents)
        rdf = RdfXmlObject()
        try:
            rdf.parse(s)
        except:
            pass
        contents = rdf.graph.serialize()

        mimetype = 'application/rdf+xml'
        self.request.response.setHeader('Content-Type', mimetype)
        self.request.response.setHeader('Content-Length', len(contents))
        return contents
Beispiel #4
0
 def test_n3_insert_nested_path(self):
     obj = RdfXmlObject()
     with open(join(dirname(testing.__file__),
             'data', '0', 'multi.rdf')) as fd:
         rawstr = fd.read()
     obj.parse(rawstr)
     graph = sorted(sparql.n3_insert(obj.graph, 'multi/path/metadata.xml'))
     self.assertEqual(graph, [
         u'<multi/parent/file#test> '
             '<http://purl.org/dc/elements/1.1/title> "Parent File" .',
         u'<multi/path/metadata.xml#test> '
             '<http://purl.org/dc/elements/1.1/title> "Metadata File" .',
         u'<multi/path/nested/file#test> '
             '<http://purl.org/dc/elements/1.1/title> "Nested File" .',
         u'<multi/path/sibling_file#test> '
             '<http://purl.org/dc/elements/1.1/title> "Sibling File" .',
     ])
Beispiel #5
0
    def test_n3_insert_base_uri_object(self):
        obj = RdfXmlObject()
        with open(join(dirname(testing.__file__),
                'data', '0', 'multi.rdf')) as fd:
            rawstr = fd.read()
        obj.parse(rawstr)
        graph = sorted(sparql.n3_insert(obj.graph))

        self.assertEqual(graph, [
            u'<#test> <http://purl.org/dc/elements/1.1/title> '
                '"Metadata File" .',
            u'<../parent/file#test> <http://purl.org/dc/elements/1.1/title> '
                '"Parent File" .',
            u'<nested/file#test> <http://purl.org/dc/elements/1.1/title> '
                '"Nested File" .',
            u'<sibling_file#test> <http://purl.org/dc/elements/1.1/title> '
                '"Sibling File" .',
        ])
Beispiel #6
0
    def test_insert_special(self):
        obj = RdfXmlObject()
        with open(join(dirname(testing.__file__),
                'data', '0', 'special_cases.xml')) as fd:
            rawstr = fd.read()
        obj.parse(rawstr)

        result = sparql.insert(obj.graph,
            'http://store.example.com/metadata.rdf')
        self.assertTrue(result.startswith('INSERT'))
        # blank IRI are converted into the <#> form
        self.assertNotIn('<> ', result)
        # but the ones inside strings shouldn't be touched.
        self.assertIn('<><>', result)
        # Strings properly escaped in a string
        self.assertIn('"Title \\"}<for> an external resource."', result)
        # Backslashes in URLs should be escaped
        self.assertNotIn('.\\file#test', result)
        self.assertIn('.%5Cfile#test', result)
Beispiel #7
0
class BaseTestCase(unittest.TestCase):

    def setUp(self):
        self.file = RdfXmlObject()

    def tearDown(self):
        pass

    def parse(self, filename):
        fd = open(filename)
        try:
            self.file.parse(fd)
        finally:
            fd.close()

    def test_0000_basic(self):
        self.parse(join(input_dir, 'well-formed-3-node.xml'))
        self.assertEqual(len(self.file.subgraphIds), 3)

    def test_0001_simple(self):
        self.parse(join(input_dir, 'simple.rdf'))
        self.assertEqual(len(self.file.subgraphIds), 1)
Beispiel #8
0
 def setUp(self):
     self.file = RdfXmlObject()