summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah BrĂ¼chert <jbb@kaidan.im>2024-04-20 00:21:53 +0200
committerJonah BrĂ¼chert <jbb@kaidan.im>2024-04-20 00:21:53 +0200
commit71c7a6b5836043e9476e98a61aa5dd907e0d4ce4 (patch)
tree51ce78554da743dbe43851e1b068f42cdc36b2eb
parentbbb87b0fb5d798b1886682ef687f8f7755f8fe81 (diff)
downloadbcfg2-71c7a6b5836043e9476e98a61aa5dd907e0d4ce4.tar.gz
bcfg2-71c7a6b5836043e9476e98a61aa5dd907e0d4ce4.tar.bz2
bcfg2-71c7a6b5836043e9476e98a61aa5dd907e0d4ce4.zip
Utils: Fix bytes / str confusion in Executor.run
-rw-r--r--.gitignore3
-rw-r--r--src/lib/Bcfg2/Utils.py16
2 files changed, 12 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 6436e466b..99d5dbad8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,6 @@ testsuite/test.sqlite
# sphinx build data
man/.doctrees
+
+# 2to3
+*.bak
diff --git a/src/lib/Bcfg2/Utils.py b/src/lib/Bcfg2/Utils.py
index faabf9346..8315cb464 100644
--- a/src/lib/Bcfg2/Utils.py
+++ b/src/lib/Bcfg2/Utils.py
@@ -13,6 +13,8 @@ import subprocess
import threading
from Bcfg2.Compat import input, any # pylint: disable=W0622
+from typing import Optional
+
class ClassName(object):
""" This very simple descriptor class exists only to get the name
@@ -167,9 +169,6 @@ class ExecutorResult(object):
self.__class__.__name__)
def __bool__(self):
- return self.__bool__()
-
- def __bool__(self):
return self.success
@@ -200,7 +199,8 @@ class Executor(object):
except OSError:
pass
- def run(self, command, inputdata=None, timeout=None, **kwargs):
+ def run(self, command: list[str], inputdata: Optional[str] = None,
+ timeout: Optional[int] = None, **kwargs):
""" Run a command, given as a list, optionally giving it the
specified input data. All additional keyword arguments are
passed through to :class:`subprocess.Popen`.
@@ -241,7 +241,9 @@ class Executor(object):
if inputdata:
for line in inputdata.splitlines():
self.logger.debug('> %s' % line)
- (stdout, stderr) = proc.communicate(input=inputdata)
+ (stdout, stderr) = proc.communicate(input=inputdata.encode())
+ else:
+ (stdout, stderr) = proc.communicate()
# py3k fixes
if not isinstance(stdout, str):
@@ -313,12 +315,12 @@ def hostnames2ranges(hostnames):
return ranges
-def safe_input(msg):
+def safe_input(msg: str) -> str:
""" input() that flushes the input buffer before accepting input """
# flush input buffer
while len(select.select([sys.stdin.fileno()], [], [], 0.0)[0]) > 0:
os.read(sys.stdin.fileno(), 4096)
- return eval(input(msg))
+ return input(msg)
def safe_module_name(prefix, module):