Made assertions more useful.

This commit is contained in:
Jeremy Fincher 2003-04-14 05:13:21 +00:00
parent 18d9d5923d
commit e3e7ce4625

View File

@ -221,72 +221,85 @@ def ping(payload, prefix=''):
def op(channel, nick, prefix=''):
"""Returns a MODE to op nick on channel."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+o', nick))
def ops(channel, nicks, prefix=''):
"""Returns a MODE to op each of nicks on channel."""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks, nicks
return IrcMsg(prefix=prefix, command=MODE,
args=(channel, '+' + ('o'*len(nicks)), nicks))
def deop(channel, nick, prefix=''):
"""Returns a MODE to deop nick on channel."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-o', nick))
def deops(channel, nicks, prefix=''):
"""Returns a MODE to deop each of nicks on channel."""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks, nicks
return IrcMsg(prefix=prefix, command=MODE,
args=(channel, '-' + ('o'*len(nicks)), nicks))
def halfop(channel, nick, prefix=''):
"""Returns a MODE to halfop nick on channel."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+h', nick))
def halfops(channel, nicks, prefix=''):
"""Returns a MODE to halfop each of nicks on channel."""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks, nicks
return IrcMsg(command=MODE, args=(channel, '+' + ('h'*len(nicks)), nicks))
def dehalfop(channel, nick, prefix=''):
"""Returns a MODE to dehalfop nick on channel."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-h', nick))
def dehalfops(channel, nicks, prefix=''):
"""Returns a MODE to dehalfop each of nicks on channel."""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks, nicks
return IrcMsg(prefix=prefix, command=MODE,
args=(channel, '-' + ('h'*len(nicks)), nicks))
def voice(channel, nick, prefix=''):
"""Returns a MODE to voice nick on channel."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '+v', nick))
def voices(channel, nicks, prefix=''):
"""Returns a MODE to voice each of nicks on channel."""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks
return IrcMsg(prefix=prefix, command=MODE,
args=(channel, '+' + ('v'*len(nicks)), nicks))
def devoice(channel, nick, prefix=''):
"""Returns a MODE to devoice nick on channel."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-v', nick))
def devoices(channel, nicks, prefix=''):
"""Returns a MODE to devoice each of nicks on channel."""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks, nicks
return IrcMsg(prefix=prefix, command=MODE,
args=(channel, '-' + ('v'*len(nicks)), nicks))
def ban(channel, hostmask, exception='', prefix=''):
"""Returns a MODE to ban nick on channel."""
assert isChannel(channel) and isUserHostmask(hostmask)
assert isChannel(channel), channel
assert isUserHostmask(hostmask), hostmask
modes = [('+b', hostmask)]
if exception:
modes.append(('+e', exception))
@ -295,25 +308,29 @@ def ban(channel, hostmask, exception='', prefix=''):
def bans(channel, hostmasks, exceptions=(), prefix=''):
"""Returns a MODE to ban each of nicks on channel."""
assert filter(isUserHostmask, hostmasks) == hostmasks
assert isChannel(channel), channel
assert filter(isUserHostmask, hostmasks) == hostmasks, hostmasks
modes = [('+b', s) for s in hostmasks] + [('+e', s) for s in exceptions]
return IrcMsg(prefix=prefix, command=MODE,
args=[channel] + ircutils.joinModes(modes))
def unban(channel, hostmask, prefix=''):
"""Returns a MODE to unban nick on channel."""
assert isChannel(channel) and isUserHostmask(hostmask)
assert isChannel(channel), channel
assert isUserHostmask(hostmask), hostmask
return IrcMsg(prefix=prefix, command=MODE, args=(channel, '-b', hostmask))
def unbans(channel, hostmasks, prefix=''):
"""Returns a MODE to unban each of nicks on channel."""
assert isChannel(channel) and filter(isUserHostmask, hostmasks) ==hostmasks
assert isChannel(channel), channel
assert filter(isUserHostmask, hostmasks) == hostmasks, hostmasks
return IrcMsg(prefix=prefix, command=MODE,
args=(channel, '-' + ('b'*len(hostmasks)), hostmasks))
def kick(channel, nick, msg='', prefix=''):
"""Returns a KICK to kick nick from channel with the message msg."""
assert isChannel(channel) and isNick(nick)
assert isChannel(channel), channel
assert isNick(nick), nick
if msg:
return IrcMsg(prefix=prefix, command='KICK', args=(channel, nick, msg))
else:
@ -322,7 +339,8 @@ def kick(channel, nick, msg='', prefix=''):
def kicks(channel, nicks, msg='', prefix=''):
"""Returns a KICK to kick each of nicks from channel with the message msg.
"""
assert isChannel(channel) and filter(isNick, nicks) == nicks
assert isChannel(channel), channel
assert filter(isNick, nicks) == nicks, nicks
if msg:
return IrcMsg(prefix=prefix, command='KICK',
args=(channel, ','.join(nicks), msg))
@ -332,23 +350,26 @@ def kicks(channel, nicks, msg='', prefix=''):
def privmsg(recipient, msg, prefix=''):
"""Returns a PRIVMSG to recipient with the message msg."""
assert (isChannel(recipient) or isNick(recipient)) and msg
assert (isChannel(recipient) or isNick(recipient)), recipient
assert msg, 'msg must not be empty.'
return IrcMsg(prefix=prefix, command='PRIVMSG', args=(recipient, msg))
def action(recipient, msg, prefix=''):
"""Returns a PRIVMSG ACTION to recipient with the message msg."""
assert (isChannel(recipient) or isNick(recipient)) and msg
assert (isChannel(recipient) or isNick(recipient)), recipient
assert msg, 'msg must not be empty.'
return IrcMsg(prefix=prefix, command='PRIVMSG',
args=(recipient,'\x01ACTION %s\x01'% msg))
def notice(recipient, msg, prefix=''):
"""Returns a NOTICE to recipient with the message msg."""
assert (isChannel(recipient) or isNick(recipient)) and msg
assert (isChannel(recipient) or isNick(recipient)), recipient
assert msg, 'msg must not be empty.'
return IrcMsg(prefix=prefix, command='NOTICE', args=(recipient, msg))
def join(channel, key=None, prefix=''):
"""Returns a JOIN to a channel"""
assert isChannel(channel)
assert isChannel(channel), channel
if key is None:
return IrcMsg(prefix=prefix, command='JOIN', args=(channel,))
else:
@ -356,7 +377,7 @@ def join(channel, key=None, prefix=''):
def joins(channels, keys=None, prefix=''):
"""Returns a JOIN to each of channels."""
assert filter(isChannel, channels) == channels
assert filter(isChannel, channels) == channels, channels
if keys is None:
keys = []
assert len(keys) <= len(channels)
@ -371,7 +392,7 @@ def joins(channels, keys=None, prefix=''):
def part(channel, msg='', prefix=''):
"""Returns a PART from channel with the message msg."""
assert isChannel(channel)
assert isChannel(channel), channel
if msg:
return IrcMsg(prefix=prefix, command='PART', args=(channel, msg))
else:
@ -379,7 +400,7 @@ def part(channel, msg='', prefix=''):
def parts(channels, msg='', prefix=''):
"""Returns a PART from each of channels with the message msg."""
assert filter(isChannel, channels) == channels
assert filter(isChannel, channels) == channels, channels
if msg:
return IrcMsg(prefix=prefix, command='PART',
args=(','.join(channels), msg,))
@ -396,12 +417,12 @@ def quit(msg='', prefix=''):
def topic(channel, topic, prefix=''):
"""Returns a TOPIC for channel with the topic topic."""
assert isChannel(channel)
assert isChannel(channel), channel
return IrcMsg(prefix=prefix, command='TOPIC', args=(channel, topic))
def nick(nick, prefix=''):
"""Returns a NICK with nick nick."""
assert isNick(nick)
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command='NICK', args=(nick,))
def user(ident, user, prefix=''):
@ -410,20 +431,22 @@ def user(ident, user, prefix=''):
def who(hostmaskOrChannel, prefix=''):
"""Returns a WHO for the hostmask or channel hostmaskOrChannel."""
assert isChannel(hostmaskOrChannel) or isUserHostmask(hostmaskOrChannel)
assert isChannel(hostmaskOrChannel) or isUserHostmask(hostmaskOrChannel), \
hostmaskOrChannel
return IrcMsg(prefix=prefix, command='WHO', args=(hostmaskOrChannel,))
def whois(nick, prefix=''):
"""Returns a WHOIS for nick."""
assert isNick(nick)
assert isNick(nick), nick
return IrcMsg(command='WHOIS', args=(nick,))
def invite(channel, nick, prefix=''):
"""Returns an INVITE for nick."""
assert isNick(nick)
assert isNick(nick), nick
return IrcMsg(prefix=prefix, command='INVITE', args=(channel, nick))
def password(password, prefix=''):
assert password, 'password must not be empty.'
return IrcMsg(prefix=prefix, command='PASS', args=(password,))
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: