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


Python readline.set_history_length方法代碼示例

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


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

示例1: enable_history

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [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

示例2: setup

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [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

示例3: Input_completer

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def Input_completer(keywords):
    completer = MyCompleter(keywords)
    readline.set_completer(completer.complete)
    if "libedit" in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind('tab: complete')
        #readline.parse_and_bind('"\\e[A": complete') # Up arrow
    readline.parse_and_bind("set colored-completion-prefix on")
    readline.parse_and_bind("set show-all-if-unmodified on")
    readline.parse_and_bind("set horizontal-scroll-mode on")
    if os.path.exists(history_file):
        readline.read_history_file(history_file)
        readline.set_history_length(20)
    readline.set_completer_delims(' ')
    atexit.register(save_history) 
開發者ID:OWASP,項目名稱:QRLJacking,代碼行數:18,代碼來源:utils.py

示例4: preloop

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def preloop(self):
        """
        preload a history file
        """
        history_file = cfg.get('history_file')
        logger.debug("using history file {}".format(history_file))
        try:
            readline.read_history_file(os.path.expanduser(history_file))
        except PermissionError:
            logger.warning("failed to read CLI history from {} " +
                            "(no permission)".format(
                history_file))
        except FileNotFoundError:
            pass

        readline.set_history_length(int(cfg.get('history_file_size')))
        if not self.registered_atexit:
            atexit.register(self.history_write) 
開發者ID:OpenSIPS,項目名稱:opensips-cli,代碼行數:20,代碼來源:cli.py

示例5: main

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def main():
    signal.signal(signal.SIGTERM, handler)
    signal.signal(signal.SIGINT, handler)
    # signal.signal(signal.SIGTSTP, handler)
    if os.name == 'posix':
        readline.set_history_length(1000)
    parser = get_parser()
    libra_args = parser.parse_args(sys.argv[1:])
    try:
        run_shell(libra_args)
    except Exception as err:
        report_error("some error occured", err, libra_args.verbose) 
開發者ID:yuan-xy,項目名稱:libra-client,代碼行數:14,代碼來源:libra_shell.py

示例6: setupReadline

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def setupReadline(local):
    """Initialize the readline library and command history.

    @return: A C{bool} to indicate whether standard input is a terminal
        (and therefore interactive).
    """
    readline.parse_and_bind('tab: complete')
    readline.set_completer_delims(' \t\n')
    readline.set_completer(Completer(local).complete)

    # Readline code from https://docs.python.org/3.7/library/readline.html
    histfile = os.path.join(os.path.expanduser('~'), '.daudin_history')

    try:
        readline.read_history_file(histfile)
        historyLen = readline.get_current_history_length()
    except FileNotFoundError:
        open(histfile, 'wb').close()
        historyLen = 0

    try:
        readline.append_history_file
    except AttributeError:
        # We won't be able to save readline history. This can happen on
        # Python 3.5 at least - not sure why.
        pass
    else:
        import atexit

        def saveHistory(prevHistoryLen, histfile):
            newHistoryLen = readline.get_current_history_length()
            readline.set_history_length(1000)
            readline.append_history_file(newHistoryLen - prevHistoryLen,
                                         histfile)

        atexit.register(saveHistory, historyLen, histfile)

    return True 
開發者ID:terrycojones,項目名稱:daudin,代碼行數:40,代碼來源:readline.py

示例7: setup

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [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

示例8: __init__

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def __init__(self, con):
        readline.set_completer_delims(' \t\n;')
        readline.set_history_length(100)
        readline.set_completer(self.complete)
        readline.parse_and_bind("tab: complete")
        self.con = con 
開發者ID:plasma-disassembler,項目名稱:plasma,代碼行數:8,代碼來源:console.py

示例9: __init__

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def __init__(self):
        self.nocmd = None
        self.last_exception = None
        super().__init__()
        try:
            import readline
            readline.set_history_length(session.Hist.MAX_SIZE)
            readline.set_completer_delims(READLINE_COMPLETER_DELIMS)
        except ImportError:
            pass 
開發者ID:nil0x42,項目名稱:phpsploit,代碼行數:12,代碼來源:interface.py

示例10: execute

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def execute(self, fn, *args, **kwargs):
        """Execute the function and handle any exceptions."""
        if readline is not None:
            readline.set_history_length(10000)
            readline.write_history_file(histfile)
        try:
            fn(*args, **kwargs)
        except Exception as e:
            self.handle_exception(e) 
開發者ID:scriptotek,項目名稱:alma-slipsomat,代碼行數:11,代碼來源:shell.py

示例11: _setup_history

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def _setup_history(history_file: Path, history_length: int) -> None:
        if not history_file.exists():
            with open(history_file, "a+") as history:
                if is_libedit():
                    history.write("_HiStOrY_V2_\n\n")

        readline.read_history_file(str(history_file))
        readline.set_history_length(history_length)
        atexit.register(readline.write_history_file, str(history_file)) 
開發者ID:fwkz,項目名稱:riposte,代碼行數:11,代碼來源:riposte.py

示例12: __init__

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def __init__(self, args):

        Cmd.__init__(self)

        self.args = args
        self.threat_q = ThreatQ(config)
        self.geo_tools = GeoTools(config)
        self.infoblox = Infoblox(config)
        self.passive_total = PassiveTotal(config)
        self.riq = RiskIQ(config)
        self.novetta = Novetta(config)
        self.config_manager = ConfigManager(config)
        self.ss = ShadowServer()
        self.cymru = Cymru()
        self.opendns = OpenDNS_API(config)
        self.umbrella = Umbrella(config)
        self.tx = ThreatExchange(config)

        self.module_map = {}
        for entry in dir(self):
            entry = getattr(self, entry)
            if hasattr(entry, "__module__"):
                if "commands" in entry.__module__:
                    self.module_map[entry.__module__] = entry

        try:
            readline.read_history_file(self.history_file)
        except IOError:
            pass

        readline.set_history_length(300)  # TODO: Maybe put this in a config 
開發者ID:salesforce,項目名稱:threatshell,代碼行數:33,代碼來源:threatshell.py

示例13: postloop

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def postloop(self):
        _Cmd.postloop(self)   ## Clean up command completion

        try:
            readline.set_history_length(_MAX_HISTORY)
            readline.write_history_file(_HISTORY_FILE)
        except:
            # readline is returning Exception for some reason
            pass 
開發者ID:nettitude,項目名稱:scrounger,代碼行數:11,代碼來源:interactive.py

示例14: do_exit

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def do_exit(self, args=''):
        """Quit the program."""
        print("Bye")
        if readline:
            readline.set_history_length(HISTFILE_SIZE)
            try:
                readline.write_history_file(HISTFILE)
            except IOError:
                pass
        raise SystemExit 
開發者ID:sergioburdisso,項目名稱:pyss3,代碼行數:12,代碼來源:cmd_line.py

示例15: initial

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_history_length [as 別名]
def initial(self):
        self.completer = MyCompleter.getInstance(self._options_start.keys(), self)
        readline.set_history_length(50)  # max 50
        readline.set_completer_delims(' \t\n;')  # override the delims (we want /)
        readline.parse_and_bind("tab: complete")
        readline.set_completer(self.completer.complete)
        self.open_sessions = Session.getInstance() 
開發者ID:Josue87,項目名稱:BoomER,代碼行數:9,代碼來源:shell.py


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