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


Python readline.get_history_item方法代码示例

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


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

示例1: _history_update

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def _history_update(self, array=None):
        if array is None:
            array = []
        try:
            import readline
            # add array elements to readline history
            for command in array:
                readline.add_history(command)
            # recreate Hist from readline history (UGLY)
            self.Hist.clear()
            history_len = readline.get_current_history_length()
            for i in range(1, history_len + 1):
                line = readline.get_history_item(i)
                self.Hist.append(line)
        except ImportError:
            pass
        # By default, hist max size is 20% of CACHE_SIZE
        max_size = int(self.Conf["CACHE_SIZE"]() * 0.2)
        # Settle Hist object to its max size
        while self.Hist.size > max_size:
            self.Hist.pop(0) 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:23,代码来源:__init__.py

示例2: refreshFromReadline

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def refreshFromReadline(self):
        """Consume as much content as possible from the line buffer.

        Returns self, so that we can chain calls to this function and 'getlines'.
        """
        newLines = []

        #for some reason, this import segfaults if we do it as part of our routine
        #setup in the test harness. Putting the import here ensures we only
        #import it when we are actively using it (e.g. there is a terminal connected
        #to stdin)
        import readline

        while len(self.lines) + len(newLines) < readline.get_current_history_length():
            newLines.append(readline.get_history_item(len(self.lines) + len(newLines) + 1) + "\n")

        self.lines += newLines
        for block in self.divideIntoBlocks(newLines):
            self.addBlock(block)

        return self 
开发者ID:ufora,项目名称:ufora,代码行数:23,代码来源:StdinCache.py

示例3: testHistoryUpdates

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def testHistoryUpdates(self):
        readline.clear_history()

        readline.add_history("first line")
        readline.add_history("second line")

        self.assertEqual(readline.get_history_item(0), None)
        self.assertEqual(readline.get_history_item(1), "first line")
        self.assertEqual(readline.get_history_item(2), "second line")

        readline.replace_history_item(0, "replaced line")
        self.assertEqual(readline.get_history_item(0), None)
        self.assertEqual(readline.get_history_item(1), "replaced line")
        self.assertEqual(readline.get_history_item(2), "second line")

        self.assertEqual(readline.get_current_history_length(), 2)

        readline.remove_history_item(0)
        self.assertEqual(readline.get_history_item(0), None)
        self.assertEqual(readline.get_history_item(1), "second line")

        self.assertEqual(readline.get_current_history_length(), 1) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:24,代码来源:test_readline.py

示例4: test_nonascii_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [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

示例5: get_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def get_history(self):
        hist = []
        for i in range(readline.get_current_history_length()):
             hist.append(readline.get_history_item(i + 1))
        return hist 
开发者ID:plasma-disassembler,项目名称:plasma,代码行数:7,代码来源:console.py

示例6: do_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def do_history(self, argv):
        """Command line history

        SYNOPSIS:
            history [<COUNT>]

        DESCRIPTION:
            Returns a formatted string giving the event number and
            contents for each of the events in the history list
            except for current event.

            If [COUNT] is specified, only the [COUNT] most recent
            events are displayed.

            > history
              - Display the full history of events.
            > history 10
              - Display last 10 commands of the history.
        """
        import readline

        argv.append('9999999999')

        try:
            count = int(argv[1])
        except ValueError:
            return self.interpret("help history")

        last = readline.get_current_history_length()
        while last > session.Hist.MAX_SIZE:
            readline.remove_history_item(0)
            last -= 1
        first = last - count
        if first < 1:
            first = 1
        for i in range(first, last):
            cmd = readline.get_history_item(i)
            print("{:4d}  {:s}".format(i, cmd))

    ####################
    # COMMAND: exploit # 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:43,代码来源:interface.py

示例7: _call

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def _call(self, objs: Iterable[drgn.Object]) -> None:
        stop = readline.get_current_history_length() + 1
        if self.args.count is not None:
            start = stop - self.args.count
        else:
            start = 1
        for i in range(start, stop):
            print(f"{i:5}  {readline.get_history_item(i)}") 
开发者ID:delphix,项目名称:sdb,代码行数:10,代码来源:history.py

示例8: postcmd

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def postcmd(self, stop, line):
        complete_line = readline.get_history_item(readline.get_current_history_length())
        if complete_line.strip() != "":
            SessionManager().log_command(complete_line) 
开发者ID:Esser420,项目名称:EvilTwinFramework,代码行数:6,代码来源:etfconsole.py

示例9: get_history_items

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def get_history_items() -> List[str]:
    return list(map(readline.get_history_item, range(1, readline.get_current_history_length() + 1))) 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:4,代码来源:main.py

示例10: do_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def do_history(self, _line):
        """
        history

          Show previously executed commands.
        """

        try:
            import readline
            hist = readline.get_current_history_length()
            for idx in range(1, hist + 1):
                self.log(readline.get_history_item(idx))
        except ImportError:
            pass 
开发者ID:openthread,项目名称:pyspinel,代码行数:16,代码来源:spinel-cli.py

示例11: process_history

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def process_history():
    """Processes python shell history to an array of code lines"""
    end_index = len(PySession.ipython_history) - 1 if PySession.is_ipython \
        else readline.get_current_history_length()

    lines_of_code = []
    for i in range(PySession.start_index, end_index):
        if i in PySession.wrong_code_lines:
            continue
        if PySession.is_ipython:
            line = PySession.ipython_history[i]
        else:
            line = readline.get_history_item(i)

        # remove 'exit' and PySession keywords from code
        if line.strip() in ['PySession.local()',
                            'PySession.gist()',
                            'PySession.off()',
                            'exit',
                            'exit()']:
            continue
        lines_of_code.append(line)

    if len(
            lines_of_code) > 0 and lines_of_code[-1] != '\n':  # adding extra last newline
        lines_of_code.append('\n')

    return lines_of_code 
开发者ID:FallibleInc,项目名称:pysession,代码行数:30,代码来源:pysession.py

示例12: test_write_read_append

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def test_write_read_append(self):
        hfile = tempfile.NamedTemporaryFile(delete=False)
        hfile.close()
        hfilename = hfile.name
        self.addCleanup(unlink, hfilename)

        # test write-clear-read == nop
        readline.clear_history()
        readline.add_history("first line")
        readline.add_history("second line")
        readline.write_history_file(hfilename)

        readline.clear_history()
        self.assertEqual(readline.get_current_history_length(), 0)

        readline.read_history_file(hfilename)
        self.assertEqual(readline.get_current_history_length(), 2)
        self.assertEqual(readline.get_history_item(1), "first line")
        self.assertEqual(readline.get_history_item(2), "second line")

        # test append
        readline.append_history_file(1, hfilename)
        readline.clear_history()
        readline.read_history_file(hfilename)
        self.assertEqual(readline.get_current_history_length(), 3)
        self.assertEqual(readline.get_history_item(1), "first line")
        self.assertEqual(readline.get_history_item(2), "second line")
        self.assertEqual(readline.get_history_item(3), "second line")

        # test 'no such file' behaviour
        os.unlink(hfilename)
        with self.assertRaises(FileNotFoundError):
            readline.append_history_file(1, hfilename)

        # write_history_file can create the target
        readline.write_history_file(hfilename) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:38,代码来源:test_readline.py

示例13: get_history_items

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def get_history_items():
    """
    Get all history item
    """
    return [
        readline.get_history_item(i)
        for i in xrange(1, readline.get_current_history_length() + 1)
    ] 
开发者ID:orakaro,项目名称:rainbowstream,代码行数:10,代码来源:interactive.py

示例14: isolate_io_context

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def isolate_io_context(function):
    """A decorator for separating I/O context.

    This decorator isolates I/O context of target
    function or method.

    I/O Context is a mix of terminal related elements,
    such as current stdout and readline completer
    attributes.

    This decorator is useful if you run something
    that reconfigures the readline completer, or
    needs to use the default stdout file descriptor
    instead of the phpsploit's stdout wrapper.
    """
    def wrapper(*args, **kwargs):
        try:
            import readline
            handle_readline = True
        except ImportError:
            handle_readline = False

        if handle_readline:
            # backup & reset readline completer
            old_readline_completer = readline.get_completer()
            readline.set_completer((lambda x: x))
            # backup & reset readline history
            old_readline_history = []
            hist_sz = readline.get_current_history_length()
            for i in range(1, hist_sz + 1):
                line = readline.get_history_item(i)
                old_readline_history.append(line)
            readline.clear_history()
        # backup & reset stdout
        old_stdout = sys.stdout
        sys.stdout = sys.__stdout__

        try:
            retval = function(*args, **kwargs)
        finally:

            if handle_readline:
                # restore old readline completer
                readline.set_completer(old_readline_completer)
                # restore old readline history
                readline.clear_history()
                for line in old_readline_history:
                    readline.add_history(line)
            # restore old stdout
            sys.stdout = old_stdout

        return retval
    return wrapper 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:55,代码来源:isolate_io_context.py

示例15: isolate_readline_context

# 需要导入模块: import readline [as 别名]
# 或者: from readline import get_history_item [as 别名]
def isolate_readline_context(function):
    """A decorator for separating readline context.

    This decorator isolates readline context of target
    function or method.

    Use when phpsploit's readline context should be
    reset temporarly is the context of triggering
    function or method.

    Unlike `isolate_io_context`, this decorator keeps
    original stdout wrapper.
    """
    def wrapper(*args, **kwargs):
        try:
            import readline
            handle_readline = True
        except ImportError:
            handle_readline = False

        if handle_readline:
            # backup & reset readline completer
            old_readline_completer = readline.get_completer()
            readline.set_completer((lambda x: x))
            # backup & reset readline history
            old_readline_history = []
            hist_sz = readline.get_current_history_length()
            for i in range(1, hist_sz + 1):
                line = readline.get_history_item(i)
                old_readline_history.append(line)
            readline.clear_history()

        try:
            retval = function(*args, **kwargs)
        finally:

            if handle_readline:
                # restore old readline completer
                readline.set_completer(old_readline_completer)
                # restore old readline history
                readline.clear_history()
                for line in old_readline_history:
                    readline.add_history(line)

        return retval
    return wrapper 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:48,代码来源:isolate_readline_context.py


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