From 6da35a899b1603a606f544ff2875496bb59b98c0 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 18 Feb 2019 12:42:52 +0000 Subject: [PATCH] don't pass around `has_arbitrary` - we don't need it. --- modules/line_handler.py | 7 ++----- src/utils/irc.py | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/line_handler.py b/modules/line_handler.py index f8a37103..77e31a33 100644 --- a/modules/line_handler.py +++ b/modules/line_handler.py @@ -28,8 +28,7 @@ class Module(ModuleManager.BaseModule): default_event = any(default_events) kwargs = {"args": line.args, "tags": line.tags, "server": server, - "prefix": line.prefix, "has_arbitrary": line.has_arbitrary, - "direction": Direction.RECV} + "prefix": line.prefix, "direction": Direction.RECV} self.events.on("raw.received").on(line.command).call_unsafe(**kwargs) if default_event or not hooks: @@ -90,9 +89,7 @@ class Module(ModuleManager.BaseModule): # server telling us what it supports @utils.hook("raw.received.005") def handle_005(self, event): - isupport_list = event["args"][1:] - if event["has_arbitrary"]: - isupport_list = isupport_list[:-1] + isupport_list = event["args"][1:-1] isupport = {} for i, item in enumerate(isupport_list): diff --git a/src/utils/irc.py b/src/utils/irc.py index c1b65df2..fcfd0f06 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -64,13 +64,12 @@ class IRCArgs(object): class IRCParsedLine(object): - def __init__(self, tags: dict, prefix: typing.Optional[IRCHostmask], - command: str, args: IRCArgs, has_arbitrary: bool): + def __init__(self, command: str, args: IRCArgs, prefix: IRCHostmask = None, + tags: dict = None): self.tags = tags self.prefix = prefix self.command = command self.args = args - self.has_arbitrary = has_arbitrary MESSAGE_TAG_ESCAPED = [r"\:", r"\s", r"\\", r"\r", r"\n"] MESSAGE_TAG_UNESCAPED = [";", " ", "\\", "\r", "\n"] @@ -98,11 +97,11 @@ def parse_line(line: str) -> IRCParsedLine: else: tags[tag] = None - line, arb_sep, arbitrary_split = line.partition(" :") - has_arbitrary = bool(arb_sep) - arbitrary = None # type: typing.Optional[str] - if has_arbitrary: - arbitrary = arbitrary_split + line, trailing_separator, trailing_split = line.partition(" :") + + trailing = None # type: typing.Optional[str] + if trailing_separator + trailing = trailing_split if line[0] == ":": prefix_str, line = line[1:].split(" ", 1) @@ -114,10 +113,10 @@ def parse_line(line: str) -> IRCParsedLine: # this is so that `args` is empty if `line` is empty args = line.split(" ") - if not arbitrary == None: - args.append(typing.cast(str, arbitrary)) + if not trailing == None: + args.append(typing.cast(str, trailing)) - return IRCParsedLine(tags, prefix, command, IRCArgs(args), has_arbitrary) + return IRCParsedLine(command, IRCArgs(args), prefix, tags) REGEX_COLOR = re.compile("%s(?:(\d{1,2})(?:,(\d{1,2}))?)?" % utils.consts.COLOR)