Skip to content
Myr

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

6 files+30 added−33 removed

modified:requests/packages/charade/charsetprober.py+2 added-2 removed
48 unmodified lines
49 def get_confidence(self):50 return 0.05152 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 aBuf5556 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 aBuf5960 def filter_with_english_letters(self, aBuf):61 # TODO
1 unmodified line
modified:requests/packages/charade/compat.py+2 added-11 removed
17 unmodified lines
18# 02110-1301 USA19######################### END LICENSE BLOCK #########################202122from sys import verion_info22from sys import version_info232425def 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 a303132def 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 s
modified:requests/packages/charade/jpcntx.py+1 added-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants28from .compat import wrap_ord2930NUM_OF_CATEGORY = 631DONT_KNOW = -1
460 unmodified lines
492 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 ] += 1
63 unmodified lines
modified:requests/packages/charade/sbcharsetprober.py+2 added-1 removed
84 unmodified lines
85 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 = order9293 if self.get_state() == constants.eDetecting:94 if self._mTotalSeqs > SB_ENOUGH_REL_THRESHOLD:
30 unmodified lines
modified:requests/packages/charade/sbcsgroupprober.py+22 added-17 removed
12 unmodified lines
13# 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 #########################2829import constants, sys30from charsetgroupprober import CharSetGroupProber31from sbcharsetprober import SingleByteCharSetProber32from langcyrillicmodel import Win1251CyrillicModel, Koi8rModel, Latin5CyrillicModel, MacCyrillicModel, Ibm866Model, Ibm855Model33from langgreekmodel import Latin7GreekModel, Win1253GreekModel34from langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel35from langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel36from langthaimodel import TIS620ThaiModel37from langhebrewmodel import Win1255HebrewModel38from hebrewprober import HebrewProber29from .charsetgroupprober import CharSetGroupProber30from .sbcharsetprober import SingleByteCharSetProber31from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel,32 Latin5CyrillicModel, MacCyrillicModel,33 Ibm866Model, Ibm855Model)34from .langgreekmodel import Latin7GreekModel, Win1253GreekModel35from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel36from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel37from .langthaimodel import TIS620ThaiModel38from .langhebrewmodel import Win1255HebrewModel39from .hebrewprober import HebrewProber404142class 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 lines
55 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])6869 self.reset()
modified:requests/compat.py+1 added
2 unmodified lines
3"""4pythoncompat5"""67from .packages import charade as chardet89import sys1011# -------
103 unmodified lines