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