source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/contrib/pymysql/charset.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 13.5 KB
Line 
1MBLENGTH = {
2        8:1,
3        33:3,
4        88:2,
5        91:2
6        }
7
8
9class Charset(object):
10    def __init__(self, id, name, collation, is_default):
11        self.id, self.name, self.collation = id, name, collation
12        self.is_default = is_default == 'Yes'
13
14    def __repr__(self):
15        return "Charset(id=%s, name=%r, collation=%r)" % (
16                self.id, self.name, self.collation)
17
18    @property
19    def encoding(self):
20        name = self.name
21        if name == 'utf8mb4':
22            return 'utf8'
23        return name
24
25    @property
26    def is_binary(self):
27        return self.id == 63
28
29
30class Charsets:
31    def __init__(self):
32        self._by_id = {}
33
34    def add(self, c):
35        self._by_id[c.id] = c
36
37    def by_id(self, id):
38        return self._by_id[id]
39
40    def by_name(self, name):
41        name = name.lower()
42        for c in self._by_id.values():
43            if c.name == name and c.is_default:
44                return c
45
46_charsets = Charsets()
47"""
48Generated with:
49
50mysql -N -s -e "select id, character_set_name, collation_name, is_default
51from information_schema.collations order by id;" | python -c "import sys
52for l in sys.stdin.readlines():
53        id, name, collation, is_default  = l.split(chr(9))
54        print '_charsets.add(Charset(%s, \'%s\', \'%s\', \'%s\'))' \
55                % (id, name, collation, is_default.strip())
56"
57
58"""
59_charsets.add(Charset(1, 'big5', 'big5_chinese_ci', 'Yes'))
60_charsets.add(Charset(2, 'latin2', 'latin2_czech_cs', ''))
61_charsets.add(Charset(3, 'dec8', 'dec8_swedish_ci', 'Yes'))
62_charsets.add(Charset(4, 'cp850', 'cp850_general_ci', 'Yes'))
63_charsets.add(Charset(5, 'latin1', 'latin1_german1_ci', ''))
64_charsets.add(Charset(6, 'hp8', 'hp8_english_ci', 'Yes'))
65_charsets.add(Charset(7, 'koi8r', 'koi8r_general_ci', 'Yes'))
66_charsets.add(Charset(8, 'latin1', 'latin1_swedish_ci', 'Yes'))
67_charsets.add(Charset(9, 'latin2', 'latin2_general_ci', 'Yes'))
68_charsets.add(Charset(10, 'swe7', 'swe7_swedish_ci', 'Yes'))
69_charsets.add(Charset(11, 'ascii', 'ascii_general_ci', 'Yes'))
70_charsets.add(Charset(12, 'ujis', 'ujis_japanese_ci', 'Yes'))
71_charsets.add(Charset(13, 'sjis', 'sjis_japanese_ci', 'Yes'))
72_charsets.add(Charset(14, 'cp1251', 'cp1251_bulgarian_ci', ''))
73_charsets.add(Charset(15, 'latin1', 'latin1_danish_ci', ''))
74_charsets.add(Charset(16, 'hebrew', 'hebrew_general_ci', 'Yes'))
75_charsets.add(Charset(18, 'tis620', 'tis620_thai_ci', 'Yes'))
76_charsets.add(Charset(19, 'euckr', 'euckr_korean_ci', 'Yes'))
77_charsets.add(Charset(20, 'latin7', 'latin7_estonian_cs', ''))
78_charsets.add(Charset(21, 'latin2', 'latin2_hungarian_ci', ''))
79_charsets.add(Charset(22, 'koi8u', 'koi8u_general_ci', 'Yes'))
80_charsets.add(Charset(23, 'cp1251', 'cp1251_ukrainian_ci', ''))
81_charsets.add(Charset(24, 'gb2312', 'gb2312_chinese_ci', 'Yes'))
82_charsets.add(Charset(25, 'greek', 'greek_general_ci', 'Yes'))
83_charsets.add(Charset(26, 'cp1250', 'cp1250_general_ci', 'Yes'))
84_charsets.add(Charset(27, 'latin2', 'latin2_croatian_ci', ''))
85_charsets.add(Charset(28, 'gbk', 'gbk_chinese_ci', 'Yes'))
86_charsets.add(Charset(29, 'cp1257', 'cp1257_lithuanian_ci', ''))
87_charsets.add(Charset(30, 'latin5', 'latin5_turkish_ci', 'Yes'))
88_charsets.add(Charset(31, 'latin1', 'latin1_german2_ci', ''))
89_charsets.add(Charset(32, 'armscii8', 'armscii8_general_ci', 'Yes'))
90_charsets.add(Charset(33, 'utf8', 'utf8_general_ci', 'Yes'))
91_charsets.add(Charset(34, 'cp1250', 'cp1250_czech_cs', ''))
92_charsets.add(Charset(35, 'ucs2', 'ucs2_general_ci', 'Yes'))
93_charsets.add(Charset(36, 'cp866', 'cp866_general_ci', 'Yes'))
94_charsets.add(Charset(37, 'keybcs2', 'keybcs2_general_ci', 'Yes'))
95_charsets.add(Charset(38, 'macce', 'macce_general_ci', 'Yes'))
96_charsets.add(Charset(39, 'macroman', 'macroman_general_ci', 'Yes'))
97_charsets.add(Charset(40, 'cp852', 'cp852_general_ci', 'Yes'))
98_charsets.add(Charset(41, 'latin7', 'latin7_general_ci', 'Yes'))
99_charsets.add(Charset(42, 'latin7', 'latin7_general_cs', ''))
100_charsets.add(Charset(43, 'macce', 'macce_bin', ''))
101_charsets.add(Charset(44, 'cp1250', 'cp1250_croatian_ci', ''))
102_charsets.add(Charset(45, 'utf8mb4', 'utf8mb4_general_ci', 'Yes'))
103_charsets.add(Charset(46, 'utf8mb4', 'utf8mb4_bin', ''))
104_charsets.add(Charset(47, 'latin1', 'latin1_bin', ''))
105_charsets.add(Charset(48, 'latin1', 'latin1_general_ci', ''))
106_charsets.add(Charset(49, 'latin1', 'latin1_general_cs', ''))
107_charsets.add(Charset(50, 'cp1251', 'cp1251_bin', ''))
108_charsets.add(Charset(51, 'cp1251', 'cp1251_general_ci', 'Yes'))
109_charsets.add(Charset(52, 'cp1251', 'cp1251_general_cs', ''))
110_charsets.add(Charset(53, 'macroman', 'macroman_bin', ''))
111_charsets.add(Charset(54, 'utf16', 'utf16_general_ci', 'Yes'))
112_charsets.add(Charset(55, 'utf16', 'utf16_bin', ''))
113_charsets.add(Charset(57, 'cp1256', 'cp1256_general_ci', 'Yes'))
114_charsets.add(Charset(58, 'cp1257', 'cp1257_bin', ''))
115_charsets.add(Charset(59, 'cp1257', 'cp1257_general_ci', 'Yes'))
116_charsets.add(Charset(60, 'utf32', 'utf32_general_ci', 'Yes'))
117_charsets.add(Charset(61, 'utf32', 'utf32_bin', ''))
118_charsets.add(Charset(63, 'binary', 'binary', 'Yes'))
119_charsets.add(Charset(64, 'armscii8', 'armscii8_bin', ''))
120_charsets.add(Charset(65, 'ascii', 'ascii_bin', ''))
121_charsets.add(Charset(66, 'cp1250', 'cp1250_bin', ''))
122_charsets.add(Charset(67, 'cp1256', 'cp1256_bin', ''))
123_charsets.add(Charset(68, 'cp866', 'cp866_bin', ''))
124_charsets.add(Charset(69, 'dec8', 'dec8_bin', ''))
125_charsets.add(Charset(70, 'greek', 'greek_bin', ''))
126_charsets.add(Charset(71, 'hebrew', 'hebrew_bin', ''))
127_charsets.add(Charset(72, 'hp8', 'hp8_bin', ''))
128_charsets.add(Charset(73, 'keybcs2', 'keybcs2_bin', ''))
129_charsets.add(Charset(74, 'koi8r', 'koi8r_bin', ''))
130_charsets.add(Charset(75, 'koi8u', 'koi8u_bin', ''))
131_charsets.add(Charset(77, 'latin2', 'latin2_bin', ''))
132_charsets.add(Charset(78, 'latin5', 'latin5_bin', ''))
133_charsets.add(Charset(79, 'latin7', 'latin7_bin', ''))
134_charsets.add(Charset(80, 'cp850', 'cp850_bin', ''))
135_charsets.add(Charset(81, 'cp852', 'cp852_bin', ''))
136_charsets.add(Charset(82, 'swe7', 'swe7_bin', ''))
137_charsets.add(Charset(83, 'utf8', 'utf8_bin', ''))
138_charsets.add(Charset(84, 'big5', 'big5_bin', ''))
139_charsets.add(Charset(85, 'euckr', 'euckr_bin', ''))
140_charsets.add(Charset(86, 'gb2312', 'gb2312_bin', ''))
141_charsets.add(Charset(87, 'gbk', 'gbk_bin', ''))
142_charsets.add(Charset(88, 'sjis', 'sjis_bin', ''))
143_charsets.add(Charset(89, 'tis620', 'tis620_bin', ''))
144_charsets.add(Charset(90, 'ucs2', 'ucs2_bin', ''))
145_charsets.add(Charset(91, 'ujis', 'ujis_bin', ''))
146_charsets.add(Charset(92, 'geostd8', 'geostd8_general_ci', 'Yes'))
147_charsets.add(Charset(93, 'geostd8', 'geostd8_bin', ''))
148_charsets.add(Charset(94, 'latin1', 'latin1_spanish_ci', ''))
149_charsets.add(Charset(95, 'cp932', 'cp932_japanese_ci', 'Yes'))
150_charsets.add(Charset(96, 'cp932', 'cp932_bin', ''))
151_charsets.add(Charset(97, 'eucjpms', 'eucjpms_japanese_ci', 'Yes'))
152_charsets.add(Charset(98, 'eucjpms', 'eucjpms_bin', ''))
153_charsets.add(Charset(99, 'cp1250', 'cp1250_polish_ci', ''))
154_charsets.add(Charset(101, 'utf16', 'utf16_unicode_ci', ''))
155_charsets.add(Charset(102, 'utf16', 'utf16_icelandic_ci', ''))
156_charsets.add(Charset(103, 'utf16', 'utf16_latvian_ci', ''))
157_charsets.add(Charset(104, 'utf16', 'utf16_romanian_ci', ''))
158_charsets.add(Charset(105, 'utf16', 'utf16_slovenian_ci', ''))
159_charsets.add(Charset(106, 'utf16', 'utf16_polish_ci', ''))
160_charsets.add(Charset(107, 'utf16', 'utf16_estonian_ci', ''))
161_charsets.add(Charset(108, 'utf16', 'utf16_spanish_ci', ''))
162_charsets.add(Charset(109, 'utf16', 'utf16_swedish_ci', ''))
163_charsets.add(Charset(110, 'utf16', 'utf16_turkish_ci', ''))
164_charsets.add(Charset(111, 'utf16', 'utf16_czech_ci', ''))
165_charsets.add(Charset(112, 'utf16', 'utf16_danish_ci', ''))
166_charsets.add(Charset(113, 'utf16', 'utf16_lithuanian_ci', ''))
167_charsets.add(Charset(114, 'utf16', 'utf16_slovak_ci', ''))
168_charsets.add(Charset(115, 'utf16', 'utf16_spanish2_ci', ''))
169_charsets.add(Charset(116, 'utf16', 'utf16_roman_ci', ''))
170_charsets.add(Charset(117, 'utf16', 'utf16_persian_ci', ''))
171_charsets.add(Charset(118, 'utf16', 'utf16_esperanto_ci', ''))
172_charsets.add(Charset(119, 'utf16', 'utf16_hungarian_ci', ''))
173_charsets.add(Charset(120, 'utf16', 'utf16_sinhala_ci', ''))
174_charsets.add(Charset(128, 'ucs2', 'ucs2_unicode_ci', ''))
175_charsets.add(Charset(129, 'ucs2', 'ucs2_icelandic_ci', ''))
176_charsets.add(Charset(130, 'ucs2', 'ucs2_latvian_ci', ''))
177_charsets.add(Charset(131, 'ucs2', 'ucs2_romanian_ci', ''))
178_charsets.add(Charset(132, 'ucs2', 'ucs2_slovenian_ci', ''))
179_charsets.add(Charset(133, 'ucs2', 'ucs2_polish_ci', ''))
180_charsets.add(Charset(134, 'ucs2', 'ucs2_estonian_ci', ''))
181_charsets.add(Charset(135, 'ucs2', 'ucs2_spanish_ci', ''))
182_charsets.add(Charset(136, 'ucs2', 'ucs2_swedish_ci', ''))
183_charsets.add(Charset(137, 'ucs2', 'ucs2_turkish_ci', ''))
184_charsets.add(Charset(138, 'ucs2', 'ucs2_czech_ci', ''))
185_charsets.add(Charset(139, 'ucs2', 'ucs2_danish_ci', ''))
186_charsets.add(Charset(140, 'ucs2', 'ucs2_lithuanian_ci', ''))
187_charsets.add(Charset(141, 'ucs2', 'ucs2_slovak_ci', ''))
188_charsets.add(Charset(142, 'ucs2', 'ucs2_spanish2_ci', ''))
189_charsets.add(Charset(143, 'ucs2', 'ucs2_roman_ci', ''))
190_charsets.add(Charset(144, 'ucs2', 'ucs2_persian_ci', ''))
191_charsets.add(Charset(145, 'ucs2', 'ucs2_esperanto_ci', ''))
192_charsets.add(Charset(146, 'ucs2', 'ucs2_hungarian_ci', ''))
193_charsets.add(Charset(147, 'ucs2', 'ucs2_sinhala_ci', ''))
194_charsets.add(Charset(159, 'ucs2', 'ucs2_general_mysql500_ci', ''))
195_charsets.add(Charset(160, 'utf32', 'utf32_unicode_ci', ''))
196_charsets.add(Charset(161, 'utf32', 'utf32_icelandic_ci', ''))
197_charsets.add(Charset(162, 'utf32', 'utf32_latvian_ci', ''))
198_charsets.add(Charset(163, 'utf32', 'utf32_romanian_ci', ''))
199_charsets.add(Charset(164, 'utf32', 'utf32_slovenian_ci', ''))
200_charsets.add(Charset(165, 'utf32', 'utf32_polish_ci', ''))
201_charsets.add(Charset(166, 'utf32', 'utf32_estonian_ci', ''))
202_charsets.add(Charset(167, 'utf32', 'utf32_spanish_ci', ''))
203_charsets.add(Charset(168, 'utf32', 'utf32_swedish_ci', ''))
204_charsets.add(Charset(169, 'utf32', 'utf32_turkish_ci', ''))
205_charsets.add(Charset(170, 'utf32', 'utf32_czech_ci', ''))
206_charsets.add(Charset(171, 'utf32', 'utf32_danish_ci', ''))
207_charsets.add(Charset(172, 'utf32', 'utf32_lithuanian_ci', ''))
208_charsets.add(Charset(173, 'utf32', 'utf32_slovak_ci', ''))
209_charsets.add(Charset(174, 'utf32', 'utf32_spanish2_ci', ''))
210_charsets.add(Charset(175, 'utf32', 'utf32_roman_ci', ''))
211_charsets.add(Charset(176, 'utf32', 'utf32_persian_ci', ''))
212_charsets.add(Charset(177, 'utf32', 'utf32_esperanto_ci', ''))
213_charsets.add(Charset(178, 'utf32', 'utf32_hungarian_ci', ''))
214_charsets.add(Charset(179, 'utf32', 'utf32_sinhala_ci', ''))
215_charsets.add(Charset(192, 'utf8', 'utf8_unicode_ci', ''))
216_charsets.add(Charset(193, 'utf8', 'utf8_icelandic_ci', ''))
217_charsets.add(Charset(194, 'utf8', 'utf8_latvian_ci', ''))
218_charsets.add(Charset(195, 'utf8', 'utf8_romanian_ci', ''))
219_charsets.add(Charset(196, 'utf8', 'utf8_slovenian_ci', ''))
220_charsets.add(Charset(197, 'utf8', 'utf8_polish_ci', ''))
221_charsets.add(Charset(198, 'utf8', 'utf8_estonian_ci', ''))
222_charsets.add(Charset(199, 'utf8', 'utf8_spanish_ci', ''))
223_charsets.add(Charset(200, 'utf8', 'utf8_swedish_ci', ''))
224_charsets.add(Charset(201, 'utf8', 'utf8_turkish_ci', ''))
225_charsets.add(Charset(202, 'utf8', 'utf8_czech_ci', ''))
226_charsets.add(Charset(203, 'utf8', 'utf8_danish_ci', ''))
227_charsets.add(Charset(204, 'utf8', 'utf8_lithuanian_ci', ''))
228_charsets.add(Charset(205, 'utf8', 'utf8_slovak_ci', ''))
229_charsets.add(Charset(206, 'utf8', 'utf8_spanish2_ci', ''))
230_charsets.add(Charset(207, 'utf8', 'utf8_roman_ci', ''))
231_charsets.add(Charset(208, 'utf8', 'utf8_persian_ci', ''))
232_charsets.add(Charset(209, 'utf8', 'utf8_esperanto_ci', ''))
233_charsets.add(Charset(210, 'utf8', 'utf8_hungarian_ci', ''))
234_charsets.add(Charset(211, 'utf8', 'utf8_sinhala_ci', ''))
235_charsets.add(Charset(223, 'utf8', 'utf8_general_mysql500_ci', ''))
236_charsets.add(Charset(224, 'utf8mb4', 'utf8mb4_unicode_ci', ''))
237_charsets.add(Charset(225, 'utf8mb4', 'utf8mb4_icelandic_ci', ''))
238_charsets.add(Charset(226, 'utf8mb4', 'utf8mb4_latvian_ci', ''))
239_charsets.add(Charset(227, 'utf8mb4', 'utf8mb4_romanian_ci', ''))
240_charsets.add(Charset(228, 'utf8mb4', 'utf8mb4_slovenian_ci', ''))
241_charsets.add(Charset(229, 'utf8mb4', 'utf8mb4_polish_ci', ''))
242_charsets.add(Charset(230, 'utf8mb4', 'utf8mb4_estonian_ci', ''))
243_charsets.add(Charset(231, 'utf8mb4', 'utf8mb4_spanish_ci', ''))
244_charsets.add(Charset(232, 'utf8mb4', 'utf8mb4_swedish_ci', ''))
245_charsets.add(Charset(233, 'utf8mb4', 'utf8mb4_turkish_ci', ''))
246_charsets.add(Charset(234, 'utf8mb4', 'utf8mb4_czech_ci', ''))
247_charsets.add(Charset(235, 'utf8mb4', 'utf8mb4_danish_ci', ''))
248_charsets.add(Charset(236, 'utf8mb4', 'utf8mb4_lithuanian_ci', ''))
249_charsets.add(Charset(237, 'utf8mb4', 'utf8mb4_slovak_ci', ''))
250_charsets.add(Charset(238, 'utf8mb4', 'utf8mb4_spanish2_ci', ''))
251_charsets.add(Charset(239, 'utf8mb4', 'utf8mb4_roman_ci', ''))
252_charsets.add(Charset(240, 'utf8mb4', 'utf8mb4_persian_ci', ''))
253_charsets.add(Charset(241, 'utf8mb4', 'utf8mb4_esperanto_ci', ''))
254_charsets.add(Charset(242, 'utf8mb4', 'utf8mb4_hungarian_ci', ''))
255_charsets.add(Charset(243, 'utf8mb4', 'utf8mb4_sinhala_ci', ''))
256_charsets.add(Charset(244, 'utf8mb4', 'utf8mb4_german2_ci', ''))
257_charsets.add(Charset(245, 'utf8mb4', 'utf8mb4_croatian_ci', ''))
258_charsets.add(Charset(246, 'utf8mb4', 'utf8mb4_unicode_520_ci', ''))
259_charsets.add(Charset(247, 'utf8mb4', 'utf8mb4_vietnamese_ci', ''))
260
261
262charset_by_name = _charsets.by_name
263charset_by_id = _charsets.by_id
264
265
266def charset_to_encoding(name):
267    """Convert MySQL's charset name to Python's codec name"""
268    if name == 'utf8mb4':
269        return 'utf8'
270    return name
Note: See TracBrowser for help on using the repository browser.