本文整理汇总了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)
示例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")
示例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)
示例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)
示例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)
示例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
示例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")
示例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
示例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
示例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)
示例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))
示例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
示例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
示例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
示例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()