Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sess(self, url):
self.etag_url = urljoin(url, "/etag")
self.update_etag_url = urljoin(url, "/update_etag")
self.cache = DictCache()
sess = CacheControl(
requests.Session(), cache=self.cache, serializer=NullSerializer()
)
yield sess
# closing session object
sess.close()
def sess(self, url):
self.url = urljoin(url, "/vary_accept")
self.cache = DictCache()
sess = CacheControl(requests.Session(), cache=self.cache)
return sess
def sess(self, url):
self.etag_url = urljoin(url, "/etag")
self.update_etag_url = urljoin(url, "/update_etag")
self.cache = DictCache()
sess = CacheControl(
requests.Session(), cache=self.cache, serializer=NullSerializer()
)
yield sess
# closing session object
sess.close()
def test_not_modified_releases_connection(self, server, url):
sess = CacheControl(requests.Session())
etag_url = urljoin(url, "/etag")
sess.get(etag_url)
resp = Mock(status=304, headers={})
# This is how the urllib3 response is created in
# requests.adapters
response_mod = "requests.adapters.HTTPResponse.from_httplib"
with patch(response_mod, Mock(return_value=resp)):
sess.get(etag_url)
assert resp.read.called
assert resp.release_conn.called
def sess(self, server, url):
self.etag_url = urljoin(url, "/etag")
self.update_etag_url = urljoin(url, "/update_etag")
self.cache = DictCache()
sess = CacheControl(
requests.Session(),
cache=self.cache,
cache_etags=False,
serializer=NullSerializer(),
)
return sess
def sess(self, server, url):
self.etag_url = urljoin(url, "/etag")
self.update_etag_url = urljoin(url, "/update_etag")
self.cache = DictCache()
sess = CacheControl(
requests.Session(),
cache=self.cache,
cache_etags=False,
serializer=NullSerializer(),
)
return sess