Skip to content

Commit

Permalink
Fix issue with namespace rebinding
Browse files Browse the repository at this point in the history
Also add additional tests for namespace rebinding.
  • Loading branch information
Graham Higgins authored and aucampia committed Apr 9, 2022
1 parent 4c4a0ea commit 2c6f3f4
Show file tree
Hide file tree
Showing 2 changed files with 501 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rdflib/plugins/stores/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,19 @@ def triples(self, triple_pattern, context=None):
yield triple, self.__contexts(triple)

def bind(self, prefix, namespace, override=True):
bound_prefix = self.__prefix.get(namespace)
if override and bound_prefix:
del self.__namespace[bound_prefix]
self.__prefix[namespace] = prefix
self.__namespace[prefix] = namespace
bound_namespace = self.__namespace.get(prefix)
bound_prefix = self.__prefix.get(namespace) or self.__prefix.get(bound_namespace)
if override:
if bound_prefix:
del self.__namespace[bound_prefix]
if bound_namespace:
del self.__prefix[bound_namespace]

self.__prefix[namespace] = prefix
self.__namespace[prefix] = namespace
else:
self.__prefix[bound_namespace or namespace] = bound_prefix or prefix
self.__namespace[bound_prefix or prefix] = bound_namespace or namespace

def namespace(self, prefix):
return self.__namespace.get(prefix, None)
Expand Down
Loading

0 comments on commit 2c6f3f4

Please sign in to comment.