Add src.utils.parse.keyvalue, mostly for IRCv3 CAP negotiation
This commit is contained in:
parent
c2ebc7b5e4
commit
9c233cd4dd
2 changed files with 11 additions and 8 deletions
|
@ -247,14 +247,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
# the server is telling us about its capabilities!
|
# the server is telling us about its capabilities!
|
||||||
@utils.hook("raw.cap")
|
@utils.hook("raw.cap")
|
||||||
def cap(self, event):
|
def cap(self, event):
|
||||||
capabilities_list = event["args"][2].split(" ")
|
capabilities = utils.parse.keyvalue(event["args"][2])
|
||||||
capabilities = {}
|
|
||||||
for capability in capabilities_list:
|
|
||||||
argument = None
|
|
||||||
if "=" in capability:
|
|
||||||
capability, argument = capability.split("=", 1)
|
|
||||||
capabilities[capability] = argument
|
|
||||||
|
|
||||||
subcommand = event["args"][1].lower()
|
subcommand = event["args"][1].lower()
|
||||||
is_multiline = len(event["args"]) > 2 and event["args"][2] == "*"
|
is_multiline = len(event["args"]) > 2 and event["args"][2] == "*"
|
||||||
|
|
||||||
|
|
|
@ -55,3 +55,13 @@ def docstring(s: str) -> Docstring:
|
||||||
description += line
|
description += line
|
||||||
return Docstring(description, items, var_items)
|
return Docstring(description, items, var_items)
|
||||||
|
|
||||||
|
def keyvalue(s, delimiter: str=" ") -> typing.Dict[str, str]:
|
||||||
|
items = {}
|
||||||
|
pairs = s.split(delimiter)
|
||||||
|
for pair in pairs:
|
||||||
|
key, sep, value = pair.partition("=")
|
||||||
|
if sep:
|
||||||
|
items[key] = value
|
||||||
|
else:
|
||||||
|
items[key] = None
|
||||||
|
return items
|
||||||
|
|
Loading…
Reference in a new issue