MCPcopy Create free account
hub / github.com/apache/impala / _check_for_command_completion

Method _check_for_command_completion

shell/impala_shell/impala_shell.py:599–659  ·  view source on GitHub ↗

Check for a delimiter at the end of user input. The end of the user input is scanned for a legal delimiter. If a delimiter is not found: - Input is not send to onecmd() - onecmd() is a method in Cmd which routes the user input to the appropriate method. An empty stri

(self, cmd)

Source from the content-addressed store, hash-verified

597 return False
598
599 def _check_for_command_completion(self, cmd):
600 """Check for a delimiter at the end of user input.
601
602 The end of the user input is scanned for a legal delimiter.
603 If a delimiter is not found:
604 - Input is not send to onecmd()
605 - onecmd() is a method in Cmd which routes the user input to the
606 appropriate method. An empty string results in a no-op.
607 - Input is removed from history.
608 - Input is appended to partial_cmd
609 If a delimiter is found:
610 - The contents of partial_cmd are put in history, as they represent
611 a completed command.
612 - The contents are passed to the appropriate method for execution.
613 - partial_cmd is reset to an empty string.
614
615 Returns text type result (unicode in Python2, str in Python3)
616 """
617 if self.readline: current_history_len = self.readline.get_current_history_length()
618 # Input is incomplete, store the contents and do nothing.
619 if not self._cmd_ends_with_delim(cmd):
620 # The user input is incomplete, change the prompt to reflect this.
621 if not self.partial_cmd and cmd:
622 self.cached_prompt = self.prompt
623 self.prompt = '> '.rjust(len(self.cached_prompt))
624
625 # partial_cmd is already populated, add the current input after a newline.
626 if self.partial_cmd and cmd:
627 self.partial_cmd = "{0}\n{1}".format(self.partial_cmd, cmd)
628 else:
629 # If the input string is empty or partial_cmd is empty.
630 self.partial_cmd = "{0}{1}".format(self.partial_cmd, cmd)
631 # Remove the most recent item from history if:
632 # -- The current state of user input in incomplete.
633 # -- The most recent user input is not an empty string
634 if self.readline and current_history_len > 0 and cmd:
635 self.readline.remove_history_item(current_history_len - 1)
636 # An empty string results in a no-op. Look at emptyline()
637 return str()
638 elif self.partial_cmd: # input ends with a delimiter and partial_cmd is not empty
639 if cmd != ImpalaShell.CMD_DELIM:
640 completed_cmd = "{0}\n{1}".format(self.partial_cmd, cmd)
641 else:
642 completed_cmd = "{0}{1}".format(self.partial_cmd, cmd)
643 # Reset partial_cmd to an empty string
644 self.partial_cmd = str()
645 # Replace the most recent history item with the completed command.
646 completed_cmd = sqlparse.format(completed_cmd)
647 if self.readline and current_history_len > 0:
648 # readline.replace_history_item(pos, line) requires 'line' in bytes in Python2,
649 # and str in Python3.
650 if sys.version_info.major == 2:
651 history_cmd = completed_cmd.encode('utf-8')
652 else:
653 history_cmd = completed_cmd
654 self.readline.replace_history_item(current_history_len - 1, history_cmd)
655 # Revert the prompt to its earlier state
656 self.prompt = self.cached_prompt

Callers 1

sanitise_inputMethod · 0.95

Calls 3

_cmd_ends_with_delimMethod · 0.95
encodeMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected