Add fallback decoding if chardet fails to guess the correct encoding

This commit is contained in:
Alexander Ralph Michael Minges 2013-01-20 17:07:58 +01:00
parent 4316e5936e
commit bbdd55bea2

View File

@ -208,6 +208,10 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
# on error, give up and replace the offending characters
except UnicodeError:
line = line.decode(errors='replace')
else:
# if no encoding could be guessed, fall back to utf-8 and
# replace offending characters
line = line.decode(encoding='utf-8', errors='replace')
# if chardet is not loaded, try to decode using utf-8 and replace any
# offending characters
else: