RDFLib/rdflib-sparql — pull request #3 by uholzer (2012-12-27 12:29:53+00:00)
Title: Take initNs ignored when parsing query

Running a query with namespaces bound via the attribute initNs of Graph.query fails:

```
>>> import rdflib
>>> g = rdflib.Graph()
>>> g.query("SELECT ?a ?b WHERE { ?a ?b test:foo }", initNs={ "test": "http://example.org/test" })
Traceback (most recent call last):
File "", line 1, in
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib/graph.py", line 943, in query
return result(processorinst.query(query_object, initBindings, initNs, **kwargs))
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/processor.py", line 57, in query
query=translateQuery(parsetree,base)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 605, in translateQuery
q[1]=traverse(q[1], visitPost=functools.partial(translatePName, prologue=prologue))
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 297, in traverse
r=_traverse(tree,visitPre,visitPost)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 282, in _traverse
e[k]=_traverse(val, visitPre,visitPost)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 282, in _traverse
e[k]=_traverse(val, visitPre,visitPost)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 276, in _traverse
return [_traverse(x,visitPre,visitPost) for x in e]
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 276, in
return [_traverse(x,visitPre,visitPost) for x in e]
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 282, in _traverse
e[k]=_traverse(val, visitPre,visitPost)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 276, in _traverse
return [_traverse(x,visitPre,visitPost) for x in e]
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 276, in
return [_traverse(x,visitPre,visitPost) for x in e]
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 276, in _traverse
return [_traverse(x,visitPre,visitPost) for x in e]
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 276, in
return [_traverse(x,visitPre,visitPost) for x in e]
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 284, in _traverse
_e=visitPost(e)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/algebra.py", line 79, in translatePName
return prologue.absolutize(p)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/sparql.py", line 308, in absolutize
return self.resolvePName(iri.prefix, iri.localname)
File "/home/urs/p/sempipe/lib/lib/python3.2/site-packages/rdflib_sparql/sparql.py", line 291, in resolvePName
raise Exception('Unknown namespace prefix : %s'%prefix)
Exception: Unknown namespace prefix : test
```
The problem is, that only evalQuery, but not translateQuery is informed about these namespaces. (I don't know whether evalQuery needs them.)

Also, initNs is a dict. The old version of evalQuery used
`for k,v in initNs` to loop through it. The right way to do it is
`for k,v in initNs.items()`

Both problems are solved in this bug fix.