tools (common/async_process): Accept bytes as stdin

This commit is contained in:
Goffi 2026-02-18 17:44:26 +01:00
commit c46f0716dc

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python3
# SAT: a jabber client
# Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
# Libervia XMPP client
# Copyright (C) 2009-2026 Jérôme Poisson (goffi@goffi.org)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@ -34,12 +34,12 @@ log = getLogger(__name__)
class CommandProtocol(protocol.ProcessProtocol):
"""handle an external command"""
# name of the command (unicode)
name = None
# full path to the command (bytes)
command = None
# True to activate logging of command outputs (bool)
log = False
# name of the command
name: str|None = None
# full path to the command
command: bytes|None = None
# True to activate logging of command outputs
log: bool = False
def __init__(self, deferred, stdin=None):
"""
@ -130,7 +130,8 @@ class CommandProtocol(protocol.ProcessProtocol):
"""
stdin = kwargs.pop("stdin", None)
if stdin is not None:
stdin = stdin.encode("utf-8")
if isinstance(stdin, str):
stdin = stdin.encode()
verbose = kwargs.pop("verbose", False)
args = list(args)
d = defer.Deferred()