Skip to content
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

graph.serialize(destination=) should accept a pathlib Path #1227

Closed
nicholascar opened this issue Jan 11, 2021 · 3 comments · Fixed by #1309
Closed

graph.serialize(destination=) should accept a pathlib Path #1227

nicholascar opened this issue Jan 11, 2021 · 3 comments · Fixed by #1309

Comments

@nicholascar
Copy link
Member

nicholascar commented Jan 11, 2021

If you try:

g.serialize(destination=pathib.Path(__file__).parent / "some" / "path" / "to" / "a" / "file.ttl", format="ttl")

You get a:

AttributeError: 'PosixPath' object has no attribute 'decode'

You have to do:

g.serialize(destination=str(pathib.Path(__file__).parent / "some" / "path" / "to" / "a" / "file.ttl"), format="ttl")

We should allow a Path to be used like this.

@aucampia
Copy link
Member

I guess the same should work for parse also

@aucampia
Copy link
Member

Actually I looked now, there is some intention to handle Path in parse, but it does not work:

Offending line

        graph.parse(
            location=(SCRIPT_PATH.parent / "data" / "prov.ttl"), format="turtle"
        )
test_prov (tests.test_namespace.Namespace) ... ERROR

======================================================================
ERROR: test_prov (tests.test_namespace.Namespace)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/iwana/syncthing/sw-wpw/d/gitlab.com/aucampia/contrib/rdflib/tests/test_namespace.py", line 25, in test_prov
    graph.parse(
  File "/home/iwana/syncthing/sw-wpw/d/gitlab.com/aucampia/contrib/rdflib/.venv/lib/python3.9/site-packages/rdflib/graph.py", line 1099, in parse
    source = create_input_source(
  File "/home/iwana/syncthing/sw-wpw/d/gitlab.com/aucampia/contrib/rdflib/.venv/lib/python3.9/site-packages/rdflib/parser.py", line 261, in create_input_source
    ) = _create_input_source_from_location(
  File "/home/iwana/syncthing/sw-wpw/d/gitlab.com/aucampia/contrib/rdflib/.venv/lib/python3.9/site-packages/rdflib/parser.py", line 289, in _create_input_source_from_location
    location = pathname2url(location)
  File "/usr/lib64/python3.9/urllib/request.py", line 1687, in pathname2url
    return quote(pathname)
  File "/usr/lib64/python3.9/urllib/parse.py", line 862, in quote
    return quote_from_bytes(string, safe)
  File "/usr/lib64/python3.9/urllib/parse.py", line 887, in quote_from_bytes
    raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

@aucampia
Copy link
Member

Nevermind, should not be using location, works fine with source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants