Overridden to ensure the variable replacement is processed in interactive as well as non-interactive mode, since the precmd method would only work for the interactive case, when cmdloop is called.
(self, line)
| 803 | return args |
| 804 | |
| 805 | def onecmd(self, line): |
| 806 | """Overridden to ensure the variable replacement is processed in interactive |
| 807 | as well as non-interactive mode, since the precmd method would only work for |
| 808 | the interactive case, when cmdloop is called. |
| 809 | """ |
| 810 | # Replace variables in the statement before it's executed |
| 811 | line = replace_variables(self.set_variables, line) |
| 812 | # Cmd is an old-style class, hence we need to call the method directly |
| 813 | # instead of using super() |
| 814 | # TODO: This may have to be changed to a super() call once we move to Python 3 |
| 815 | if line is None: |
| 816 | return CmdStatus.ERROR |
| 817 | else: |
| 818 | # This code is based on the code from the standard Python library package cmd.py: |
| 819 | # https://github.com/python/cpython/blob/master/Lib/cmd.py#L192 |
| 820 | # One change is lowering command before getting a function. The lowering |
| 821 | # is necessary to find a proper function and here is a right place |
| 822 | # because the lowering command in front of the finding can avoid a |
| 823 | # side effect. |
| 824 | command, arg, line, leading_comment = self.parseline(line) |
| 825 | if not line: |
| 826 | return self.emptyline() |
| 827 | # orig_cmd and last_leading_comment are passed into do_*() functions |
| 828 | # via this side mechanism because the cmd module limits us to passing |
| 829 | # in the argument list only. |
| 830 | self.orig_cmd = command |
| 831 | self.last_leading_comment = leading_comment |
| 832 | self.lastcmd = line |
| 833 | if not command: |
| 834 | return self.default(line) |
| 835 | elif line == 'EOF': |
| 836 | self.lastcmd = '' |
| 837 | else: |
| 838 | try: |
| 839 | func = getattr(self, 'do_' + command.lower()) |
| 840 | except AttributeError: |
| 841 | return self.default(line) |
| 842 | return func(arg) |
| 843 | |
| 844 | def postcmd(self, status, args): |
| 845 | # status conveys to shell how the shell should continue execution |
no test coverage detected