diff options
author | Tom Gillespie <tgbugs@gmail.com> | 2021-03-26 15:56:26 -0700 |
---|---|---|
committer | Tom Gillespie <tgbugs@gmail.com> | 2021-03-26 15:56:26 -0700 |
commit | dd6f620f6b7e15723664de2afad5d13506c0e966 (patch) | |
tree | 1f1ad20635b519bb6ec8a29ee805823097b3e6ef | |
parent | 2f2c6a79ddfc6c882412fa15fcce8af2ce196c8a (diff) | |
download | rdflib-dd6f620f6b7e15723664de2afad5d13506c0e966.tar.gz |
tweaks to hierarchy to improve load times
I think that most of the difference actually comes from patching uuid
to not waste 25 milliseconds every time it is imported but there is a
bit of improvement here
-rw-r--r-- | rdflib/container.py | 3 | ||||
-rw-r--r-- | rdflib/namespace.py | 6 | ||||
-rw-r--r-- | rdflib/parser.py | 8 |
3 files changed, 7 insertions, 10 deletions
diff --git a/rdflib/container.py b/rdflib/container.py index ca884a4e..b5679e3e 100644 --- a/rdflib/container.py +++ b/rdflib/container.py @@ -1,6 +1,5 @@ from rdflib.namespace import RDF -from rdflib.term import BNode -from rdflib import URIRef +from rdflib.term import BNode, URIRef from random import randint __all__ = ["Container", "Bag", "Seq", "Alt", "NoElementException"] diff --git a/rdflib/namespace.py b/rdflib/namespace.py index bdb0000a..61fd5d85 100644 --- a/rdflib/namespace.py +++ b/rdflib/namespace.py @@ -1,10 +1,8 @@ import logging -import os from unicodedata import category - -from urllib.request import pathname2url +from pathlib import Path from urllib.parse import urldefrag from urllib.parse import urljoin @@ -850,7 +848,7 @@ class NamespaceManager(object): yield prefix, namespace def absolutize(self, uri, defrag=1): - base = urljoin("file:", pathname2url(os.getcwd())) + base = Path.cwd().as_uri() result = urljoin("%s/" % base, uri, allow_fragments=not defrag) if defrag: result = urldefrag(result)[0] diff --git a/rdflib/parser.py b/rdflib/parser.py index a6f155a6..7dd9185d 100644 --- a/rdflib/parser.py +++ b/rdflib/parser.py @@ -17,7 +17,6 @@ import sys from io import BytesIO, TextIOBase, TextIOWrapper, StringIO, BufferedIOBase -from urllib.request import pathname2url from urllib.request import Request from urllib.request import url2pathname from urllib.parse import urljoin @@ -285,10 +284,11 @@ def create_input_source( def _create_input_source_from_location(file, format, input_source, location): # Fix for Windows problem https://github.com/RDFLib/rdflib/issues/145 - if os.path.exists(location): - location = pathname2url(location) + location = pathlib.Path(location) + if location.exists(): + location = location.as_uri() - base = urljoin("file:", "%s/" % pathname2url(os.getcwd())) + base = pathlib.Path.cwd().as_uri() absolute_location = URIRef(location, base=base) |