summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Aastrand Grimnes <gromgull@gmail.com>2017-01-12 12:28:00 +0100
committerGunnar Aastrand Grimnes <gromgull@gmail.com>2017-01-12 14:23:35 +0100
commit5e2c71e1cd79f8e0b818a6ce057388882188b3b4 (patch)
treeff80210c8677319e858dc5ff41f2da49c71ed835
parent3e74b392b831c3c26f67174d9fd57e27bb58ff92 (diff)
downloadrdflib-fix638.tar.gz
make SparqlStore close underlying urllib response bodyfix638
fixes #638
-rw-r--r--rdflib/plugins/stores/sparqlstore.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/rdflib/plugins/stores/sparqlstore.py b/rdflib/plugins/stores/sparqlstore.py
index 25cfb61d..d3557b38 100644
--- a/rdflib/plugins/stores/sparqlstore.py
+++ b/rdflib/plugins/stores/sparqlstore.py
@@ -13,6 +13,7 @@ ORDERBY = 'ORDER BY'
import re
import collections
+import contextlib
import urllib2
import warnings
@@ -330,7 +331,9 @@ class SPARQLStore(NSSPARQLWrapper, Store):
self.timeout = self._timeout
self.setQuery(query)
- return Result.parse(SPARQLWrapper.query(self).response)
+ with contextlib.closing(SPARQLWrapper.query(self).response) as res:
+ return Result.parse(res)
+
def triples(self, (s, p, o), context=None):
"""
@@ -418,7 +421,9 @@ class SPARQLStore(NSSPARQLWrapper, Store):
self.timeout = self._timeout
self.setQuery(query)
- doc = ElementTree.parse(SPARQLWrapper.query(self).response)
+ with contextlib.closing(SPARQLWrapper.query(self).response) as res:
+ doc = ElementTree.parse(res)
+
# ElementTree.dump(doc)
for rt, vars in _traverse_sparql_result_dom(
doc,
@@ -449,7 +454,8 @@ class SPARQLStore(NSSPARQLWrapper, Store):
if self._is_contextual(context):
self.addParameter("default-graph-uri", context.identifier)
self.setQuery(q)
- doc = ElementTree.parse(SPARQLWrapper.query(self).response)
+ with contextlib.closing(SPARQLWrapper.query(self).response) as res:
+ doc = ElementTree.parse(res)
rt, vars = iter(
_traverse_sparql_result_dom(
doc,
@@ -485,7 +491,8 @@ class SPARQLStore(NSSPARQLWrapper, Store):
else:
self.setQuery('SELECT ?name WHERE { GRAPH ?name {} }')
- doc = ElementTree.parse(SPARQLWrapper.query(self).response)
+ with contextlib.closing(SPARQLWrapper.query(self).response) as res:
+ doc = ElementTree.parse(res)
return (
rt.get(Variable("name"))
@@ -770,7 +777,8 @@ class SPARQLUpdateStore(SPARQLStore):
# we must read (and discard) the whole response
# otherwise the network socket buffer will at some point be "full"
# and we will block
- result.response.read()
+ with contextlib.closing(result.response) as res:
+ res.read()
def update(self, query,
initNs={},