diff options
author | kotfu <kotfu@kotfu.net> | 2018-08-08 21:33:13 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-08-08 21:33:13 -0600 |
commit | 34784566f926b57234388150a550ca005f6f3ef9 (patch) | |
tree | 13a9f8ab97ac1bf2d496ccd3bfd8cfe105064666 /cmd2 | |
parent | ad09ee3d3bd87c3dddefa890f8dad03bcb4c143c (diff) | |
download | cmd2-git-34784566f926b57234388150a550ca005f6f3ef9.tar.gz |
Allow newlines inside unclosed quotes. Fixes #495
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/cmd2.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 7273286b..94b75e5f 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1858,8 +1858,30 @@ class Cmd(cmd.Cmd): pipe runs out. We can't refactor it because we need to retain backwards compatibility with the standard library version of cmd. """ - statement = self.statement_parser.parse(self.preparse(line)) - while statement.multiline_command and not statement.terminator: + # preparse() is deprecated, use self.register_postparsing_hook() instead + line = self.preparse(line) + + while True: + try: + statement = self.statement_parser.parse(line) + if statement.multiline_command and statement.terminator: + # we have a completed multiline command, we are done + break + if not statement.multiline_command: + # it's not a multiline command, but we parsed it ok + # so we are done + break + except ValueError: + # we have unclosed quotation marks, lets parse only the command + # and see if it's a multiline + statement = self.statement_parser.parse_command_only(line) + if not statement.multiline_command: + # not a multiline command, so raise the exception + raise + + # if we get here we must have: + # - a multiline command with no terminator + # - a multiline command with unclosed quotation marks if not self.quit_on_sigint: try: newline = self.pseudo_raw_input(self.continuation_prompt) @@ -1885,7 +1907,6 @@ class Cmd(cmd.Cmd): newline = '\n' self.poutput(newline) line = '{}\n{}'.format(statement.raw, newline) - statement = self.statement_parser.parse(line) if not statement.command: raise EmptyStatement() |