forked from SkyLined/alpha3
-
Notifications
You must be signed in to change notification settings - Fork 12
/
charsets.py
70 lines (64 loc) · 2.65 KB
/
charsets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: latin1 -*-
# http://en.wikipedia.org/wiki/Ascii
# http://en.wikipedia.org/wiki/Code_page_437
# http://en.wikipedia.org/wiki/ISO/IEC_8859-1
valid_character_encodings = ["ascii", "cp437", "latin-1", "utf-16"];
valid_character_casings = ["lowercase", "mixedcase", "uppercase"];
numbers = "0123456789";
symbols = " !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~";
symbols_cp437 = "��戍貝物洎悖停眾斯須號獄播噶擱藏霰帊昅恘倳眑婭笫崷窙嗲睧斀貘覷鏷禴矙�";
symbols_latin_1 = "╯丰戍貝物洎悖停眾斯須號獄播噶釬";
uppercase_alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
uppercase_alpha_cp437 = "��睼儰膫�";
uppercase_alpha_latin_1 = "擱藏霰帊昅恘倳眑婭笭欹詘棰";
lowercase_alpha = "abcdefghijklmnopqrstuvwxyz";
lowercase_alpha_cp437 = "�����������﹜ㄓ颬樉賟�";
lowercase_alpha_latin_1 = "葮摵蜠樉賥濋錎膼瀔嚦黀蘜矙�";
uppercase = numbers + uppercase_alpha;
uppercase_cp437 = uppercase + uppercase_alpha_cp437;
uppercase_latin_1 = uppercase + uppercase_alpha_latin_1;
lowercase = numbers + lowercase_alpha;
lowercase_cp437 = lowercase + lowercase_alpha_cp437;
lowercase_latin_1 = lowercase + lowercase_alpha_latin_1;
mixedcase = numbers + uppercase_alpha + lowercase_alpha;
mixedcase_cp437 = mixedcase + uppercase_alpha_cp437 + lowercase_alpha_cp437;
mixedcase_latin_1 = mixedcase + uppercase_alpha_latin_1 + lowercase_alpha_latin_1;
printable = mixedcase + symbols;
printable_cp437 = mixedcase_cp437 + symbols + symbols_cp437;
printable_latin_1 = mixedcase_latin_1 + symbols + symbols_latin_1;
valid_chars = {
"ascii": {
"lowercase": lowercase,
"mixedcase": mixedcase,
"uppercase": uppercase,
},
"cp437": {
"lowercase": lowercase_cp437,
"mixedcase": mixedcase_cp437,
"uppercase": uppercase_cp437,
},
"latin-1": {
"lowercase": lowercase_latin_1,
"mixedcase": mixedcase_latin_1,
"uppercase": uppercase_latin_1,
},
"utf-16": {
"lowercase": lowercase,
"mixedcase": mixedcase,
"uppercase": uppercase,
},
}
# Automatically generate a similar table with arrays of integer character codes:
valid_charcodes = {}
for char_encoding in valid_chars:
valid_charcodes[char_encoding] = {}
for case, chars in valid_chars[char_encoding].items():
valid_charcodes[char_encoding][case] = []
for char in chars:
valid_charcodes[char_encoding][case] += [ord(char)]
charcode_fmtstr = {
"ascii": "%02X",
"cp437": "%02X",
"latin-1": "%02X",
"utf-16": "%04X"
}