diff options
author | Iwan Aucamp <aucampia@gmail.com> | 2023-03-13 01:18:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 01:18:21 +0100 |
commit | 35a35375d213afe83a825d7dfcc59008f8e2352c (patch) | |
tree | 1fa971ef3a9e897e19b5df5fc304fe9c02697e41 /examples/simple_example.py | |
parent | 7a7cc1f929ff6fbc8c3238368e518a00af1025b6 (diff) | |
download | rdflib-35a35375d213afe83a825d7dfcc59008f8e2352c.tar.gz |
fix: validation issues with examples (#2269)
I want to add examples for securing RDFLib network access using
`sys.addaudithook` and `urllib.request.install_opener`, but I want to
also validate the examples in our CI pipeline, so we can demonstrate
they work to our users.
This change adds validation for all examples, and the addition of the
security examples in a seperate PR will then also get validated.
Diffstat (limited to 'examples/simple_example.py')
-rw-r--r-- | examples/simple_example.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/examples/simple_example.py b/examples/simple_example.py index 49f08408..c27f3181 100644 --- a/examples/simple_example.py +++ b/examples/simple_example.py @@ -1,8 +1,10 @@ -from rdflib import Graph, Literal, BNode, RDF -from rdflib.namespace import FOAF, DC +import os.path +from tempfile import TemporaryDirectory -if __name__ == "__main__": +from rdflib import RDF, BNode, Graph, Literal +from rdflib.namespace import DC, FOAF +if __name__ == "__main__": store = Graph() # Bind a few prefix, namespace pairs for pretty output @@ -29,9 +31,11 @@ if __name__ == "__main__": for mbox in store.objects(person, FOAF["mbox"]): print(mbox) - print("--- saving RDF to a file (donna_foaf.rdf) ---") + tmp_dir = TemporaryDirectory() + output_file = os.path.join(tmp_dir.name, "donna_foaf.rdf") + print(f"--- saving RDF to a file ({output_file}) ---") # Serialize the store as RDF/XML to the file donna_foaf.rdf. - store.serialize("donna_foaf.rdf", format="pretty-xml", max_depth=3) + store.serialize(f"{output_file}", format="pretty-xml", max_depth=3) # Let's show off the serializers print() |