MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Tools/unicode/makeunicodedata.py:1021–1243  ·  view source on GitHub ↗
(self, version, ideograph_check=True)

Source from the content-addressed store, hash-verified

1019 # table: List[Optional[UcdRecord]] # index is codepoint; None means unassigned
1020
1021 def __init__(self, version, ideograph_check=True):
1022 self.changed = []
1023 table = [None] * 0x110000
1024 for s in UcdFile(UNICODE_DATA, version):
1025 char = int(s[0], 16)
1026 table[char] = from_row(s)
1027
1028 self.derived_name_ranges = []
1029 self.derived_name_prefixes = {
1030 prefix: i
1031 for i, (_, prefix) in enumerate(derived_name_range_names)
1032 }
1033
1034 # expand first-last ranges
1035 field = None
1036 for i in range(0, 0x110000):
1037 # The file UnicodeData.txt has its own distinct way of
1038 # expressing ranges. See:
1039 # https://www.unicode.org/reports/tr44/#Code_Point_Ranges
1040 s = table[i]
1041 if s:
1042 if s.name[-6:] == "First>":
1043 s.name = ""
1044 field = dataclasses.astuple(s)[:15]
1045 elif s.name[-5:] == "Last>":
1046 for j, (rangename, _) in enumerate(derived_name_range_names):
1047 if s.name.startswith("<" + rangename):
1048 self.derived_name_ranges.append(
1049 (field[0], s.codepoint, j))
1050 break
1051 s.name = ""
1052 field = None
1053 else:
1054 codepoint = s.codepoint
1055 if s.name.endswith(codepoint):
1056 prefix = s.name[:-len(codepoint)]
1057 j = self.derived_name_prefixes.get(prefix)
1058 if j is None:
1059 j = len(self.derived_name_prefixes)
1060 self.derived_name_prefixes[prefix] = j
1061 if (self.derived_name_ranges
1062 and self.derived_name_ranges[-1][2] == j
1063 and int(self.derived_name_ranges[-1][1], 16) == i - 1):
1064 self.derived_name_ranges[-1][1] = codepoint
1065 else:
1066 self.derived_name_ranges.append(
1067 [codepoint, codepoint, j])
1068 s.name = ""
1069 elif field:
1070 table[i] = from_row(('%04X' % i,) + field[1:])
1071
1072 # public attributes
1073 self.filename = UNICODE_DATA % ''
1074 self.table = table
1075 self.chars = list(range(0x110000)) # unicode 3.2
1076
1077 # check for name aliases and named sequences, see #12753
1078 # aliases and named sequences are not in 3.2.0

Callers

nothing calls this directly

Calls 15

openMethod · 0.95
UcdFileClass · 0.85
from_rowFunction · 0.85
enumerateFunction · 0.85
listClass · 0.85
open_dataFunction · 0.85
expand_rangeFunction · 0.85
expandedMethod · 0.80
recordsMethod · 0.80
startswithMethod · 0.45
appendMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected