Please add this test, which fails on 2.3.1 and trunk:
##### test/n3_quoting.py #####
import unittest
from rdflib import Graph, Literal, Namespace, StringInputSource
cases = ['no quotes',
"single ' quote",
'double " quote',
'"',
"'",
'"\'"',
'\\', # len 1
'\\"', # len 2
'\\\\"', # len 3
'\\"\\', # len 3
'<a some="typical" html="content">here</a>',
]
class N3Quoting(unittest.TestCase):
def test(self):
g = Graph()
NS = Namespace("http://quoting.test/")
for i, case in enumerate(cases):
g.add((NS['subj'], NS['case%s' % i], Literal(case)))
n3txt = g.serialize(format="n3")
print n3txt
g2 = Graph()
g2.parse(StringInputSource(n3txt), format="n3")
for i, case in enumerate(cases):
l = g2.value(NS['subj'], NS['case%s' % i])
print repr(l), repr(case)
self.assertEqual(l, Literal(case))
if __name__ == "__main__":
unittest.main()
################################
At least those tests can pass with this revised line in Literal.n3:
encoded = self.encode('unicode-escape').replace('\\', '\\\
\').replace('"','\\"')
but I haven't consulted the n3 spec lately, so who knows what else I'm
forgetting.
_______________________________________________
Dev mailing list
[email protected]
http://rdflib.net/mailman/listinfo/dev