renewed cchardet.detect().

This commit is contained in:
PyYoshi 2012-07-07 13:08:42 +09:00
parent 4b07638a73
commit 8588d1fd1e
3 changed files with 48 additions and 61 deletions

View file

@ -69,8 +69,6 @@ import cchardet
msg = file(r"test/testdata/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt").read() msg = file(r"test/testdata/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt").read()
result = cchardet.detect(msg) result = cchardet.detect(msg)
print(result) print(result)
result2 = cchardet.detect_with_confidence(msg)
print(result2)
``` ```
# Test # Test

View file

@ -4,17 +4,6 @@
from cchardet import _cchardet from cchardet import _cchardet
def detect(msg): def detect(msg):
"""
Args:
msg: str
Returns:
charset: str
Warnings:
UserWarning
"""
return _cchardet.detect(msg)
def detect_with_confidence(msg):
""" """
Args: Args:
msg: str msg: str

View file

@ -48,7 +48,7 @@ class TestCchardet():
encoding = "ISO-8859-5" encoding = "ISO-8859-5"
path = r"testdata/bg/ISO-8859-5/wikitop_bg_ISO-8859-5.txt" path = r"testdata/bg/ISO-8859-5/wikitop_bg_ISO-8859-5.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -56,7 +56,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/bg/UTF-8/wikitop_bg_UTF-8.txt" path = r"testdata/bg/UTF-8/wikitop_bg_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -64,7 +64,7 @@ class TestCchardet():
encoding = "WINDOWS-1251" encoding = "WINDOWS-1251"
path = r"testdata/bg/WINDOWS-1251/wikitop_bg_WINDOWS-1251.txt" path = r"testdata/bg/WINDOWS-1251/wikitop_bg_WINDOWS-1251.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -72,7 +72,7 @@ class TestCchardet():
encoding = "ISO-8859-2" encoding = "ISO-8859-2"
path = r"testdata/cz/ISO-8859-2/wikitop_cz_ISO-8859-2.txt" path = r"testdata/cz/ISO-8859-2/wikitop_cz_ISO-8859-2.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -80,7 +80,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/cz/UTF-8/wikitop_cz_UTF-8.txt" path = r"testdata/cz/UTF-8/wikitop_cz_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -88,7 +88,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/de/UTF-8/wikitop_de_UTF-8.txt" path = r"testdata/de/UTF-8/wikitop_de_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -96,7 +96,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/de/WINDOWS-1252/wikitop_de_WINDOWS-1252.txt" path = r"testdata/de/WINDOWS-1252/wikitop_de_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -104,7 +104,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/dk/UTF-8/wikitop_dk_UTF-8.txt" path = r"testdata/dk/UTF-8/wikitop_dk_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -112,7 +112,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/dk/WINDOWS-1252/wikitop_dk_WINDOWS-1252.txt" path = r"testdata/dk/WINDOWS-1252/wikitop_dk_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -120,7 +120,7 @@ class TestCchardet():
encoding = "ISO-8859-7" encoding = "ISO-8859-7"
path = r"testdata/el/ISO-8859-7/wikitop_el_ISO-8859-7.txt" path = r"testdata/el/ISO-8859-7/wikitop_el_ISO-8859-7.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -128,7 +128,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/el/UTF-8/wikitop_el_UTF-8.txt" path = r"testdata/el/UTF-8/wikitop_el_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -136,7 +136,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/en/UTF-8/wikitop_en_UTF-8.txt" path = r"testdata/en/UTF-8/wikitop_en_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -144,7 +144,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/en/WINDOWS-1252/wikitop_en_WINDOWS-1252.txt" path = r"testdata/en/WINDOWS-1252/wikitop_en_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -152,7 +152,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/es/UTF-8/wikitop_es_UTF-8.txt" path = r"testdata/es/UTF-8/wikitop_es_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -160,7 +160,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/es/WINDOWS-1252/wikitop_es_WINDOWS-1252.txt" path = r"testdata/es/WINDOWS-1252/wikitop_es_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -168,7 +168,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/fi/UTF-8/wikitop_fi_UTF-8.txt" path = r"testdata/fi/UTF-8/wikitop_fi_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -176,7 +176,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/fi/WINDOWS-1252/wikitop_fi_WINDOWS-1252.txt" path = r"testdata/fi/WINDOWS-1252/wikitop_fi_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -184,7 +184,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/fr/UTF-8/wikitop_fr_UTF-8.txt" path = r"testdata/fr/UTF-8/wikitop_fr_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -192,7 +192,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/fr/WINDOWS-1252/wikitop_fr_WINDOWS-1252.txt" path = r"testdata/fr/WINDOWS-1252/wikitop_fr_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -200,7 +200,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/he/UTF-8/wikitop_he_UTF-8.txt" path = r"testdata/he/UTF-8/wikitop_he_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -208,7 +208,7 @@ class TestCchardet():
encoding = "WINDOWS-1255" encoding = "WINDOWS-1255"
path = r"testdata/he/WINDOWS-1255/wikitop_he_WINDOWS-1255.txt" path = r"testdata/he/WINDOWS-1255/wikitop_he_WINDOWS-1255.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -216,7 +216,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/hu/UTF-8/wikitop_hu_UTF-8.txt" path = r"testdata/hu/UTF-8/wikitop_hu_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -224,7 +224,7 @@ class TestCchardet():
encoding = "ISO-8859-2" encoding = "ISO-8859-2"
path = r"testdata/hu/ISO-8859-2/wikitop_hu_ISO-8859-2.txt" path = r"testdata/hu/ISO-8859-2/wikitop_hu_ISO-8859-2.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -232,7 +232,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/it/UTF-8/wikitop_it_UTF-8.txt" path = r"testdata/it/UTF-8/wikitop_it_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -240,7 +240,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/it/WINDOWS-1252/wikitop_it_WINDOWS-1252.txt" path = r"testdata/it/WINDOWS-1252/wikitop_it_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -248,7 +248,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/nl/UTF-8/wikitop_nl_UTF-8.txt" path = r"testdata/nl/UTF-8/wikitop_nl_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -256,7 +256,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/nl/WINDOWS-1252/wikitop_nl_WINDOWS-1252.txt" path = r"testdata/nl/WINDOWS-1252/wikitop_nl_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -264,7 +264,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/no/UTF-8/wikitop_no_UTF-8.txt" path = r"testdata/no/UTF-8/wikitop_no_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -272,7 +272,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/no/WINDOWS-1252/wikitop_no_WINDOWS-1252.txt" path = r"testdata/no/WINDOWS-1252/wikitop_no_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -280,7 +280,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/pl/UTF-8/wikitop_pl_UTF-8.txt" path = r"testdata/pl/UTF-8/wikitop_pl_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -288,7 +288,7 @@ class TestCchardet():
encoding = "ISO-8859-2" encoding = "ISO-8859-2"
path = r"testdata/pl/ISO-8859-2/wikitop_pl_ISO-8859-2.txt" path = r"testdata/pl/ISO-8859-2/wikitop_pl_ISO-8859-2.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -296,7 +296,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/pt/UTF-8/wikitop_pt_UTF-8.txt" path = r"testdata/pt/UTF-8/wikitop_pt_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -304,7 +304,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/pt/WINDOWS-1252/wikitop_pt_WINDOWS-1252.txt" path = r"testdata/pt/WINDOWS-1252/wikitop_pt_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -312,7 +312,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/ru/UTF-8/wikitop_ru_UTF-8.txt" path = r"testdata/ru/UTF-8/wikitop_ru_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -320,7 +320,7 @@ class TestCchardet():
encoding = "WINDOWS-1251" encoding = "WINDOWS-1251"
path = r"testdata/ru/WINDOWS-1251/wikitop_ru_WINDOWS-1251.txt" path = r"testdata/ru/WINDOWS-1251/wikitop_ru_WINDOWS-1251.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -328,7 +328,7 @@ class TestCchardet():
encoding = "IBM855" encoding = "IBM855"
path = r"testdata/ru/IBM855/wikitop_ru_IBM855.txt" path = r"testdata/ru/IBM855/wikitop_ru_IBM855.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -336,7 +336,7 @@ class TestCchardet():
encoding = "KOI8-R" encoding = "KOI8-R"
path = r"testdata/ru/KOI8-R/wikitop_ru_KOI8-R.txt" path = r"testdata/ru/KOI8-R/wikitop_ru_KOI8-R.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -344,7 +344,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/se/UTF-8/wikitop_se_UTF-8.txt" path = r"testdata/se/UTF-8/wikitop_se_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -352,7 +352,7 @@ class TestCchardet():
encoding = "WINDOWS-1252" encoding = "WINDOWS-1252"
path = r"testdata/se/WINDOWS-1252/wikitop_se_WINDOWS-1252.txt" path = r"testdata/se/WINDOWS-1252/wikitop_se_WINDOWS-1252.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -360,7 +360,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/th/UTF-8/wikitop_th_UTF-8.txt" path = r"testdata/th/UTF-8/wikitop_th_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -368,7 +368,7 @@ class TestCchardet():
encoding = "TIS-620" encoding = "TIS-620"
path = r"testdata/th/TIS-620/utffool_th_TIS-620.txt" path = r"testdata/th/TIS-620/utffool_th_TIS-620.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -376,7 +376,7 @@ class TestCchardet():
encoding = "TIS-620" encoding = "TIS-620"
path = r"testdata/th/TIS-620/wikitop_th_TIS-620.txt" path = r"testdata/th/TIS-620/wikitop_th_TIS-620.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -384,7 +384,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/tr/UTF-8/wikitop_tr_UTF-8.txt" path = r"testdata/tr/UTF-8/wikitop_tr_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -392,7 +392,7 @@ class TestCchardet():
encoding = "ISO-8859-9" encoding = "ISO-8859-9"
path = r"testdata/tr/ISO-8859-9/wikitop_tr_ISO-8859-9.txt" path = r"testdata/tr/ISO-8859-9/wikitop_tr_ISO-8859-9.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -400,7 +400,7 @@ class TestCchardet():
encoding = "UTF-8" encoding = "UTF-8"
path = r"testdata/zh/UTF-8/wikitop_zh_UTF-8.txt" path = r"testdata/zh/UTF-8/wikitop_zh_UTF-8.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -408,7 +408,7 @@ class TestCchardet():
encoding = "GB18030" encoding = "GB18030"
path = r"testdata/zh/GB18030/wikitop_zh_GB18030.txt" path = r"testdata/zh/GB18030/wikitop_zh_GB18030.txt"
msg =file(path).read() msg =file(path).read()
detected_encoding = cchardet.detect_with_confidence(msg) detected_encoding = cchardet.detect(msg)
print(detected_encoding) print(detected_encoding)
eq_(encoding.lower(),detected_encoding['encoding'].lower()) eq_(encoding.lower(),detected_encoding['encoding'].lower())
@ -424,7 +424,7 @@ class TestCchardetSpeed():
end_chardet = time.time() end_chardet = time.time()
# Test cchardet # Test cchardet
start_cchardet = time.time() start_cchardet = time.time()
detected_encoding_cchardet = cchardet.detect_with_confidence(msg) detected_encoding_cchardet = cchardet.detect(msg)
end_cchardet = time.time() end_cchardet = time.time()
# print result # print result
result_chardet = end_chardet - start_chardet result_chardet = end_chardet - start_chardet