當前位置: 首頁>>代碼示例>>Python>>正文


Python cmd.cmdloop方法代碼示例

本文整理匯總了Python中cmd.cmdloop方法的典型用法代碼示例。如果您正苦於以下問題:Python cmd.cmdloop方法的具體用法?Python cmd.cmdloop怎麽用?Python cmd.cmdloop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cmd的用法示例。


在下文中一共展示了cmd.cmdloop方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_input_reset_at_EOF

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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")) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_cmd.py

示例2: test_input_reset_at_EOF

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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")) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:test_cmd.py

示例3: test_file_with_missing_final_nl

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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) ")) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_cmd.py

示例4: runcmds_plus_hooks

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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 
開發者ID:TuuuNya,項目名稱:WebPocket,代碼行數:43,代碼來源:cmd2.py

示例5: test_file_with_missing_final_nl

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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) ")) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:12,代碼來源:test_cmd.py

示例6: main

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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() 
開發者ID:newsettle,項目名稱:ns4_chatbot,代碼行數:13,代碼來源:cmd_bot.py

示例7: preloop

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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 
開發者ID:python-cmd2,項目名稱:cmd2,代碼行數:11,代碼來源:cmd2.py

示例8: postloop

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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 
開發者ID:python-cmd2,項目名稱:cmd2,代碼行數:11,代碼來源:cmd2.py

示例9: _cmdloop

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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 ----- 
開發者ID:python-cmd2,項目名稱:cmd2,代碼行數:40,代碼來源:cmd2.py

示例10: pseudo_raw_input

# 需要導入模塊: import cmd [as 別名]
# 或者: from cmd import cmdloop [as 別名]
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() 
開發者ID:TuuuNya,項目名稱:WebPocket,代碼行數:53,代碼來源:cmd2.py


注:本文中的cmd.cmdloop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。