fixes for python2
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 0af19a0 · Browse files · 3 files·+19 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+19 added−12 removed
- other:+19 added−12 removed
Provenance
- Commit
ccd14dd- Tree
cdcad60- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
0af19a0
3 files changed+19 added−12 removed
modified:requests/packages/chardet/codingstatemachine.py+5 added-2 removed
11 unmodified lines12 # This library is free software; you can redistribute it and/or13 # modify it under the terms of the GNU Lesser General Public14 # License as published by the Free Software Foundation; either15 # version 2.1 of the License, or (at your option) any later version.16-# 16+#17 # This library is distributed in the hope that it will be useful,18 # but WITHOUT ANY WARRANTY; without even the implied warranty of19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU20 # Lesser General Public License for more details.21-# 21+#22 # You should have received a copy of the GNU Lesser General Public23 # License along with this library; if not, write to the Free Software24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA14 unmodified lines40 def next_state(self, c):41 # for each byte we get its class42 # if it is first byte, we also get byte length43 # PY3K: aBuf is a byte stream, so c is an int, not a byte44+ if hasattr(c, 'encode'):45+ c = int(c.encode('hex'), 16)46+47 byteCls = self._mModel['classTable'][c]48 if self._mCurrentState == eStart:49 self._mCurrentBytePos = 050 self._mCurrentCharLen = self._mModel['charLenTable'][byteCls]10 unmodified linesmodified:requests/packages/chardet/latin1prober.py+9 added-7 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 USA48 unmodified lines75 ASO, ASO, ASV, ASV, ASV, ASV, ASV, OTH, # F0 - F776 ASV, ASV, ASV, ASV, ASV, ASO, ASO, ASO, # F8 - FF77 )78 79-# 0 : illegal 80-# 1 : very unlikely 81-# 2 : normal 79+# 0 : illegal80+# 1 : very unlikely81+# 2 : normal82 # 3 : very likely83 Latin1ClassModel = ( \84 # UDF OTH ASC ASS ACV ACO ASV ASO85 0, 0, 0, 0, 0, 0, 0, 0, # UDF21 unmodified lines107 108 def feed(self, aBuf):109 aBuf = self.filter_with_english_letters(aBuf)110 for c in aBuf:111+ if hasattr(c, 'encode'):112+ c = int(c.encode('hex'), 16)113 charClass = Latin1_CharToClass[c]114 freq = Latin1ClassModel[(self._mLastCharClass * CLASS_NUM) + charClass]115 if freq == 0:116 self._mState = constants.eNotMe5 unmodified lines122 123 def get_confidence(self):124 if self.get_state() == constants.eNotMe:125 return 0.01124- 126+127 total = sum(self._mFreqCounter)128 if total < 0.01:129 confidence = 0.0130 else:131 confidence = (self._mFreqCounter[3] / total) - (self._mFreqCounter[1] * 20.0 / total)132 if confidence < 0.0:133 confidence = 0.0132- # lower the confidence of latin1 so that other more accurate detector 134+ # lower the confidence of latin1 so that other more accurate detector135 # can take priority.136 confidence = confidence * 0.5137 return confidencemodified:requests/packages/chardet/sbcharsetprober.py+5 added-3 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 USA10 unmodified lines37 SYMBOL_CAT_ORDER = 25038 NUMBER_OF_SEQ_CAT = 439 POSITIVE_CAT = NUMBER_OF_SEQ_CAT - 140 #NEGATIVE_CAT = 041- 41+42 class SingleByteCharSetProber(CharSetProber):43 def __init__(self, model, reversed=False, nameProber=None):44 CharSetProber.__init__(self)45 self._mModel = model21 unmodified lines67 aLen = len(aBuf)68 if not aLen:69 return self.get_state()70 for c in aBuf:71+ if hasattr(c, 'encode'):72+ c = int(c.encode('hex'), 16)73 order = self._mModel['charToOrderMap'][c]74 if order < SYMBOL_CAT_ORDER:75 self._mTotalChar += 176 if order < SAMPLE_SIZE:33 unmodified lines