mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-10 12:59:22 +01:00
Merge pull request #476 from carstene1ns/master
Switch from chardet to charade
This commit is contained in:
commit
c39cc4a6b5
@ -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
|
||||
|
@ -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,7 +215,7 @@ 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')
|
||||
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user