MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / make

Function make

tools/python-3.11.9-amd64/Tools/i18n/msgfmt.py:99–215  ·  view source on GitHub ↗
(filename, outfile)

Source from the content-addressed store, hash-verified

97
98
99def make(filename, outfile):
100 ID = 1
101 STR = 2
102 CTXT = 3
103
104 # Compute .mo name from .po name and arguments
105 if filename.endswith('.po'):
106 infile = filename
107 else:
108 infile = filename + '.po'
109 if outfile is None:
110 outfile = os.path.splitext(infile)[0] + '.mo'
111
112 try:
113 with open(infile, 'rb') as f:
114 lines = f.readlines()
115 except IOError as msg:
116 print(msg, file=sys.stderr)
117 sys.exit(1)
118
119 section = msgctxt = None
120 fuzzy = 0
121
122 # Start off assuming Latin-1, so everything decodes without failure,
123 # until we know the exact encoding
124 encoding = 'latin-1'
125
126 # Parse the catalog
127 lno = 0
128 for l in lines:
129 l = l.decode(encoding)
130 lno += 1
131 # If we get a comment line after a msgstr, this is a new entry
132 if l[0] == '#' and section == STR:
133 add(msgctxt, msgid, msgstr, fuzzy)
134 section = msgctxt = None
135 fuzzy = 0
136 # Record a fuzzy mark
137 if l[:2] == '#,' and 'fuzzy' in l:
138 fuzzy = 1
139 # Skip comments
140 if l[0] == '#':
141 continue
142 # Now we are in a msgid or msgctxt section, output previous section
143 if l.startswith('msgctxt'):
144 if section == STR:
145 add(msgctxt, msgid, msgstr, fuzzy)
146 section = CTXT
147 l = l[7:]
148 msgctxt = b''
149 elif l.startswith('msgid') and not l.startswith('msgid_plural'):
150 if section == STR:
151 add(msgctxt, msgid, msgstr, fuzzy)
152 if not msgid:
153 # See whether there is an encoding declaration
154 p = HeaderParser()
155 charset = p.parsestr(msgstr.decode(encoding)).get_content_charset()
156 if charset:

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 15

parsestrMethod · 0.95
HeaderParserClass · 0.90
endswithMethod · 0.80
splitextMethod · 0.80
startswithMethod · 0.80
get_content_charsetMethod · 0.80
stripMethod · 0.80
addFunction · 0.70
generateFunction · 0.70
openFunction · 0.50
printFunction · 0.50
readlinesMethod · 0.45

Tested by

no test coverage detected