mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-30 14:49:28 +01:00
protocols: rename various parse* functions (no migration stub)
Renamed to camel case: - parseArgs -> parse_args - parsePrefixedArgs -> parse_prefixed_args Renamed to show that we're specifically parsing ISUPPORT data: - parseCapabilities -> parse_isupport - parsePrefixes -> parse_isupport_prefixes
This commit is contained in:
parent
6684f9bf08
commit
310f3f23b8
@ -372,7 +372,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
tag = tag.replace(r'\:', ';')
|
||||
tagdata[idx] = tag
|
||||
|
||||
results = self.parseCapabilities(tagdata, fallback=None)
|
||||
results = self.parse_isupport(tagdata, fallback=None)
|
||||
log.debug('(%s) parsed message tags %s', self.name, results)
|
||||
return results
|
||||
return {}
|
||||
@ -387,14 +387,14 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
data = data[1:]
|
||||
|
||||
try:
|
||||
args = self.parsePrefixedArgs(data)
|
||||
args = self.parse_prefixed_args(data)
|
||||
sender = args[0]
|
||||
command = args[1]
|
||||
args = args[2:]
|
||||
|
||||
except IndexError:
|
||||
# Raw command without an explicit sender; assume it's being sent by our uplink.
|
||||
args = self.parseArgs(data)
|
||||
args = self.parse_args(data)
|
||||
idsource = sender = self.uplink
|
||||
command = args[0]
|
||||
args = args[1:]
|
||||
@ -528,7 +528,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
# Server: CAP * LS * :cap-notify server-time example.org/dummy-cap=dummyvalue example.org/second-dummy-cap
|
||||
# Server: CAP * LS :userhost-in-names sasl=EXTERNAL,DH-AES,DH-BLOWFISH,ECDSA-NIST256P-CHALLENGE,PLAIN
|
||||
log.debug('(%s) Got new capabilities %s', self.name, args[-1])
|
||||
self.ircv3_caps_available.update(self.parseCapabilities(args[-1], None))
|
||||
self.ircv3_caps_available.update(self.parse_isupport(args[-1], None))
|
||||
if args[2] != '*':
|
||||
self.requestNewCaps()
|
||||
|
||||
@ -554,7 +554,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
# Note: CAP NEW allows capabilities with values (e.g. sasl=mech1,mech2), while CAP DEL
|
||||
# does not.
|
||||
log.debug('(%s) Got new capabilities %s', self.name, args[-1])
|
||||
newcaps = self.parseCapabilities(args[-1], None)
|
||||
newcaps = self.parse_isupport(args[-1], None)
|
||||
self.ircv3_caps_available.update(newcaps)
|
||||
self.requestNewCaps()
|
||||
|
||||
@ -582,7 +582,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
"""
|
||||
Handles 005 / RPL_ISUPPORT.
|
||||
"""
|
||||
self.caps.update(self.parseCapabilities(args[1:-1]))
|
||||
self.caps.update(self.parse_isupport(args[1:-1]))
|
||||
log.debug('(%s) handle_005: self.caps is %s', self.name, self.caps)
|
||||
|
||||
if 'CHANMODES' in self.caps:
|
||||
@ -599,7 +599,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
|
||||
log.debug('(%s) handle_005: casemapping set to %s', self.name, self.casemapping)
|
||||
|
||||
if 'PREFIX' in self.caps:
|
||||
self.prefixmodes = prefixmodes = self.parsePrefixes(self.caps['PREFIX'])
|
||||
self.prefixmodes = prefixmodes = self.parse_isupport_prefixes(self.caps['PREFIX'])
|
||||
log.debug('(%s) handle_005: prefix modes set to %s', self.name, self.prefixmodes)
|
||||
|
||||
# Autodetect common prefix mode names.
|
||||
|
@ -477,7 +477,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
|
||||
# USERMODES=,,s,BHIRSWcghikorwx GLOBOPS=1 SVSPART=1
|
||||
|
||||
# First, turn the arguments into a dict
|
||||
caps = self.parseCapabilities(args[-1])
|
||||
caps = self.parse_isupport(args[-1])
|
||||
log.debug("(%s) capabilities list: %s", self.name, caps)
|
||||
|
||||
# Check the protocol version
|
||||
@ -508,7 +508,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
|
||||
|
||||
# Separate the prefixes field (e.g. "(Yqaohv)!~&@%+") into a
|
||||
# dict mapping mode characters to mode prefixes.
|
||||
self.prefixmodes = self.parsePrefixes(caps['PREFIX'])
|
||||
self.prefixmodes = self.parse_isupport_prefixes(caps['PREFIX'])
|
||||
log.debug('(%s) self.prefixmodes set to %r', self.name,
|
||||
self.prefixmodes)
|
||||
|
||||
|
@ -20,7 +20,7 @@ class IRCCommonProtocol(IRCNetwork):
|
||||
assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.name)
|
||||
|
||||
@staticmethod
|
||||
def parseArgs(args):
|
||||
def parse_args(args):
|
||||
"""
|
||||
Parses a string or list of of RFC1459-style arguments, where ":" may
|
||||
be used for multi-word arguments that last until the end of a line.
|
||||
@ -41,10 +41,10 @@ class IRCCommonProtocol(IRCNetwork):
|
||||
return real_args
|
||||
|
||||
@classmethod
|
||||
def parsePrefixedArgs(cls, args):
|
||||
"""Similar to parseArgs(), but stripping leading colons from the first argument
|
||||
def parse_prefixed_args(cls, args):
|
||||
"""Similar to parse_args(), but stripping leading colons from the first argument
|
||||
of a line (usually the sender field)."""
|
||||
args = cls.parseArgs(args)
|
||||
args = cls.parse_args(args)
|
||||
args[0] = args[0].split(':', 1)[1]
|
||||
return args
|
||||
|
||||
@ -106,7 +106,7 @@ class IRCCommonProtocol(IRCNetwork):
|
||||
'channeldata': old_channels}
|
||||
|
||||
@staticmethod
|
||||
def parseCapabilities(args, fallback=''):
|
||||
def parse_isupport(args, fallback=''):
|
||||
"""
|
||||
Parses a string of capabilities in the 005 / RPL_ISUPPORT format.
|
||||
"""
|
||||
@ -127,7 +127,7 @@ class IRCCommonProtocol(IRCNetwork):
|
||||
return caps
|
||||
|
||||
@staticmethod
|
||||
def parsePrefixes(args):
|
||||
def parse_isupport_prefixes(args):
|
||||
"""
|
||||
Separates prefixes field like "(qaohv)~&@%+" into a dict mapping mode characters to mode
|
||||
prefixes.
|
||||
@ -159,7 +159,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
|
||||
the SID of the uplink server.
|
||||
"""
|
||||
data = data.split(" ")
|
||||
args = self.parseArgs(data)
|
||||
args = self.parse_args(data)
|
||||
|
||||
sender = args[0]
|
||||
sender = sender.lstrip(':')
|
||||
|
@ -586,7 +586,7 @@ class P10Protocol(IRCS2SProtocol):
|
||||
if linenum: # Implies "if linenum > 0"
|
||||
# XXX: Ugh, this postprocessing sucks, but we have to make sure that mode prefixes are accounted
|
||||
# for in the burst.
|
||||
wrapped_args = self.parseArgs(wrapped_msg.split(" "))
|
||||
wrapped_args = self.parse_args(wrapped_msg.split(" "))
|
||||
wrapped_namelist = wrapped_args[-1].split(',')
|
||||
log.debug('(%s) sjoin: wrapped args: %s (post-wrap fixing)', self.name,
|
||||
wrapped_args)
|
||||
|
Loading…
Reference in New Issue
Block a user