Fix installation with Python 3.7. Fixes #1414.

Fix deprecated use of aiohttp.Timeout. Fixes #1296.
Use "async with" with aiohttp.ClientSession().
Make sure websocket connections are properly closed, see https://docs.aiohttp.org/en/stable/web_advanced.html#graceful-shutdown
Finish to drop Python 3.4.
This commit is contained in:
grossmj committed 2018-10-16 15:56:06 +07:00
1 parent 8217f65e97
commit 86f87aec74
11 files changed
+124 -155

No files matched your search

+10 -11
View File
@@ -93,6 +93,8 @@ class Docker(BaseManager):
if self._connected:
if self._connector and not self._connector.closed:
self._connector.close()
if self._session and not self._session.closed:
await self._session.close()
async def query(self, method, path, data={}, params={}):
"""
@@ -106,6 +108,7 @@ class Docker(BaseManager):
response = await self.http_query(method, path, data=data, params=params)
body = await response.read()
response.close()
if body and len(body):
if response.headers['CONTENT-TYPE'] == 'application/json':
body = json.loads(body.decode("utf-8"))
@@ -140,14 +143,12 @@ class Docker(BaseManager):
if self._session is None or self._session.closed:
connector = self.connector()
self._session = aiohttp.ClientSession(connector=connector)
response = await self._session.request(
method,
url,
params=params,
data=data,
headers={"content-type": "application/json", },
timeout=timeout
)
response = await self._session.request(method,
url,
params=params,
data=data,
headers={"content-type": "application/json", },
timeout=timeout)
except (aiohttp.ClientResponseError, aiohttp.ClientOSError) as e:
raise DockerError("Docker has returned an error: {}".format(str(e)))
except (asyncio.TimeoutError):
@@ -177,9 +178,7 @@ class Docker(BaseManager):
"""
url = "http://docker/v" + self._api_version + "/" + path
connection = await self._session.ws_connect(url,
origin="http://docker",
autoping=True)
connection = await self._session.ws_connect(url, origin="http://docker", autoping=True)
return connection
@locking