constant.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. from codecs import BOM_UTF8, BOM_UTF16_BE, BOM_UTF16_LE, BOM_UTF32_BE, BOM_UTF32_LE
  2. from collections import OrderedDict
  3. from encodings.aliases import aliases
  4. from re import IGNORECASE, compile as re_compile
  5. from typing import Dict, List, Set, Union
  6. from .assets import FREQUENCIES
  7. # Contain for each eligible encoding a list of/item bytes SIG/BOM
  8. ENCODING_MARKS = OrderedDict(
  9. [
  10. ("utf_8", BOM_UTF8),
  11. (
  12. "utf_7",
  13. [
  14. b"\x2b\x2f\x76\x38",
  15. b"\x2b\x2f\x76\x39",
  16. b"\x2b\x2f\x76\x2b",
  17. b"\x2b\x2f\x76\x2f",
  18. b"\x2b\x2f\x76\x38\x2d",
  19. ],
  20. ),
  21. ("gb18030", b"\x84\x31\x95\x33"),
  22. ("utf_32", [BOM_UTF32_BE, BOM_UTF32_LE]),
  23. ("utf_16", [BOM_UTF16_BE, BOM_UTF16_LE]),
  24. ]
  25. ) # type: Dict[str, Union[bytes, List[bytes]]]
  26. TOO_SMALL_SEQUENCE = 32 # type: int
  27. TOO_BIG_SEQUENCE = int(10e6) # type: int
  28. UTF8_MAXIMAL_ALLOCATION = 1112064 # type: int
  29. UNICODE_RANGES_COMBINED = {
  30. "Control character": range(31 + 1),
  31. "Basic Latin": range(32, 127 + 1),
  32. "Latin-1 Supplement": range(128, 255 + 1),
  33. "Latin Extended-A": range(256, 383 + 1),
  34. "Latin Extended-B": range(384, 591 + 1),
  35. "IPA Extensions": range(592, 687 + 1),
  36. "Spacing Modifier Letters": range(688, 767 + 1),
  37. "Combining Diacritical Marks": range(768, 879 + 1),
  38. "Greek and Coptic": range(880, 1023 + 1),
  39. "Cyrillic": range(1024, 1279 + 1),
  40. "Cyrillic Supplement": range(1280, 1327 + 1),
  41. "Armenian": range(1328, 1423 + 1),
  42. "Hebrew": range(1424, 1535 + 1),
  43. "Arabic": range(1536, 1791 + 1),
  44. "Syriac": range(1792, 1871 + 1),
  45. "Arabic Supplement": range(1872, 1919 + 1),
  46. "Thaana": range(1920, 1983 + 1),
  47. "NKo": range(1984, 2047 + 1),
  48. "Samaritan": range(2048, 2111 + 1),
  49. "Mandaic": range(2112, 2143 + 1),
  50. "Syriac Supplement": range(2144, 2159 + 1),
  51. "Arabic Extended-A": range(2208, 2303 + 1),
  52. "Devanagari": range(2304, 2431 + 1),
  53. "Bengali": range(2432, 2559 + 1),
  54. "Gurmukhi": range(2560, 2687 + 1),
  55. "Gujarati": range(2688, 2815 + 1),
  56. "Oriya": range(2816, 2943 + 1),
  57. "Tamil": range(2944, 3071 + 1),
  58. "Telugu": range(3072, 3199 + 1),
  59. "Kannada": range(3200, 3327 + 1),
  60. "Malayalam": range(3328, 3455 + 1),
  61. "Sinhala": range(3456, 3583 + 1),
  62. "Thai": range(3584, 3711 + 1),
  63. "Lao": range(3712, 3839 + 1),
  64. "Tibetan": range(3840, 4095 + 1),
  65. "Myanmar": range(4096, 4255 + 1),
  66. "Georgian": range(4256, 4351 + 1),
  67. "Hangul Jamo": range(4352, 4607 + 1),
  68. "Ethiopic": range(4608, 4991 + 1),
  69. "Ethiopic Supplement": range(4992, 5023 + 1),
  70. "Cherokee": range(5024, 5119 + 1),
  71. "Unified Canadian Aboriginal Syllabics": range(5120, 5759 + 1),
  72. "Ogham": range(5760, 5791 + 1),
  73. "Runic": range(5792, 5887 + 1),
  74. "Tagalog": range(5888, 5919 + 1),
  75. "Hanunoo": range(5920, 5951 + 1),
  76. "Buhid": range(5952, 5983 + 1),
  77. "Tagbanwa": range(5984, 6015 + 1),
  78. "Khmer": range(6016, 6143 + 1),
  79. "Mongolian": range(6144, 6319 + 1),
  80. "Unified Canadian Aboriginal Syllabics Extended": range(6320, 6399 + 1),
  81. "Limbu": range(6400, 6479 + 1),
  82. "Tai Le": range(6480, 6527 + 1),
  83. "New Tai Lue": range(6528, 6623 + 1),
  84. "Khmer Symbols": range(6624, 6655 + 1),
  85. "Buginese": range(6656, 6687 + 1),
  86. "Tai Tham": range(6688, 6831 + 1),
  87. "Combining Diacritical Marks Extended": range(6832, 6911 + 1),
  88. "Balinese": range(6912, 7039 + 1),
  89. "Sundanese": range(7040, 7103 + 1),
  90. "Batak": range(7104, 7167 + 1),
  91. "Lepcha": range(7168, 7247 + 1),
  92. "Ol Chiki": range(7248, 7295 + 1),
  93. "Cyrillic Extended C": range(7296, 7311 + 1),
  94. "Sundanese Supplement": range(7360, 7375 + 1),
  95. "Vedic Extensions": range(7376, 7423 + 1),
  96. "Phonetic Extensions": range(7424, 7551 + 1),
  97. "Phonetic Extensions Supplement": range(7552, 7615 + 1),
  98. "Combining Diacritical Marks Supplement": range(7616, 7679 + 1),
  99. "Latin Extended Additional": range(7680, 7935 + 1),
  100. "Greek Extended": range(7936, 8191 + 1),
  101. "General Punctuation": range(8192, 8303 + 1),
  102. "Superscripts and Subscripts": range(8304, 8351 + 1),
  103. "Currency Symbols": range(8352, 8399 + 1),
  104. "Combining Diacritical Marks for Symbols": range(8400, 8447 + 1),
  105. "Letterlike Symbols": range(8448, 8527 + 1),
  106. "Number Forms": range(8528, 8591 + 1),
  107. "Arrows": range(8592, 8703 + 1),
  108. "Mathematical Operators": range(8704, 8959 + 1),
  109. "Miscellaneous Technical": range(8960, 9215 + 1),
  110. "Control Pictures": range(9216, 9279 + 1),
  111. "Optical Character Recognition": range(9280, 9311 + 1),
  112. "Enclosed Alphanumerics": range(9312, 9471 + 1),
  113. "Box Drawing": range(9472, 9599 + 1),
  114. "Block Elements": range(9600, 9631 + 1),
  115. "Geometric Shapes": range(9632, 9727 + 1),
  116. "Miscellaneous Symbols": range(9728, 9983 + 1),
  117. "Dingbats": range(9984, 10175 + 1),
  118. "Miscellaneous Mathematical Symbols-A": range(10176, 10223 + 1),
  119. "Supplemental Arrows-A": range(10224, 10239 + 1),
  120. "Braille Patterns": range(10240, 10495 + 1),
  121. "Supplemental Arrows-B": range(10496, 10623 + 1),
  122. "Miscellaneous Mathematical Symbols-B": range(10624, 10751 + 1),
  123. "Supplemental Mathematical Operators": range(10752, 11007 + 1),
  124. "Miscellaneous Symbols and Arrows": range(11008, 11263 + 1),
  125. "Glagolitic": range(11264, 11359 + 1),
  126. "Latin Extended-C": range(11360, 11391 + 1),
  127. "Coptic": range(11392, 11519 + 1),
  128. "Georgian Supplement": range(11520, 11567 + 1),
  129. "Tifinagh": range(11568, 11647 + 1),
  130. "Ethiopic Extended": range(11648, 11743 + 1),
  131. "Cyrillic Extended-A": range(11744, 11775 + 1),
  132. "Supplemental Punctuation": range(11776, 11903 + 1),
  133. "CJK Radicals Supplement": range(11904, 12031 + 1),
  134. "Kangxi Radicals": range(12032, 12255 + 1),
  135. "Ideographic Description Characters": range(12272, 12287 + 1),
  136. "CJK Symbols and Punctuation": range(12288, 12351 + 1),
  137. "Hiragana": range(12352, 12447 + 1),
  138. "Katakana": range(12448, 12543 + 1),
  139. "Bopomofo": range(12544, 12591 + 1),
  140. "Hangul Compatibility Jamo": range(12592, 12687 + 1),
  141. "Kanbun": range(12688, 12703 + 1),
  142. "Bopomofo Extended": range(12704, 12735 + 1),
  143. "CJK Strokes": range(12736, 12783 + 1),
  144. "Katakana Phonetic Extensions": range(12784, 12799 + 1),
  145. "Enclosed CJK Letters and Months": range(12800, 13055 + 1),
  146. "CJK Compatibility": range(13056, 13311 + 1),
  147. "CJK Unified Ideographs Extension A": range(13312, 19903 + 1),
  148. "Yijing Hexagram Symbols": range(19904, 19967 + 1),
  149. "CJK Unified Ideographs": range(19968, 40959 + 1),
  150. "Yi Syllables": range(40960, 42127 + 1),
  151. "Yi Radicals": range(42128, 42191 + 1),
  152. "Lisu": range(42192, 42239 + 1),
  153. "Vai": range(42240, 42559 + 1),
  154. "Cyrillic Extended-B": range(42560, 42655 + 1),
  155. "Bamum": range(42656, 42751 + 1),
  156. "Modifier Tone Letters": range(42752, 42783 + 1),
  157. "Latin Extended-D": range(42784, 43007 + 1),
  158. "Syloti Nagri": range(43008, 43055 + 1),
  159. "Common Indic Number Forms": range(43056, 43071 + 1),
  160. "Phags-pa": range(43072, 43135 + 1),
  161. "Saurashtra": range(43136, 43231 + 1),
  162. "Devanagari Extended": range(43232, 43263 + 1),
  163. "Kayah Li": range(43264, 43311 + 1),
  164. "Rejang": range(43312, 43359 + 1),
  165. "Hangul Jamo Extended-A": range(43360, 43391 + 1),
  166. "Javanese": range(43392, 43487 + 1),
  167. "Myanmar Extended-B": range(43488, 43519 + 1),
  168. "Cham": range(43520, 43615 + 1),
  169. "Myanmar Extended-A": range(43616, 43647 + 1),
  170. "Tai Viet": range(43648, 43743 + 1),
  171. "Meetei Mayek Extensions": range(43744, 43775 + 1),
  172. "Ethiopic Extended-A": range(43776, 43823 + 1),
  173. "Latin Extended-E": range(43824, 43887 + 1),
  174. "Cherokee Supplement": range(43888, 43967 + 1),
  175. "Meetei Mayek": range(43968, 44031 + 1),
  176. "Hangul Syllables": range(44032, 55215 + 1),
  177. "Hangul Jamo Extended-B": range(55216, 55295 + 1),
  178. "High Surrogates": range(55296, 56191 + 1),
  179. "High Private Use Surrogates": range(56192, 56319 + 1),
  180. "Low Surrogates": range(56320, 57343 + 1),
  181. "Private Use Area": range(57344, 63743 + 1),
  182. "CJK Compatibility Ideographs": range(63744, 64255 + 1),
  183. "Alphabetic Presentation Forms": range(64256, 64335 + 1),
  184. "Arabic Presentation Forms-A": range(64336, 65023 + 1),
  185. "Variation Selectors": range(65024, 65039 + 1),
  186. "Vertical Forms": range(65040, 65055 + 1),
  187. "Combining Half Marks": range(65056, 65071 + 1),
  188. "CJK Compatibility Forms": range(65072, 65103 + 1),
  189. "Small Form Variants": range(65104, 65135 + 1),
  190. "Arabic Presentation Forms-B": range(65136, 65279 + 1),
  191. "Halfwidth and Fullwidth Forms": range(65280, 65519 + 1),
  192. "Specials": range(65520, 65535 + 1),
  193. "Linear B Syllabary": range(65536, 65663 + 1),
  194. "Linear B Ideograms": range(65664, 65791 + 1),
  195. "Aegean Numbers": range(65792, 65855 + 1),
  196. "Ancient Greek Numbers": range(65856, 65935 + 1),
  197. "Ancient Symbols": range(65936, 65999 + 1),
  198. "Phaistos Disc": range(66000, 66047 + 1),
  199. "Lycian": range(66176, 66207 + 1),
  200. "Carian": range(66208, 66271 + 1),
  201. "Coptic Epact Numbers": range(66272, 66303 + 1),
  202. "Old Italic": range(66304, 66351 + 1),
  203. "Gothic": range(66352, 66383 + 1),
  204. "Old Permic": range(66384, 66431 + 1),
  205. "Ugaritic": range(66432, 66463 + 1),
  206. "Old Persian": range(66464, 66527 + 1),
  207. "Deseret": range(66560, 66639 + 1),
  208. "Shavian": range(66640, 66687 + 1),
  209. "Osmanya": range(66688, 66735 + 1),
  210. "Osage": range(66736, 66815 + 1),
  211. "Elbasan": range(66816, 66863 + 1),
  212. "Caucasian Albanian": range(66864, 66927 + 1),
  213. "Linear A": range(67072, 67455 + 1),
  214. "Cypriot Syllabary": range(67584, 67647 + 1),
  215. "Imperial Aramaic": range(67648, 67679 + 1),
  216. "Palmyrene": range(67680, 67711 + 1),
  217. "Nabataean": range(67712, 67759 + 1),
  218. "Hatran": range(67808, 67839 + 1),
  219. "Phoenician": range(67840, 67871 + 1),
  220. "Lydian": range(67872, 67903 + 1),
  221. "Meroitic Hieroglyphs": range(67968, 67999 + 1),
  222. "Meroitic Cursive": range(68000, 68095 + 1),
  223. "Kharoshthi": range(68096, 68191 + 1),
  224. "Old South Arabian": range(68192, 68223 + 1),
  225. "Old North Arabian": range(68224, 68255 + 1),
  226. "Manichaean": range(68288, 68351 + 1),
  227. "Avestan": range(68352, 68415 + 1),
  228. "Inscriptional Parthian": range(68416, 68447 + 1),
  229. "Inscriptional Pahlavi": range(68448, 68479 + 1),
  230. "Psalter Pahlavi": range(68480, 68527 + 1),
  231. "Old Turkic": range(68608, 68687 + 1),
  232. "Old Hungarian": range(68736, 68863 + 1),
  233. "Rumi Numeral Symbols": range(69216, 69247 + 1),
  234. "Brahmi": range(69632, 69759 + 1),
  235. "Kaithi": range(69760, 69839 + 1),
  236. "Sora Sompeng": range(69840, 69887 + 1),
  237. "Chakma": range(69888, 69967 + 1),
  238. "Mahajani": range(69968, 70015 + 1),
  239. "Sharada": range(70016, 70111 + 1),
  240. "Sinhala Archaic Numbers": range(70112, 70143 + 1),
  241. "Khojki": range(70144, 70223 + 1),
  242. "Multani": range(70272, 70319 + 1),
  243. "Khudawadi": range(70320, 70399 + 1),
  244. "Grantha": range(70400, 70527 + 1),
  245. "Newa": range(70656, 70783 + 1),
  246. "Tirhuta": range(70784, 70879 + 1),
  247. "Siddham": range(71040, 71167 + 1),
  248. "Modi": range(71168, 71263 + 1),
  249. "Mongolian Supplement": range(71264, 71295 + 1),
  250. "Takri": range(71296, 71375 + 1),
  251. "Ahom": range(71424, 71487 + 1),
  252. "Warang Citi": range(71840, 71935 + 1),
  253. "Zanabazar Square": range(72192, 72271 + 1),
  254. "Soyombo": range(72272, 72367 + 1),
  255. "Pau Cin Hau": range(72384, 72447 + 1),
  256. "Bhaiksuki": range(72704, 72815 + 1),
  257. "Marchen": range(72816, 72895 + 1),
  258. "Masaram Gondi": range(72960, 73055 + 1),
  259. "Cuneiform": range(73728, 74751 + 1),
  260. "Cuneiform Numbers and Punctuation": range(74752, 74879 + 1),
  261. "Early Dynastic Cuneiform": range(74880, 75087 + 1),
  262. "Egyptian Hieroglyphs": range(77824, 78895 + 1),
  263. "Anatolian Hieroglyphs": range(82944, 83583 + 1),
  264. "Bamum Supplement": range(92160, 92735 + 1),
  265. "Mro": range(92736, 92783 + 1),
  266. "Bassa Vah": range(92880, 92927 + 1),
  267. "Pahawh Hmong": range(92928, 93071 + 1),
  268. "Miao": range(93952, 94111 + 1),
  269. "Ideographic Symbols and Punctuation": range(94176, 94207 + 1),
  270. "Tangut": range(94208, 100351 + 1),
  271. "Tangut Components": range(100352, 101119 + 1),
  272. "Kana Supplement": range(110592, 110847 + 1),
  273. "Kana Extended-A": range(110848, 110895 + 1),
  274. "Nushu": range(110960, 111359 + 1),
  275. "Duployan": range(113664, 113823 + 1),
  276. "Shorthand Format Controls": range(113824, 113839 + 1),
  277. "Byzantine Musical Symbols": range(118784, 119039 + 1),
  278. "Musical Symbols": range(119040, 119295 + 1),
  279. "Ancient Greek Musical Notation": range(119296, 119375 + 1),
  280. "Tai Xuan Jing Symbols": range(119552, 119647 + 1),
  281. "Counting Rod Numerals": range(119648, 119679 + 1),
  282. "Mathematical Alphanumeric Symbols": range(119808, 120831 + 1),
  283. "Sutton SignWriting": range(120832, 121519 + 1),
  284. "Glagolitic Supplement": range(122880, 122927 + 1),
  285. "Mende Kikakui": range(124928, 125151 + 1),
  286. "Adlam": range(125184, 125279 + 1),
  287. "Arabic Mathematical Alphabetic Symbols": range(126464, 126719 + 1),
  288. "Mahjong Tiles": range(126976, 127023 + 1),
  289. "Domino Tiles": range(127024, 127135 + 1),
  290. "Playing Cards": range(127136, 127231 + 1),
  291. "Enclosed Alphanumeric Supplement": range(127232, 127487 + 1),
  292. "Enclosed Ideographic Supplement": range(127488, 127743 + 1),
  293. "Miscellaneous Symbols and Pictographs": range(127744, 128511 + 1),
  294. "Emoticons range(Emoji)": range(128512, 128591 + 1),
  295. "Ornamental Dingbats": range(128592, 128639 + 1),
  296. "Transport and Map Symbols": range(128640, 128767 + 1),
  297. "Alchemical Symbols": range(128768, 128895 + 1),
  298. "Geometric Shapes Extended": range(128896, 129023 + 1),
  299. "Supplemental Arrows-C": range(129024, 129279 + 1),
  300. "Supplemental Symbols and Pictographs": range(129280, 129535 + 1),
  301. "CJK Unified Ideographs Extension B": range(131072, 173791 + 1),
  302. "CJK Unified Ideographs Extension C": range(173824, 177983 + 1),
  303. "CJK Unified Ideographs Extension D": range(177984, 178207 + 1),
  304. "CJK Unified Ideographs Extension E": range(178208, 183983 + 1),
  305. "CJK Unified Ideographs Extension F": range(183984, 191471 + 1),
  306. "CJK Compatibility Ideographs Supplement": range(194560, 195103 + 1),
  307. "Tags": range(917504, 917631 + 1),
  308. "Variation Selectors Supplement": range(917760, 917999 + 1),
  309. } # type: Dict[str, range]
  310. UNICODE_SECONDARY_RANGE_KEYWORD = [
  311. "Supplement",
  312. "Extended",
  313. "Extensions",
  314. "Modifier",
  315. "Marks",
  316. "Punctuation",
  317. "Symbols",
  318. "Forms",
  319. "Operators",
  320. "Miscellaneous",
  321. "Drawing",
  322. "Block",
  323. "Shapes",
  324. "Supplemental",
  325. "Tags",
  326. ] # type: List[str]
  327. RE_POSSIBLE_ENCODING_INDICATION = re_compile(
  328. r"(?:(?:encoding)|(?:charset)|(?:coding))(?:[\:= ]{1,10})(?:[\"\']?)([a-zA-Z0-9\-_]+)(?:[\"\']?)",
  329. IGNORECASE,
  330. )
  331. IANA_SUPPORTED = sorted(
  332. filter(
  333. lambda x: x.endswith("_codec") is False
  334. and x not in {"rot_13", "tactis", "mbcs"},
  335. list(set(aliases.values())),
  336. )
  337. ) # type: List[str]
  338. IANA_SUPPORTED_COUNT = len(IANA_SUPPORTED) # type: int
  339. # pre-computed code page that are similar using the function cp_similarity.
  340. IANA_SUPPORTED_SIMILAR = {
  341. "cp037": ["cp1026", "cp1140", "cp273", "cp500"],
  342. "cp1026": ["cp037", "cp1140", "cp273", "cp500"],
  343. "cp1125": ["cp866"],
  344. "cp1140": ["cp037", "cp1026", "cp273", "cp500"],
  345. "cp1250": ["iso8859_2"],
  346. "cp1251": ["kz1048", "ptcp154"],
  347. "cp1252": ["iso8859_15", "iso8859_9", "latin_1"],
  348. "cp1253": ["iso8859_7"],
  349. "cp1254": ["iso8859_15", "iso8859_9", "latin_1"],
  350. "cp1257": ["iso8859_13"],
  351. "cp273": ["cp037", "cp1026", "cp1140", "cp500"],
  352. "cp437": ["cp850", "cp858", "cp860", "cp861", "cp862", "cp863", "cp865"],
  353. "cp500": ["cp037", "cp1026", "cp1140", "cp273"],
  354. "cp850": ["cp437", "cp857", "cp858", "cp865"],
  355. "cp857": ["cp850", "cp858", "cp865"],
  356. "cp858": ["cp437", "cp850", "cp857", "cp865"],
  357. "cp860": ["cp437", "cp861", "cp862", "cp863", "cp865"],
  358. "cp861": ["cp437", "cp860", "cp862", "cp863", "cp865"],
  359. "cp862": ["cp437", "cp860", "cp861", "cp863", "cp865"],
  360. "cp863": ["cp437", "cp860", "cp861", "cp862", "cp865"],
  361. "cp865": ["cp437", "cp850", "cp857", "cp858", "cp860", "cp861", "cp862", "cp863"],
  362. "cp866": ["cp1125"],
  363. "iso8859_10": ["iso8859_14", "iso8859_15", "iso8859_4", "iso8859_9", "latin_1"],
  364. "iso8859_11": ["tis_620"],
  365. "iso8859_13": ["cp1257"],
  366. "iso8859_14": [
  367. "iso8859_10",
  368. "iso8859_15",
  369. "iso8859_16",
  370. "iso8859_3",
  371. "iso8859_9",
  372. "latin_1",
  373. ],
  374. "iso8859_15": [
  375. "cp1252",
  376. "cp1254",
  377. "iso8859_10",
  378. "iso8859_14",
  379. "iso8859_16",
  380. "iso8859_3",
  381. "iso8859_9",
  382. "latin_1",
  383. ],
  384. "iso8859_16": [
  385. "iso8859_14",
  386. "iso8859_15",
  387. "iso8859_2",
  388. "iso8859_3",
  389. "iso8859_9",
  390. "latin_1",
  391. ],
  392. "iso8859_2": ["cp1250", "iso8859_16", "iso8859_4"],
  393. "iso8859_3": ["iso8859_14", "iso8859_15", "iso8859_16", "iso8859_9", "latin_1"],
  394. "iso8859_4": ["iso8859_10", "iso8859_2", "iso8859_9", "latin_1"],
  395. "iso8859_7": ["cp1253"],
  396. "iso8859_9": [
  397. "cp1252",
  398. "cp1254",
  399. "cp1258",
  400. "iso8859_10",
  401. "iso8859_14",
  402. "iso8859_15",
  403. "iso8859_16",
  404. "iso8859_3",
  405. "iso8859_4",
  406. "latin_1",
  407. ],
  408. "kz1048": ["cp1251", "ptcp154"],
  409. "latin_1": [
  410. "cp1252",
  411. "cp1254",
  412. "cp1258",
  413. "iso8859_10",
  414. "iso8859_14",
  415. "iso8859_15",
  416. "iso8859_16",
  417. "iso8859_3",
  418. "iso8859_4",
  419. "iso8859_9",
  420. ],
  421. "mac_iceland": ["mac_roman", "mac_turkish"],
  422. "mac_roman": ["mac_iceland", "mac_turkish"],
  423. "mac_turkish": ["mac_iceland", "mac_roman"],
  424. "ptcp154": ["cp1251", "kz1048"],
  425. "tis_620": ["iso8859_11"],
  426. } # type: Dict[str, List[str]]
  427. CHARDET_CORRESPONDENCE = {
  428. "iso2022_kr": "ISO-2022-KR",
  429. "iso2022_jp": "ISO-2022-JP",
  430. "euc_kr": "EUC-KR",
  431. "tis_620": "TIS-620",
  432. "utf_32": "UTF-32",
  433. "euc_jp": "EUC-JP",
  434. "koi8_r": "KOI8-R",
  435. "iso8859_1": "ISO-8859-1",
  436. "iso8859_2": "ISO-8859-2",
  437. "iso8859_5": "ISO-8859-5",
  438. "iso8859_6": "ISO-8859-6",
  439. "iso8859_7": "ISO-8859-7",
  440. "iso8859_8": "ISO-8859-8",
  441. "utf_16": "UTF-16",
  442. "cp855": "IBM855",
  443. "mac_cyrillic": "MacCyrillic",
  444. "gb2312": "GB2312",
  445. "gb18030": "GB18030",
  446. "cp932": "CP932",
  447. "cp866": "IBM866",
  448. "utf_8": "utf-8",
  449. "utf_8_sig": "UTF-8-SIG",
  450. "shift_jis": "SHIFT_JIS",
  451. "big5": "Big5",
  452. "cp1250": "windows-1250",
  453. "cp1251": "windows-1251",
  454. "cp1252": "Windows-1252",
  455. "cp1253": "windows-1253",
  456. "cp1255": "windows-1255",
  457. "cp1256": "windows-1256",
  458. "cp1254": "Windows-1254",
  459. "cp949": "CP949",
  460. } # type: Dict[str, str]
  461. COMMON_SAFE_ASCII_CHARACTERS = {
  462. "<",
  463. ">",
  464. "=",
  465. ":",
  466. "/",
  467. "&",
  468. ";",
  469. "{",
  470. "}",
  471. "[",
  472. "]",
  473. ",",
  474. "|",
  475. '"',
  476. "-",
  477. } # type: Set[str]
  478. KO_NAMES = {"johab", "cp949", "euc_kr"} # type: Set[str]
  479. ZH_NAMES = {"big5", "cp950", "big5hkscs", "hz"} # type: Set[str]
  480. NOT_PRINTABLE_PATTERN = re_compile(r"[0-9\W\n\r\t]+")
  481. LANGUAGE_SUPPORTED_COUNT = len(FREQUENCIES) # type: int