From e491e14bc30d911ecc15839fe8632568980b7554 Mon Sep 17 00:00:00 2001 From: nyuszika7h Date: Sun, 3 Feb 2013 18:50:20 +0100 Subject: [PATCH] Final fix for SASL and py3k --- src/irclib.py | 22 ++++++++++++++++------ src/ircutils.py | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/irclib.py b/src/irclib.py index d048753ab..1d31faa20 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -887,8 +887,16 @@ class Irc(IrcCommandDispatcher): self.ident = conf.supybot.ident() self.alternateNicks = conf.supybot.nick.alternates()[:] self.password = conf.supybot.networks.get(self.network).password() - self.sasl_username = conf.supybot.networks.get(self.network).sasl.username() - self.sasl_password = conf.supybot.networks.get(self.network).sasl.password() + self.sasl_username = \ + conf.supybot.networks.get(self.network).sasl.username() + # TODO Find a better way to fix this + if hasattr(self.sasl_username, 'decode'): + self.sasl_username = self.sasl_username.decode('utf-8') + self.sasl_password = \ + conf.supybot.networks.get(self.network).sasl.password() + # TODO Find a better way to fix this + if hasattr(self.sasl_password, 'decode'): + self.sasl_password = self.sasl_password.decode('utf-8') self.prefix = '%s!%s@%s' % (self.nick, self.ident, 'unset.domain') # The rest. self.lastTake = 0 @@ -897,6 +905,7 @@ class Irc(IrcCommandDispatcher): self.lastping = time.time() self.outstandingPing = False + def _queueConnectMessages(self): if self.zombie: self.driver.die() @@ -906,10 +915,11 @@ class Irc(IrcCommandDispatcher): if not self.sasl_username: log.error('SASL username is not set, unable to identify.') else: - auth_string = base64.b64encode(('%s\x00%s\x00%s' % - (self.sasl_username, self.sasl_username, - self.sasl_password)).encode('utf-8')).decode( - 'utf-8') + auth_string = base64.b64encode('\x00'.join([ + self.sasl_username, + self.sasl_username, + self.sasl_password + ]).encode('utf-8')).decode('utf-8') log.debug('Sending CAP REQ command, requesting capability \'sasl\'.') self.queueMsg(ircmsgs.IrcMsg(command="CAP", args=('REQ', 'sasl'))) log.debug('Sending AUTHENTICATE command, using mechanism PLAIN.') diff --git a/src/ircutils.py b/src/ircutils.py index fa340458e..abb6f69f0 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -461,6 +461,7 @@ def wrap(s, length, break_on_hyphens = False, break_long_words = False): def isValidArgument(s): """Returns whether s is strictly a valid argument for an IRC message.""" + return '\r' not in s and '\n' not in s and '\x00' not in s def safeArgument(s):