mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-02 19:11:54 +08:00
refactoring
This commit is contained in:
@@ -120,10 +120,10 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
|
||||
except asyncio.CancelledError:
|
||||
logger.info("%s [%s]: Cancelling subtask ...", self._remote, name)
|
||||
raise
|
||||
except RfbConnectionError as err:
|
||||
logger.info("%s [%s]: Gone: %s", self._remote, name, err)
|
||||
except (RfbError, ssl.SSLError) as err:
|
||||
logger.error("%s [%s]: Error: %s", self._remote, name, err)
|
||||
except RfbConnectionError as ex:
|
||||
logger.info("%s [%s]: Gone: %s", self._remote, name, ex)
|
||||
except (RfbError, ssl.SSLError) as ex:
|
||||
logger.error("%s [%s]: Error: %s", self._remote, name, ex)
|
||||
except Exception:
|
||||
logger.exception("%s [%s]: Unhandled exception", self._remote, name)
|
||||
|
||||
|
||||
@@ -29,5 +29,5 @@ class RfbError(Exception):
|
||||
|
||||
|
||||
class RfbConnectionError(RfbError):
|
||||
def __init__(self, msg: str, err: Exception) -> None:
|
||||
super().__init__(f"{msg}: {tools.efmt(err)}")
|
||||
def __init__(self, msg: str, ex: Exception) -> None:
|
||||
super().__init__(f"{msg}: {tools.efmt(ex)}")
|
||||
|
||||
@@ -51,22 +51,22 @@ class RfbClientStream:
|
||||
else:
|
||||
fmt = f">{fmt}"
|
||||
return struct.unpack(fmt, await self.__reader.readexactly(struct.calcsize(fmt)))[0]
|
||||
except (ConnectionError, asyncio.IncompleteReadError) as err:
|
||||
raise RfbConnectionError(f"Can't read {msg}", err)
|
||||
except (ConnectionError, asyncio.IncompleteReadError) as ex:
|
||||
raise RfbConnectionError(f"Can't read {msg}", ex)
|
||||
|
||||
async def _read_struct(self, msg: str, fmt: str) -> tuple[int, ...]:
|
||||
assert len(fmt) > 1
|
||||
try:
|
||||
fmt = f">{fmt}"
|
||||
return struct.unpack(fmt, (await self.__reader.readexactly(struct.calcsize(fmt))))
|
||||
except (ConnectionError, asyncio.IncompleteReadError) as err:
|
||||
raise RfbConnectionError(f"Can't read {msg}", err)
|
||||
except (ConnectionError, asyncio.IncompleteReadError) as ex:
|
||||
raise RfbConnectionError(f"Can't read {msg}", ex)
|
||||
|
||||
async def _read_text(self, msg: str, length: int) -> str:
|
||||
try:
|
||||
return (await self.__reader.readexactly(length)).decode("utf-8", errors="ignore")
|
||||
except (ConnectionError, asyncio.IncompleteReadError) as err:
|
||||
raise RfbConnectionError(f"Can't read {msg}", err)
|
||||
except (ConnectionError, asyncio.IncompleteReadError) as ex:
|
||||
raise RfbConnectionError(f"Can't read {msg}", ex)
|
||||
|
||||
# =====
|
||||
|
||||
@@ -84,8 +84,8 @@ class RfbClientStream:
|
||||
self.__writer.write(struct.pack(f">{fmt}", *values))
|
||||
if drain:
|
||||
await self.__writer.drain()
|
||||
except ConnectionError as err:
|
||||
raise RfbConnectionError(f"Can't write {msg}", err)
|
||||
except ConnectionError as ex:
|
||||
raise RfbConnectionError(f"Can't write {msg}", ex)
|
||||
|
||||
async def _write_reason(self, msg: str, text: str, drain: bool=True) -> None:
|
||||
encoded = text.encode("utf-8", errors="ignore")
|
||||
@@ -94,8 +94,8 @@ class RfbClientStream:
|
||||
self.__writer.write(encoded)
|
||||
if drain:
|
||||
await self.__writer.drain()
|
||||
except ConnectionError as err:
|
||||
raise RfbConnectionError(f"Can't write {msg}", err)
|
||||
except ConnectionError as ex:
|
||||
raise RfbConnectionError(f"Can't write {msg}", ex)
|
||||
|
||||
async def _write_fb_update(self, msg: str, width: int, height: int, encoding: int, drain: bool=True) -> None:
|
||||
await self._write_struct(
|
||||
@@ -123,8 +123,8 @@ class RfbClientStream:
|
||||
server_side=True,
|
||||
ssl_handshake_timeout=ssl_timeout,
|
||||
)
|
||||
except ConnectionError as err:
|
||||
raise RfbConnectionError("Can't start TLS", err)
|
||||
except ConnectionError as ex:
|
||||
raise RfbConnectionError("Can't start TLS", ex)
|
||||
|
||||
ssl_reader.set_transport(transport) # type: ignore
|
||||
ssl_writer = asyncio.StreamWriter(
|
||||
|
||||
Reference in New Issue
Block a user