Skip to content

Commit

Permalink
if reading from source returns bytes do utf-8 decoding
Browse files Browse the repository at this point in the history
don’t pass StringIO returning decoded unicode to Result parser
  • Loading branch information
Gerhard Weis committed Mar 4, 2014
1 parent 50cdbea commit b7fa8d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion rdflib/plugins/sparql/results/csvresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def parse(self, source):

r = Result('SELECT')

if hasattr(source, 'mode') and 'b' in source.mode:
if isinstance(source.read(0), py3compat.bytestype):
# if reading from source returns bytes do utf-8 decoding
source = codecs.getreader('utf-8')(source)

reader = csv.reader(source, delimiter=self.delim)
Expand Down
5 changes: 4 additions & 1 deletion rdflib/plugins/sparql/results/tsvresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from rdflib import Literal as RDFLiteral

from rdflib.py3compat import bytestype

ParserElement.setDefaultWhitespaceChars(" \n")


Expand All @@ -40,7 +42,8 @@
class TSVResultParser(ResultParser):
def parse(self, source):

if hasattr(source, 'mode') and 'b' in source.mode:
if isinstance(source.read(0), bytestype):
# if reading from source returns bytes do utf-8 decoding
source = codecs.getreader('utf-8')(source)

try:
Expand Down
3 changes: 1 addition & 2 deletions test/test_dawg.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ def skip(reason='(none)'):
# write bytes, read strings...
s = BytesIO()
res2.serialize(s, format='csv')
print s.getvalue()
s = StringIO(s.getvalue().decode('utf-8')) # hmm ?
s.seek(0)
res2 = Result.parse(s, format='csv')

else:
Expand Down

0 comments on commit b7fa8d6

Please sign in to comment.