-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: issues with string destination handling in {Graph,Result}.serialize
#2065
fix: issues with string destination handling in {Graph,Result}.serialize
#2065
Conversation
5cd02f4
to
3ed412d
Compare
{Graph,Result}.serialize
3ed412d
to
b53be4b
Compare
Not sure what is up with coverage, I'm guessing it is somehow related to the latest build on master failing (https://github.com/RDFLib/rdflib/actions?query=branch%3Amaster), I will rebase once #2068 is merged. |
b53be4b
to
ea6bd62
Compare
Nevermind, it is because I fiddled with tox.ini when I was trying to debug this. |
72abe6d
to
00a9167
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, windows tax - paid, gj 👍
00a9167
to
4e90415
Compare
…lize` Change `{Graph,Result}.serialize` to only handle string destinations as URIs if the schema is `file` and to treat it as operating system paths in all other cases. This is for the following reasons: - `Result.serialize` was treating URI paths as OS paths which only works for some cases, for special charachters and percentage encoding it does not work. - Many valid Unix and Windows paths parse using `urlparse` and have no netloc, e.g. `C:\some\path` and `some:/path`, however they should be treated as paths and not as URIs. - `Graph` and `Result` should behave consistently. Some caveats in this change: - non-file URIs will now be treated as OS paths which may result in slightly confusing error messages, such as `FileNotFoundError: [Errno 2] No such file or directory: 'http://example.com/'` if http://example.com/ is passed. - some valid file URIs (e.g. `file:/path/to/file` from https://datatracker.ietf.org/doc/html/rfc8089) are also valid Posix paths but will be treated as file-URIs instead of Posix paths. For `Graph.serialize` this ambiguity can be avoided by using `pathlib.Path`, but for `Result.serialize` there is currently no way to avoid it, though I will work on RDFLib#1834 soon and in that provide a way to avoid the ambiguity there also.
Summary of changes
Change
{Graph,Result}.serialize
to only handle string destinations as URIs ifthe schema is
file
and to treat it as operating system paths in allother cases.
This is for the following reasons:
Result.serialize
was treating URI paths as OS paths which only worksfor some cases, for special charachters and percentage encoding it
does not work.
urlparse
and have no netloc, e.g.C:\some\path
and
some:/path
, however they should be treated as paths and not as URIs.Graph
andResult
should behave consistently.Some caveats in this change:
slightly confusing error messages, such as
FileNotFoundError: [Errno 2] No such file or directory: 'http://example.com/'
if http://example.com/ is passed.
file:/path/to/file
from https://datatracker.ietf.org/doc/html/rfc8089)are also valid Posix paths but will be treated as file-URIs instead of
Posix paths. For
Graph.serialize
this ambiguity can be avoided byusing
pathlib.Path
, but forResult.serialize
there is currently noway to avoid it, though I will work on Make serialize() on a CONSTRUCT result act like normal g.serialize() #1834
soon and in that provide a way to avoid the ambiguity there also.
Result.serialize()
path handling is broken for windows paths and some other cases #2067Checklist
the same change.
CHANGELOG.md
).so maintainers can fix minor issues and keep your PR up to date.