Merge pull request #476 from carstene1ns/master

Switch from chardet to charade
This commit is contained in:
Valentin Lorentz 2013-06-27 11:16:09 -07:00
commit c39cc4a6b5
3 changed files with 11 additions and 11 deletions

View File

@ -7,7 +7,7 @@ python:
- "pypy"
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
- pip install pytz feedparser chardet --use-mirrors
- pip install pytz feedparser charade --use-mirrors
# command to run tests, e.g. python setup.py test
script:
- echo $TRAVIS_PYTHON_VERSION

View File

@ -46,13 +46,13 @@ import supybot.drivers as drivers
import supybot.schedule as schedule
from itertools import imap
try:
from chardet.universaldetector import UniversalDetector
chardetLoaded = True
from charade.universaldetector import UniversalDetector
charadeLoaded = True
except:
drivers.log.debug('chardet module not available, '
drivers.log.debug('charade module not available, '
'cannot guess character encoding if'
'using Python3')
chardetLoaded = False
charadeLoaded = False
try:
import ssl
SSLError = ssl.SSLError
@ -198,8 +198,8 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
try:
line = line.decode('utf8', 'strict')
except UnicodeError:
# if this fails and chardet is loaded, try to guess the correct encoding
if chardetLoaded:
# if this fails and charade is loaded, try to guess the correct encoding
if charadeLoaded:
u = UniversalDetector()
u.feed(line)
u.close()
@ -215,11 +215,11 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
# if no encoding could be guessed, fall back to utf-8 and
# replace offending characters
line = line.decode('utf8', 'replace')
# if chardet is not loaded, try to decode using utf-8 and replace any
# if charade is not loaded, try to decode using utf-8 and replace any
# offending characters
else:
line = line.decode('utf8', 'replace')
msg = drivers.parseMsg(line)
if msg is not None:
self.irc.feedMsg(msg)

View File

@ -195,8 +195,8 @@ def htmlToText(s, tagReplace=' '):
"""Turns HTML into text. tagReplace is a string to replace HTML tags with.
"""
try:
import chardet.universaldetector
u = chardet.universaldetector.UniversalDetector()
import charade.universaldetector
u = charade.universaldetector.UniversalDetector()
u.feed(s)
u.close()
s = s.decode(u.result['encoding'])