Python cmd.cmdloop() Examples
The following are 24
code examples of cmd.cmdloop().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cmd
, or try the search function
.
Example #1
Source File: test_cmd.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_input_reset_at_EOF(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = StringIO.StringIO("print \n\n") output = StringIO.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #2
Source File: test_cmd.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_input_reset_at_EOF(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = StringIO.StringIO("print \n\n") output = StringIO.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #3
Source File: test_cmd.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_input_reset_at_EOF(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = StringIO.StringIO("print \n\n") output = StringIO.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #4
Source File: test_cmd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_input_reset_at_EOF(self): input = io.StringIO("print test\nprint test2") output = io.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = io.StringIO("print \n\n") output = io.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #5
Source File: test_cmd.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_input_reset_at_EOF(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = StringIO.StringIO("print \n\n") output = StringIO.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #6
Source File: test_cmd.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_input_reset_at_EOF(self): input = io.StringIO("print test\nprint test2") output = io.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = io.StringIO("print \n\n") output = io.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #7
Source File: test_cmd.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_input_reset_at_EOF(self): input = io.StringIO("print test\nprint test2") output = io.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = io.StringIO("print \n\n") output = io.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #8
Source File: test_cmd.py From oss-ftp with MIT License | 6 votes |
def test_input_reset_at_EOF(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = StringIO.StringIO("print \n\n") output = StringIO.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #9
Source File: test_cmd.py From BinderFilter with MIT License | 6 votes |
def test_input_reset_at_EOF(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd2(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) *** Unknown syntax: EOF\n")) input = StringIO.StringIO("print \n\n") output = StringIO.StringIO() cmd.stdin = input cmd.stdout = output cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) \n" "(Cmd) \n" "(Cmd) *** Unknown syntax: EOF\n"))
Example #10
Source File: cmd2.py From cmd2 with MIT License | 5 votes |
def preloop(self): """Hook method executed once when the :meth:`~.cmd2.Cmd.cmdloop()` method is called. See :meth:`~cmd2.Cmd.register_preloop_hook` for a more robust way to run hooks before the command loop begins. See :ref:`features/hooks:Application Lifecycle Hooks` for more information. """ pass
Example #11
Source File: test_cmd.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_file_with_missing_final_nl(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #12
Source File: test_cmd.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_file_with_missing_final_nl(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #13
Source File: test_cmd.py From BinderFilter with MIT License | 5 votes |
def test_file_with_missing_final_nl(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #14
Source File: test_cmd.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_file_with_missing_final_nl(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #15
Source File: test_cmd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_file_with_missing_final_nl(self): input = io.StringIO("print test\nprint test2") output = io.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #16
Source File: cmd2.py From cmd2 with MIT License | 5 votes |
def _cmdloop(self) -> None: """Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument. This serves the same role as cmd.cmdloop(). """ saved_readline_settings = None try: # Get sigint protection while we set up readline for cmd2 with self.sigint_protection: saved_readline_settings = self._set_up_cmd2_readline() # Run startup commands stop = self.runcmds_plus_hooks(self._startup_commands) self._startup_commands.clear() while not stop: # Get commands from user try: line = self._read_command_line(self.prompt) except KeyboardInterrupt as ex: if self.quit_on_sigint: raise ex else: self.poutput('^C') line = '' # Run the command along with all associated pre and post hooks stop = self.onecmd_plus_hooks(line) finally: # Get sigint protection while we restore readline settings with self.sigint_protection: if saved_readline_settings is not None: self._restore_readline(saved_readline_settings) # ----- Alias subcommand functions -----
Example #17
Source File: cmd2.py From cmd2 with MIT License | 5 votes |
def postloop(self): """Hook method executed once when the :meth:`~.cmd2.Cmd.cmdloop()` method is about to return. See :meth:`~cmd2.Cmd.register_postloop_hook` for a more robust way to run hooks after the command loop completes. See :ref:`features/hooks:Application Lifecycle Hooks` for more information. """ pass
Example #18
Source File: test_cmd.py From oss-ftp with MIT License | 5 votes |
def test_file_with_missing_final_nl(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #19
Source File: test_cmd.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_file_with_missing_final_nl(self): input = StringIO.StringIO("print test\nprint test2") output = StringIO.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #20
Source File: cmd_bot.py From ns4_chatbot with Apache License 2.0 | 5 votes |
def main(): #训练的NLU模型,所以,不需要再提供nlu_config.yml了,在这里 logger.info("Rasa process starting") nlu_model_path = '../model/default/latest' model_directory = "../model/dialogue" agent = Agent.load(model_directory, nlu_model_path) logger.info("Finished loading agent, starting input channel & server.") cmd = RasaCmd(agent) cmd.cmdloop()
Example #21
Source File: test_cmd.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_file_with_missing_final_nl(self): input = io.StringIO("print test\nprint test2") output = io.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #22
Source File: cmd2.py From WebPocket with GNU General Public License v3.0 | 5 votes |
def runcmds_plus_hooks(self, cmds: List[str]) -> bool: """Convenience method to run multiple commands by onecmd_plus_hooks. This method adds the given cmds to the command queue and processes the queue until completion or an error causes it to abort. Scripts that are loaded will have their commands added to the queue. Scripts may even load other scripts recursively. This means, however, that you should not use this method if there is a running cmdloop or some other event-loop. This method is only intended to be used in "one-off" scenarios. NOTE: You may need this method even if you only have one command. If that command is a load, then you will need this command to fully process all the subsequent commands that are loaded from the script file. This is an improvement over onecmd_plus_hooks, which expects to be used inside of a command loop which does the processing of loaded commands. Example: cmd_obj.runcmds_plus_hooks(['load myscript.txt']) :param cmds: command strings suitable for onecmd_plus_hooks. :return: True implies the entire application should exit. """ stop = False self.cmdqueue = list(cmds) + self.cmdqueue try: while self.cmdqueue and not stop: line = self.cmdqueue.pop(0) if self.echo and line != 'eos': self.poutput('{}{}'.format(self.prompt, line)) stop = self.onecmd_plus_hooks(line) finally: # Clear out the command queue and script directory stack, just in # case we hit an error and they were not completed. self.cmdqueue = [] self._script_dir = [] # NOTE: placing this return here inside the finally block will # swallow exceptions. This is consistent with what is done in # onecmd_plus_hooks and _cmdloop, although it may not be # necessary/desired here. return stop
Example #23
Source File: test_cmd.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_file_with_missing_final_nl(self): input = io.StringIO("print test\nprint test2") output = io.StringIO() cmd = self.simplecmd(stdin=input, stdout=output) cmd.use_rawinput = False cmd.cmdloop() self.assertMultiLineEqual(output.getvalue(), ("(Cmd) test\n" "(Cmd) test2\n" "(Cmd) "))
Example #24
Source File: cmd2.py From WebPocket with GNU General Public License v3.0 | 4 votes |
def pseudo_raw_input(self, prompt: str) -> str: """Began life as a copy of cmd's cmdloop; like raw_input but - accounts for changed stdin, stdout - if input is a pipe (instead of a tty), look at self.echo to decide whether to print the prompt and the input """ if self.use_rawinput: try: if sys.stdin.isatty(): # Wrap in try since terminal_lock may not be locked when this function is called from unit tests try: # A prompt is about to be drawn. Allow asynchronous changes to the terminal. self.terminal_lock.release() except RuntimeError: pass # Deal with the vagaries of readline and ANSI escape codes safe_prompt = rl_make_safe_prompt(prompt) line = input(safe_prompt) else: line = input() if self.echo: sys.stdout.write('{}{}\n'.format(self.prompt, line)) except EOFError: line = 'eof' finally: if sys.stdin.isatty(): # The prompt is gone. Do not allow asynchronous changes to the terminal. self.terminal_lock.acquire() else: if self.stdin.isatty(): # on a tty, print the prompt first, then read the line self.poutput(self.prompt, end='') self.stdout.flush() line = self.stdin.readline() if len(line) == 0: line = 'eof' else: # we are reading from a pipe, read the line to see if there is # anything there, if so, then decide whether to print the # prompt or not line = self.stdin.readline() if len(line): # we read something, output the prompt and the something if self.echo: self.poutput('{}{}'.format(self.prompt, line)) else: line = 'eof' return line.strip()