python类Cmd()的实例源码

test_cmd.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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"))
cmd2.py 文件源码 项目:minihydra 作者: VillanCh 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pseudo_raw_input(self, prompt):
        """copied from cmd's cmdloop; like raw_input, but accounts for changed stdin, stdout"""

        if self.use_rawinput:
            try:
                line = sm.input(prompt)
            except EOFError:
                line = 'EOF'
        else:
            self.stdout.write(prompt)
            self.stdout.flush()
            line = self.stdin.readline()
            if not len(line):
                line = 'EOF'
            else:
                if line[-1] == '\n':  # this was always true in Cmd
                    line = line[:-1]
        return line
cli.py 文件源码 项目:RPKI-toolkit 作者: pavel-odintsov 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def onecmd(self, line):
    """
    Wrap error handling around cmd.Cmd.onecmd().  Might want to do
    something kinder than showing a traceback, eventually.
    """

    self.last_command_failed = False
    try:
      return cmd.Cmd.onecmd(self, line)
    except SystemExit:
      raise
    except ExitArgparse, e:
      if e.message is not None:
        print e.message
      self.last_command_failed = e.status != 0
      return False
    except BadCommandSyntax, e:
      print e
    except Exception:
      traceback.print_exc()
    self.last_command_failed = True
    return False
pdb.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def onecmd(self, line):
        """Interpret the argument as though it had been typed in response
        to the prompt.

        Checks whether this line is typed at the normal prompt or in
        a breakpoint command list definition.
        """
        if not self.commands_defining:
            return cmd.Cmd.onecmd(self, line)
        else:
            return self.handle_command_def(line)
pstats.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self, profile=None):
            cmd.Cmd.__init__(self)
            self.prompt = "% "
            self.stats = None
            self.stream = sys.stdout
            if profile is not None:
                self.do_read(profile)
__init__.py 文件源码 项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        cmd.Cmd.__init__(self)
        self.prompt = 'QUANTAXIS> '    # ????????
test_lib.py 文件源码 项目:VPP_P4 作者: RuchaMarathe 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def __init__(self, pre_type, standard_client, mc_client=None):
        cmd.Cmd.__init__(self)
        self.client = standard_client
        self.mc_client = mc_client
        self.pre_type = pre_type
cli.py 文件源码 项目:ravel 作者: ravel-net 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, env, quiet=False):
        self.env = env

        if not quiet:
            self.intro = "RavelConsole: interactive console for Ravel.\n" \
                         "Configuration:\n" + self.env.pprint()

        cmd.Cmd.__init__(self)
        self.env.set_cli(self)
cli.py 文件源码 项目:ravel 作者: ravel-net 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def do_help(self, arg):
        "List available commands with 'help' or detailed help with 'help cmd'"
        # extend to include loaded apps and their help methods
        tokens = arg.split()
        if len(tokens) > 0 and tokens[0] in self.env.loaded:
            app = self.env.apps[tokens[0]]
            if len(tokens) <= 1:
                print app.description
                app.console.do_help("")
            else:
                app.console.do_help(" ".join(tokens[1:]))
        else:
            cmd.Cmd.do_help(self, arg)
cli.py 文件源码 项目:ravel 作者: ravel-net 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def completenames(self, text, *ignored):
        "Add loaded application names/shortcuts to cmd name completions"
        completions = cmd.Cmd.completenames(self, text, ignored)

        apps = self.env.loaded.keys()
        if not text:
            completions.extend(apps)
        else:
            completions.extend([d for d in apps if d.startswith(text)])

        return completions
app.py 文件源码 项目:ravel 作者: ravel-net 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, db, env, components):
        """db: a ravel.db.RavelDb instance
           env: a ravel.env.Environment instance of the CLI's executing environment
           components: list of the app's SQL components (tables, view, etc.)"""
        self.db = db
        self.env = env
        self.components = components
        cmd.Cmd.__init__(self)
workflow_template.py 文件源码 项目:girlfriend 作者: chihongze 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, file_name, options):
        cmd.Cmd.__init__(self)
        self.units = []
        self.file_name = file_name
        self.env_list = []  # ??????
        self.cmd_parser = False
        self.options = options
repl.py 文件源码 项目:GrimREPL 作者: emehrkay 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, request, print_full_response=False):
        cmd.Cmd.__init__(self)
        self.request = request
        self.print_full_response = print_full_response
        self.prompt = PROMPT
pdb.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def onecmd(self, line):
        """Interpret the argument as though it had been typed in response
        to the prompt.

        Checks whether this line is typed at the normal prompt or in
        a breakpoint command list definition.
        """
        if not self.commands_defining:
            return cmd.Cmd.onecmd(self, line)
        else:
            return self.handle_command_def(line)
pstats.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self, profile=None):
            cmd.Cmd.__init__(self)
            self.prompt = "% "
            self.stats = None
            self.stream = sys.stdout
            if profile is not None:
                self.do_read(profile)
CommandLine.py 文件源码 项目:turtle 作者: icse-turtle 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):
        cmd.Cmd.__init__(self)

        # Declaration of the variables.
        self.__strategy = DepthStrategy()
        self.clear()

        # Declaration of the variables of the shell.
        global wstream, colored_loaded
        self.__milestone = 'Almost Ninja'
        self.__version = '1.0'
        self.__main_title = 'TURTLE v' + self.__version + ' (' + self.__milestone + ')'
        self.__wstream = wstream
        self.__colored_loaded = colored_loaded
        self.__error_prefix = str(colortext(r'[ERROR] ', 'red', True))
        self.__start_time = 0
        self.__elapsed_time = 0
        self.__stats = True
        self.__default_exception_message = 'Unknown exception!'
        self.use_rawinput = True
        self.ruler = '='
        self.default_file_name = 'new.clp'
        self.prompt = str(colortext('TURTLE> ', 'green'))
        self.intro = """\

                 __
      .,-;-;-,. /'_\  """ + self.__main_title + """
    _/_/_/_|_\_\) /
  '-<_><_><_><_>=/\   An expert system shell inspired by CLIPS syntax
    `/_/====/_/-'\_\\  Running on Python """ + str(platform.python_version()) + ' ' + str(platform.architecture()[0]) + """
     ''     ''    ''
    Usage: help to see online help
           <Tab> to show commands
           <Up-arrow>, <Down-arrow> to scroll through the history
           <Ctrl-d>, quit or exit to leave

       """
cmd_illustrate_methods.py 文件源码 项目:pymotw3 作者: reingart 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def cmdloop(self, intro=None):
        print('cmdloop({})'.format(intro))
        return cmd.Cmd.cmdloop(self, intro)
cmd_illustrate_methods.py 文件源码 项目:pymotw3 作者: reingart 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def parseline(self, line):
        print('parseline({!r}) =>'.format(line), end='')
        ret = cmd.Cmd.parseline(self, line)
        print(ret)
        return ret
cmd_illustrate_methods.py 文件源码 项目:pymotw3 作者: reingart 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def onecmd(self, s):
        print('onecmd({})'.format(s))
        return cmd.Cmd.onecmd(self, s)
cmd_illustrate_methods.py 文件源码 项目:pymotw3 作者: reingart 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def emptyline(self):
        print('emptyline()')
        return cmd.Cmd.emptyline(self)


问题


面经


文章

微信
公众号

扫码关注公众号