lib.ec.ssh.AsyncSSH: Code beautification

Apply some style changes:

  - Replace double by single quotes for consistency

  - Add spaces around equal signs in long parameter lists

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-19 14:04:27 +02:00
commit f1898941e7

View file

@ -25,28 +25,28 @@ class AsyncSSH(Base):
super().__init__(
uri,
caps = self.Caps.LogOutput | self.Caps.Wd | self.Caps.Interactive | self.Caps.ModEnv,
caps = self.Caps.LogOutput | self.Caps.Wd | self.Caps.Interactive | self.Caps.Env,
**kwargs
)
self.client_keys = client_keys
self.known_hosts = known_hosts
self.term_type = term_type or os.environ.get("TERM", "xterm")
self.term_type = term_type or os.environ.get('TERM', 'xterm')
self.connect_timeout = connect_timeout
def _connect_kwargs(self, hide_secrets: bool=False) -> dict:
kwargs: dict = {
"host": self.hostname,
"port": self.port,
"username": self.username,
"password": self.password,
"client_keys": self.client_keys,
"connect_timeout": self.connect_timeout,
'host': self.hostname,
'port': self.port,
'username': self.username,
'password': self.password,
'client_keys': self.client_keys,
'connect_timeout': self.connect_timeout,
}
if self.known_hosts is not _USE_DEFAULT_KNOWN_HOSTS:
kwargs["known_hosts"] = self.known_hosts
kwargs['known_hosts'] = self.known_hosts
ret = {k: v for k, v in kwargs.items() if v is not None}
if hide_secrets and 'password' in kwargs:
@ -57,13 +57,13 @@ class AsyncSSH(Base):
def _build_remote_command(cmd: list[str], wd: str | None) -> str:
if not cmd:
raise ValueError("cmd must not be empty")
raise ValueError('cmd must not be empty')
inner = f"exec {join_cmd(cmd)}"
inner = f'exec {join_cmd(cmd)}'
if wd is not None:
inner = f"cd {shlex.quote(wd)} && {inner}"
inner = f'cd {shlex.quote(wd)} && {inner}'
return f"/bin/sh -lc {shlex.quote(inner)}"
return f'/bin/sh -lc {shlex.quote(inner)}'
@staticmethod
def _has_local_tty() -> bool:
@ -80,8 +80,8 @@ class AsyncSSH(Base):
try:
import fcntl, termios, struct
packed = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, b"\0" * 8)
rows2, cols2, xpixel, ypixel = struct.unpack("HHHH", packed)
packed = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, b'\0' * 8)
rows2, cols2, xpixel, ypixel = struct.unpack('HHHH', packed)
if cols2 > 0 and rows2 > 0:
cols, rows = cols2, rows2
@ -100,7 +100,7 @@ class AsyncSSH(Base):
log_prefix: str,
log_enc: str,
) -> None:
buf = b""
buf = b''
while True:
chunk = await stream.read(4096)
@ -111,12 +111,12 @@ class AsyncSSH(Base):
if verbose:
buf += chunk
while b"\n" in buf:
line, buf = buf.split(b"\n", 1)
log(prio, log_prefix, line.decode(log_enc, errors="replace"))
while b'\n' in buf:
line, buf = buf.split(b'\n', 1)
log(prio, log_prefix, line.decode(log_enc, errors='replace'))
if verbose and buf:
log(prio, log_prefix, buf.decode(log_enc, errors="replace"))
log(prio, log_prefix, buf.decode(log_enc, errors='replace'))
async def _run_interactive_on_conn(
self,
@ -137,7 +137,7 @@ class AsyncSSH(Base):
stdout = asyncssh.PIPE,
stderr = asyncssh.STDOUT,
encoding = None,
request_pty="force",
request_pty = 'force',
term_type = self.term_type,
term_size = self._get_local_term_size(),
)
@ -161,7 +161,7 @@ class AsyncSSH(Base):
try:
data = os.read(stdin_fd, 4096)
except OSError:
data = b""
data = b''
if data:
stdin_queue.put_nowait(data)
@ -223,7 +223,7 @@ class AsyncSSH(Base):
except (NotImplementedError, RuntimeError):
stdin_queue.put_nowait(None)
if hasattr(signal, "SIGWINCH"):
if hasattr(signal, 'SIGWINCH'):
try:
old_winch_handler = signal.getsignal(signal.SIGWINCH)
signal.signal(signal.SIGWINCH, _on_winch)
@ -247,7 +247,7 @@ class AsyncSSH(Base):
if exit_code is None:
exit_code = completed.returncode if completed.returncode is not None else -1
stdout = b"".join(stdout_parts) if stdout_parts else None
stdout = b''.join(stdout_parts) if stdout_parts else None
return Result(stdout, None, exit_code)
finally:
@ -257,7 +257,7 @@ class AsyncSSH(Base):
except Exception:
pass
if old_winch_handler is not None and hasattr(signal, "SIGWINCH"):
if old_winch_handler is not None and hasattr(signal, 'SIGWINCH'):
try:
signal.signal(signal.SIGWINCH, old_winch_handler)
except Exception:
@ -289,7 +289,7 @@ class AsyncSSH(Base):
command = self._build_remote_command(cmd, wd)
stdout_parts: list[bytes] = []
stdout_log_enc = sys.stdout.encoding or "utf-8"
stdout_log_enc = sys.stdout.encoding or 'utf-8'
proc = await conn.create_process(
command = command,
@ -298,7 +298,7 @@ class AsyncSSH(Base):
stdout = asyncssh.PIPE,
stderr = asyncssh.STDOUT,
encoding = None,
request_pty="force",
request_pty = 'force',
term_type = self.term_type,
)
@ -325,7 +325,7 @@ class AsyncSSH(Base):
if exit_code is None:
exit_code = completed.returncode if completed.returncode is not None else -1
stdout = b"".join(stdout_parts) if stdout_parts else None
stdout = b''.join(stdout_parts) if stdout_parts else None
return Result(stdout, None, exit_code)
async def _run_on_conn(
@ -364,8 +364,8 @@ class AsyncSSH(Base):
stdout_parts: list[bytes] = []
stderr_parts: list[bytes] = []
stdout_log_enc = sys.stdout.encoding or "utf-8"
stderr_log_enc = sys.stderr.encoding or "utf-8"
stdout_log_enc = sys.stdout.encoding or 'utf-8'
stderr_log_enc = sys.stderr.encoding or 'utf-8'
stdin_mode = asyncssh.PIPE if cmd_input is not None else asyncssh.DEVNULL
@ -410,8 +410,8 @@ class AsyncSSH(Base):
completed = await proc.wait(check=False)
await asyncio.gather(*tasks)
stdout = b"".join(stdout_parts) if stdout_parts else None
stderr = b"".join(stderr_parts) if stderr_parts else None
stdout = b''.join(stdout_parts) if stdout_parts else None
stderr = b''.join(stderr_parts) if stderr_parts else None
exit_code = completed.exit_status
if exit_code is None: