[Python-modules-commits] [python-pyld] 88/276: Add escaping to N-Quads.

Wolfgang Borgert debacle at moszumanska.debian.org
Wed Oct 8 23:47:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-pyld.

commit 4f560cda38191eb4cd0c646e394a8d2563de7c58
Author: Dave Longley <dlongley at digitalbazaar.com>
Date:   Sun May 13 16:31:06 2012 -0400

    Add escaping to N-Quads.
---
 lib/pyld/jsonld.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index be72cc6..00f494c 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -868,8 +868,14 @@ class JsonLdProcessor:
                 s['object'] = {
                     'nominalValue': match[4], 'interfaceName': 'BlankNode'}
             else:
+                unescaped = (match[5]
+                    .replace('\\"', '\"')
+                    .replace('\\t', '\t')
+                    .replace('\\n', '\n')
+                    .replace('\\r', '\r')
+                    .replace('\\\\', '\\'))
                 s['object'] = {
-                    'nominalValue': match[5], 'interfaceName': 'LiteralNode'}
+                    'nominalValue': unescaped, 'interfaceName': 'LiteralNode'}
                 if match[6] is not None:
                     s['object']['datatype'] = {
                         'nominalValue': match[6], 'interfaceName': 'IRI'}
@@ -930,6 +936,12 @@ class JsonLdProcessor:
             else:
                 quad += o['nominalValue']
         else:
+            escaped = (o['nominalValue']
+                .replace('\\', '\\\\')
+                .replace('\t', '\\t')
+                .replace('\n', '\\n')
+                .replace('\r', '\\r')
+                .replace('\"', '\\"'))
             quad += '"' + o['nominalValue'] + '"'
             if 'datatype' in o:
                 quad += '^^<' + o['datatype']['nominalValue'] + '>'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git



More information about the Python-modules-commits mailing list