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

Suppress warning for not using custom encoding. #800

Merged

Conversation

white-gecko
Copy link
Member

Suppress the warning "NQuadsSerializer/NTSerializer does not use custom encoding." in the case that the encoding argument (custom encoding) is set to the same value as the default encoding (self.encoding).

This is especially relevant, if one is selecting the NQuadsSerializer/NTSerializer for serializing query results, since it is setting utf-8 as encoding:

rdflib/rdflib/query.py

Lines 203 to 230 in 0469adb

def serialize(
self, destination=None, encoding="utf-8", format='xml', **args):
if self.type in ('CONSTRUCT', 'DESCRIBE'):
return self.graph.serialize(
destination, encoding=encoding, format=format, **args)
"""stolen wholesale from graph.serialize"""
from rdflib import plugin
serializer = plugin.get(format, ResultSerializer)(self)
if destination is None:
stream = BytesIO()
stream2 = EncodeOnlyUnicode(stream)
serializer.serialize(stream2, encoding=encoding, **args)
return stream.getvalue()
if hasattr(destination, "write"):
stream = destination
serializer.serialize(stream, encoding=encoding, **args)
else:
location = destination
scheme, netloc, path, params, query, fragment = urlparse(location)
if netloc != "":
print("WARNING: not saving as location" +
"is not a local file reference")
return
fd, name = tempfile.mkstemp()
stream = os.fdopen(fd, 'wb')
serializer.serialize(stream, encoding=encoding, **args)

Suppress the warning "NQuadsSerializer/NTSerializer does not use custom encoding." in the case that the `encoding` argument (custom encoding) is set to the same value as the default encoding (`self.encoding`).
@joernhees
Copy link
Member

👍 thanks

@joernhees joernhees merged commit 300db62 into RDFLib:master Dec 14, 2017
@white-gecko white-gecko deleted the white-gecko-suppress-encoding-warning branch December 14, 2017 15:04
@joernhees joernhees added cleanup enhancement New feature or request serialization Related to serialization. labels Dec 14, 2017
@joernhees joernhees added this to the rdflib 5.0.0 milestone Dec 14, 2017
@RDFLib RDFLib deleted a comment from coveralls Dec 14, 2017
@RDFLib RDFLib deleted a comment from coveralls Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup enhancement New feature or request serialization Related to serialization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants