summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim McCusker <mccusker@gmail.com>2017-04-09 13:26:33 -0400
committerGitHub <noreply@github.com>2017-04-09 13:26:33 -0400
commit59c46ec81a6759edf2f2a3c8e2bd5e01ca516861 (patch)
treec6fc09513e2014d755aeb27b5a29141ca99cd122
parent7283c6bf896df7bc644badd5ad1a6217ab145f7a (diff)
parentaf230076e7796c368ec4c912404fe3baf44761e5 (diff)
downloadrdflib-59c46ec81a6759edf2f2a3c8e2bd5e01ca516861.tar.gz
Merge branch 'master' into issue725
-rw-r--r--rdflib/compare.py10
-rw-r--r--rdflib/parser.py2
-rw-r--r--test/test_canonicalization.py35
3 files changed, 43 insertions, 4 deletions
diff --git a/rdflib/compare.py b/rdflib/compare.py
index d5c12c3b..91eb8a7b 100644
--- a/rdflib/compare.py
+++ b/rdflib/compare.py
@@ -168,6 +168,9 @@ class IsomorphicGraph(ConjunctiveGraph):
"""Negative graph isomorphism testing."""
return not self.__eq__(other)
+ def __hash__(self):
+ return super(IsomorphicGraph, self).__hash__()
+
def graph_digest(self, stats=None):
"""Synonym for IsomorphicGraph.internal_hash."""
return self.internal_hash(stats=stats)
@@ -487,8 +490,11 @@ class _TripleCanonicalizer(object):
def to_isomorphic(graph):
if isinstance(graph, IsomorphicGraph):
return graph
- return IsomorphicGraph(store=graph.store)
-
+ result = IsomorphicGraph()
+ if hasattr(graph, "identifier"):
+ result = IsomorphicGraph(identifier=graph.identifier)
+ result += graph
+ return result
def isomorphic(graph1, graph2):
"""Compare graph for equality.
diff --git a/rdflib/parser.py b/rdflib/parser.py
index d98006e2..5864820a 100644
--- a/rdflib/parser.py
+++ b/rdflib/parser.py
@@ -101,7 +101,7 @@ class URLInputSource(InputSource):
myheaders['Accept'] = 'text/plain, */*;q=0.1'
elif format == 'json-ld':
myheaders['Accept'] = (
- 'application/ld+json, application/json;p=0.9, */*;q=0.1')
+ 'application/ld+json, application/json;q=0.9, */*;q=0.1')
else:
myheaders['Accept'] = (
'application/rdf+xml,text/rdf+n3;q=0.9,' +
diff --git a/test/test_canonicalization.py b/test/test_canonicalization.py
index 97f49036..515756a4 100644
--- a/test/test_canonicalization.py
+++ b/test/test_canonicalization.py
@@ -1,6 +1,9 @@
-from rdflib import Graph, RDF, BNode, URIRef
+from rdflib import Graph, RDF, BNode, URIRef, Namespace, ConjunctiveGraph, Literal
from rdflib.compare import to_isomorphic, to_canonical_graph
+
import rdflib
+from rdflib.plugins.memory import IOMemory
+
from six import text_type
from io import StringIO
@@ -376,3 +379,33 @@ def test_issue494_collapsing_bnodes():
'canonicalization changed number of statements'
assert g_node_degs == cg_node_degs, \
'canonicalization changed node degrees'
+
+def test_issue682_signing_named_graphs():
+ ns = Namespace("http://love.com#")
+
+ mary = BNode()
+ john = URIRef("http://love.com/lovers/john#")
+
+ cmary=URIRef("http://love.com/lovers/mary#")
+ cjohn=URIRef("http://love.com/lovers/john#")
+
+ store = IOMemory()
+
+ g = ConjunctiveGraph(store=store)
+ g.bind("love",ns)
+
+ gmary = Graph(store=store, identifier=cmary)
+
+ gmary.add((mary, ns['hasName'], Literal("Mary")))
+ gmary.add((mary, ns['loves'], john))
+
+ gjohn = Graph(store=store, identifier=cjohn)
+ gjohn.add((john, ns['hasName'], Literal("John")))
+
+ ig = to_isomorphic(g)
+ igmary = to_isomorphic(gmary)
+
+ assert len(igmary) == len(gmary)
+ assert len(ig) == len(g)
+ assert len(igmary) < len(ig)
+ assert ig.graph_digest() != igmary.graph_digest()