本文整理匯總了Python中readline.remove_history_item方法的典型用法代碼示例。如果您正苦於以下問題:Python readline.remove_history_item方法的具體用法?Python readline.remove_history_item怎麽用?Python readline.remove_history_item使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類readline
的用法示例。
在下文中一共展示了readline.remove_history_item方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testHistoryUpdates
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import remove_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)
示例2: do_history
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import remove_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 #
示例3: pyreadline_remove_history_item
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import remove_history_item [as 別名]
def pyreadline_remove_history_item(pos: int) -> None:
"""
An implementation of remove_history_item() for pyreadline
:param pos: The 0-based position in history to remove
"""
# Save of the current location of the history cursor
saved_cursor = readline.rl.mode._history.history_cursor
# Delete the history item
del(readline.rl.mode._history.history[pos])
# Update the cursor if needed
if saved_cursor > pos:
readline.rl.mode._history.history_cursor -= 1
示例4: remove_last_history_item
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import remove_history_item [as 別名]
def remove_last_history_item() -> None:
"""The user just typed a password..."""
last = readline.get_current_history_length() - 1
readline.remove_history_item(last)
示例5: multiline
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import remove_history_item [as 別名]
def multiline(self, firstline=''):
full_input = []
# keep a list of the entries that we've made in history
old_hist = []
if firstline:
full_input.append(firstline)
while True:
if hasReadline:
# add the current readline position
old_hist.append(readline.get_current_history_length())
if self.use_rawinput:
try:
line = raw_input(self.multiline_prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.multiline_prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line[:-1] # chop \n
if line == 'EOF':
print
break
full_input.append(line)
if ';' in line:
break
# add the final readline history position
if hasReadline:
old_hist.append(readline.get_current_history_length())
cmd = ' '.join(full_input)
if hasReadline:
# remove the old, individual readline history entries.
# first remove any duplicate entries
old_hist = sorted(set(old_hist))
# Make sure you do this in reversed order so you move from
# the end of the history up.
for pos in reversed(old_hist):
# get_current_history_length returns pos + 1
readline.remove_history_item(pos - 1)
# now add the full line
readline.add_history(cmd)
return cmd