RDFLib/rdfextras — Issue #40: 2 failing SPARQL result tests under py24 and py25, skipped
Author: gjhiggins
Created: 2012-02-22 05:49:09+00:00
State: open
Labels: bug, in-resolution, sparql-p, tests

XML serialization of SPARQL results is broken under Python 2.4 and 2.5 for XML namespace handling. This is a known problem with a history stretching back to [August 2007](http://www.mail-archive.com/dev@rdflib.net/msg00236.html).

The [source code](https://github.com/RDFLib/rdfextras/blob/master/rdfextras/sparql/results/xmlresults.py#L133) is commented "# TODO: Rewrite with ElementTree?"

ElementTree is available for Python2.4, is it worth trying to adapt [Mikael Högqvist's implementation](http://www.mail-archive.com/dev@rdflib.net/msg00238.html)?

```
======================================================================
ERROR: testXML (test_results.TestSparqlResultsFormats)
----------------------------------------------------------------------
Traceback (most recent call last):
File "...rdfextras/test/test_results.py", line 59, in testXML
self._test(xmlres,"xml")
File "...rdfextras/test/test_results.py", line 11, in _test
s = r.serialize(format=format)
File "...lib/python2.4/site-packages/rdflib/query.py", line 96, in serialize
serializer.serialize(stream2, encoding=encoding, **args)
File "...rdfextras/rdfextras/sparql/results/xmlresults.py", line 121, in serialize
writer.write_header(self.result.vars)
File "...rdfextras/rdfextras/sparql/results/xmlresults.py", line 160, in write_header
AttributesNSImpl(attr_vals, attr_qnames))
File "...lib/python2.4/xml/sax/saxutils.py", line 141, in startElementNS
name = self._current_context[name[0]] + ":" + name[1]
KeyError

======================================================================
ERROR: testSimple (test_sparql.test_sparql_xml_results.TestSparqlXmlResults)
----------------------------------------------------------------------
Traceback (most recent call last):
File "...rdfextras/test/test_sparql/test_sparql_xml_results.py", line 66, in testSimple
self._query_result_contains(query, expected_fragments)
File "...rdfextras/test/test_sparql/test_sparql_xml_results.py", line 70, in _query_result_contains
result_xml = results.serialize(format='xml')
File "...lib/python2.4/site-packages/rdflib/query.py", line 96, in serialize
serializer.serialize(stream2, encoding=encoding, **args)
File "...rdfextras/rdfextras/sparql/results/xmlresults.py", line 121, in serialize
writer.write_header(self.result.vars)
File "...rdfextras/rdfextras/sparql/results/xmlresults.py", line 160, in write_header
AttributesNSImpl(attr_vals, attr_qnames))
File "...lib/python2.4/xml/sax/saxutils.py", line 141, in startElementNS
name = self._current_context[name[0]] + ":" + name[1]
KeyError
```