Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

1 participant

@gweis
Collaborator

It's a bit tricky to do this properly for python 2 and 3, but I think this patch goes into the right direction.

For later on I think rdflib should be clear about what source is, and what attributes, methods and return values are expected.

If that would be defined, then a user of the library would know when to wrap a source within a codec or not.

cheers,

@gweis
Collaborator

Trying to resubmit this pull request to attach to issue 344

@gweis gweis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 rdflib/plugins/sparql/results/csvresults.py
@@ -23,7 +23,10 @@ def parse(self, source):
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)
reader = csv.reader(source, delimiter=self.delim)
View
5 rdflib/plugins/sparql/results/tsvresults.py
@@ -40,7 +40,10 @@
class TSVResultParser(ResultParser):
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)
try:
Something went wrong with that request. Please try again.