当前位置: 首页>>代码示例>>Python>>正文


Python readline.write_history_file方法代码示例

本文整理汇总了Python中readline.write_history_file方法的典型用法代码示例。如果您正苦于以下问题:Python readline.write_history_file方法的具体用法?Python readline.write_history_file怎么用?Python readline.write_history_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在readline的用法示例。


在下文中一共展示了readline.write_history_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_console

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def run_console(glob):
    import readline
    import rlcompleter
    import atexit
    import code

    history_path = os.path.expanduser("~/.python_history")

    def save_history(history_path=history_path):
        readline.write_history_file(history_path)
    if os.path.exists(history_path):
        readline.read_history_file(history_path)

    atexit.register(save_history)

    readline.set_completer(rlcompleter.Completer(glob).complete)
    readline.parse_and_bind("tab: complete")
    code.InteractiveConsole(locals=glob).interact() 
开发者ID:Deepwalker,项目名称:pundler,代码行数:20,代码来源:pundle.py

示例2: __init__

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def __init__(self):
        """Create the main mode.

        If titus.inspector.defs.CONFIG_DIRECTORY_EXISTS is ``True``, get the readline history file from the user's titus.inspector.defs.CONFIG_DIRECTORY.
        """

        if CONFIG_DIRECTORY_EXISTS:
            self.historyPath = os.path.join(os.path.expanduser(CONFIG_DIRECTORY), self.historyFileName)
            if not os.path.exists(self.historyPath):
                open(self.historyPath, "w").close()

            self.active = True
            self.tabCompleter = TabCompleter(self)
            readline.read_history_file(self.historyPath)
            readline.set_completer(self.tabCompleter.complete)

            def writehistory():
                if self.active:
                    readline.write_history_file(self.historyPath)
            atexit.register(writehistory) 
开发者ID:modelop,项目名称:hadrian,代码行数:22,代码来源:defs.py

示例3: save_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def save_history(self):
        if self.history_file_full_path is not None:
            global readline
            if readline is None:
                try:
                    import readline
                except ImportError:
                    return
            try:
                readline.write_history_file(self.history_file_full_path)
            except IOError:
                e = sys.exc_info()[1]
                warnings.warn("Cannot save history file, reason: %s" % str(e))

#------------------------------------------------------------------------------
# Main loop

    # Debugging loop. 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:20,代码来源:interactive.py

示例4: enable_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def enable_history(self, history_file: str) -> None:
        self.histfile = os.path.expanduser(history_file)
        try:
            readline.read_history_file(self.histfile)
        except FileNotFoundError:
            pass
        except PermissionError:
            self.histfile = ""
            print(
                f"Warning: You don't have permissions to read {history_file} and\n"
                "         the command history of this session won't be saved.\n"
                "         Either change this file's permissions, recreate it,\n"
                "         or use an alternate path with the SDB_HISTORY_FILE\n"
                "         environment variable.")
            return
        readline.set_history_length(1000)
        atexit.register(readline.write_history_file, self.histfile) 
开发者ID:delphix,项目名称:sdb,代码行数:19,代码来源:repl.py

示例5: setup

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def setup(self):
        """ Initialization of third-party libraries

        Setting interpreter history.
        Setting appropriate completer function.

        :return:
        """
        if not os.path.exists(self.history_file):
            open(self.history_file, 'a+').close()

        readline.read_history_file(self.history_file)
        readline.set_history_length(self.history_length)
        atexit.register(readline.write_history_file, self.history_file)

        readline.parse_and_bind('set enable-keypad on')

        readline.set_completer(self.complete)
        readline.set_completer_delims(' \t\n;')
        readline.parse_and_bind("tab: complete") 
开发者ID:d0ubl3g,项目名称:Industrial-Security-Auditing-Framework,代码行数:22,代码来源:BaseInterpreter.py

示例6: init_readline

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def init_readline(complete_method, histfile=None):
    """init the readline library if available"""
    try:
        import readline
        readline.parse_and_bind("tab: complete")
        readline.set_completer(complete_method)
        string = readline.get_completer_delims().replace(':', '')
        readline.set_completer_delims(string)
        if histfile is not None:
            try:
                readline.read_history_file(histfile)
            except IOError:
                pass
            import atexit
            atexit.register(readline.write_history_file, histfile)
    except:
        print('readline si not available :-(') 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:19,代码来源:cli.py

示例7: hook_readline_hist

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def hook_readline_hist():
    try:
        import readline
    except ImportError:
        return

    histfile = os.environ['HOME'] + '/.web_develop_history'  # 定义一个存储历史记录的文件地址
    readline.parse_and_bind('tab: complete')
    try:
        readline.read_history_file(histfile)
    except IOError:
        pass  # It doesn't exist yet.

    def savehist():
        try:
            readline.write_history_file(histfile)
        except:
            print 'Unable to save Python command history'
    atexit.register(savehist) 
开发者ID:dongweiming,项目名称:web_develop,代码行数:21,代码来源:shell.py

示例8: postloop

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def postloop(self):
        """Take care of any unfinished business.
        Despite the claims in the Cmd documentaion, Cmd.postloop() is not a stub.
        """
        try:
            if readline:
                readline.write_history_file(sys.argv[0] + ".history")
        except Exception as err:
            if not isinstance(err, IOError):
                self.stdout.write("history error: %s\n" % err)

        # clean up command completion
        cmd.Cmd.postloop(self)

        if self.interactive:
            self.stdout.write("Exiting...\n")

        # tell the core we have stopped
        core.deferred(core.stop) 
开发者ID:JoelBender,项目名称:bacpypes,代码行数:21,代码来源:consolecmd.py

示例9: save_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def save_history(self):
        if self.history_file_full_path is not None:
            global readline
            if readline is None:
                try:
                    import readline
                except ImportError:
                    return
            try:
                readline.write_history_file(self.history_file_full_path)
            except IOError, e:
                warnings.warn("Cannot save history file, reason: %s" % str(e))

#------------------------------------------------------------------------------
# Main loop

    # Debugging loop. 
开发者ID:debasishm89,项目名称:OpenXMolar,代码行数:19,代码来源:interactive.py

示例10: test_nonascii_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def test_nonascii_history(self):
        readline.clear_history()
        try:
            readline.add_history("entrée 1")
        except UnicodeEncodeError as err:
            self.skipTest("Locale cannot encode test data: " + format(err))
        readline.add_history("entrée 2")
        readline.replace_history_item(1, "entrée 22")
        readline.write_history_file(TESTFN)
        self.addCleanup(os.remove, TESTFN)
        readline.clear_history()
        readline.read_history_file(TESTFN)
        if is_editline:
            # An add_history() call seems to be required for get_history_
            # item() to register items from the file
            readline.add_history("dummy")
        self.assertEqual(readline.get_history_item(1), "entrée 1")
        self.assertEqual(readline.get_history_item(2), "entrée 22") 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:20,代码来源:test_readline.py

示例11: start

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def start(self):
        self.cmd_manager.init()
        log('%s started - GL HF!' % Color.colorify('frick', 'green highligh'))

        readline.parse_and_bind('tab: complete')
        hist = os.path.join(os.environ['HOME'], '.frick_history')

        try:
            readline.read_history_file(hist)
        except IOError:
            pass
        atexit.register(readline.write_history_file, hist)

        while True:
            inp = six.moves.input().strip()
            if len(inp) > 0:
                self.cmd_manager.handle_command(inp) 
开发者ID:iGio90,项目名称:frick,代码行数:19,代码来源:main.py

示例12: pause

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def pause(self):
        """Write the current history to the history file and stop readline."""
        readline.write_history_file(self.historyPath)
        readline.clear_history()
        readline.set_completer()
        self.active = False 
开发者ID:modelop,项目名称:hadrian,代码行数:8,代码来源:defs.py

示例13: remote_api_shell

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def remote_api_shell(servername, appid, path, secure, rpc_server_factory):
  """Actually run the remote_api_shell."""


  remote_api_stub.ConfigureRemoteApi(appid, path, auth_func,
                                     servername=servername,
                                     save_cookies=True, secure=secure,
                                     rpc_server_factory=rpc_server_factory)
  remote_api_stub.MaybeInvokeAuthentication()


  os.environ['SERVER_SOFTWARE'] = 'Development (remote_api_shell)/1.0'

  if not appid:

    appid = os.environ['APPLICATION_ID']
  sys.ps1 = '%s> ' % appid
  if readline is not None:

    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)


  if '' not in sys.path:
    sys.path.insert(0, '')

  preimported_locals = {
      'memcache': memcache,
      'urlfetch': urlfetch,
      'users': users,
      'db': db,
      'ndb': ndb,
      }


  code.interact(banner=BANNER, local=preimported_locals) 
开发者ID:elsigh,项目名称:browserscope,代码行数:40,代码来源:remote_api_shell.py

示例14: setup

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def setup():
    history_file = "./.history"
    if not os.path.exists(history_file):
        open(history_file, 'a+').close()

    readline.read_history_file(history_file)
    readline.set_history_length(history_length)
    atexit.register(readline.write_history_file, history_file)

    readline.parse_and_bind('set enable-keypad on')

    readline.set_completer(complete)
    readline.set_completer_delims(' \t\n;')
    readline.parse_and_bind("tab: complete") 
开发者ID:WangYihang,项目名称:Exploit-Framework,代码行数:16,代码来源:framework.py

示例15: do_exit

# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def do_exit(self, line):
        self.close()
        if not self.execute_only_mode and readline.get_current_history_length() > 0:
            readline.write_history_file(self.admin_history)

        return True 
开发者ID:aerospike,项目名称:aerospike-admin,代码行数:8,代码来源:asadm.py


注:本文中的readline.write_history_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。