mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Irc: rewrite parseArgs to be more efficient
This commit is contained in:
parent
01dd209647
commit
03fc16dd5a
22
classes.py
22
classes.py
@ -1327,27 +1327,21 @@ class Protocol():
|
|||||||
port = self.irc.serverdata['port']
|
port = self.irc.serverdata['port']
|
||||||
assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.irc.name)
|
assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.irc.name)
|
||||||
|
|
||||||
def parseArgs(self, args):
|
@staticmethod
|
||||||
|
def parseArgs(args):
|
||||||
"""Parses a string of RFC1459-style arguments split into a list, where ":" may
|
"""Parses a string of RFC1459-style arguments split into a list, 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.
|
||||||
"""
|
"""
|
||||||
real_args = []
|
real_args = []
|
||||||
for idx, arg in enumerate(args):
|
for idx, arg in enumerate(args):
|
||||||
real_args.append(arg)
|
|
||||||
# If the argument starts with ':' and ISN'T the first argument.
|
|
||||||
# The first argument is used for denoting the source UID/SID.
|
|
||||||
if arg.startswith(':') and idx != 0:
|
if arg.startswith(':') and idx != 0:
|
||||||
# : is used for multi-word arguments that last until the end
|
# ":" is used to begin multi-word arguments that last until the end of the message.
|
||||||
# of the message. We can use list splicing here to turn them all
|
# Use list splicing here to join them into one argument, and then add it to our list of args.
|
||||||
# into one argument.
|
joined_arg = ' '.join(args[idx:])[1:] # Cut off the leading : as well
|
||||||
# Set the last arg to a joined version of the remaining args
|
real_args.append(joined_arg)
|
||||||
arg = args[idx:]
|
|
||||||
arg = ' '.join(arg)[1:]
|
|
||||||
# Cut the original argument list right before the multi-word arg,
|
|
||||||
# and then append the multi-word arg.
|
|
||||||
real_args = args[:idx]
|
|
||||||
real_args.append(arg)
|
|
||||||
break
|
break
|
||||||
|
real_args.append(arg)
|
||||||
|
|
||||||
return real_args
|
return real_args
|
||||||
|
|
||||||
def removeClient(self, numeric):
|
def removeClient(self, numeric):
|
||||||
|
Loading…
Reference in New Issue
Block a user