Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_LUF_completer_touch():
c = LatestUsedFirstWordCompleter(3, ["one", "two"])
c.touch("hello")
assert c.words == ["hello", "one", "two"]
c.touch("foo")
assert c.words == ["foo", "hello", "one"]
c.touch("hello")
assert c.words == ["hello", "foo", "one"]
def test_LUF_completer_touch_words():
c = LatestUsedFirstWordCompleter(3, [])
c.touch_words(["hello", "world", "foo", "bar"])
assert c.words == ["bar", "foo", "world"]
c.touch_words(["one", "two"])
assert c.words == ["two", "one", "bar"]
completer_mapping = {}
# patch command completer with hint
command_hint = {key: info["summary"] for key, info in commands_summary.items()}
for command_group, commands in group2commands.items():
words = commands + [command.lower() for command in commands]
if config.newbie_mode:
hint = {command: command_hint.get(command.upper()) for command in words}
else:
hint = None
completer_mapping[command_group] = WordCompleter(
words, sentence=True, meta_dict=hint
)
key_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
member_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
field_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
completer_mapping.update(
{
key: WordCompleter(tokens.split(" "), ignore_case=True)
for key, tokens in CONST.items()
}
)
completer_mapping.update(
{
# all key related completers share the same completer
"keys": key_completer,
"key": key_completer,
"destination": key_completer,
"newkey": key_completer,
# member
"member": member_completer,
"members": member_completer,
def get_completer(group2commands, redis_grammar):
completer_mapping = {}
# patch command completer with hint
command_hint = {key: info["summary"] for key, info in commands_summary.items()}
for command_group, commands in group2commands.items():
words = commands + [command.lower() for command in commands]
if config.newbie_mode:
hint = {command: command_hint.get(command.upper()) for command in words}
else:
hint = None
completer_mapping[command_group] = WordCompleter(
words, sentence=True, meta_dict=hint
)
key_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
member_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
field_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
completer_mapping.update(
{
key: WordCompleter(tokens.split(" "), ignore_case=True)
for key, tokens in CONST.items()
}
)
completer_mapping.update(
{
# all key related completers share the same completer
"keys": key_completer,
"key": key_completer,
"destination": key_completer,
"newkey": key_completer,
# member
"member": member_completer,
def get_completer(group2commands, redis_grammar):
completer_mapping = {}
# patch command completer with hint
command_hint = {key: info["summary"] for key, info in commands_summary.items()}
for command_group, commands in group2commands.items():
words = commands + [command.lower() for command in commands]
if config.newbie_mode:
hint = {command: command_hint.get(command.upper()) for command in words}
else:
hint = None
completer_mapping[command_group] = WordCompleter(
words, sentence=True, meta_dict=hint
)
key_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
member_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
field_completer = LatestUsedFirstWordCompleter(config.completer_max, [])
completer_mapping.update(
{
key: WordCompleter(tokens.split(" "), ignore_case=True)
for key, tokens in CONST.items()
}
)
completer_mapping.update(
{
# all key related completers share the same completer
"keys": key_completer,
"key": key_completer,
"destination": key_completer,
"newkey": key_completer,
# member
return
redis_grammar = completer.compiled_grammar
m = redis_grammar.match(command)
if not m:
# invalide command!
return
variables = m.variables()
# zset withscores
withscores = variables.get("withscores")
logger.debug(f"[PRE HOOK] withscores: {withscores}")
if withscores:
config.withscores = True
# auto update LatestUsedFirstWordCompleter
for _token, _completer in completer.completers.items():
if not isinstance(_completer, LatestUsedFirstWordCompleter):
continue
# getall always returns a []
tokens_in_command = variables.getall(_token)
for tokens_in_command in tokens_in_command:
# prompt_toolkit didn't support multi tokens
# like DEL key1 key2 key3
# so we have to split them manualy
for single_token in _strip_quote_args(tokens_in_command):
_completer.touch(single_token)
logger.debug(f"[Complter {_token} updated] Done: {_completer.words}")