upgrade to charade v1.0.3
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 0d07d1a · Browse files · 10 files·+68 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+68 added−19 removed
- other:+68 added−19 removed
Provenance
- Commit
80a861c- Tree
0dbf715- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
0d07d1a
10 files changed+68 added−19 removed
modified:requests/packages/charade/__init__.py+6 added-1 removed
13 unmodified lines14 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA15 # 02110-1301 USA16 ######################### END LICENSE BLOCK #########################17 18-__version__ = "1.0.1"18+__version__ = "1.0.3"19+from sys import version_info20 21 22 def detect(aBuf):23+ if ((version_info < (3, 0) and isinstance(aBuf, unicode)) or24+ (version_info >= (3, 0) and not isinstance(aBuf, bytes))):25+ raise ValueError('Expected a bytes object, not a unicode object')26+27 from . import universaldetector28 u = universaldetector.UniversalDetector()29 u.reset()30 u.feed(aBuf)2 unmodified linesmodified:requests/packages/charade/chardistribution.py+2 added-1 removed
38 unmodified lines39 40 ENOUGH_DATA_THRESHOLD = 102441 SURE_YES = 0.9942 SURE_NO = 0.0143+MINIMUM_DATA_THRESHOLD = 344 45 46 class CharDistributionAnalysis:47 def __init__(self):34 unmodified lines82 def get_confidence(self):83 """return confidence based on existing data"""84 # if we didn't receive any character in our consideration range,85 # return negative answer85- if self._mTotalChars <= 0:86+ if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD:87 return SURE_NO88 89 if self._mTotalChars != self._mFreqChars:90 r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)141 unmodified linesmodified:requests/packages/charade/compat.py+10 added-2 removed
16 unmodified lines17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA18 # 02110-1301 USA19 ######################### END LICENSE BLOCK #########################20 21+import sys22 23+24+if sys.version_info < (3, 0):25+ base_str = (str, unicode)26+else:27+ base_str = (bytes, str)28+29+30 def wrap_ord(a):23- if isinstance(a, str):31+ if sys.version_info < (3, 0) and isinstance(a, base_str):32 return ord(a)25- elif isinstance(a, int):33+ else:34 return amodified:requests/packages/charade/langcyrillicmodel.py-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants29-28 # KOI8-R language model29 # Character Mapping Table:30 KOI8R_CharToOrderMap = (31 255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00298 unmodified linesmodified:requests/packages/charade/langgreekmodel.py-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants29-28 # 255: Control characters that usually does not exist in any text29 # 254: Carriage/Return30 # 253: symbol (punctuation) that does not belong to word31 # 252: 0 - 9194 unmodified linesmodified:requests/packages/charade/langhebrewmodel.py-2 removed
25 unmodified lines26 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA27 # 02110-1301 USA28 ######################### END LICENSE BLOCK #########################29 30-from . import constants31-30 # 255: Control characters that usually does not exist in any text31 # 254: Carriage/Return32 # 253: symbol (punctuation) that does not belong to word33 # 252: 0 - 9168 unmodified linesmodified:requests/packages/charade/langhungarianmodel.py-2 removed
23 unmodified lines24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25 # 02110-1301 USA26 ######################### END LICENSE BLOCK #########################27 28-from . import constants29-28 # 255: Control characters that usually does not exist in any text29 # 254: Carriage/Return30 # 253: symbol (punctuation) that does not belong to word31 # 252: 0 - 9194 unmodified linesmodified:requests/packages/charade/mbcsgroupprober.py+2 added
31 unmodified lines32 from .sjisprober import SJISProber33 from .eucjpprober import EUCJPProber34 from .gb2312prober import GB2312Prober35 from .euckrprober import EUCKRProber36+from .cp949prober import CP949Prober37 from .big5prober import Big5Prober38 from .euctwprober import EUCTWProber39 40 5 unmodified lines46 SJISProber(),47 EUCJPProber(),48 GB2312Prober(),49 EUCKRProber(),50+ CP949Prober(),51 Big5Prober(),52 EUCTWProber()53 ]54 self.reset()modified:requests/packages/charade/mbcssm.py+40 added
76 unmodified lines77 'stateTable': BIG5_st,78 'charLenTable': Big5CharLenTable,79 'name': 'Big5'}80 81+# CP94982+83+CP949_cls = (84+ 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,0,0, # 00 - 0f85+ 1,1,1,1,1,1,1,1, 1,1,1,0,1,1,1,1, # 10 - 1f86+ 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, # 20 - 2f87+ 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, # 30 - 3f88+ 1,4,4,4,4,4,4,4, 4,4,4,4,4,4,4,4, # 40 - 4f89+ 4,4,5,5,5,5,5,5, 5,5,5,1,1,1,1,1, # 50 - 5f90+ 1,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5, # 60 - 6f91+ 5,5,5,5,5,5,5,5, 5,5,5,1,1,1,1,1, # 70 - 7f92+ 0,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6, # 80 - 8f93+ 6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6, # 90 - 9f94+ 6,7,7,7,7,7,7,7, 7,7,7,7,7,8,8,8, # a0 - af95+ 7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7, # b0 - bf96+ 7,7,7,7,7,7,9,2, 2,3,2,2,2,2,2,2, # c0 - cf97+ 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, # d0 - df98+ 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, # e0 - ef99+ 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,0, # f0 - ff100+)101+102+CP949_st = (103+#cls= 0 1 2 3 4 5 6 7 8 9 # previous state =104+ eError,eStart, 3,eError,eStart,eStart, 4, 5,eError, 6, # eStart105+ eError,eError,eError,eError,eError,eError,eError,eError,eError,eError, # eError106+ eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe,eItsMe, # eItsMe107+ eError,eError,eStart,eStart,eError,eError,eError,eStart,eStart,eStart, # 3108+ eError,eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart,eStart, # 4109+ eError,eStart,eStart,eStart,eStart,eStart,eStart,eStart,eStart,eStart, # 5110+ eError,eStart,eStart,eStart,eStart,eError,eError,eStart,eStart,eStart, # 6111+)112+113+CP949CharLenTable = (0, 1, 2, 0, 1, 1, 2, 2, 0, 2)114+115+CP949SMModel = {'classTable': CP949_cls,116+ 'classFactor': 10,117+ 'stateTable': CP949_st,118+ 'charLenTable': CP949CharLenTable,119+ 'name': 'CP949'}120+121 # EUC-JP122 123 EUCJP_cls = (124 4,4,4,4,4,4,4,4, # 00 - 07451 unmodified linesmodified:requests/packages/charade/universaldetector.py+8 added-7 removed
26 unmodified lines27 ######################### END LICENSE BLOCK #########################28 29 from . import constants30 import sys31+import codecs32 from .latin1prober import Latin1Prober # windows-125233 from .mbcsgroupprober import MBCSGroupProber # multi-byte character sets34 from .sbcsgroupprober import SBCSGroupProber # single-byte character sets35 from .escprober import EscCharSetProber # ISO-2122, etc.34 unmodified lines70 return71 72 if not self._mGotData:73 # If the data starts with BOM, we know it is UTF73- if aBuf[:3] == '\xEF\xBB\xBF':74+ if aBuf[:3] == codecs.BOM:75 # EF BB BF UTF-8 with BOM76 self.result = {'encoding': "UTF-8", 'confidence': 1.0}76- elif aBuf[:4] == '\xFF\xFE\x00\x00':77+ elif aBuf[:4] == codecs.BOM_UTF32_LE:78 # FF FE 00 00 UTF-32, little-endian BOM79 self.result = {'encoding': "UTF-32LE", 'confidence': 1.0}79- elif aBuf[:4] == '\x00\x00\xFE\xFF':80+ elif aBuf[:4] == codecs.BOM_UTF32_BE:81 # 00 00 FE FF UTF-32, big-endian BOM82 self.result = {'encoding': "UTF-32BE", 'confidence': 1.0}82- elif aBuf[:4] == '\xFE\xFF\x00\x00':83+ elif aBuf[:4] == b'\xFE\xFF\x00\x00':84 # FE FF 00 00 UCS-4, unusual octet order BOM (3412)85 self.result = {86 'encoding': "X-ISO-10646-UCS-4-3412",87 'confidence': 1.088 }88- elif aBuf[:4] == '\x00\x00\xFF\xFE':89+ elif aBuf[:4] == b'\x00\x00\xFF\xFE':90 # 00 00 FF FE UCS-4, unusual octet order BOM (2143)91 self.result = {92 'encoding': "X-ISO-10646-UCS-4-2143",93 'confidence': 1.094 }94- elif aBuf[:2] == '\xFF\xFE':95+ elif aBuf[:2] == codecs.BOM_LE:96 # FF FE UTF-16, little endian BOM97 self.result = {'encoding': "UTF-16LE", 'confidence': 1.0}97- elif aBuf[:2] == '\xFE\xFF':98+ elif aBuf[:2] == codecs.BOM_BE:99 # FE FF UTF-16, big endian BOM100 self.result = {'encoding': "UTF-16BE", 'confidence': 1.0}101 102 self._mGotData = True70 unmodified lines