Mon, 16 Jun 2014 23:12:13 +0300
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
cobalt.py | file | annotate | diff | comparison | revisions |
--- a/cobalt.py Mon Jun 16 00:14:56 2014 +0300 +++ b/cobalt.py Mon Jun 16 23:12:13 2014 +0300 @@ -220,8 +220,11 @@ print "Connected to [%s] %s:%d" % (self.name, self.host, self.port) self.register_to_irc() - def write (self, data): - self.send_buffer.append ("%s" % data) + def write (self, utfdata): + try: + self.send_buffer.append ("%s" % utfdata.decode("utf-8","ignore").encode("ascii","ignore")) + except UnicodeEncodeError: + pass def handle_close (self): print "Connection to [%s] %s:%d terminated." % (self.name, self.host, self.port) @@ -247,7 +250,7 @@ lines = self.recv (4096).splitlines() for utfline in lines: try: - line = utfline.decode("utf-8").encode("ascii","ignore") + line = utfline.decode("utf-8","ignore").encode("ascii","ignore") except UnicodeDecodeError: continue