3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +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:
James Lu 2017-06-27 17:15:27 -07:00
parent 6684f9bf08
commit 310f3f23b8
4 changed files with 17 additions and 17 deletions

View File

@ -372,7 +372,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
tag = tag.replace(r'\:', ';') tag = tag.replace(r'\:', ';')
tagdata[idx] = tag 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) log.debug('(%s) parsed message tags %s', self.name, results)
return results return results
return {} return {}
@ -387,14 +387,14 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
data = data[1:] data = data[1:]
try: try:
args = self.parsePrefixedArgs(data) args = self.parse_prefixed_args(data)
sender = args[0] sender = args[0]
command = args[1] command = args[1]
args = args[2:] args = args[2:]
except IndexError: except IndexError:
# Raw command without an explicit sender; assume it's being sent by our uplink. # 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 idsource = sender = self.uplink
command = args[0] command = args[0]
args = args[1:] 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 * :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 # 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]) 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] != '*': if args[2] != '*':
self.requestNewCaps() self.requestNewCaps()
@ -554,7 +554,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# Note: CAP NEW allows capabilities with values (e.g. sasl=mech1,mech2), while CAP DEL # Note: CAP NEW allows capabilities with values (e.g. sasl=mech1,mech2), while CAP DEL
# does not. # does not.
log.debug('(%s) Got new capabilities %s', self.name, args[-1]) 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.ircv3_caps_available.update(newcaps)
self.requestNewCaps() self.requestNewCaps()
@ -582,7 +582,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
""" """
Handles 005 / RPL_ISUPPORT. 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) log.debug('(%s) handle_005: self.caps is %s', self.name, self.caps)
if 'CHANMODES' in 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) log.debug('(%s) handle_005: casemapping set to %s', self.name, self.casemapping)
if 'PREFIX' in self.caps: 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) log.debug('(%s) handle_005: prefix modes set to %s', self.name, self.prefixmodes)
# Autodetect common prefix mode names. # Autodetect common prefix mode names.

View File

@ -477,7 +477,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
# USERMODES=,,s,BHIRSWcghikorwx GLOBOPS=1 SVSPART=1 # USERMODES=,,s,BHIRSWcghikorwx GLOBOPS=1 SVSPART=1
# First, turn the arguments into a dict # 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) log.debug("(%s) capabilities list: %s", self.name, caps)
# Check the protocol version # Check the protocol version
@ -508,7 +508,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
# Separate the prefixes field (e.g. "(Yqaohv)!~&@%+") into a # Separate the prefixes field (e.g. "(Yqaohv)!~&@%+") into a
# dict mapping mode characters to mode prefixes. # 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, log.debug('(%s) self.prefixmodes set to %r', self.name,
self.prefixmodes) self.prefixmodes)

View File

@ -20,7 +20,7 @@ class IRCCommonProtocol(IRCNetwork):
assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.name) assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.name)
@staticmethod @staticmethod
def parseArgs(args): def parse_args(args):
""" """
Parses a string or list of of RFC1459-style arguments, where ":" may 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. be used for multi-word arguments that last until the end of a line.
@ -41,10 +41,10 @@ class IRCCommonProtocol(IRCNetwork):
return real_args return real_args
@classmethod @classmethod
def parsePrefixedArgs(cls, args): def parse_prefixed_args(cls, args):
"""Similar to parseArgs(), but stripping leading colons from the first argument """Similar to parse_args(), but stripping leading colons from the first argument
of a line (usually the sender field).""" of a line (usually the sender field)."""
args = cls.parseArgs(args) args = cls.parse_args(args)
args[0] = args[0].split(':', 1)[1] args[0] = args[0].split(':', 1)[1]
return args return args
@ -106,7 +106,7 @@ class IRCCommonProtocol(IRCNetwork):
'channeldata': old_channels} 'channeldata': old_channels}
@staticmethod @staticmethod
def parseCapabilities(args, fallback=''): def parse_isupport(args, fallback=''):
""" """
Parses a string of capabilities in the 005 / RPL_ISUPPORT format. Parses a string of capabilities in the 005 / RPL_ISUPPORT format.
""" """
@ -127,7 +127,7 @@ class IRCCommonProtocol(IRCNetwork):
return caps return caps
@staticmethod @staticmethod
def parsePrefixes(args): def parse_isupport_prefixes(args):
""" """
Separates prefixes field like "(qaohv)~&@%+" into a dict mapping mode characters to mode Separates prefixes field like "(qaohv)~&@%+" into a dict mapping mode characters to mode
prefixes. prefixes.
@ -159,7 +159,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
the SID of the uplink server. the SID of the uplink server.
""" """
data = data.split(" ") data = data.split(" ")
args = self.parseArgs(data) args = self.parse_args(data)
sender = args[0] sender = args[0]
sender = sender.lstrip(':') sender = sender.lstrip(':')

View File

@ -586,7 +586,7 @@ class P10Protocol(IRCS2SProtocol):
if linenum: # Implies "if linenum > 0" if linenum: # Implies "if linenum > 0"
# XXX: Ugh, this postprocessing sucks, but we have to make sure that mode prefixes are accounted # XXX: Ugh, this postprocessing sucks, but we have to make sure that mode prefixes are accounted
# for in the burst. # 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(',') wrapped_namelist = wrapped_args[-1].split(',')
log.debug('(%s) sjoin: wrapped args: %s (post-wrap fixing)', self.name, log.debug('(%s) sjoin: wrapped args: %s (post-wrap fixing)', self.name,
wrapped_args) wrapped_args)