File: kevin_table.py

package info (click to toggle)
python-precis-i18n 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,836 kB
  • sloc: python: 1,825; sh: 28; makefile: 3
file content (68 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download | duplicates (2)
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
"""
Generate 'Kevin' table for README.
"""

import precis_i18n.codec  # noqa: F401

letter_k = [
    ord("K"),
    0x212A,
    0xFF2B,
    0x039A,
    0x1E32,
    0x1E34,
    0x2C69,
    0xA740,
    0xA742,
    0xA744,
    0xA7A2,
    0x24C0,
    0x1F11A,
    0x1F13A,
    0x1F15A,
    0x1F17A,
]


def _escape(s):
    return s.encode("raw-unicode-escape").decode("ascii").replace("\\", "\")


def _xml_escape(s):
    return s.encode("ascii", errors="xmlcharrefreplace").decode("ascii")


def _column(s):
    try:
        # Leave ASCII strings alone.
        s.encode("ascii")
        return s
    except UnicodeEncodeError:
        pass
    return "%s (%s)" % (_xml_escape(s), _escape(s))


print("Original String|UsernameCasePreserved|UsernameCaseMapped|NicknameCaseMapped")
print("---------------|---------------------|------------------|------------------")

for k in letter_k:
    kevin = chr(k) + "evin"

    try:
        case_preserved = kevin.encode("UsernameCasePreserved").decode("utf-8")
    except UnicodeEncodeError:
        case_preserved = "DISALLOWED"

    try:
        case_mapped = kevin.encode("UsernameCaseMapped").decode("utf-8")
    except UnicodeEncodeError:
        case_mapped = "DISALLOWED"

    nickname = kevin.encode("NicknameCaseMapped").decode("utf-8")

    col1 = _column(kevin)
    col2 = _column(case_preserved)
    col3 = _column(case_mapped)
    col4 = _column(nickname)

    print("%s | %s | %s | %s" % (col1, col2, col3, col4))