Hey Kendall.

On 4/28/06, Kendall Clark <[EMAIL PROTECTED]> wrote:
Folks,

Since Literal.n3() doesn't do any escaping, the ntriples serializer
emits illegal NTriples (so, " chars aren't escaped, for example).

Actually, I'm pretty sure by virtue of:

encoded = self.encode('unicode-escape')

It does cover a majority of the required escaping.  From my brief
perusal, it seems to me that the only explicit escaping required would
be for the " (double quote) character and the "\U extension introduced
by NTriples spec."

The latter might require some REGEX trickery that is beyond me (I'm
not generally very familiar with the ins-and-outs of unicode
escaping), but since the double quote character is the only one used
to enclose strings, I made the following change which should be
sufficient:

encoded = self.encode('unicode-escape').replace('"','\\"')

from rdflib import Literal
Literal('" a string"').n3()
'"\\" a string\\""'

The extra \ is due to python's own escaping for output and would be
left out of serialization.  I've checked in the changes

Chimezie

_______________________________________________
Dev mailing list
[email protected]
http://rdflib.net/mailman/listinfo/dev

Reply via email to