Python readline 模块,set_history_length() 实例源码

我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用readline.set_history_length()

项目:routersploit    作者:reverse-shell    | 项目源码 | 文件源码
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")
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
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")
项目:isf    作者:w3h    | 项目源码 | 文件源码
def pre_input(self, completefn):
        if self.raw_input:
            if HAVE_READLINE:
                import atexit
                self.old_completer = readline.get_completer()
                # Fix Bug #3129: Limit the history size to consume less memory
                readline.set_history_length(self.historysize)
                readline.set_completer(completefn)
                readline.parse_and_bind(self.completekey+": complete")
                try:
                    readline.read_history_file()
                except IOError:
                    pass
                atexit.register(readline.write_history_file)
                self.havecolor = True
                if mswindows and self.enablecolor:
                    self.cwrite = readline.GetOutputFile().write_color
                else:
                    self.cwrite = self.stdout.write
项目:isf    作者:dark-lbp    | 项目源码 | 文件源码
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")
项目:routersploit    作者:Exploit-install    | 项目源码 | 文件源码
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")
项目:shadowbroker-auto    作者:wrfly    | 项目源码 | 文件源码
def pre_input(self, completefn):
        if self.raw_input:
            if HAVE_READLINE:
                import atexit
                self.old_completer = readline.get_completer()
                # Fix Bug #3129: Limit the history size to consume less memory
                readline.set_history_length(self.historysize)   
                readline.set_completer(completefn)
                readline.parse_and_bind(self.completekey+": complete")
                try:
                    readline.read_history_file()
                except IOError:
                    pass
                atexit.register(readline.write_history_file)
                self.havecolor = True
                if mswindows and self.enablecolor:
                    self.cwrite = readline.GetOutputFile().write_color
                else:
                    self.cwrite = self.stdout.write
项目:pythonrc    作者:lonetwin    | 项目源码 | 文件源码
def init_readline(self):
        """Activates history and tab completion
        """
        # - mainly borrowed from site.enablerlcompleter() from py3.4+

        # Reading the initialization (config) file may not be enough to set a
        # completion key, so we set one first and then read the file.
        readline_doc = getattr(readline, '__doc__', '')
        if readline_doc is not None and 'libedit' in readline_doc:
            readline.parse_and_bind('bind ^I rl_complete')
        else:
            readline.parse_and_bind('tab: complete')

        try:
            readline.read_init_file()
        except OSError:
            # An OSError here could have many causes, but the most likely one
            # is that there's no .inputrc file (or .editrc file in the case of
            # Mac OS X + libedit) in the expected location.  In that case, we
            # want to ignore the exception.
            pass

        if readline.get_current_history_length() == 0:
            # If no history was loaded, default to .python_history.
            # The guard is necessary to avoid doubling history size at
            # each interpreter exit when readline was already configured
            # see: http://bugs.python.org/issue5845#msg198636
            try:
                readline.read_history_file(config['HISTFILE'])
            except IOError:
                pass
            atexit.register(readline.write_history_file,
                            config['HISTFILE'])
        readline.set_history_length(config['HISTSIZE'])

        # - replace default completer
        readline.set_completer(self.improved_rlcompleter())

        # - enable auto-indenting
        readline.set_pre_input_hook(self.auto_indent_hook)
项目:AlphaHooks    作者:AlphaHooks    | 项目源码 | 文件源码
def __init__(self, ui, config, parent=None):
        """
        Loads default configuration for console_log. A new thread is
        spawned to which the interpreter is moved. This is done to
        increase the responsiveness of the main user interface.

        :param ui: used to access 'main.ui' methods
        :param config: used to configure classes
        """
        super(ConsoleProperty, self).__init__(parent)
        self.ui = ui
        self.config = config

        # Document
        self.ui.console_log.document().setMaximumBlockCount(
            self.config["Console"]["Scrollback Buffer"]
        )
        self.ui.console_log.setWordWrapMode(QTextOption.WrapAnywhere)

        # Console Input History
        self.index = -1
        self.length = 0

        readline.set_history_length(50)
        self.ui.console_input.installEventFilter(self)

        try:
            open(self.HISTORY_PATH, "x")
        except FileExistsError:
            readline.read_history_file(self.HISTORY_PATH)
            self.length = readline.get_current_history_length()

        # Display
        self.display = PythonDisplay(self.ui, self.config, self)
项目:athena-cli    作者:guardian    | 项目源码 | 文件源码
def init_history(self):
        try:
            readline.read_history_file(self.hist_file)
            readline.set_history_length(HISTORY_FILE_SIZE)
            readline.write_history_file(self.hist_file)
        except IOError:
            readline.write_history_file(self.hist_file)

        atexit.register(self.save_history)
项目:fastweb    作者:BSlience    | 项目源码 | 文件源码
def save_history(self, histfile):
        readline.set_history_length(1000)
        readline.write_history_file(histfile)
项目:fastweb    作者:BSlience    | 项目源码 | 文件源码
def save_history(self, histfile):
        readline.set_history_length(1000)
        readline.write_history_file(histfile)
项目:weevely3-stealth    作者:edibledinos    | 项目源码 | 文件源码
def _load_history(self):
        """Load history file and register dump on exit."""

        # Create a file without truncating it in case it exists.
        open(config.history_path, 'a').close()

        readline.set_history_length(100)
        try:
            readline.read_history_file(config.history_path)
        except IOError:
            pass
        atexit.register(readline.write_history_file,
            config.history_path)
项目:trex-http-proxy    作者:alwye    | 项目源码 | 文件源码
def __init__(self):
        cmd.Cmd.__init__(self)
        # configure history behaviour
        self._history_file_dir = "/tmp/trex/console/"
        self._history_file = self.get_history_file_full_path()
        readline.set_history_length(100)
        # load history, if any
        self.load_console_history()
项目:aide    作者:Lambda-3    | 项目源码 | 文件源码
def save_history(self, histfile):
        readline.set_history_length(1000)
        readline.write_history_file(histfile)
项目:Alex    作者:candlewill    | 项目源码 | 文件源码
def init_readline(self):
        "Initialize the readline functionality to enable console history."
        if self.hub_history_file is not None:
            readline.set_history_length(self.hub_history_length)
            try:
                readline.read_history_file(self.hub_history_file)
            except IOError:
                pass

            atexit.register(readline.write_history_file, self.hub_history_file)
项目:scimitar    作者:parsa    | 项目源码 | 文件源码
def load_history():
    readline.set_history_length(10000)
    try:
        if os.path.exists(history_file_path):
            readline.read_history_file(history_file_path)
    except IOError:
        pass
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def clear_history(self):
        try:
            readline.clear_history()
        except AttributeError:
            len = self.get_max_length()
            readline.set_history_length(0)
            readline.set_history_length(len)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def set_max_length(self, n):
        readline.set_history_length(n)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def set_max_length(self, n):
        readline.set_history_length(n)
项目:python-yakumo    作者:yosshy    | 项目源码 | 文件源码
def save_history(self, histfile):
        readline.set_history_length(1000)
        readline.write_history_file(histfile)
项目:lc_cloud    作者:refractionPOINT    | 项目源码 | 文件源码
def __init__( self, beachConfig = None, token = None, hbsKey = None, logFile = None, callbackDomain1 = None, callbackDomain2 = None ):
        self.histFile = os.path.expanduser( '~/.lc_history' )
        self.logFile = logFile
        if self.logFile is not None:
            self.logFile = open( self.logFile, 'w', 0 )

        cmd.Cmd.__init__( self, stdout = ( self.logFile if self.logFile is not None else sys.stdout ) )
        self.be = None
        self.user = None
        self.hbsKey = None
        self.aid = None
        self.investigationId = None
        self.tags = Symbols()
        self.cbDomain1 = callbackDomain1
        self.cbDomain2 = callbackDomain2
        readline.set_completer_delims(":;'\"? \t")
        readline.set_history_length( 100 )
        try:
            readline.read_history_file( self.histFile )
        except:
            self.outputString( 'Failed to load history file' )
            open( self.histFile, 'w' ).close()


        if beachConfig is not None:
            self.connectWithConfig( beachConfig, token )

        if hbsKey is not None:
            self.loadKey( hbsKey )
项目:Atrophy    作者:Thiefyface    | 项目源码 | 文件源码
def __init__(self,cmdcomplete,init_flag=True):
        self.text = ""
        self.matches = []
        self.cmdcomplete = cmdcomplete
        self.symbols = []
        self.index = 0

        self.cleanup_flag = True 
        self.init_flag = init_flag
        self.session_start_index = 0

        self.HISTLEN = 2000
        self.HISTFILE = ".atrophy-history"
        self.DEFAULT_HIST_DISPLAY_LEN = 20

        self.delims = readline.get_completer_delims()
        readline.set_completer_delims(self.delims.replace("/",''))
        self.delims = readline.get_completer_delims()
        readline.set_completer_delims(self.delims.replace("?",''))
        self.delims = readline.get_completer_delims()
        readline.set_completer_delims(self.delims.replace("@",''))
        readline.parse_and_bind('tab: complete')
        readline.set_completer(self.complete)

        # persistant commands that actually affect a session 
        # (e.g. breakpoints, mem writes, comments)
        self.project_cmds = [ "sd", "b", "db", "sb","#", "//" ]


        if self.init_flag == True:
            self.init_flag = False
            try:
                readline.read_history_file(self.HISTFILE)
                self.session_start_index = readline.get_current_history_length()
                readline.set_history_length(self.HISTLEN)
            except Exception as e:
                pass

            atexit.register(self.on_exit,self.HISTFILE)
项目:Atrophy    作者:Thiefyface    | 项目源码 | 文件源码
def on_exit(self,histfile):
        if self.cleanup_flag == True:
            self.cleanup_flag = False
            readline.set_history_length(self.HISTLEN)
            readline.write_history_file(histfile)
项目:gitsome    作者:donnemartin    | 项目源码 | 文件源码
def setup_readline():
    """Sets up the readline module and completion supression, if available."""
    global RL_COMPLETION_SUPPRESS_APPEND, RL_LIB, RL_CAN_RESIZE
    if RL_COMPLETION_SUPPRESS_APPEND is not None:
        return
    try:
        import readline
    except ImportError:
        return
    import ctypes
    import ctypes.util
    readline.set_completer_delims(' \t\n')
    if not readline.__file__.endswith('.py'):
        RL_LIB = lib = ctypes.cdll.LoadLibrary(readline.__file__)
        try:
            RL_COMPLETION_SUPPRESS_APPEND = ctypes.c_int.in_dll(
                lib, 'rl_completion_suppress_append')
        except ValueError:
            # not all versions of readline have this symbol, ie Macs sometimes
            RL_COMPLETION_SUPPRESS_APPEND = None
        RL_CAN_RESIZE = hasattr(lib, 'rl_reset_screen_size')
    env = builtins.__xonsh_env__
    # reads in history
    readline.set_history_length(-1)
    ReadlineHistoryAdder()
    # sets up IPython-like history matching with up and down
    readline.parse_and_bind('"\e[B": history-search-forward')
    readline.parse_and_bind('"\e[A": history-search-backward')
    # Setup Shift-Tab to indent
    readline.parse_and_bind('"\e[Z": "{0}"'.format(env.get('INDENT')))

    # handle tab completion differences found in libedit readline compatibility
    # as discussed at http://stackoverflow.com/a/7116997
    if readline.__doc__ and 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")
项目:alma-slipsomat    作者:scriptotek    | 项目源码 | 文件源码
def execute(self, function, *args):
        "Executes the function, and handle exceptions"

        if readline is not None:
            readline.set_history_length(10000)
            readline.write_history_file(histfile)
        try:
            function(self.browser, *args)
        except Exception as e:
            self.handle_exception(e)
项目:zpy    作者:albertaleksieiev    | 项目源码 | 文件源码
def init_history(self):
        histfile = os.path.join(os.getcwd(), ".python_history")
        try:
            readline.read_history_file(histfile)
            readline.set_history_length(1000)
            readline.write_history_file(histfile)
        except (FileNotFoundError, PermissionError):
            readline.write_history_file(histfile)
            pass
        atexit.register(readline.write_history_file, histfile)