diff options
author | Nicholas Car <nick@kurrawong.net> | 2020-03-16 12:25:12 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-16 12:25:12 +1000 |
commit | 471399d8bacfff993a8bee47c3f63c6e1a3db9c1 (patch) | |
tree | 2ce5eff471b008cd9558a36bafdb7e0a2f2d8ab9 | |
parent | 94b4cd12615a3b29e834cb665b79e6256be221ef (diff) | |
parent | 74264f3902a8de25f67c2987ee10573e20737873 (diff) | |
download | rdflib-471399d8bacfff993a8bee47c3f63c6e1a3db9c1.tar.gz |
Merge pull request #914 from tgbugs/keep-prefixes
make round tripping of prefixes configurable
-rw-r--r-- | rdflib/plugins/serializers/turtle.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/rdflib/plugins/serializers/turtle.py b/rdflib/plugins/serializers/turtle.py index 3a1e5a61..1c58ba1b 100644 --- a/rdflib/plugins/serializers/turtle.py +++ b/rdflib/plugins/serializers/turtle.py @@ -43,6 +43,7 @@ class RecursiveSerializer(Serializer): predicateOrder = [RDF.type, RDFS.label] maxDepth = 10 indentString = u" " + roundtrip_prefixes = tuple() def __init__(self, store): @@ -110,6 +111,15 @@ class RecursiveSerializer(Serializer): self._subjects = {} self._topLevels = {} + if self.roundtrip_prefixes: + if hasattr(self.roundtrip_prefixes, '__iter__'): + for prefix, ns in self.store.namespaces(): + if prefix in self.roundtrip_prefixes: + self.addNamespace(prefix, ns) + else: + for prefix, ns in self.store.namespaces(): + self.addNamespace(prefix, ns) + def buildPredicateHash(self, subject): """ Build a hash key by predicate to a list of objects for the given |