[go: up one dir, main page]

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

Support Python 3 #14

Open
jayvdb opened this issue Apr 4, 2016 · 0 comments
Open

Support Python 3 #14

jayvdb opened this issue Apr 4, 2016 · 0 comments

Comments

@jayvdb
Copy link
jayvdb commented Apr 4, 2016

The bootstrap uses syntax not acceptable on Python 3 and there are fairly basic Python 3 syntax errors in the anzsrc library.

With my four "basic" Python 3 PRs (bootstrap, next, print, unicode), there is still one Python 3 problem remaining with using rdflib 3 and 4. It is a little less basic, so here is the problem when using rdflib 3

$ ./bin/genanzsrc
...
Traceback (most recent call last):
  File "./bin/genanzsrc", line 12, in <module>
    sys.exit(anzsrc.scripts.genanzsrc.main())
  File "../src/anzsrc/src/anzsrc/scripts/genanzsrc.py", line 27, in main
    genoutput(seo.genseo, 'seo', SEO)
  File "../src/anzsrc/src/anzsrc/scripts/genanzsrc.py", line 14, in genoutput
    g.serialize(f, format='xml')
  File "../site-packages/rdflib/graph.py", line 777, in serialize
    serializer.serialize(stream, base=base, encoding=encoding, **args)
  File "../site-packages/rdflib/plugins/serializers/rdfxml.py", line 49, in serialize
    write('<?xml version="1.0" encoding="%s"?>\n' % self.encoding)
  File "../site-packages/rdflib/plugins/serializers/rdfxml.py", line 46, in <lambda>
    self.write = write = lambda uni: stream.write(uni.encode(encoding, 'replace'))
TypeError: must be str, not bytes

... and the same occurs with rdflib 4 with a slightly different backtrace

$ ./bin/genanzsrc
Traceback (most recent call last):
  File "./bin/genanzsrc", line 12, in <module>
    sys.exit(anzsrc.scripts.genanzsrc.main())
  File "../src/anzsrc/src/anzsrc/scripts/genanzsrc.py", line 27, in main
    genoutput(seo.genseo, 'seo', SEO)
  File "../src/anzsrc/src/anzsrc/scripts/genanzsrc.py", line 14, in genoutput
    g.serialize(f, format='xml')
  File ".../site-packages/rdflib/graph.py", line 946, in serialize
    serializer.serialize(stream, base=base, encoding=encoding, **args)
  File ".../site-packages/rdflib/plugins/serializers/rdfxml.py", line 55, in serialize
    write('<?xml version="1.0" encoding="%s"?>\n' % self.encoding)
  File ".../site-packages/rdflib/plugins/serializers/rdfxml.py", line 52, in <lambda>
    uni.encode(encoding, 'replace'))
TypeError: must be str, not bytes

This is fixed by specifying that the serialisation file needs to be binary.

With all the py3-x PRs, it 'works' on Python 3:
https://travis-ci.org/jayvdb/anzsrco/builds/120541306

(more testing is probably needed to confirm the output is 100% correct.

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

1 participant