File: print_has_compat_exceptions.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 (22 lines) | stat: -rw-r--r-- 650 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
from precis_i18n import get_profile
from precis_i18n.derived import derived_property
from precis_i18n.unicode import UnicodeData

UCD = UnicodeData()
profile = get_profile("UsernameCasePreserved")

count = 0
ascii = 0
for cp in range(0, 0x110000):
    _, reason = derived_property(cp, UCD)
    if reason == "has_compat":
        try:
            result = profile.enforce(chr(cp)).encode("utf-8")
            print("%04x => %s" % (cp, result))

            if len(result) == 1 and result[0] < 128:
                ascii += 1
            count += 1
        except UnicodeEncodeError:
            pass
print("Exceptions: %d, %d ascii" % (count, ascii))