chardet fixes!
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent a5cb635 · Browse files · 6 files·+30 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+30 added−33 removed
- other:+30 added−33 removed
Provenance
- Commit
2eb63be- Tree
44f7b93- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
a5cb635
6 files changed+30 added−33 removed
modified:requests/packages/charade/charsetprober.py+2 added-2 removed
48 unmodified lines49 def get_confidence(self):50 return 0.051 52 def filter_high_bit_only(self, aBuf):53- aBuf = re.sub(b'([\x00-\x7F])+', ' ', aBuf)53+ aBuf = re.sub(b'([\x00-\x7F])+', b' ', aBuf)54 return aBuf55 56 def filter_without_english_letters(self, aBuf):57- aBuf = re.sub(b'([A-Za-z])+', ' ', aBuf)57+ aBuf = re.sub(b'([A-Za-z])+', b' ', aBuf)58 return aBuf59 60 def filter_with_english_letters(self, aBuf):61 # TODO1 unmodified linemodified:requests/packages/charade/compat.py+2 added-11 removed
17 unmodified lines18 # 02110-1301 USA19 ######################### END LICENSE BLOCK #########################20 21 22-from sys import verion_info22+from sys import version_info23 24 25 def wrap_ord(a):26- if isinstance(a, 'str') and version_info < (3, 0):26+ if isinstance(a, str) and version_info < (3, 0):27 return ord(a)28 elif isinstance(a, int) and version_info >= (3, 0):29 return a30-31-32-def cmp_corrector(s):33- if version_info >= (3, 0):34- if s.startswith('\x'):35- return ord(s)36- elif s.startswith('\\'):37- return int(s[1:])38- return smodified:requests/packages/charade/jpcntx.py+1 added-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants28 from .compat import wrap_ord29 30 NUM_OF_CATEGORY = 631 DONT_KNOW = -1460 unmodified lines492 else:493 if (order != -1) and (self._mLastCharOrder != -1):494 self._mTotalRel += 1495 if self._mTotalRel > MAX_REL_THRESHOLD:497- self._mDone = constants.True496+ self._mDone = True497 break498 self._mRelSample[499 jp2CharContext[self._mLastCharOrder][order]500 ] += 163 unmodified linesmodified:requests/packages/charade/sbcharsetprober.py+2 added-1 removed
84 unmodified lines85 if not self._mReversed:86 i = (self._mLastOrder * SAMPLE_SIZE) + order87 else: # reverse the order of the letters in the lookup88 i = (order * SAMPLE_SIZE) + self._mLastOrder89- self._mSeqCounters[self.mModel['precedenceMatrix'][i]] += 189+ model = self._mModel['precedenceMatrix'][i]90+ self._mSeqCounters[model] += 191 self._mLastOrder = order92 93 if self.get_state() == constants.eDetecting:94 if self._mTotalSeqs > SB_ENOUGH_REL_THRESHOLD:30 unmodified linesmodified:requests/packages/charade/sbcsgroupprober.py+22 added-17 removed
12 unmodified lines13 # This library is free software; you can redistribute it and/or14 # modify it under the terms of the GNU Lesser General Public15 # License as published by the Free Software Foundation; either16 # version 2.1 of the License, or (at your option) any later version.17-# 17+#18 # This library is distributed in the hope that it will be useful,19 # but WITHOUT ANY WARRANTY; without even the implied warranty of20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU21 # Lesser General Public License for more details.22-# 22+#23 # You should have received a copy of the GNU Lesser General Public24 # License along with this library; if not, write to the Free Software25 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA26 # 02110-1301 USA27 ######################### END LICENSE BLOCK #########################28 29-import constants, sys30-from charsetgroupprober import CharSetGroupProber31-from sbcharsetprober import SingleByteCharSetProber32-from langcyrillicmodel import Win1251CyrillicModel, Koi8rModel, Latin5CyrillicModel, MacCyrillicModel, Ibm866Model, Ibm855Model33-from langgreekmodel import Latin7GreekModel, Win1253GreekModel34-from langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel35-from langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel36-from langthaimodel import TIS620ThaiModel37-from langhebrewmodel import Win1255HebrewModel38-from hebrewprober import HebrewProber29+from .charsetgroupprober import CharSetGroupProber30+from .sbcharsetprober import SingleByteCharSetProber31+from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel,32+ Latin5CyrillicModel, MacCyrillicModel,33+ Ibm866Model, Ibm855Model)34+from .langgreekmodel import Latin7GreekModel, Win1253GreekModel35+from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel36+from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel37+from .langthaimodel import TIS620ThaiModel38+from .langhebrewmodel import Win1255HebrewModel39+from .hebrewprober import HebrewProber40 41+42 class SBCSGroupProber(CharSetGroupProber):43 def __init__(self):44 CharSetGroupProber.__init__(self)43- self._mProbers = [ \45+ self._mProbers = [46 SingleByteCharSetProber(Win1251CyrillicModel),47 SingleByteCharSetProber(Koi8rModel),48 SingleByteCharSetProber(Latin5CyrillicModel),49 SingleByteCharSetProber(MacCyrillicModel),5 unmodified lines55 SingleByteCharSetProber(Win1251BulgarianModel),56 SingleByteCharSetProber(Latin2HungarianModel),57 SingleByteCharSetProber(Win1250HungarianModel),58 SingleByteCharSetProber(TIS620ThaiModel),57- ]59+ ]60 hebrewProber = HebrewProber()59- logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, constants.False, hebrewProber)60- visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, constants.True, hebrewProber)61+ logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel,62+ False, hebrewProber)63+ visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, True,64+ hebrewProber)65 hebrewProber.set_model_probers(logicalHebrewProber, visualHebrewProber)62- self._mProbers.extend([hebrewProber, logicalHebrewProber, visualHebrewProber])66+ self._mProbers.extend([hebrewProber, logicalHebrewProber,67+ visualHebrewProber])68 69 self.reset()modified:requests/compat.py+1 added
2 unmodified lines3 """4 pythoncompat5 """6 7+from .packages import charade as chardet8 9 import sys10 11 # -------103 unmodified lines