1######################## BEGIN LICENSE BLOCK ########################
2# The Original Code is Mozilla Universal charset detector code.
3#
4# The Initial Developer of the Original Code is
5# Netscape Communications Corporation.
6# Portions created by the Initial Developer are Copyright (C) 2001
7# the Initial Developer. All Rights Reserved.
8#
9# Contributor(s):
10# Mark Pilgrim - port to Python
11# Shy Shalom - original C code
12#
13# This library is free software; you can redistribute it and/or
14# modify it under the terms of the GNU Lesser General Public
15# License as published by the Free Software Foundation; either
16# version 2.1 of the License, or (at your option) any later version.
17#
18# This library is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# Lesser General Public License for more details.
22#
23# You should have received a copy of the GNU Lesser General Public
24# License along with this library; if not, see
25# <https://www.gnu.org/licenses/>.
26######################### END LICENSE BLOCK #########################
27
28from .charsetgroupprober import CharSetGroupProber
29from .hebrewprober import HebrewProber
30from .langbulgarianmodel import ISO_8859_5_BULGARIAN_MODEL, WINDOWS_1251_BULGARIAN_MODEL
31from .langgreekmodel import ISO_8859_7_GREEK_MODEL, WINDOWS_1253_GREEK_MODEL
32from .langhebrewmodel import WINDOWS_1255_HEBREW_MODEL
33
34# from .langhungarianmodel import (ISO_8859_2_HUNGARIAN_MODEL,
35# WINDOWS_1250_HUNGARIAN_MODEL)
36from .langrussianmodel import (
37 IBM855_RUSSIAN_MODEL,
38 IBM866_RUSSIAN_MODEL,
39 ISO_8859_5_RUSSIAN_MODEL,
40 KOI8_R_RUSSIAN_MODEL,
41 MACCYRILLIC_RUSSIAN_MODEL,
42 WINDOWS_1251_RUSSIAN_MODEL,
43)
44from .langthaimodel import TIS_620_THAI_MODEL
45from .langturkishmodel import ISO_8859_9_TURKISH_MODEL
46from .sbcharsetprober import SingleByteCharSetProber
47
48
49class SBCSGroupProber(CharSetGroupProber):
50 def __init__(self) -> None:
51 super().__init__()
52 hebrew_prober = HebrewProber()
53 logical_hebrew_prober = SingleByteCharSetProber(
54 WINDOWS_1255_HEBREW_MODEL, is_reversed=False, name_prober=hebrew_prober
55 )
56 # TODO: See if using ISO-8859-8 Hebrew model works better here, since
57 # it's actually the visual one
58 visual_hebrew_prober = SingleByteCharSetProber(
59 WINDOWS_1255_HEBREW_MODEL, is_reversed=True, name_prober=hebrew_prober
60 )
61 hebrew_prober.set_model_probers(logical_hebrew_prober, visual_hebrew_prober)
62 # TODO: ORDER MATTERS HERE. I changed the order vs what was in master
63 # and several tests failed that did not before. Some thought
64 # should be put into the ordering, and we should consider making
65 # order not matter here, because that is very counter-intuitive.
66 self.probers = [
67 SingleByteCharSetProber(WINDOWS_1251_RUSSIAN_MODEL),
68 SingleByteCharSetProber(KOI8_R_RUSSIAN_MODEL),
69 SingleByteCharSetProber(ISO_8859_5_RUSSIAN_MODEL),
70 SingleByteCharSetProber(MACCYRILLIC_RUSSIAN_MODEL),
71 SingleByteCharSetProber(IBM866_RUSSIAN_MODEL),
72 SingleByteCharSetProber(IBM855_RUSSIAN_MODEL),
73 SingleByteCharSetProber(ISO_8859_7_GREEK_MODEL),
74 SingleByteCharSetProber(WINDOWS_1253_GREEK_MODEL),
75 SingleByteCharSetProber(ISO_8859_5_BULGARIAN_MODEL),
76 SingleByteCharSetProber(WINDOWS_1251_BULGARIAN_MODEL),
77 # TODO: Restore Hungarian encodings (iso-8859-2 and windows-1250)
78 # after we retrain model.
79 # SingleByteCharSetProber(ISO_8859_2_HUNGARIAN_MODEL),
80 # SingleByteCharSetProber(WINDOWS_1250_HUNGARIAN_MODEL),
81 SingleByteCharSetProber(TIS_620_THAI_MODEL),
82 SingleByteCharSetProber(ISO_8859_9_TURKISH_MODEL),
83 hebrew_prober,
84 logical_hebrew_prober,
85 visual_hebrew_prober,
86 ]
87 self.reset()