diff options
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-x | cmd2/cmd2.py | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 7f5b21d2..8be68370 100755 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -180,21 +180,6 @@ def _which(editor: str) -> Optional[str]: return editor_path -def strip_quotes(arg: str) -> str: - """ Strip outer quotes from a string. - - Applies to both single and double quotes. - - :param arg: string to strip outer quotes from - :return: same string with potentially outer quotes stripped - """ - quote_chars = '"' + "'" - - if len(arg) > 1 and arg[0] == arg[-1] and arg[0] in quote_chars: - arg = arg[1:-1] - return arg - - def parse_quoted_string(cmdline: str) -> List[str]: """Parse a quoted string into a list of arguments.""" if isinstance(cmdline, list): @@ -207,7 +192,7 @@ def parse_quoted_string(cmdline: str) -> List[str]: if not POSIX_SHLEX and STRIP_QUOTES_FOR_NON_POSIX: temp_arglist = [] for arg in lexed_arglist: - temp_arglist.append(strip_quotes(arg)) + temp_arglist.append(utils.strip_quotes(arg)) lexed_arglist = temp_arglist return lexed_arglist @@ -373,7 +358,7 @@ def replace_with_file_contents(fname: str) -> str: """ try: # Any outer quotes are not part of the filename - unquoted_file = strip_quotes(fname[0]) + unquoted_file = utils.strip_quotes(fname[0]) with open(os.path.expanduser(unquoted_file)) as source_file: result = source_file.read() except IOError: @@ -1108,7 +1093,7 @@ class Cmd(cmd.Cmd): raw_tokens = initial_tokens # Save the unquoted tokens - tokens = [strip_quotes(cur_token) for cur_token in raw_tokens] + tokens = [utils.strip_quotes(cur_token) for cur_token in raw_tokens] # If the token being completed had an unclosed quote, we need # to remove the closing quote that was added in order for it @@ -2830,7 +2815,7 @@ Usage: Usage: unalias [-a] name [name ...] # an unclosed quote, so we only need to check the first character. first_char = tokens[index][0] if first_char in constants.QUOTES: - tokens[index] = strip_quotes(tokens[index]) + tokens[index] = utils.strip_quotes(tokens[index]) tokens[index] = os.path.expanduser(tokens[index]) @@ -3342,7 +3327,7 @@ class ParserManager: ignore=do_not_parse)('pipeTo')) + \ pyparsing.Optional(output_destination_parser + pyparsing.SkipTo(string_end, ignore=do_not_parse). - setParseAction(lambda x: strip_quotes(x[0].strip()))('outputTo')) + setParseAction(lambda x: utils.strip_quotes(x[0].strip()))('outputTo')) multilineCommand.setParseAction(lambda x: x[0]) oneline_command.setParseAction(lambda x: x[0]) |