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 #########################
29 from charsetprober
import CharSetProber
31 class CharSetGroupProber(CharSetProber
):
33 CharSetProber
.__init
__(self
)
36 self
._mBestGuessProber
= None
39 CharSetProber
.reset(self
)
41 for prober
in self
._mProbers
:
44 prober
.active
= constants
.True
46 self
._mBestGuessProber
= None
48 def get_charset_name(self
):
49 if not self
._mBestGuessProber
:
51 if not self
._mBestGuessProber
: return None
52 # self._mBestGuessProber = self._mProbers[0]
53 return self
._mBestGuessProber
.get_charset_name()
56 for prober
in self
._mProbers
:
57 if not prober
: continue
58 if not prober
.active
: continue
59 st
= prober
.feed(aBuf
)
61 if st
== constants
.eFoundIt
:
62 self
._mBestGuessProber
= prober
63 return self
.get_state()
64 elif st
== constants
.eNotMe
:
65 prober
.active
= constants
.False
67 if self
._mActiveNum
<= 0:
68 self
._mState
= constants
.eNotMe
69 return self
.get_state()
70 return self
.get_state()
72 def get_confidence(self
):
74 if st
== constants
.eFoundIt
:
76 elif st
== constants
.eNotMe
:
79 self
._mBestGuessProber
= None
80 for prober
in self
._mProbers
:
81 if not prober
: continue
84 sys
.stderr
.write(prober
.get_charset_name() + ' not active\n')
86 cf
= prober
.get_confidence()
88 sys
.stderr
.write('%s confidence = %s\n' % (prober
.get_charset_name(), cf
))
91 self
._mBestGuessProber
= prober
92 if not self
._mBestGuessProber
: return 0.0
95 # self._mBestGuessProber = self._mProbers[0]
96 # return self._mBestGuessProber.get_confidence()