summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim McCusker <mccusker@gmail.com>2017-04-09 13:32:45 -0400
committerJim McCusker <mccusker@gmail.com>2017-04-09 13:32:45 -0400
commit6b5bd6367baf75d8af8022290b869e02dfb75236 (patch)
tree5b64e695f63e277dfbf6f531f94d55a47c263ad1
parentbc78af8ac3537814a938d56d854da7cdfb41bd20 (diff)
parent59c46ec81a6759edf2f2a3c8e2bd5e01ca516861 (diff)
downloadrdflib-6b5bd6367baf75d8af8022290b869e02dfb75236.tar.gz
Merge branch 'issue725' of https://github.com/jimmccusker/rdflib 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 bc74de83..97de047b 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)
@@ -485,8 +488,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()