From 1b920d2045768a4107919eb730627ee3e6df9937 Mon Sep 17 00:00:00 2001 From: dr644w Date: Tue, 8 Oct 2013 15:44:17 -0500 Subject: [PATCH] Fixed duplicate creation of namespace prefixes --- rdflib/namespace.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rdflib/namespace.py b/rdflib/namespace.py index 5d6419e5a..dea7a2dc7 100644 --- a/rdflib/namespace.py +++ b/rdflib/namespace.py @@ -351,6 +351,12 @@ def bind(self, prefix, namespace, override=True): if prefix is None: prefix = '' bound_namespace = self.store.namespace(prefix) + # Check if the bound_namespace contains a URI + # and if so convert it into a URIRef for comparison + # This is to prevent duplicate namespaces with the + # same URI + if bound_namespace: + bound_namespace = URIRef(bound_namespace) if bound_namespace and bound_namespace != namespace: # prefix already in use for different namespace # @@ -361,6 +367,11 @@ def bind(self, prefix, namespace, override=True): num = 1 while 1: new_prefix = "%s%s" % (prefix, num) + tnamespace = self.store.namespace(new_prefix) + if tnamespace and namespace == URIRef(tnamespace): + # the prefix is already bound to the correct + # namespace + return if not self.store.namespace(new_prefix): break num += 1