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

if query result source has no encoding set, fall back to utf-8 encoding. resolves #344 #365

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion rdflib/plugins/sparql/results/csvresults.py
Expand Up @@ -23,7 +23,10 @@ def parse(self, source):


r = Result('SELECT') r = Result('SELECT')


if hasattr(source, 'mode') and 'b' in source.mode: if not hasattr(source, 'mode') or 'b' in source.mode and not getattr(source, 'encoding', None):
# if there is no mode, or source is in binary mode
# assume we need to decode from utf-8.
# if there is a mode set and it's not binary, check if source has encoding set.
source = codecs.getreader('utf-8')(source) source = codecs.getreader('utf-8')(source)


reader = csv.reader(source, delimiter=self.delim) reader = csv.reader(source, delimiter=self.delim)
Expand Down
5 changes: 4 additions & 1 deletion rdflib/plugins/sparql/results/tsvresults.py
Expand Up @@ -40,7 +40,10 @@
class TSVResultParser(ResultParser): class TSVResultParser(ResultParser):
def parse(self, source): def parse(self, source):


if hasattr(source, 'mode') and 'b' in source.mode: if not hasattr(source, 'mode') or 'b' in source.mode and not getattr(source, 'encoding', None):
# if there is no mode, or source is in binary mode
# assume we need to decode from utf-8.
# if there is a mode set and it's not binary, check if source has encoding set.
source = codecs.getreader('utf-8')(source) source = codecs.getreader('utf-8')(source)


try: try:
Expand Down