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

Broken stdin (-) handling #94

Closed
aucampia opened this issue Sep 9, 2020 · 2 comments
Closed

Broken stdin (-) handling #94

aucampia opened this issue Sep 9, 2020 · 2 comments

Comments

@aucampia
Copy link
Member

aucampia commented Sep 9, 2020

JSON-LD does not correctly process stdin when supplied with -.

Test case:

echo '{"@context": { "@vocab": "http://xmlns.com/foaf/0.1/" }, "@id": "http://example.com", "name": "Example"}' | rdfpipe -i  json-ld -o turtle -

Expected result:

$ echo '{"@context": { "@vocab": "http://xmlns.com/foaf/0.1/" }, "@id": "http://example.com", "name": "Example"}' | rdfpipe -i  json-ld -o turtle -
@prefix : <http://xmlns.com/foaf/0.1/> .

<http://example.com/> :name "Example" .

Actual result:

$ echo '{"@context": { "@vocab": "http://xmlns.com/foaf/0.1/" }, "@id": "http://example.com", "name": "Example"}' | rdfpipe -i  json-ld -o turtle -
Traceback (most recent call last):
  File "/home/iwana/.local/bin/rdfpipe", line 8, in <module>
    sys.exit(main())
  File "/home/iwana/.local/lib/python3.8/site-packages/rdflib/tools/rdfpipe.py", line 183, in main
    parse_and_serialize(args, opts.input_format, opts.guess,
  File "/home/iwana/.local/lib/python3.8/site-packages/rdflib/tools/rdfpipe.py", line 51, in parse_and_serialize
    graph.parse(fpath, format=use_format, **kws)
  File "/home/iwana/.local/lib/python3.8/site-packages/rdflib/graph.py", line 1549, in parse
    context.parse(source, publicID=publicID, format=format, **args)
  File "/home/iwana/.local/lib/python3.8/site-packages/rdflib/graph.py", line 1078, in parse
    parser.parse(source, self, **args)
  File "/home/iwana/.local/lib/python3.8/site-packages/rdflib_jsonld/parser.py", line 83, in parse
    data = source_to_json(source)
  File "/home/iwana/.local/lib/python3.8/site-packages/rdflib_jsonld/util.py", line 28, in source_to_json
    return json.load(StringIO(stream.read().decode('utf-8')))
AttributeError: 'str' object has no attribute 'decode'

Workaround

Specify /dev/stdin instead of -

$ echo '{"@context": { "@vocab": "http://xmlns.com/foaf/0.1/" }, "@id": "http://example.com", "name": "Example"}' | rdfpipe -i  json-ld -o turtle /dev/stdin 
@prefix : <http://xmlns.com/foaf/0.1/> .

<http://example.com/> :name "Example" .
@Fak3
Copy link

Fak3 commented Jun 2, 2021

Duplicate of #91

@aucampia
Copy link
Member Author

aucampia commented Jun 2, 2021

Thanks, closing this then.

@aucampia aucampia closed this as completed Jun 2, 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

No branches or pull requests

2 participants