-
Notifications
You must be signed in to change notification settings - Fork 555
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 turtle serialization of PNames that contain brackets #1678
Fix turtle serialization of PNames that contain brackets #1678
Conversation
9e9d072
to
d610d5f
Compare
d610d5f
to
088d447
Compare
I used str.replace instead of re.sub as it is a lot faster, and in this case I can't really think of problems like we had with #1663 benchmark code is here
|
Also to clarify, this only fixes the escaping of brackets, the other cases are handled already by other logic: $ .venv/bin/pytest test/test_turtle_quoting.py test/test_turtle_quoting.py::test_serialize_roundtrip --log-level DEBUG -rA
============================================================================ test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/iwana/sw/d/github.com/iafork/rdflib, configfile: tox.ini
plugins: subtests-0.5.0, cov-3.0.0, monkeytype-1.1.0
collected 50 items
test/test_turtle_quoting.py ss...s............................................ [100%]
================================================================================== PASSES ===================================================================================
______________________________________________________________________ test_pname_escaping[turtle-x-x] ______________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:185 format = turtle, char = 'x', escaped = 'x', pattern = re.compile('\\segns:propx\\s'), data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:propx "foo"@en .
_____________________________________________________________________ test_pname_escaping[turtle-(-\\(] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:185 format = turtle, char = '(', escaped = '\\(', pattern = re.compile('\\segns:prop\\\\\\(\\s'), data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop\( "foo"@en .
_____________________________________________________________________ test_pname_escaping[turtle-)-\\)] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:185 format = turtle, char = ')', escaped = '\\)', pattern = re.compile('\\segns:prop\\\\\\)\\s'), data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop\) "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-A] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = A, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:propA "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-2] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = 2, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop2 "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-c] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = c, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:propc "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-_] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = _, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop_ "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-~] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ~, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop~> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-.] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ., data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop.> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle--] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = -, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop- "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-!] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = !, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop!> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-$] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = $, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop$> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-&] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = &, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop&> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-'] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ', data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop'> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-(] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = (, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop\( "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-)] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ), data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe egns:prop\) "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-*] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = *, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop*> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-+] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = +, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop+> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-,] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ,, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop,> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-;] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ;, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop;> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-=] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = =, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop=> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-/] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = /, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop/> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-?] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = ?, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop?> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-#] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = #, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop#> "foo"@en .
____________________________________________________________________ test_serialize_roundtrip[turtle-@] _____________________________________________________________________
----------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG root:test_turtle_quoting.py:215 format = turtle, char = @, data = @prefix egns: <http://example.com/prefix/> .
egns:John_Doe <http://example.com/prefix/prop@> "foo"@en . |
088d447
to
d845f9a
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.
d845f9a
to
1bbe307
Compare
Brackets in pnames will now be escaped in output. This fix is based on a suggestion by Niklas Lindström (@niklasl). This is somewhat of a stopgap fix, there are some problems being masked and various cases that could still result in questionable Turtle being written out, however these can be addressed seperately.
1bbe307
to
9c1b55c
Compare
planning to merge this tomorrow |
Yes, I think so. |
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.
Looks good and thoroughly tested! Do we want to keep #1661 open to track the remaining characters (the total being ~!$&'()*+,;=/?#@%
), or do you think distinct issues are needed for those?
I think it is best we open separate issues for them. Round trip tests for |
Brackets in pnames will now be escaped in output.
This fix is based on a suggestion by Niklas Lindström (@niklasl).
This is somewhat of a stopgap fix, there are some problems being
masked and various cases that could still result in questionable Turtle being
written out, however these can be addressed seperately.
Fixes #1661