summaryrefslogtreecommitdiff
path: root/kvmd/aiotools.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-05-18 13:34:23 +0300
committerDevaev Maxim <[email protected]>2020-05-18 13:34:23 +0300
commit028e0b06ff6730e309e1d3c7fb6abebb81360f5b (patch)
tree981760a61c3645ad85b6327dadbde3194d31c9e2 /kvmd/aiotools.py
parent3947640771a8d212e13196808679ba3caa1c411d (diff)
refactoring
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r--kvmd/aiotools.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py
index a2bed6bf..bd4bd37e 100644
--- a/kvmd/aiotools.py
+++ b/kvmd/aiotools.py
@@ -39,6 +39,8 @@ from typing import TypeVar
from typing import Optional
from typing import Any
+import aiohttp
+
import aiofiles
import aiofiles.base
@@ -94,6 +96,20 @@ async def wait_first(*aws: Awaitable) -> Tuple[Set[asyncio.Future], Set[asyncio.
# =====
+def raise_not_200(response: aiohttp.ClientResponse) -> None:
+ if response.status != 200:
+ assert response.reason is not None
+ response.release()
+ raise aiohttp.ClientResponseError(
+ response.request_info,
+ response.history,
+ status=response.status,
+ message=response.reason,
+ headers=response.headers,
+ )
+
+
+# =====
async def afile_write_now(afile: aiofiles.base.AiofilesContextManager, data: bytes) -> None:
await afile.write(data)
await afile.flush()