src/ircmsgs.py: Assert string parameters are actually strings.

This prevents a plugin from sending another object and messing with outFilter methods of other plugins.
This commit is contained in:
Valentin Lorentz 2012-10-06 21:12:40 +00:00
parent 40801513ac
commit 364a3e50e8

View File

@ -532,6 +532,7 @@ def kick(channel, nick, s='', prefix='', msg=None):
assert isNick(nick), repr(nick) assert isNick(nick), repr(nick)
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
assert isinstance(s, str)
if s: if s:
return IrcMsg(prefix=prefix, command='KICK', return IrcMsg(prefix=prefix, command='KICK',
args=(channel, nick, s), msg=msg) args=(channel, nick, s), msg=msg)
@ -547,6 +548,7 @@ def kicks(channel, nicks, s='', prefix='', msg=None):
assert all(isNick, nicks), nicks assert all(isNick, nicks), nicks
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
assert isinstance(s, str)
if s: if s:
return IrcMsg(prefix=prefix, command='KICK', return IrcMsg(prefix=prefix, command='KICK',
args=(channel, ','.join(nicks), s), msg=msg) args=(channel, ','.join(nicks), s), msg=msg)
@ -559,6 +561,7 @@ def privmsg(recipient, s, prefix='', msg=None):
if conf.supybot.protocols.irc.strictRfc(): if conf.supybot.protocols.irc.strictRfc():
assert (isChannel(recipient) or isNick(recipient)), repr(recipient) assert (isChannel(recipient) or isNick(recipient)), repr(recipient)
assert s, 's must not be empty.' assert s, 's must not be empty.'
assert isinstance(s, str)
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
return IrcMsg(prefix=prefix, command='PRIVMSG', return IrcMsg(prefix=prefix, command='PRIVMSG',
@ -588,6 +591,7 @@ def notice(recipient, s, prefix='', msg=None):
if conf.supybot.protocols.irc.strictRfc(): if conf.supybot.protocols.irc.strictRfc():
assert (isChannel(recipient) or isNick(recipient)), repr(recipient) assert (isChannel(recipient) or isNick(recipient)), repr(recipient)
assert s, 'msg must not be empty.' assert s, 'msg must not be empty.'
assert isinstance(s, str)
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
return IrcMsg(prefix=prefix, command='NOTICE', args=(recipient, s), msg=msg) return IrcMsg(prefix=prefix, command='NOTICE', args=(recipient, s), msg=msg)
@ -635,6 +639,7 @@ def part(channel, s='', prefix='', msg=None):
assert isChannel(channel), repr(channel) assert isChannel(channel), repr(channel)
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
assert isinstance(s, str)
if s: if s:
return IrcMsg(prefix=prefix, command='PART', return IrcMsg(prefix=prefix, command='PART',
args=(channel, s), msg=msg) args=(channel, s), msg=msg)
@ -648,6 +653,7 @@ def parts(channels, s='', prefix='', msg=None):
assert all(isChannel, channels), channels assert all(isChannel, channels), channels
if msg and not prefix: if msg and not prefix:
prefix = msg.prefix prefix = msg.prefix
assert isinstance(s, str)
if s: if s:
return IrcMsg(prefix=prefix, command='PART', return IrcMsg(prefix=prefix, command='PART',
args=(','.join(channels), s), msg=msg) args=(','.join(channels), s), msg=msg)
@ -674,6 +680,7 @@ def topic(channel, topic=None, prefix='', msg=None):
return IrcMsg(prefix=prefix, command='TOPIC', return IrcMsg(prefix=prefix, command='TOPIC',
args=(channel,), msg=msg) args=(channel,), msg=msg)
else: else:
assert isinstance(topic, str)
return IrcMsg(prefix=prefix, command='TOPIC', return IrcMsg(prefix=prefix, command='TOPIC',
args=(channel, topic), msg=msg) args=(channel, topic), msg=msg)