Make chardet a non-optional dependency in 1.2.x
This commit is contained in:
parent
629b239739
commit
bbdcf7534c
|
@ -37,6 +37,8 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
import chardet
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from hashlib import sha1 as sha
|
from hashlib import sha1 as sha
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -60,12 +62,7 @@ def decode_string(s, encoding="utf8"):
|
||||||
try:
|
try:
|
||||||
s = s.decode(encoding).encode("utf8")
|
s = s.decode(encoding).encode("utf8")
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
try:
|
s = s.decode(chardet.detect(s)["encoding"]).encode("utf8")
|
||||||
import chardet
|
|
||||||
except ImportError:
|
|
||||||
s = s.decode(encoding, "replace").encode("utf8")
|
|
||||||
else:
|
|
||||||
s = s.decode(chardet.detect(s)["encoding"]).encode("utf8")
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
class TorrentInfo(object):
|
class TorrentInfo(object):
|
||||||
|
|
Loading…
Reference in New Issue