1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-01 00:59:48 +00:00

bitbake: hashserv: Use generic ConnectionError

The Python built-in ConnectionError type can be used instead of a custom
HashConnectionError type. This will make code refactoring simpler.

(Bitbake rev: 8a796c3d6d99cfa8ef7aff0ae55bb0f23bbbeae1)

Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Barker
2021-04-26 09:16:28 +01:00
committed by Richard Purdie
parent bf348561f3
commit 1023671823
3 changed files with 12 additions and 17 deletions
+8 -12
View File
@@ -14,10 +14,6 @@ from . import chunkify, DEFAULT_MAX_CHUNK, create_async_client
logger = logging.getLogger("hashserv.client")
class HashConnectionError(Exception):
pass
class AsyncClient(object):
MODE_NORMAL = 0
MODE_GET_STREAM = 1
@@ -66,14 +62,14 @@ class AsyncClient(object):
return await proc()
except (
OSError,
HashConnectionError,
ConnectionError,
json.JSONDecodeError,
UnicodeDecodeError,
) as e:
logger.warning("Error talking to server: %s" % e)
if count >= 3:
if not isinstance(e, HashConnectionError):
raise HashConnectionError(str(e))
if not isinstance(e, ConnectionError):
raise ConnectionError(str(e))
raise e
await self.close()
count += 1
@@ -82,12 +78,12 @@ class AsyncClient(object):
async def get_line():
line = await self.reader.readline()
if not line:
raise HashConnectionError("Connection closed")
raise ConnectionError("Connection closed")
line = line.decode("utf-8")
if not line.endswith("\n"):
raise HashConnectionError("Bad message %r" % message)
raise ConnectionError("Bad message %r" % message)
return line
@@ -119,7 +115,7 @@ class AsyncClient(object):
await self.writer.drain()
l = await self.reader.readline()
if not l:
raise HashConnectionError("Connection closed")
raise ConnectionError("Connection closed")
return l.decode("utf-8").rstrip()
return await self._send_wrapper(proc)
@@ -128,11 +124,11 @@ class AsyncClient(object):
if new_mode == self.MODE_NORMAL and self.mode == self.MODE_GET_STREAM:
r = await self.send_stream("END")
if r != "ok":
raise HashConnectionError("Bad response from server %r" % r)
raise ConnectionError("Bad response from server %r" % r)
elif new_mode == self.MODE_GET_STREAM and self.mode == self.MODE_NORMAL:
r = await self.send_message({"get-stream": None})
if r != "ok":
raise HashConnectionError("Bad response from server %r" % r)
raise ConnectionError("Bad response from server %r" % r)
elif new_mode != self.mode:
raise Exception(
"Undefined mode transition %r -> %r" % (self.mode, new_mode)