get around occasional utf8 conversion exceptions by swallowing

those exceptions and moving on, since the output never seemed
wrong in these cases anyway
This commit is contained in:
Brian S. Stephan 2010-08-24 13:25:30 -05:00
parent 7dfdf28c19
commit 713b1e560b
2 changed files with 11 additions and 3 deletions

View File

@ -52,9 +52,15 @@ class DrBotServerConnection(irclib.ServerConnection):
self.send_raw("PRIVMSG %s :%s" % (target, unicode(splittext).encode('utf-8')))
# done splitting
self.send_raw("PRIVMSG %s :%s" % (target, unicode(text).encode('utf-8')))
try:
text = unicode(text).encode('utf-8')
except UnicodeDecodeError: pass
self.send_raw("PRIVMSG %s :%s" % (target, text))
else:
self.send_raw("PRIVMSG %s :%s" % (target, unicode(text).encode('utf-8')))
try:
text = unicode(text).encode('utf-8')
except UnicodeDecodeError: pass
self.send_raw("PRIVMSG %s :%s" % (target, text))
class DrBotIRC(irclib.IRC):
"""Subclass irclib's IRC, in order to create a DrBotServerConnection."""

View File

@ -33,7 +33,9 @@ class GoogleTranslate(Module):
fromlang = whats[1]
tolang = whats[2]
text = ' '.join(whats[3:])
text = text.encode('utf-8')
try:
text = text.encode('utf-8')
except UnicodeDecodeError: pass
langpair = '%s|%s' % (fromlang, tolang)
gt_url = 'http://ajax.googleapis.com/ajax/services/language/translate?'