summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Arndt <arndtn@gmail.com>2021-03-10 14:58:29 +0100
committerGitHub <noreply@github.com>2021-03-10 14:58:29 +0100
commit83b3e99e6e4ed4cd6825773c24280373537b2ca9 (patch)
tree1e14444135ccb1a1892647d59409f7f442aac8cf
parent83a6fda9e207dc849ed42fecfcf28cbaaa0c2f2c (diff)
parent7cdd668607f70f3aa848d6087b0b826355c91bc1 (diff)
downloadrdflib-83b3e99e6e4ed4cd6825773c24280373537b2ca9.tar.gz
Merge pull request #1274 from nemesamade/master
Correct behaviour of compute_qname for URNs
-rw-r--r--rdflib/namespace.py4
-rw-r--r--test/test_namespace.py11
-rw-r--r--test/test_turtle_serialize.py12
3 files changed, 23 insertions, 4 deletions
diff --git a/rdflib/namespace.py b/rdflib/namespace.py
index 8228a0e0..bdb0000a 100644
--- a/rdflib/namespace.py
+++ b/rdflib/namespace.py
@@ -897,7 +897,7 @@ class NamespaceManager(object):
NAME_START_CATEGORIES = ["Ll", "Lu", "Lo", "Lt", "Nl"]
SPLIT_START_CATEGORIES = NAME_START_CATEGORIES + ["Nd"]
NAME_CATEGORIES = NAME_START_CATEGORIES + ["Mc", "Me", "Mn", "Lm", "Nd"]
-ALLOWED_NAME_CHARS = ["\u00B7", "\u0387", "-", ".", "_", ":", "%"]
+ALLOWED_NAME_CHARS = ["\u00B7", "\u0387", "-", ".", "_", "%"]
# http://www.w3.org/TR/REC-xml-names/#NT-NCName
@@ -914,7 +914,7 @@ def is_ncname(name):
for i in range(1, len(name)):
c = name[i]
if not category(c) in NAME_CATEGORIES:
- if c != ":" and c in ALLOWED_NAME_CHARS:
+ if c in ALLOWED_NAME_CHARS:
continue
return 0
# if in compatibility area
diff --git a/test/test_namespace.py b/test/test_namespace.py
index 2a8a1e65..5c73d223 100644
--- a/test/test_namespace.py
+++ b/test/test_namespace.py
@@ -31,6 +31,15 @@ class NamespacePrefixTest(unittest.TestCase):
g.compute_qname(URIRef("http://foo/bar/")),
("ns1", URIRef("http://foo/bar/"), ""),
)
+ # should compute qnames of URNs correctly as well
+ self.assertEqual(
+ g.compute_qname(URIRef("urn:ISSN:0167-6423")),
+ ("ns5", URIRef("urn:ISSN:"), "0167-6423"),
+ )
+ self.assertEqual(
+ g.compute_qname(URIRef("urn:ISSN:")),
+ ("ns5", URIRef("urn:ISSN:"), ""),
+ )
def test_reset(self):
data = (
@@ -123,4 +132,4 @@ class NamespacePrefixTest(unittest.TestCase):
self.assertFalse(ref in RDFS, "ClosedNamespace(RDFS) includes out-of-ns member rdfs:example")
ref = URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
- self.assertTrue(ref in RDF, "_RDFNamespace does not include rdf:type") \ No newline at end of file
+ self.assertTrue(ref in RDF, "_RDFNamespace does not include rdf:type")
diff --git a/test/test_turtle_serialize.py b/test/test_turtle_serialize.py
index 9c073e8c..3725bcd0 100644
--- a/test/test_turtle_serialize.py
+++ b/test/test_turtle_serialize.py
@@ -1,4 +1,4 @@
-from rdflib import Graph, URIRef, BNode, RDF, Literal, Namespace
+from rdflib import Graph, URIRef, BNode, RDF, RDFS, Literal, Namespace
from rdflib.collection import Collection
from rdflib.plugins.serializers.turtle import TurtleSerializer
@@ -80,6 +80,7 @@ def test_turtle_namespace():
graph.bind("GENO", "http://purl.obolibrary.org/obo/GENO_")
graph.bind("RO", "http://purl.obolibrary.org/obo/RO_")
graph.bind("RO_has_phenotype", "http://purl.obolibrary.org/obo/RO_0002200")
+ graph.bind("SERIAL", "urn:ISSN:")
graph.add(
(
URIRef("http://example.org"),
@@ -87,6 +88,14 @@ def test_turtle_namespace():
URIRef("http://purl.obolibrary.org/obo/GENO_0000385"),
)
)
+ graph.add(
+ (
+ URIRef("urn:ISSN:0167-6423"),
+ RDFS.label,
+ Literal("Science of Computer Programming"),
+
+ )
+ )
output = [
val
for val in graph.serialize(format="turtle").splitlines()
@@ -95,6 +104,7 @@ def test_turtle_namespace():
output = " ".join(output)
assert "RO_has_phenotype:" in output
assert "GENO:0000385" in output
+ assert "SERIAL:0167-6423" in output
if __name__ == "__main__":