3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

Move ts6_common.parseTS6Args to ts6_common.parsePrefixedArgs

This commit is contained in:
James Lu 2016-07-16 22:41:52 -07:00
parent 0a0e19d4c2
commit 1770058e1b
2 changed files with 9 additions and 9 deletions

View File

@ -1256,6 +1256,13 @@ class Protocol():
target = self.irc.nickToUid(target) or target target = self.irc.nickToUid(target) or target
return target return target
def parsePrefixedArgs(self, args):
"""Similar to parseArgs(), but stripping leading colons from the first argument
of a line (usually the sender field)."""
args = self.parseArgs(args)
args[0] = args[0].split(':', 1)[1]
return args
### FakeIRC classes, used for test cases ### FakeIRC classes, used for test cases
class FakeIRC(Irc): class FakeIRC(Irc):

View File

@ -113,13 +113,6 @@ class TS6BaseProtocol(IRCS2SProtocol):
"""Sends a TS6-style raw command from a source numeric to the self.irc connection given.""" """Sends a TS6-style raw command from a source numeric to the self.irc connection given."""
self.irc.send(':%s %s' % (source, msg)) self.irc.send(':%s %s' % (source, msg))
def parseTS6Args(self, args):
"""Similar to parseArgs(), but stripping leading colons from the first argument
of a line (usually the sender field)."""
args = self.parseArgs(args)
args[0] = args[0].split(':', 1)[1]
return args
def _getOutgoingNick(self, uid): def _getOutgoingNick(self, uid):
""" """
Returns the outgoing nick for the given UID. In the base ts6_common implementation, Returns the outgoing nick for the given UID. In the base ts6_common implementation,
@ -314,7 +307,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
""" """
data = data.split(" ") data = data.split(" ")
try: # Message starts with a SID/UID prefix. try: # Message starts with a SID/UID prefix.
args = self.parseTS6Args(data) args = self.parsePrefixedArgs(data)
sender = args[0] sender = args[0]
command = args[1] command = args[1]
args = args[2:] args = args[2:]
@ -328,7 +321,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
# Sender is a user. # Sender is a user.
numeric = self._getUid(sender) numeric = self._getUid(sender)
# parseTS6Args() will raise IndexError if the TS6 sender prefix is missing. # parsePrefixedArgs() will raise IndexError if the TS6 sender prefix is missing.
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.parseArgs(data)