Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for command in traverse_commands(self):
regex = command.to_regex()
formatted_regex = self.regex_format.format(regex)
command_info = {"re": re.compile(formatted_regex, re.U),
"command": command,
"exclusive": command.exclusive}
command_infos.append(command_info)
# Sort exclusive commands before non-exclusive ones
command_infos.sort(key=lambda c:c["exclusive"], reverse=True)
return CommandParser(command_infos)
class FacetCommandSet(CommandSet):
def add(self, *args, **kwargs):
def doit(handler):
return CommandSet.add(self, *args, **kwargs)(thing_command(handler, self.name))
return doit
# TODO: stripping listen commands such as --/++
class Command(object):
def __init__(self, parent, format, handler, help=None, visible=True, exclusive=False):
self.parent = parent
self.format = format
self.handler = handler
self.help = help
self.visible = visible
self.exclusive = exclusive
def doit(handler):
return CommandSet.add(self, *args, **kwargs)(thing_command(handler, self.name))
if name == "thing":
parameter_regex = r"(?:\([^()]+\))|[#!\w]+"
else:
# This regex may come back to haunt me.
parameter_regex = r".+"
return r"(?P<{name}>{regex})".format(name=name,
regex=parameter_regex)
regex = self.format
regex = regex.replace("+", r"\+")
regex = re.sub(r"{(\w+)}", sub_parameter, regex)
return regex
listen = CommandSet("listen")
thing = CommandSet("thing", regex_format="(^{0}$)")
name = match.group(1)
if name == "thing":
parameter_regex = r"(?:\([^()]+\))|[#!\w]+"
else:
# This regex may come back to haunt me.
parameter_regex = r".+"
return r"(?P<{name}>{regex})".format(name=name,
regex=parameter_regex)
regex = self.format
regex = regex.replace("+", r"\+")
regex = re.sub(r"{(\w+)}", sub_parameter, regex)
return regex
listen = CommandSet("listen")
thing = CommandSet("thing", regex_format="(^{0}$)")