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
33 class CharSetGroupProber(CharSetProber):
35 CharSetProber.__init__(self)
38 self._mBestGuessProber = None
41 CharSetProber.reset(self)
43 for prober in self._mProbers:
48 self._mBestGuessProber = None
50 def get_charset_name(self):
51 if not self._mBestGuessProber:
53 if not self._mBestGuessProber:
55 # self._mBestGuessProber = self._mProbers[0]
56 return self._mBestGuessProber.get_charset_name()
59 for prober in self._mProbers:
64 st = prober.feed(aBuf)
67 if st == constants.eFoundIt:
68 self._mBestGuessProber = prober
69 return self.get_state()
70 elif st == constants.eNotMe:
73 if self._mActiveNum <= 0:
74 self._mState = constants.eNotMe
75 return self.get_state()
76 return self.get_state()
78 def get_confidence(self):
80 if st == constants.eFoundIt:
82 elif st == constants.eNotMe:
85 self._mBestGuessProber = None
86 for prober in self._mProbers:
91 sys.stderr.write(prober.get_charset_name()
94 cf = prober.get_confidence()
96 sys.stderr.write('%s confidence = %s\n' %
97 (prober.get_charset_name(), cf))
100 self._mBestGuessProber = prober
101 if not self._mBestGuessProber:
105 # self._mBestGuessProber = self._mProbers[0]
106 # return self._mBestGuessProber.get_confidence()