Skip to content
Myr

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

10 files+68 added−19 removed

modified:requests/packages/charade/__init__.py+6 added-1 removed
13 unmodified lines
14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA15# 02110-1301 USA16######################### END LICENSE BLOCK #########################1718__version__ = "1.0.1"18__version__ = "1.0.3"19from sys import version_info202122def 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')2627 from . import universaldetector28 u = universaldetector.UniversalDetector()29 u.reset()30 u.feed(aBuf)
2 unmodified lines
modified:requests/packages/charade/chardistribution.py+2 added-1 removed
38 unmodified lines
3940ENOUGH_DATA_THRESHOLD = 102441SURE_YES = 0.9942SURE_NO = 0.0143MINIMUM_DATA_THRESHOLD = 3444546class CharDistributionAnalysis:47 def __init__(self):
34 unmodified lines
82 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_NO8889 if self._mTotalChars != self._mFreqChars:90 r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)
141 unmodified lines
modified:requests/packages/charade/compat.py+10 added-2 removed
16 unmodified lines
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA18# 02110-1301 USA19######################### END LICENSE BLOCK #########################2021import sys222324if sys.version_info < (3, 0):25 base_str = (str, unicode)26else:27 base_str = (bytes, str)282930def 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 a
modified:requests/packages/charade/langcyrillicmodel.py-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants2928# KOI8-R language model29# Character Mapping Table:30KOI8R_CharToOrderMap = (31255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
298 unmodified lines
modified:requests/packages/charade/langgreekmodel.py-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants2928# 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 - 9
194 unmodified lines
modified:requests/packages/charade/langhebrewmodel.py-2 removed
25 unmodified lines
26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA27# 02110-1301 USA28######################### END LICENSE BLOCK #########################2930from . import constants3130# 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 - 9
168 unmodified lines
modified:requests/packages/charade/langhungarianmodel.py-2 removed
23 unmodified lines
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA25# 02110-1301 USA26######################### END LICENSE BLOCK #########################2728from . import constants2928# 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 - 9
194 unmodified lines
modified:requests/packages/charade/mbcsgroupprober.py+2 added
31 unmodified lines
32from .sjisprober import SJISProber33from .eucjpprober import EUCJPProber34from .gb2312prober import GB2312Prober35from .euckrprober import EUCKRProber36from .cp949prober import CP949Prober37from .big5prober import Big5Prober38from .euctwprober import EUCTWProber3940
5 unmodified lines
46 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 lines
77 'stateTable': BIG5_st,78 'charLenTable': Big5CharLenTable,79 'name': 'Big5'}8081# CP9498283CP949_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)101102CP949_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)112113CP949CharLenTable = (0, 1, 2, 0, 1, 1, 2, 2, 0, 2)114115CP949SMModel = {'classTable': CP949_cls,116 'classFactor': 10,117 'stateTable': CP949_st,118 'charLenTable': CP949CharLenTable,119 'name': 'CP949'}120121# EUC-JP122123EUCJP_cls = (124 4,4,4,4,4,4,4,4, # 00 - 07
451 unmodified lines
modified:requests/packages/charade/universaldetector.py+8 added-7 removed
26 unmodified lines
27######################### END LICENSE BLOCK #########################2829from . import constants30import sys31import codecs32from .latin1prober import Latin1Prober # windows-125233from .mbcsgroupprober import MBCSGroupProber # multi-byte character sets34from .sbcsgroupprober import SBCSGroupProber # single-byte character sets35from .escprober import EscCharSetProber # ISO-2122, etc.
34 unmodified lines
70 return7172 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}101102 self._mGotData = True
70 unmodified lines