Simplify by removing shlex.quote and shlex.split when using EnvironmentExecutor

This commit is contained in:
Yannick Jadoul
2020-07-19 17:37:25 +02:00
parent 3a2d7a21b1
commit 28af49a006
2 changed files with 6 additions and 8 deletions
+4 -6
View File
@@ -1,15 +1,14 @@
import shlex
import subprocess
from typing import Callable, Dict, List, NamedTuple, Optional, Sequence
import bashlex # type: ignore
# a function that takes a shell command and the environment, and returns the result
EnvironmentExecutor = Callable[[str, Dict[str, str]], str]
EnvironmentExecutor = Callable[[List[str], Dict[str, str]], str]
def local_environment_executor(command: str, env: Dict[str, str]) -> str:
return subprocess.check_output(shlex.split(command), env=env, universal_newlines=True)
def local_environment_executor(command: List[str], env: Dict[str, str]) -> str:
return subprocess.check_output(command, env=env, universal_newlines=True)
class NodeExecutionContext(NamedTuple):
@@ -97,8 +96,7 @@ def evaluate_nodes_as_compound_command(nodes: Sequence[bashlex.ast.node], contex
def evaluate_nodes_as_simple_command(nodes: List[bashlex.ast.node], context: NodeExecutionContext):
words = [shlex.quote(evaluate_node(part, context=context)) for part in nodes]
command = ' '.join(words)
command = [evaluate_node(part, context=context) for part in nodes]
return context.executor(command, context.environment)