Skip to content

Commit

Permalink
SPARQLStore does not transform Literal('') into Literal('None') anymo…
Browse files Browse the repository at this point in the history
…re, fixes RDFLib#457
  • Loading branch information
joernhees committed Feb 24, 2015
1 parent 74c520f commit 8a0eae0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rdflib/plugins/stores/sparqlstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ def CastToTerm(node):
elif node.tag == '{%s}uri' % SPARQL_NS:
return URIRef(node.text)
elif node.tag == '{%s}literal' % SPARQL_NS:
value = node.text if node.text is not None else ''
if 'datatype' in node.attrib:
dT = URIRef(node.attrib['datatype'])
if False: # not node.xpath('*'):
return Literal('', datatype=dT)
else:
return Literal(node.text, datatype=dT)
return Literal(value, datatype=dT)
elif '{http://www.w3.org/XML/1998/namespace}lang' in node.attrib:
return Literal(node.text, lang=node.attrib[
return Literal(value, lang=node.attrib[
"{http://www.w3.org/XML/1998/namespace}lang"])
else:
return Literal(node.text)
return Literal(value)
else:
raise Exception('Unknown answer type')

Expand Down
13 changes: 13 additions & 0 deletions test/test_issue457.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# test for https://github.com/RDFLib/rdflib/issues/457

import io
from xml.etree import ElementTree

import rdflib
from rdflib.plugins.stores.sparqlstore import CastToTerm

s = """<ns0:literal xmlns:ns0="http://www.w3.org/2005/sparql-results#" />"""
node = ElementTree.parse(io.BytesIO(s)).getroot()
term = CastToTerm(node)
assert term == rdflib.Literal(''), repr(term)

0 comments on commit 8a0eae0

Please sign in to comment.