1414import re
1515import collections
1616
17- from .sparqlwrapper import SPARQLWrapper
17+ from .sparqlconnector import SPARQLConnector
1818
1919from rdflib .plugins .stores .regexmatching import NATIVE_REGEX
2020
@@ -37,11 +37,10 @@ def _node_to_sparql(node):
3737 return node .n3 ()
3838
3939
40- class SPARQLStore (SPARQLWrapper , Store ):
41- """
42- An RDFLib store around a SPARQL endpoint
40+ class SPARQLStore (SPARQLConnector , Store ):
41+ """An RDFLib store around a SPARQL endpoint
4342
44- This is in theory context-aware and should work as expected
43+ This is context-aware and should work as expected
4544 when a context is specified.
4645
4746 For ConjunctiveGraphs, reading is done from the "default graph". Exactly
@@ -51,7 +50,7 @@ class SPARQLStore(SPARQLWrapper, Store):
5150 motivated by the SPARQL 1.1.
5251
5352 Fuseki/TDB has a flag for specifying that the default graph
54- is the union of all graphs (tdb:unionDefaultGraph in the Fuseki config).
53+ is the union of all graphs (`` tdb:unionDefaultGraph`` in the Fuseki config).
5554
5655 .. warning:: By default the SPARQL Store does not support blank-nodes!
5756
@@ -61,9 +60,9 @@ class SPARQLStore(SPARQLWrapper, Store):
6160
6261 See http://www.w3.org/TR/sparql11-query/#BGPsparqlBNodes
6362
64- You can make use of such extensions through the node_to_sparql and
65- node_from_result arguments . For example if you want to transform
66- BNode('0001') into "<bnode:b0001>", you can use a function like this:
63+ You can make use of such extensions through the `` node_to_sparql``
64+ argument . For example if you want to transform BNode('0001') into
65+ "<bnode:b0001>", you can use a function like this:
6766
6867 >>> def my_bnode_ext(node):
6968 ... if isinstance(node, BNode):
@@ -72,6 +71,22 @@ class SPARQLStore(SPARQLWrapper, Store):
7271 >>> store = SPARQLStore('http://dbpedia.org/sparql',
7372 ... node_to_sparql=my_bnode_ext)
7473
74+ You can request a particular result serialization with the
75+ ``returnFormat`` parameter. This is a string that must have a
76+ matching plugin registered. Built in is support for ``xml``,
77+ ``json``, ``csv``, ``tsv`` and ``application/rdf+xml``.
78+
79+ The underlying SPARQLConnector builds in the requests library.
80+ Any extra kwargs passed to the SPARQLStore connector are passed to
81+ requests when doing HTTP calls. I.e. you have full control of
82+ cookies/auth/headers.
83+
84+ Form example:
85+
86+ >>> store = SPARQLStore('...my endpoint ...', auth=('user','pass'))
87+
88+ will use HTTP basic auth.
89+
7590 """
7691 formula_aware = False
7792 transaction_aware = False
@@ -83,11 +98,11 @@ def __init__(self,
8398 sparql11 = True , context_aware = True ,
8499 node_to_sparql = _node_to_sparql ,
85100 returnFormat = 'xml' ,
86- ** sparqlwrapper_kwargs ):
101+ ** sparqlconnector_kwargs ):
87102 """
88103 """
89104 super (SPARQLStore , self ).__init__ (
90- endpoint , returnFormat = returnFormat , ** sparqlwrapper_kwargs )
105+ endpoint , returnFormat = returnFormat , ** sparqlconnector_kwargs )
91106
92107 self .node_to_sparql = node_to_sparql
93108 self .nsBindings = {}
@@ -353,7 +368,7 @@ def _is_contextual(self, graph):
353368 return graph .identifier != DATASET_DEFAULT_GRAPH_ID
354369
355370 def close (self , commit_pending_transaction = None ):
356- SPARQLWrapper .close (self )
371+ SPARQLConnector .close (self )
357372
358373
359374class SPARQLUpdateStore (SPARQLStore ):
@@ -588,7 +603,7 @@ def _update(self, update):
588603
589604 self ._updates += 1
590605
591- SPARQLWrapper .update (self , update )
606+ SPARQLConnector .update (self , update )
592607
593608 def update (self , query ,
594609 initNs = {},
0 commit comments