RDFLib/rdflib-sparql — pull request #6 by uholzer (2012-12-30 17:28:58+00:00)
Title: Non-existent str.decode called under Python 3

The parser makes use of Regex.setParseAction from pyparsing. It takes a function as argument. This function is later called with a str object when running in py3. According to my tests, it is also a str object in py2, but the corresponding class in py3 is called bytes. Unfortunately, parser.py gives setParseAction a function that calls decode which does not exist in py3's str class.

With Python 3:
```
>>> from rdflib import Graph
>>> g = Graph()
>>> g.query("SELECT * WHERE { ?a ?b 'foo' }")
Traceback (most recent call last):
File "", line 1, in
File "/home/urs/.local/lib/python3.2/site-packages/rdflib/graph.py", line 943, in query
return result(processorinst.query(query_object, initBindings, initNs, **kwargs))
File "rdflib_sparql/processor.py", line 56, in query
parsetree=parseQuery(strOrQuery)
File "rdflib_sparql/parser.py", line 946, in parseQuery
return Query.parseString(q, parseAll=True)
File "/usr/lib/python3/dist-packages/pyparsing.py", line 959, in parseString
loc, tokens = self._parse( instring, 0 )
[...]
File "/usr/lib/python3/dist-packages/pyparsing.py", line 632, in wrapper
return func(*args[limit:])
File "rdflib_sparql/parser.py", line 255, in
STRING_LITERAL1.setParseAction(lambda x: rdflib.Literal(x[0][1:-1].decode('string-escape')))
AttributeError: 'str' object has no attribute 'decode'
```

In my fix I dared to just remove the calls to decode. It does work in Python 2.7 for me. But I don't know the reason why they have been put there in the first place.