Mercurial > xib
changeset 56:b048c4c03b00
Fixed encoding issues
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Thu, 27 Aug 2009 22:31:47 +0200 |
parents | c09f9523fe2e |
children | ebd4278e472f |
files | bot.py bridge.py irclib.py participant.py |
diffstat | 4 files changed, 19 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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']:
--- 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):
--- 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:
--- 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=[]):