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

Function generate

Tools/i18n/msgfmt.py:59–97  ·  view source on GitHub ↗

Return the generated output.

()

Source from the content-addressed store, hash-verified

57
58
59def generate():
60 "Return the generated output."
61 global MESSAGES
62 # the keys are sorted in the .mo file
63 keys = sorted(MESSAGES.keys())
64 offsets = []
65 ids = strs = b''
66 for id in keys:
67 # For each string, we need size and file offset. Each string is NUL
68 # terminated; the NUL does not count into the size.
69 offsets.append((len(ids), len(id), len(strs), len(MESSAGES[id])))
70 ids += id + b'\0'
71 strs += MESSAGES[id] + b'\0'
72 output = ''
73 # The header is 7 32-bit unsigned integers. We don't use hash tables, so
74 # the keys start right after the index tables.
75 # translated string.
76 keystart = 7*4+16*len(keys)
77 # and the values start after the keys
78 valuestart = keystart + len(ids)
79 koffsets = []
80 voffsets = []
81 # The string table first has the list of keys, then the list of values.
82 # Each entry has first the size of the string, then the file offset.
83 for o1, l1, o2, l2 in offsets:
84 koffsets += [l1, o1+keystart]
85 voffsets += [l2, o2+valuestart]
86 offsets = koffsets + voffsets
87 output = struct.pack("Iiiiiii",
88 0x950412de, # Magic
89 0, # Version
90 len(keys), # # of entries
91 7*4, # start of key index
92 7*4+len(keys)*8, # start of value index
93 0, 0) # size and offset of hash table
94 output += array.array("i", offsets).tobytes()
95 output += ids
96 output += strs
97 return output
98
99
100def make(filename, outfile):

Callers 1

makeFunction · 0.85

Calls 3

keysMethod · 0.45
appendMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…