From 5e6cf76bd85de2ca63e2c78d5c4a865dc69d63c2 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Sat, 6 Oct 2018 22:00:48 -0400 Subject: Quoting strings with utility function --- cmd2/pyscript_bridge.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'cmd2/pyscript_bridge.py') diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index 5f5c3542..9a1d0fec 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -13,7 +13,7 @@ import sys from typing import List, Callable, Optional from .argparse_completer import _RangeAction -from .utils import namedtuple_with_defaults, StdSim +from .utils import namedtuple_with_defaults, StdSim, quote_string_if_needed # Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout if sys.version_info < (3, 5): @@ -225,8 +225,7 @@ class ArgparseFunctor: if isinstance(value, List) or isinstance(value, tuple): for item in value: item = str(item).strip() - if ' ' in item: - item = '"{}"'.format(item) + item = quote_string_if_needed(item) cmd_str[0] += '{} '.format(item) # If this is a flag parameter that can accept a variable number of arguments and we have not @@ -238,8 +237,7 @@ class ArgparseFunctor: else: value = str(value).strip() - if ' ' in value: - value = '"{}"'.format(value) + value = quote_string_if_needed(value) cmd_str[0] += '{} '.format(value) # If this is a flag parameter that can accept a variable number of arguments and we have not -- cgit v1.2.1