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

fix for issue 1484 raised and solved by Graham Klyne: #1490

Merged
merged 2 commits into from Dec 7, 2021
Merged

fix for issue 1484 raised and solved by Graham Klyne: #1490

merged 2 commits into from Dec 7, 2021

Conversation

ghost
Copy link

@ghost ghost commented Dec 3, 2021

Error reading JSON-LD from text IO stream

Fix and test provided by Graham Klyne, transcribed into a separate branch.

Confirmatory results from the “validate.yaml” workflow are here

Error reading JSON-LD from text IO stream
Copy link
Member

@nicholascar nicholascar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Graham Klyne & Graham Higgins!

# TODO: conneg for JSON (fix support in rdflib's URLInputSource!)
source = create_input_source(source, format="json-ld")

stream = source.getByteStream()
try:
return json.load(StringIO(stream.read().decode("utf-8")))
# Use character stream as-is, or interpret byte stream as UTF-8
if isinstance(stream, TextIOBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually unsure if this condition will be true given this code from rdflib.parser.FileInputSource:

rdflib/rdflib/parser.py

Lines 239 to 244 in 9379a69

if isinstance(file, TextIOBase): # Python3 unicode fp
self.setCharacterStream(file)
self.setEncoding(file.encoding)
try:
b = file.buffer
self.setByteStream(b)

Copy link

@gklyne gklyne Dec 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I was trying to home in on the error that was triggered by trying to parse the output from json.dump, which specifically caused the stream result from source.getByteStream() to be a character stream. I agree that seems not quite right, and the problem may lie deeper in the logic that sorts out the data stream to be parsed.

But I was also trying to identify a minimal fix that could solve my immediate problem. Hopefully if someone chooses to delve deeper into the create_input_source logic, the test cases provided will still be helpful.

@nicholascar nicholascar merged commit f450bd6 into RDFLib:master Dec 7, 2021
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 this pull request may close these issues.

None yet

3 participants