1
######################## BEGIN LICENSE BLOCK ########################
2
# The Original Code is Mozilla Communicator client code.
4
# The Initial Developer of the Original Code is
5
# Netscape Communications Corporation.
6
# Portions created by the Initial Developer are Copyright (C) 1998
7
# the Initial Developer. All Rights Reserved.
10
# Mark Pilgrim - port to Python
12
# This library is free software; you can redistribute it and/or
13
# modify it under the terms of the GNU Lesser General Public
14
# License as published by the Free Software Foundation; either
15
# version 2.1 of the License, or (at your option) any later version.
17
# This library is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
# Lesser General Public License for more details.
22
# You should have received a copy of the GNU Lesser General Public
23
# License along with this library; if not, write to the Free Software
24
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26
######################### END LICENSE BLOCK #########################
28
from . import constants
30
from .charsetprober import CharSetProber
32
class CharSetGroupProber(CharSetProber):
34
CharSetProber.__init__(self)
37
self._mBestGuessProber = None
40
CharSetProber.reset(self)
42
for prober in self._mProbers:
47
self._mBestGuessProber = None
49
def get_charset_name(self):
50
if not self._mBestGuessProber:
52
if not self._mBestGuessProber: return None
53
# self._mBestGuessProber = self._mProbers[0]
54
return self._mBestGuessProber.get_charset_name()
57
for prober in self._mProbers:
58
if not prober: continue
59
if not prober.active: continue
60
st = prober.feed(aBuf)
62
if st == constants.eFoundIt:
63
self._mBestGuessProber = prober
64
return self.get_state()
65
elif st == constants.eNotMe:
68
if self._mActiveNum <= 0:
69
self._mState = constants.eNotMe
70
return self.get_state()
71
return self.get_state()
73
def get_confidence(self):
75
if st == constants.eFoundIt:
77
elif st == constants.eNotMe:
80
self._mBestGuessProber = None
81
for prober in self._mProbers:
82
if not prober: continue
85
sys.stderr.write(prober.get_charset_name() + ' not active\n')
87
cf = prober.get_confidence()
89
sys.stderr.write('%s confidence = %s\n' % (prober.get_charset_name(), cf))
92
self._mBestGuessProber = prober
93
if not self._mBestGuessProber: return 0.0
96
# self._mBestGuessProber = self._mProbers[0]
97
# return self._mBestGuessProber.get_confidence()