summaryrefslogtreecommitdiff
path: root/kvmd/clients
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-01-25 18:33:41 +0300
committerDevaev Maxim <[email protected]>2021-01-26 06:28:40 +0300
commita0ae387a6c24daec8ccef208a724035914d6c428 (patch)
tree85f71ba4ce4b94c1d1c17fc2963c50134ee53215 /kvmd/clients
parent3360a3fce602bcbc2d6fe45004fd9abe15cb4ded (diff)
refactoring
Diffstat (limited to 'kvmd/clients')
-rw-r--r--kvmd/clients/streamer.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/kvmd/clients/streamer.py b/kvmd/clients/streamer.py
index e5430ef7..7d572026 100644
--- a/kvmd/clients/streamer.py
+++ b/kvmd/clients/streamer.py
@@ -59,21 +59,6 @@ class BaseStreamerClient:
yield
-# =====
-def _patch_stream_reader(reader: aiohttp.StreamReader) -> None:
- # https://github.com/pikvm/pikvm/issues/92
- # Infinite looping in BodyPartReader.read() because _at_eof flag.
-
- orig_read = reader.read
-
- async def read(self: aiohttp.StreamReader, n: int=-1) -> bytes: # pylint: disable=invalid-name
- if self.is_eof():
- raise StreamerTempError("StreamReader.read(): Reached EOF")
- return (await orig_read(n))
-
- reader.read = types.MethodType(read, reader) # type: ignore
-
-
class StreamerHttpClient(BaseStreamerClient):
def __init__(
self,
@@ -102,7 +87,7 @@ class StreamerHttpClient(BaseStreamerClient):
) as response:
htclient.raise_not_200(response)
reader = aiohttp.MultipartReader.from_response(response)
- _patch_stream_reader(reader.resp.content)
+ self.__patch_stream_reader(reader.resp.content)
while True:
frame = await reader.next() # pylint: disable=not-callable
@@ -142,6 +127,19 @@ class StreamerHttpClient(BaseStreamerClient):
assert not handle.startswith("/"), handle
return f"http://{self.__host}:{self.__port}/{handle}"
+ def __patch_stream_reader(self, reader: aiohttp.StreamReader) -> None:
+ # https://github.com/pikvm/pikvm/issues/92
+ # Infinite looping in BodyPartReader.read() because _at_eof flag.
+
+ orig_read = reader.read
+
+ async def read(self: aiohttp.StreamReader, n: int=-1) -> bytes: # pylint: disable=invalid-name
+ if self.is_eof():
+ raise StreamerTempError("StreamReader.read(): Reached EOF")
+ return (await orig_read(n))
+
+ reader.read = types.MethodType(read, reader) # type: ignore
+
def __str__(self) -> str:
return f"StreamerHttpClient({self.__name})"