# HG changeset patch # User Charly COSTE # Date 1251405107 -7200 # Node ID b048c4c03b00998c45beca47cc5b6c050b85c75f # Parent c09f9523fe2e75e8744c5ebf988dc665ce77cbd4 Fixed encoding issues Signed-off-by: Charly COSTE diff --git a/bot.py b/bot.py --- a/bot.py +++ b/bot.py @@ -267,7 +267,7 @@ class bot(Thread): # A string representation of the event - event_str = '==> Debug: Received IRC event.\nconnection='+str(connection)+'\neventtype='+event.eventtype()+'\nsource='+str(event.source())+'\ntarget='+str(event.target())+'\narguments='+str(event.arguments()) + event_str = '==> Debug: Received IRC event.\nconnection='+connection.__str__()+'\neventtype='+event.eventtype()+'\nsource='+auto_decode(event.source().__str__())+'\ntarget='+auto_decode(event.target().__str__())+'\narguments='+auto_decode(event.arguments().__str__()) if event.eventtype() in ['pubmsg', 'action', 'privmsg', 'quit', 'part', 'nick', 'kick']: diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -235,7 +235,7 @@ class bridge: if on_xmpp == True: self.xmpp_room.say(message) if on_irc == True: - self.irc_connection.privmsg(self.irc_room, auto_encode(message)) + self.irc_connection.privmsg(self.irc_room, message) def switchFromLimitedToNormalMode(self): diff --git a/irclib.py b/irclib.py --- a/irclib.py +++ b/irclib.py @@ -431,7 +431,7 @@ class ServerConnection(Connection): if self.connected == True: self.used_by += 1 - self.irclibobj.bot.error('===> Debug: using existing IRC connection for '+str(self)+', this connection is now used by '+str(self.used_by)+' bridges', debug=True) + self.irclibobj.bot.error('===> Debug: using existing IRC connection for '+self.__str__()+', this connection is now used by '+str(self.used_by)+' bridges', debug=True) self.nick(self.real_nickname, callback=nick_callback) self.lock.release() return self @@ -449,7 +449,7 @@ class ServerConnection(Connection): self.localport = localport self.localhost = socket.gethostname() - self.irclibobj.bot.error('===> Debug: opening new IRC connection for '+str(self), debug=True) + self.irclibobj.bot.error('===> Debug: opening new IRC connection for '+self.__str__(), debug=True) if ipv6: self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) @@ -471,8 +471,8 @@ class ServerConnection(Connection): # Log on... if self.password: self.pass_(self.password) - self.nick(self.nickname, callback=nick_callback) - self.user(self.username, self.ircname) + if self.nick(self.nickname, callback=nick_callback) == True: + self.user(self.username, self.ircname) self.lock.release() return self @@ -484,9 +484,9 @@ class ServerConnection(Connection): f(error, arguments=arguments) self.nick_callbacks = [] if i == 0: - self.irclibobj.bot.error('=> Debug: no nick callback for "'+str(self)+'"', debug=True) + self.irclibobj.bot.error('=> Debug: no nick callback for "'+self.__str__()+'"', debug=True) else: - self.irclibobj.bot.error('=> Debug: called '+str(i)+' callback(s) for "'+str(self)+'"', debug=True) + self.irclibobj.bot.error('=> Debug: called '+str(i)+' callback(s) for "'+self.__str__()+'"', debug=True) def add_nick_callback(self, callback): @@ -779,8 +779,14 @@ class ServerConnection(Connection): self.add_nick_callback(callback) if ' ' in newnick: self._call_nick_callbacks('erroneusnickname') - return + return False + try: + str(newnick) + except: + self._call_nick_callbacks('erroneusnickname') + return False self.send_raw("NICK " + newnick) + return True def notice(self, target, text): """Send a NOTICE command.""" @@ -833,14 +839,13 @@ class ServerConnection(Connection): The string will be padded with appropriate CR LF. """ - from encoding import * if self.socket is None: raise ServerNotConnectedError, "Not connected." try: if self.ssl: - self.ssl.write(auto_encode(string) + "\r\n") + self.ssl.write(string.encode('utf-8') + "\r\n") else: - self.socket.send(auto_encode(string) + "\r\n") + self.socket.send(string.encode('utf-8') + "\r\n") if DEBUG: print "TO SERVER:", string except socket.error, x: diff --git a/participant.py b/participant.py --- a/participant.py +++ b/participant.py @@ -69,7 +69,8 @@ class participant: sleep(1) # try to prevent "reconnecting too fast" shit self.irc_connection = self.bridge.bot.irc.server(self.bridge.irc_server, self.bridge.irc_port, self.nickname) self.irc_connection.connect(nick_callback=self._irc_nick_callback) - self.irc_connection.join(self.bridge.irc_room) + if self.irc_connection != None: + self.irc_connection.join(self.bridge.irc_room) def _irc_nick_callback(self, error, arguments=[]):