本文整理汇总了Python中readline.clear_history方法的典型用法代码示例。如果您正苦于以下问题:Python readline.clear_history方法的具体用法?Python readline.clear_history怎么用?Python readline.clear_history使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.clear_history方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testHistoryUpdates
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [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: test_nonascii_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [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")
示例3: pause
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [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
示例4: clear_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [as 别名]
def clear_history(): pass
示例5: clear_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [as 别名]
def clear_history():
pass
示例6: test_write_read_append
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [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)
示例7: isolate_io_context
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [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
示例8: isolate_readline_context
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [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
示例9: interact
# 需要导入模块: import readline [as 别名]
# 或者: from readline import clear_history [as 别名]
def interact(self):
"""Interact with an active session"""
readline.clear_history()
readline.set_completer(self.tab_complete)
readline.parse_and_bind('tab: complete')
command_modules = self.server.get_modules(self.type)
while 1:
try:
#prepare command
raw = input(self.get_handle()).strip(" ")
if not raw or raw.replace(" ","") == "":
continue
cmd = raw.split()[0]
cmd_data = {"cmd": cmd, "args":raw[len(cmd) + 1:]}
if self.needs_refresh:
# don't do anything if we are in the middle of updating session
pass
elif cmd == "exit":
self.disconnect(True)
return
elif cmd == "back" and self.server.is_multi:
return
elif cmd == "help":
self.show_commands()
elif cmd in command_modules.keys():
command_modules[cmd].run(self,cmd_data)
elif cmd in self.server.modules_local.keys():
self.server.modules_local[cmd].run(self,cmd_data)
else:
h.info_error("Unrecognized command!")
except KeyboardInterrupt:
try:
print("")
if readline.get_line_buffer():
continue
except:
pass
self.disconnect(True)
return
except Exception as e:
print(e)