mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +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"
|
- "pypy"
|
||||||
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
|
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
|
||||||
install:
|
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
|
# command to run tests, e.g. python setup.py test
|
||||||
script:
|
script:
|
||||||
- echo $TRAVIS_PYTHON_VERSION
|
- echo $TRAVIS_PYTHON_VERSION
|
||||||
|
@ -46,13 +46,13 @@ import supybot.drivers as drivers
|
|||||||
import supybot.schedule as schedule
|
import supybot.schedule as schedule
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
try:
|
try:
|
||||||
from chardet.universaldetector import UniversalDetector
|
from charade.universaldetector import UniversalDetector
|
||||||
chardetLoaded = True
|
charadeLoaded = True
|
||||||
except:
|
except:
|
||||||
drivers.log.debug('chardet module not available, '
|
drivers.log.debug('charade module not available, '
|
||||||
'cannot guess character encoding if'
|
'cannot guess character encoding if'
|
||||||
'using Python3')
|
'using Python3')
|
||||||
chardetLoaded = False
|
charadeLoaded = False
|
||||||
try:
|
try:
|
||||||
import ssl
|
import ssl
|
||||||
SSLError = ssl.SSLError
|
SSLError = ssl.SSLError
|
||||||
@ -198,8 +198,8 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
try:
|
try:
|
||||||
line = line.decode('utf8', 'strict')
|
line = line.decode('utf8', 'strict')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
# if this fails and chardet is loaded, try to guess the correct encoding
|
# if this fails and charade is loaded, try to guess the correct encoding
|
||||||
if chardetLoaded:
|
if charadeLoaded:
|
||||||
u = UniversalDetector()
|
u = UniversalDetector()
|
||||||
u.feed(line)
|
u.feed(line)
|
||||||
u.close()
|
u.close()
|
||||||
@ -215,7 +215,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
# if no encoding could be guessed, fall back to utf-8 and
|
# if no encoding could be guessed, fall back to utf-8 and
|
||||||
# replace offending characters
|
# replace offending characters
|
||||||
line = line.decode('utf8', 'replace')
|
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
|
# offending characters
|
||||||
else:
|
else:
|
||||||
line = line.decode('utf8', 'replace')
|
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.
|
"""Turns HTML into text. tagReplace is a string to replace HTML tags with.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import chardet.universaldetector
|
import charade.universaldetector
|
||||||
u = chardet.universaldetector.UniversalDetector()
|
u = charade.universaldetector.UniversalDetector()
|
||||||
u.feed(s)
|
u.feed(s)
|
||||||
u.close()
|
u.close()
|
||||||
s = s.decode(u.result['encoding'])
|
s = s.decode(u.result['encoding'])
|
||||||
|
Loading…
Reference in New Issue
Block a user