mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-11 20:52:42 +01:00
classes: Drop FakeIRC, FakeProto
This commit is contained in:
parent
87c558537f
commit
f45cb3a583
71
classes.py
71
classes.py
@ -1346,74 +1346,3 @@ class Protocol():
|
|||||||
"""
|
"""
|
||||||
prefixsearch = re.search(r'\(([A-Za-z]+)\)(.*)', args)
|
prefixsearch = re.search(r'\(([A-Za-z]+)\)(.*)', args)
|
||||||
return dict(zip(prefixsearch.group(1), prefixsearch.group(2)))
|
return dict(zip(prefixsearch.group(1), prefixsearch.group(2)))
|
||||||
|
|
||||||
### FakeIRC classes, used for test cases
|
|
||||||
|
|
||||||
class FakeIRC(Irc):
|
|
||||||
"""Fake IRC object used for unit tests."""
|
|
||||||
def connect(self):
|
|
||||||
self.messages = []
|
|
||||||
self.hookargs = []
|
|
||||||
self.hookmsgs = []
|
|
||||||
self.socket = None
|
|
||||||
self.initVars()
|
|
||||||
self.connected = threading.Event()
|
|
||||||
self.connected.set()
|
|
||||||
|
|
||||||
def run(self, data):
|
|
||||||
"""Queues a message to the fake IRC server."""
|
|
||||||
log.debug('<- ' + data)
|
|
||||||
hook_args = self.proto.handle_events(data)
|
|
||||||
if hook_args is not None:
|
|
||||||
self.hookmsgs.append(hook_args)
|
|
||||||
self.callHooks(hook_args)
|
|
||||||
|
|
||||||
def send(self, data):
|
|
||||||
self.messages.append(data)
|
|
||||||
log.debug('-> ' + data)
|
|
||||||
|
|
||||||
def takeMsgs(self):
|
|
||||||
"""Returns a list of messages sent by the protocol module since
|
|
||||||
the last takeMsgs() call, so we can track what has been sent."""
|
|
||||||
msgs = self.messages
|
|
||||||
self.messages = []
|
|
||||||
return msgs
|
|
||||||
|
|
||||||
def takeCommands(self, msgs):
|
|
||||||
"""Returns a list of commands parsed from the output of takeMsgs()."""
|
|
||||||
sidprefix = ':' + self.sid
|
|
||||||
commands = []
|
|
||||||
for m in msgs:
|
|
||||||
args = m.split()
|
|
||||||
if m.startswith(sidprefix):
|
|
||||||
commands.append(args[1])
|
|
||||||
else:
|
|
||||||
commands.append(args[0])
|
|
||||||
return commands
|
|
||||||
|
|
||||||
def takeHooks(self):
|
|
||||||
"""Returns a list of hook arguments sent by the protocol module since
|
|
||||||
the last takeHooks() call."""
|
|
||||||
hookmsgs = self.hookmsgs
|
|
||||||
self.hookmsgs = []
|
|
||||||
return hookmsgs
|
|
||||||
|
|
||||||
class FakeProto(Protocol):
|
|
||||||
"""Dummy protocol module for testing purposes."""
|
|
||||||
def handle_events(self, data):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def connect(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def spawnClient(self, nick, *args, **kwargs):
|
|
||||||
uid = str(randint(1, 10000000000))
|
|
||||||
ts = int(time.time())
|
|
||||||
self.irc.users[uid] = user = IrcUser(nick, ts, uid)
|
|
||||||
return user
|
|
||||||
|
|
||||||
def join(self, client, channel):
|
|
||||||
self.irc.channels[channel].users.add(client)
|
|
||||||
self.irc.users[client].channels.add(channel)
|
|
||||||
|
|
||||||
FakeProto.Class = FakeProto
|
|
||||||
|
Loading…
Reference in New Issue
Block a user