aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Crama <pcfeb0009@gmx.com>2011-02-08 00:24:37 +0100
committerMiklos Vajna <vmiklos@frugalware.org>2011-02-08 00:24:37 +0100
commit3423be07392acb960fed3e014141ce5df177c06f (patch)
treec3c92a9e4af39211f5fa7db08b1c4dcdcd73c699
parentc899eb01dbe590be257a619a3da577a78c08a8a2 (diff)
Always use UTF-8 encoding when dealing with BitlBee
BitlBee internally always uses UTF-8 (see initialization of irc->iconv and irc->oconv in set_eval_charset in irc.c of BitlBee's source and their usage in eg irc_vawrite in the same file; confirmed on #bitlbee), so it makes no sense to either get an encoding from the current locale or to make it a runtime setting.
-rw-r--r--skype/skyped.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/skype/skyped.py b/skype/skyped.py
index 2730966f..733080f1 100644
--- a/skype/skyped.py
+++ b/skype/skyped.py
@@ -236,12 +236,15 @@ class SkypeApi:
else:
msg_text = [msg_text]
for i in msg_text:
- # use utf-8 here to solve the following problem:
- # people use env vars like LC_ALL=en_US (latin1) then
- # they complain about why can't they receive latin2
- # messages.. so here it is: always use utf-8 then
- # everybody will be happy
- e = i.encode('UTF-8')
+ try:
+ # Internally, BitlBee always uses UTF-8 and encodes/decodes as
+ # necessary to communicate with the IRC client; thus send the
+ # UTF-8 it expects
+ e = i.encode('UTF-8')
+ except:
+ # Should never happen, but it's better to send difficult to
+ # read data than crash because some message couldn't be encoded
+ e = i.encode('ascii', 'backslashreplace')
if options.conn:
dprint('<< ' + e)
try:
@@ -259,12 +262,14 @@ class SkypeApi:
options.last_bitlbee_pong = time.time()
return
try:
- encoding = locale.getdefaultlocale()[1]
- if not encoding:
- raise ValueError
- e = msg_text.decode(encoding)
- except ValueError:
+ # Internally, BitlBee always uses UTF-8 and encodes/decodes as
+ # necessary to communicate with the IRC client; thus decode the
+ # UTF-8 it sent us
e = msg_text.decode('UTF-8')
+ except:
+ # Should never happen, but it's better to send difficult to read
+ # data to Skype than to crash
+ e = msg_text.decode('ascii', 'backslashreplace')
dprint('>> ' + e)
try:
c = self.skype.Command(e, Block=True)