diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-24 15:05:35 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-24 15:05:35 -0400 |
| commit | a5054a0fb0d61930b1f6de2cbeba1b0d3b050209 (patch) | |
| tree | e8f54b86ec9cf26717a5f37fbd6bd40803d821a1 | |
| parent | e056174cb3404780adf1c2888b566ebf872d1708 (diff) | |
| download | cmd2-git-a5054a0fb0d61930b1f6de2cbeba1b0d3b050209.tar.gz | |
Allow quoted file paths when redirecting with < and >
| -rwxr-xr-x | cmd2.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -748,7 +748,9 @@ def replace_with_file_contents(fname): :return: str - contents of file "fname" """ try: - with open(os.path.expanduser(fname[0])) as source_file: + # Any outer quotes are not part of the filename + unquoted_file = strip_quotes(fname[0]) + with open(os.path.expanduser(unquoted_file)) as source_file: result = source_file.read() except IOError: result = '< %s' % fname[0] # wasn't a file after all @@ -2936,8 +2938,8 @@ class ParserManager: pyparsing.Optional(pipe + pyparsing.SkipTo(output_destination_parser ^ string_end, ignore=do_not_parse)('pipeTo')) + \ pyparsing.Optional(output_destination_parser + - pyparsing.SkipTo(string_end, - ignore=do_not_parse).setParseAction(lambda x: x[0].strip())('outputTo')) + pyparsing.SkipTo(string_end, ignore=do_not_parse). + setParseAction(lambda x: strip_quotes(x[0].strip()))('outputTo')) multilineCommand.setParseAction(lambda x: x[0]) oneline_command.setParseAction(lambda x: x[0]) @@ -2984,7 +2986,10 @@ class ParserManager: input_mark = pyparsing.Literal('<') input_mark.setParseAction(lambda x: '') - file_name = pyparsing.Word(legalChars + '/\\') + + # Also allow spaces, slashes, and quotes + file_name = pyparsing.Word(legalChars + ' /\\"\'') + input_from = file_name('inputFrom') input_from.setParseAction(replace_with_file_contents) # a not-entirely-satisfactory way of distinguishing < as in "import from" from < |
