diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-08-09 00:25:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-09 00:25:57 -0400 |
commit | 88b739f6a11a2a1796b2758fa2ce94c562e24316 (patch) | |
tree | 13a9f8ab97ac1bf2d496ccd3bfd8cfe105064666 /cmd2/cmd2.py | |
parent | 46955ec2f403a94ca3582fe3225bdcc369f334e1 (diff) | |
parent | 34784566f926b57234388150a550ca005f6f3ef9 (diff) | |
download | cmd2-git-88b739f6a11a2a1796b2758fa2ce94c562e24316.tar.gz |
Merge pull request #496 from python-cmd2/embedded_newlines
Fix #495 by allowing embedded newlines in unclosed quote marks when entering multiline commands
Diffstat (limited to 'cmd2/cmd2.py')
-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() |