You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
######################## BEGIN LICENSE BLOCK ######################### This code was modified from latin1prober.py by Rob Speer <rob@lumino.so>.# The Original Code is Mozilla Universal charset detector code.## The Initial Developer of the Original Code is# Netscape Communications Corporation.# Portions created by the Initial Developer are Copyright (C) 2001# the Initial Developer. All Rights Reserved.## Contributor(s):# Rob Speer - adapt to MacRoman encoding# Mark Pilgrim - port to Python# Shy Shalom - original C code## This library is free software; you can redistribute it and/or# modify it under the terms of the GNU Lesser General Public# License as published by the Free Software Foundation; either# version 2.1 of the License, or (at your option) any later version.## This library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public# License along with this library; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA# 02110-1301 USA######################### END LICENSE BLOCK #########################fromcharsetproberimportCharSetProberimportconstantsimportoperatorFREQ_CAT_NUM=4UDF=0# undefinedOTH=1# otherASC=2# ascii capital letterASS=3# ascii small letterACV=4# accent capital vowelACO=5# accent capital otherASV=6# accent small vowelASO=7# accent small otherODD=8# character that is unlikely to appearCLASS_NUM=9# total classes# The change from Latin1 is that we explicitly look for extended characters# that are infrequently-occurring symbols, and consider them to always be# improbable. This should let MacRoman get out of the way of more likely# encodings in most situations.MacRoman_CharToClass= ( \
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 00 - 07OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 08 - 0FOTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 10 - 17OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 18 - 1FOTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 20 - 27OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 28 - 2FOTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 30 - 37OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 38 - 3FOTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 40 - 47ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 48 - 4FASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 50 - 57ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, # 58 - 5FOTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 60 - 67ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 68 - 6FASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 70 - 77ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, # 78 - 7FACV, ACV, ACO, ACV, ACO, ACV, ACV, ASV, # 80 - 87ASV, ASV, ASV, ASV, ASV, ASO, ASV, ASV, # 88 - 8FASV, ASV, ASV, ASV, ASV, ASV, ASO, ASV, # 90 - 97ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, # 98 - 9FOTH, OTH, OTH, OTH, OTH, OTH, OTH, ASO, # A0 - A7OTH, OTH, ODD, ODD, OTH, OTH, ACV, ACV, # A8 - AFOTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B0 - B7OTH, OTH, OTH, OTH, OTH, OTH, ASV, ASV, # B8 - BFOTH, OTH, ODD, OTH, ODD, OTH, OTH, OTH, # C0 - C7OTH, OTH, OTH, ACV, ACV, ACV, ACV, ASV, # C8 - CFOTH, OTH, OTH, OTH, OTH, OTH, OTH, ODD, # D0 - D7ASV, ACV, ODD, OTH, OTH, OTH, OTH, OTH, # D8 - DFOTH, OTH, OTH, OTH, OTH, ACV, ACV, ACV, # E0 - E7ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, # E8 - EFODD, ACV, ACV, ACV, ACV, ASV, ODD, ODD, # F0 - F7ODD, ODD, ODD, ODD, ODD, ODD, ODD, ODD, # F8 - FF
)
# 0 : illegal# 1 : very unlikely# 2 : normal# 3 : very likelyMacRomanClassModel= ( \
# UDF OTH ASC ASS ACV ACO ASV ASO ODD0, 0, 0, 0, 0, 0, 0, 0, 0, # UDF0, 3, 3, 3, 3, 3, 3, 3, 1, # OTH0, 3, 3, 3, 3, 3, 3, 3, 1, # ASC0, 3, 3, 3, 1, 1, 3, 3, 1, # ASS0, 3, 3, 3, 1, 2, 1, 2, 1, # ACV0, 3, 3, 3, 3, 3, 3, 3, 1, # ACO0, 3, 1, 3, 1, 1, 1, 3, 1, # ASV0, 3, 1, 3, 1, 1, 3, 3, 1, # ASO0, 1, 1, 1, 1, 1, 1, 1, 1, # ODD
)
classMacRomanProber(CharSetProber):
def__init__(self):
CharSetProber.__init__(self)
self.reset()
defreset(self):
self._mLastCharClass=OTHself._mFreqCounter= [0] *FREQ_CAT_NUM# express the prior that MacRoman is a somewhat rare encoding;# this can be done by starting out in a slightly improbable state# that must be overcomeself._mFreqCounter[2] =10CharSetProber.reset(self)
defget_charset_name(self):
return"macroman"deffeed(self, aBuf):
aBuf=self.filter_with_english_letters(aBuf)
forcinaBuf:
try:
charClass=MacRoman_CharToClass[ord(c)]
exceptIndexError:
returnconstants.eErrorfreq=MacRomanClassModel[(self._mLastCharClass*CLASS_NUM) +charClass]
iffreq==0:
self._mState=constants.eNotMebreakself._mFreqCounter[freq] +=1self._mLastCharClass=charClassreturnself.get_state()
defget_confidence(self):
ifself.get_state() ==constants.eNotMe:
return0.01total=float(reduce(operator.add, self._mFreqCounter))
iftotal<0.01:
confidence=0.0else:
confidence= (self._mFreqCounter[3] /total) - (self._mFreqCounter[1] *20.0/total)
ifconfidence<0.0:
confidence=0.0returnconfidence
The text was updated successfully, but these errors were encountered:
Hello!
We may consider adding detection for encoding 'x-mac-romanian'
See chardet/chardet#5
chardet/macromanprober.py
The text was updated successfully, but these errors were encountered: