Check if the input command ends with a command delimiter. A command ending with the delimiter and containing an open quotation character is not considered terminated. If no open quotation is found, it's considered terminated.
(self, line)
| 548 | return list(my_split) |
| 549 | |
| 550 | def _cmd_ends_with_delim(self, line): |
| 551 | """Check if the input command ends with a command delimiter. |
| 552 | |
| 553 | A command ending with the delimiter and containing an open quotation character is |
| 554 | not considered terminated. If no open quotation is found, it's considered |
| 555 | terminated. |
| 556 | """ |
| 557 | # Strip any comments to make a statement such as the following be considered as |
| 558 | # ending with a delimiter: |
| 559 | # select 1 + 1; -- this is a comment |
| 560 | line = strip_comments(line).rstrip() |
| 561 | if line.endswith(ImpalaShell.CMD_DELIM): |
| 562 | try: |
| 563 | # Look for an open quotation in the entire command, and not just the |
| 564 | # current line. |
| 565 | if self.partial_cmd: |
| 566 | line = strip_comments('%s %s' % (self.partial_cmd, line)) |
| 567 | self._shlex_split(line) |
| 568 | return True |
| 569 | # If the command ends with a delimiter, check if it has an open quotation. |
| 570 | # shlex in self._split() throws a ValueError iff an open quotation is found. |
| 571 | # A quotation can either be a single quote or a double quote. |
| 572 | except ValueError: |
| 573 | pass |
| 574 | |
| 575 | # This checks to see if there are any backslashed quotes |
| 576 | # outside of quotes, since backslashed quotes |
| 577 | # outside of single or double quotes should not be escaped. |
| 578 | # Ex. 'abc\'xyz' -> closed because \' is escaped |
| 579 | # \'abcxyz -> open because \' is not escaped |
| 580 | # \'abcxyz' -> closed |
| 581 | # Iterate through the line and switch the state if a single or double quote is found |
| 582 | # and ignore escaped single and double quotes if the line is considered open (meaning |
| 583 | # a previous single or double quote has not been closed yet) |
| 584 | state_closed = True |
| 585 | opener = None |
| 586 | for i, char in enumerate(line): |
| 587 | if state_closed and (char in ['\'', '\"']): |
| 588 | state_closed = False |
| 589 | opener = char |
| 590 | elif not state_closed and opener == char: |
| 591 | if line[i - 1] != '\\': |
| 592 | state_closed = True |
| 593 | opener = None |
| 594 | |
| 595 | return state_closed |
| 596 | |
| 597 | return False |
| 598 | |
| 599 | def _check_for_command_completion(self, cmd): |
| 600 | """Check for a delimiter at the end of user input. |
no test coverage detected