|
0 |
From 38cd4a0fda5b963611a212b4debc0c9aa1c61538 Mon Sep 17 00:00:00 2001
|
|
1 |
From: Nobuhiro Iwamatsu <iwamatsu@debian.org>
|
|
2 |
Date: Sat, 23 May 2020 20:41:49 +0900
|
|
3 |
Subject: [PATCH] Change from python2 code to python3
|
|
4 |
|
|
5 |
The original patch was took from:
|
|
6 |
https://github.com/google/mozc/issues/462
|
|
7 |
https://github.com/google/mozc/files/4048079/mozc-2.23.2815.102-python-3.patch.txt
|
|
8 |
|
|
9 |
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
|
|
10 |
---
|
|
11 |
src/android/gen_emoji_data.py | 224 +++++++++---------
|
|
12 |
src/android/gen_emoticon_data.py | 23 +-
|
|
13 |
src/android/gen_mozc_drawable.py | 10 +-
|
|
14 |
src/android/gen_touch_event_stats.py | 8 +-
|
|
15 |
src/android/run_android_test.py | 17 +-
|
|
16 |
src/base/gen_character_set.py | 13 +-
|
|
17 |
src/base/gen_config_file_stream_data.py | 6 +-
|
|
18 |
src/build_mozc.py | 20 +-
|
|
19 |
src/build_tools/android_util.py | 6 +-
|
|
20 |
src/build_tools/binary_size_checker.py | 8 +-
|
|
21 |
src/build_tools/build_and_sign_pkg_mac.py | 4 +-
|
|
22 |
src/build_tools/build_breakpad.py | 4 +-
|
|
23 |
src/build_tools/build_diskimage_mac.py | 2 +-
|
|
24 |
src/build_tools/change_reference_mac.py | 4 +-
|
|
25 |
src/build_tools/code_generator_util.py | 49 ++--
|
|
26 |
src/build_tools/codesign_mac.py | 26 +-
|
|
27 |
src/build_tools/copy_dll_and_symbol.py | 4 +-
|
|
28 |
src/build_tools/copy_file.py | 2 +-
|
|
29 |
src/build_tools/copy_qt_frameworks_mac.py | 6 +-
|
|
30 |
src/build_tools/embed_file.py | 38 +--
|
|
31 |
src/build_tools/embed_pathname.py | 6 +-
|
|
32 |
src/build_tools/ensure_gyp_module_path.py | 12 +-
|
|
33 |
src/build_tools/gen_win32_resource_header.py | 2 +-
|
|
34 |
src/build_tools/mozc_version.py | 17 +-
|
|
35 |
src/build_tools/redirect.py | 7 +-
|
|
36 |
src/build_tools/run_after_chdir.py | 2 +-
|
|
37 |
.../serialized_string_array_builder.py | 6 +-
|
|
38 |
src/build_tools/test_tools/gtest_report.py | 10 +-
|
|
39 |
src/build_tools/test_tools/test_launcher.py | 5 +-
|
|
40 |
src/build_tools/tweak_data.py | 2 +-
|
|
41 |
src/build_tools/tweak_info_plist.py | 6 +-
|
|
42 |
src/build_tools/tweak_info_plist_strings.py | 4 +-
|
|
43 |
src/build_tools/tweak_macinstaller_script.py | 2 +-
|
|
44 |
src/build_tools/tweak_pkgproj.py | 4 +-
|
|
45 |
src/build_tools/util.py | 6 +-
|
|
46 |
src/build_tools/zlib_util.py | 4 +-
|
|
47 |
src/chrome/nacl/nacl_net_test_server.py | 49 ++--
|
|
48 |
src/chrome/nacl/pnacl_translate.py | 24 +-
|
|
49 |
src/chrome/nacl/run_nacl_test.py | 2 +-
|
|
50 |
src/client/gen_client_quality_test_data.py | 44 ++--
|
|
51 |
src/composer/internal/gen_typing_model.py | 19 +-
|
|
52 |
src/converter/gen_boundary_data.py | 16 +-
|
|
53 |
.../gen_quality_regression_test_data.py | 22 +-
|
|
54 |
src/converter/gen_segmenter_code.py | 25 +-
|
|
55 |
src/data/test/calculator/gen_test.py | 64 +++--
|
|
56 |
src/data_manager/gen_connection_data.py | 33 ++-
|
|
57 |
src/dictionary/gen_pos_map.py | 18 +-
|
|
58 |
src/dictionary/gen_pos_rewrite_rule.py | 19 +-
|
|
59 |
src/dictionary/gen_suffix_data.py | 8 +-
|
|
60 |
src/dictionary/gen_user_pos_data.py | 4 +-
|
|
61 |
src/dictionary/gen_zip_code_seed.py | 22 +-
|
|
62 |
src/dictionary/zip_code_util.py | 10 +-
|
|
63 |
src/gui/character_pad/data/gen_cp932_map.py | 26 +-
|
|
64 |
.../data/gen_local_character_map.py | 27 ++-
|
|
65 |
.../character_pad/data/gen_unicode_blocks.py | 15 +-
|
|
66 |
.../character_pad/data/gen_unicode_data.py | 21 +-
|
|
67 |
src/gui/character_pad/data/gen_unihan_data.py | 43 ++--
|
|
68 |
src/mac/generate_mapping.py | 36 +--
|
|
69 |
src/prediction/gen_zero_query_data.py | 50 ++--
|
|
70 |
src/prediction/gen_zero_query_number_data.py | 10 +-
|
|
71 |
src/prediction/gen_zero_query_util.py | 2 +-
|
|
72 |
src/rewriter/gen_counter_suffix_array.py | 2 +-
|
|
73 |
src/rewriter/gen_emoji_rewriter_data.py | 40 ++--
|
|
74 |
src/rewriter/gen_reading_correction_data.py | 4 +-
|
|
75 |
.../gen_single_kanji_rewriter_data.py | 8 +-
|
|
76 |
src/session/gen_session_stress_test_data.py | 18 +-
|
|
77 |
src/unix/ibus/gen_mozc_xml.py | 42 ++--
|
|
78 |
src/usage_stats/gen_stats_list.py | 21 +-
|
|
79 |
src/win32/installer/postbuilds_win.py | 16 +-
|
|
80 |
69 files changed, 685 insertions(+), 644 deletions(-)
|
|
81 |
|
|
82 |
diff --git a/src/android/gen_emoji_data.py b/src/android/gen_emoji_data.py
|
|
83 |
index 8a351272..385a030a 100644
|
|
84 |
--- a/src/android/gen_emoji_data.py
|
|
85 |
+++ b/src/android/gen_emoji_data.py
|
|
86 |
@@ -48,23 +48,23 @@ from build_tools import code_generator_util
|
|
87 |
# We assign 100,000 and greater values for carrier emoji, so "offset" should be
|
|
88 |
# less than 100,000.
|
|
89 |
_CATEGORY_MAP = {
|
|
90 |
- 'SMILEY_PEOPLE': {'category': 'FACE', 'offset': 0},
|
|
91 |
- 'ANIMALS_NATURE': {'category': 'FOOD', 'offset': 0},
|
|
92 |
- 'FOOD_DRINK': {'category': 'FOOD', 'offset': 10000},
|
|
93 |
- 'TRAVEL_PLACES': {'category': 'CITY', 'offset': 0},
|
|
94 |
- 'ACTIVITY': {'category': 'ACTIVITY', 'offset': 0},
|
|
95 |
- 'OBJECTS': {'category': 'ACTIVITY', 'offset': 10000},
|
|
96 |
- 'SYMBOLS': {'category': 'NATURE', 'offset': 0},
|
|
97 |
- 'FLAGS': {'category': 'NATURE', 'offset': 10000},
|
|
98 |
+ b'SMILEY_PEOPLE': {'category': b'FACE', 'offset': 0},
|
|
99 |
+ b'ANIMALS_NATURE': {'category': b'FOOD', 'offset': 0},
|
|
100 |
+ b'FOOD_DRINK': {'category': b'FOOD', 'offset': 10000},
|
|
101 |
+ b'TRAVEL_PLACES': {'category': b'CITY', 'offset': 0},
|
|
102 |
+ b'ACTIVITY': {'category': b'ACTIVITY', 'offset': 0},
|
|
103 |
+ b'OBJECTS': {'category': b'ACTIVITY', 'offset': 10000},
|
|
104 |
+ b'SYMBOLS': {'category': b'NATURE', 'offset': 0},
|
|
105 |
+ b'FLAGS': {'category': b'NATURE', 'offset': 10000},
|
|
106 |
}
|
|
107 |
-_CATEGORY_LIST = list(set(
|
|
108 |
- [entry['category'] for entry in _CATEGORY_MAP.itervalues()]))
|
|
109 |
+_CATEGORY_LIST = sorted(set(
|
|
110 |
+ [entry['category'] for entry in _CATEGORY_MAP.values()]))
|
|
111 |
|
|
112 |
|
|
113 |
def ReadData(stream):
|
|
114 |
category_map = defaultdict(list)
|
|
115 |
stream = code_generator_util.SkipLineComment(stream)
|
|
116 |
- stream = code_generator_util.ParseColumnStream(stream, delimiter='\t')
|
|
117 |
+ stream = code_generator_util.ParseColumnStream(stream, delimiter=b'\t')
|
|
118 |
stream = code_generator_util.SelectColumn(stream, [0, 2, 8, 9, 10, 11, 12])
|
|
119 |
for (code, pua_code, japanese_name, docomo_name, softbank_name, kddi_name,
|
|
120 |
category_index) in stream:
|
|
121 |
@@ -76,19 +76,19 @@ def ReadData(stream):
|
|
122 |
sys.exit(-1)
|
|
123 |
if not code:
|
|
124 |
# Use dummy code point
|
|
125 |
- code = '0'
|
|
126 |
+ code = b'0'
|
|
127 |
if not pua_code:
|
|
128 |
# Use dummy code point
|
|
129 |
- pua_code = '0'
|
|
130 |
- if pua_code[0] == '>':
|
|
131 |
+ pua_code = b'0'
|
|
132 |
+ if pua_code[0:1] == b'>':
|
|
133 |
# Don't skip entires which has non-primary PUA codepoint since they also
|
|
134 |
# has unique Unicode codepoint.
|
|
135 |
# e.g. "BLACK SQUARE BUTTON" and "LARGE BLUE CIRCLE"
|
|
136 |
pua_code = pua_code[1:]
|
|
137 |
|
|
138 |
- code_values = [int(c, 16) for c in re.split(r' +', code.strip())]
|
|
139 |
+ code_values = [int(c, 16) for c in re.split(br' +', code.strip())]
|
|
140 |
pua_code_value = int(pua_code, 16)
|
|
141 |
- (category, index) = category_index.split('-')
|
|
142 |
+ (category, index) = category_index.split(b'-')
|
|
143 |
index = int(index) + _CATEGORY_MAP[category]['offset']
|
|
144 |
category = _CATEGORY_MAP[category]['category']
|
|
145 |
category_map[category].append(
|
|
146 |
@@ -98,92 +98,92 @@ def ReadData(stream):
|
|
147 |
|
|
148 |
|
|
149 |
_CHARACTER_NORMALIZE_MAP = {
|
|
150 |
- u'A': 'A',
|
|
151 |
- u'B': 'B',
|
|
152 |
- u'C': 'C',
|
|
153 |
- u'D': 'D',
|
|
154 |
- u'E': 'E',
|
|
155 |
- u'F': 'F',
|
|
156 |
- u'G': 'G',
|
|
157 |
- u'H': 'H',
|
|
158 |
- u'I': 'I',
|
|
159 |
- u'J': 'J',
|
|
160 |
- u'K': 'K',
|
|
161 |
- u'L': 'L',
|
|
162 |
- u'M': 'M',
|
|
163 |
- u'N': 'N',
|
|
164 |
- u'O': 'O',
|
|
165 |
- u'P': 'P',
|
|
166 |
- u'Q': 'Q',
|
|
167 |
- u'R': 'R',
|
|
168 |
- u'S': 'S',
|
|
169 |
- u'T': 'T',
|
|
170 |
- u'U': 'U',
|
|
171 |
- u'V': 'V',
|
|
172 |
- u'W': 'W',
|
|
173 |
- u'X': 'X',
|
|
174 |
- u'Y': 'Y',
|
|
175 |
- u'Z': 'Z',
|
|
176 |
-
|
|
177 |
- u'a': 'a',
|
|
178 |
- u'b': 'b',
|
|
179 |
- u'c': 'c',
|
|
180 |
- u'd': 'd',
|
|
181 |
- u'e': 'e',
|
|
182 |
- u'f': 'f',
|
|
183 |
- u'g': 'g',
|
|
184 |
- u'h': 'h',
|
|
185 |
- u'i': 'i',
|
|
186 |
- u'j': 'j',
|
|
187 |
- u'k': 'k',
|
|
188 |
- u'l': 'l',
|
|
189 |
- u'm': 'm',
|
|
190 |
- u'n': 'n',
|
|
191 |
- u'o': 'o',
|
|
192 |
- u'p': 'p',
|
|
193 |
- u'q': 'q',
|
|
194 |
- u'r': 'r',
|
|
195 |
- u's': 's',
|
|
196 |
- u't': 't',
|
|
197 |
- u'u': 'u',
|
|
198 |
- u'v': 'v',
|
|
199 |
- u'w': 'w',
|
|
200 |
- u'x': 'x',
|
|
201 |
- u'y': 'y',
|
|
202 |
- u'z': 'z',
|
|
203 |
-
|
|
204 |
- u'0': '0',
|
|
205 |
- u'1': '1',
|
|
206 |
- u'2': '2',
|
|
207 |
- u'3': '3',
|
|
208 |
- u'4': '4',
|
|
209 |
- u'5': '5',
|
|
210 |
- u'6': '6',
|
|
211 |
- u'7': '7',
|
|
212 |
- u'8': '8',
|
|
213 |
- u'9': '9',
|
|
214 |
-
|
|
215 |
- u'(': '(',
|
|
216 |
- u')': ')',
|
|
217 |
+ 'A': 'A',
|
|
218 |
+ 'B': 'B',
|
|
219 |
+ 'C': 'C',
|
|
220 |
+ 'D': 'D',
|
|
221 |
+ 'E': 'E',
|
|
222 |
+ 'F': 'F',
|
|
223 |
+ 'G': 'G',
|
|
224 |
+ 'H': 'H',
|
|
225 |
+ 'I': 'I',
|
|
226 |
+ 'J': 'J',
|
|
227 |
+ 'K': 'K',
|
|
228 |
+ 'L': 'L',
|
|
229 |
+ 'M': 'M',
|
|
230 |
+ 'N': 'N',
|
|
231 |
+ 'O': 'O',
|
|
232 |
+ 'P': 'P',
|
|
233 |
+ 'Q': 'Q',
|
|
234 |
+ 'R': 'R',
|
|
235 |
+ 'S': 'S',
|
|
236 |
+ 'T': 'T',
|
|
237 |
+ 'U': 'U',
|
|
238 |
+ 'V': 'V',
|
|
239 |
+ 'W': 'W',
|
|
240 |
+ 'X': 'X',
|
|
241 |
+ 'Y': 'Y',
|
|
242 |
+ 'Z': 'Z',
|
|
243 |
+
|
|
244 |
+ 'a': 'a',
|
|
245 |
+ 'b': 'b',
|
|
246 |
+ 'c': 'c',
|
|
247 |
+ 'd': 'd',
|
|
248 |
+ 'e': 'e',
|
|
249 |
+ 'f': 'f',
|
|
250 |
+ 'g': 'g',
|
|
251 |
+ 'h': 'h',
|
|
252 |
+ 'i': 'i',
|
|
253 |
+ 'j': 'j',
|
|
254 |
+ 'k': 'k',
|
|
255 |
+ 'l': 'l',
|
|
256 |
+ 'm': 'm',
|
|
257 |
+ 'n': 'n',
|
|
258 |
+ 'o': 'o',
|
|
259 |
+ 'p': 'p',
|
|
260 |
+ 'q': 'q',
|
|
261 |
+ 'r': 'r',
|
|
262 |
+ 's': 's',
|
|
263 |
+ 't': 't',
|
|
264 |
+ 'u': 'u',
|
|
265 |
+ 'v': 'v',
|
|
266 |
+ 'w': 'w',
|
|
267 |
+ 'x': 'x',
|
|
268 |
+ 'y': 'y',
|
|
269 |
+ 'z': 'z',
|
|
270 |
+
|
|
271 |
+ '0': '0',
|
|
272 |
+ '1': '1',
|
|
273 |
+ '2': '2',
|
|
274 |
+ '3': '3',
|
|
275 |
+ '4': '4',
|
|
276 |
+ '5': '5',
|
|
277 |
+ '6': '6',
|
|
278 |
+ '7': '7',
|
|
279 |
+ '8': '8',
|
|
280 |
+ '9': '9',
|
|
281 |
+
|
|
282 |
+ '(': '(',
|
|
283 |
+ ')': ')',
|
|
284 |
}
|
|
285 |
|
|
286 |
|
|
287 |
def PreprocessName(name):
|
|
288 |
if not name:
|
|
289 |
- return 'null'
|
|
290 |
- name = unicode(name, 'utf-8')
|
|
291 |
- name = u''.join(_CHARACTER_NORMALIZE_MAP.get(c, c) for c in name)
|
|
292 |
+ return b'null'
|
|
293 |
+ name = str(name, 'utf-8')
|
|
294 |
+ name = ''.join(_CHARACTER_NORMALIZE_MAP.get(c, c) for c in name)
|
|
295 |
name = name.encode('utf-8')
|
|
296 |
- name = name.replace('(', '\\n(')
|
|
297 |
- return '"%s"' % name
|
|
298 |
+ name = name.replace(b'(', b'\\n(')
|
|
299 |
+ return b'"%b"' % name
|
|
300 |
|
|
301 |
|
|
302 |
def OutputData(category_map, stream):
|
|
303 |
- for data_list in category_map.itervalues():
|
|
304 |
+ for data_list in category_map.values():
|
|
305 |
data_list.sort()
|
|
306 |
|
|
307 |
- stream.write('package org.mozc.android.inputmethod.japanese.emoji;\n'
|
|
308 |
- 'public class EmojiData {\n')
|
|
309 |
+ stream.write(b'package org.mozc.android.inputmethod.japanese.emoji;\n'
|
|
310 |
+ b'public class EmojiData {\n')
|
|
311 |
|
|
312 |
for category in _CATEGORY_LIST:
|
|
313 |
# The content of data list is
|
|
314 |
@@ -197,45 +197,45 @@ def OutputData(category_map, stream):
|
|
315 |
data_list = [c for c in category_map[category]
|
|
316 |
if c[3] or c[4] or c[5] or c[6]]
|
|
317 |
stream.write(
|
|
318 |
- ' public static final String[] %s_VALUES = new String[]{\n' %
|
|
319 |
+ b' public static final String[] %b_VALUES = new String[]{\n' %
|
|
320 |
category)
|
|
321 |
for _, codes, pua_code, japanese, docomo, softbank, kddi in data_list:
|
|
322 |
- stream.write(' %s,\n' % code_generator_util.ToJavaStringLiteral(codes))
|
|
323 |
- stream.write(' };\n')
|
|
324 |
+ stream.write(b' %b,\n' % code_generator_util.ToJavaStringLiteral(codes))
|
|
325 |
+ stream.write(b' };\n')
|
|
326 |
|
|
327 |
stream.write(
|
|
328 |
- ' public static final String[] %s_PUA_VALUES = new String[]{\n' %
|
|
329 |
+ b' public static final String[] %b_PUA_VALUES = new String[]{\n' %
|
|
330 |
category)
|
|
331 |
for _, codes, pua_code, japanese, docomo, softbank, kddi in data_list:
|
|
332 |
stream.write(
|
|
333 |
- ' %s,\n' % code_generator_util.ToJavaStringLiteral(pua_code))
|
|
334 |
- stream.write(' };\n')
|
|
335 |
+ b' %b,\n' % code_generator_util.ToJavaStringLiteral(pua_code))
|
|
336 |
+ stream.write(b' };\n')
|
|
337 |
|
|
338 |
stream.write(
|
|
339 |
- ' public static final String[] UNICODE_%s_NAME = {\n' % category)
|
|
340 |
+ b' public static final String[] UNICODE_%b_NAME = {\n' % category)
|
|
341 |
for _, codes, pua_code, japanese, docomo, softbank, kddi in data_list:
|
|
342 |
- stream.write(' %s, \n' % PreprocessName(japanese))
|
|
343 |
- stream.write(' };\n')
|
|
344 |
+ stream.write(b' %b, \n' % PreprocessName(japanese))
|
|
345 |
+ stream.write(b' };\n')
|
|
346 |
|
|
347 |
stream.write(
|
|
348 |
- ' public static final String[] DOCOMO_%s_NAME = {\n' % category)
|
|
349 |
+ b' public static final String[] DOCOMO_%b_NAME = {\n' % category)
|
|
350 |
for _, codes, pua_code, japanese, docomo, softbank, kddi in data_list:
|
|
351 |
- stream.write(' %s, \n' % PreprocessName(docomo))
|
|
352 |
- stream.write(' };\n')
|
|
353 |
+ stream.write(b' %b, \n' % PreprocessName(docomo))
|
|
354 |
+ stream.write(b' };\n')
|
|
355 |
|
|
356 |
stream.write(
|
|
357 |
- ' public static final String[] SOFTBANK_%s_NAME = {\n' % category)
|
|
358 |
+ b' public static final String[] SOFTBANK_%b_NAME = {\n' % category)
|
|
359 |
for _, codes, pua_code, japanese, docomo, softbank, kddi in data_list:
|
|
360 |
- stream.write(' %s, \n' % PreprocessName(softbank))
|
|
361 |
- stream.write(' };\n')
|
|
362 |
+ stream.write(b' %b, \n' % PreprocessName(softbank))
|
|
363 |
+ stream.write(b' };\n')
|
|
364 |
|
|
365 |
stream.write(
|
|
366 |
- ' public static final String[] KDDI_%s_NAME = {\n' % category)
|
|
367 |
+ b' public static final String[] KDDI_%b_NAME = {\n' % category)
|
|
368 |
for _, codes, pua_code, japanese, docomo, softbank, kddi in data_list:
|
|
369 |
- stream.write(' %s, \n' % PreprocessName(kddi))
|
|
370 |
- stream.write(' };\n')
|
|
371 |
+ stream.write(b' %b, \n' % PreprocessName(kddi))
|
|
372 |
+ stream.write(b' };\n')
|
|
373 |
|
|
374 |
- stream.write('}\n')
|
|
375 |
+ stream.write(b'}\n')
|
|
376 |
|
|
377 |
|
|
378 |
def ParseOptions():
|
|
379 |
@@ -248,10 +248,10 @@ def ParseOptions():
|
|
380 |
|
|
381 |
def main():
|
|
382 |
options = ParseOptions()
|
|
383 |
- with open(options.emoji_data) as stream:
|
|
384 |
+ with open(options.emoji_data, 'rb') as stream:
|
|
385 |
emoji_data = ReadData(stream)
|
|
386 |
|
|
387 |
- with open(options.output, 'w') as stream:
|
|
388 |
+ with open(options.output, 'wb') as stream:
|
|
389 |
OutputData(emoji_data, stream)
|
|
390 |
|
|
391 |
|
|
392 |
diff --git a/src/android/gen_emoticon_data.py b/src/android/gen_emoticon_data.py
|
|
393 |
index 5e6878b6..310e5e8e 100644
|
|
394 |
--- a/src/android/gen_emoticon_data.py
|
|
395 |
+++ b/src/android/gen_emoticon_data.py
|
|
396 |
@@ -38,7 +38,6 @@ The first line of .tsv file is ignored because it is used as label.
|
|
397 |
|
|
398 |
__author__ = "matsuzakit"
|
|
399 |
|
|
400 |
-import io
|
|
401 |
import optparse
|
|
402 |
import sys
|
|
403 |
import unicodedata
|
|
404 |
@@ -58,7 +57,8 @@ def ParseSymbolFile(file_name, value_column, category_column,
|
|
405 |
"""Parses symbol file and returns tag->symbols dictionary."""
|
|
406 |
tag2symbol = {}
|
|
407 |
is_first_line = True
|
|
408 |
- for line in io.open(file_name, encoding='utf-8'):
|
|
409 |
+ file = open(file_name, encoding='utf-8')
|
|
410 |
+ for line in file:
|
|
411 |
line_parts = line.rstrip().split('\t')
|
|
412 |
if is_first_line:
|
|
413 |
# Skip the first line, which is used as label.
|
|
414 |
@@ -77,6 +77,7 @@ def ParseSymbolFile(file_name, value_column, category_column,
|
|
415 |
tag2symbol.setdefault(tag, []).append(symbol)
|
|
416 |
if tag in expand_variant_tags and symbol != normalized:
|
|
417 |
tag2symbol[tag].append(normalized)
|
|
418 |
+ file.close()
|
|
419 |
|
|
420 |
return tag2symbol
|
|
421 |
|
|
422 |
@@ -110,7 +111,7 @@ def GetStringArrayOfSymbols(tag_name, original_symbols, ordering_rule_list):
|
|
423 |
else:
|
|
424 |
symbols = original_symbols
|
|
425 |
|
|
426 |
- _ESCAPE = (u'"', u'\\')
|
|
427 |
+ _ESCAPE = ('"', '\\')
|
|
428 |
for symbol in symbols:
|
|
429 |
# Escape characters (defined above) have to be escaped by backslashes.
|
|
430 |
# e.g.
|
|
431 |
@@ -125,7 +126,7 @@ def GetStringArrayOfSymbols(tag_name, original_symbols, ordering_rule_list):
|
|
432 |
# which include '\u0022' will terminate here.
|
|
433 |
# They are not what we want so before such characters we place '\'
|
|
434 |
# in order to escape them.
|
|
435 |
- line = ['%s\\u%04x' % ('' if c not in _ESCAPE else '\u005c', ord(c))
|
|
436 |
+ line = ['%s\\u%04x' % ('' if c not in _ESCAPE else '\\u005c', ord(c))
|
|
437 |
for c in symbol]
|
|
438 |
# The white space is quick fix for the backslash at the tail of symbol.
|
|
439 |
lines.append(' "%s", // %s ' % (''.join(line), symbol))
|
|
440 |
@@ -135,8 +136,8 @@ def GetStringArrayOfSymbols(tag_name, original_symbols, ordering_rule_list):
|
|
441 |
|
|
442 |
def WriteOut(output, tag2symbol, class_name, ordering_rule_list):
|
|
443 |
body = [GetStringArrayOfSymbols(tag, symbols, ordering_rule_list)
|
|
444 |
- for tag, symbols in tag2symbol.iteritems()]
|
|
445 |
- with io.open(output, 'w', encoding='utf-8') as out_file:
|
|
446 |
+ for tag, symbols in sorted(tag2symbol.items())]
|
|
447 |
+ with open(output, 'w', encoding='utf-8') as out_file:
|
|
448 |
out_file.write(TEMPLATE_CLASS % (PACKAGE_NAME, class_name, '\n'.join(body)))
|
|
449 |
|
|
450 |
|
|
451 |
@@ -162,12 +163,14 @@ def ParseOption():
|
|
452 |
|
|
453 |
def CreateOrderingRuleList(file_name):
|
|
454 |
ordering_rule_list = []
|
|
455 |
- for line in io.open(file_name, encoding='utf-8'):
|
|
456 |
+ file = open(file_name, encoding='utf-8')
|
|
457 |
+ for line in file:
|
|
458 |
# Do not forget such line of which content is ' '.
|
|
459 |
# Such line has to be appended into the list.
|
|
460 |
- if not line.startswith(u'# ') and not line.startswith(u'\n'):
|
|
461 |
- value = line.rstrip(u'\r\n')
|
|
462 |
+ if not line.startswith('# ') and not line.startswith('\n'):
|
|
463 |
+ value = line.rstrip('\r\n')
|
|
464 |
ordering_rule_list.append(value)
|
|
465 |
+ file.close()
|
|
466 |
return ordering_rule_list
|
|
467 |
|
|
468 |
|
|
469 |
@@ -176,7 +179,7 @@ def main():
|
|
470 |
if not (options.input and options.output and options.class_name and
|
|
471 |
options.value_column is not None and
|
|
472 |
options.category_column is not None):
|
|
473 |
- print 'Some options cannot be omitted. See --help.'
|
|
474 |
+ print('Some options cannot be omitted. See --help.')
|
|
475 |
sys.exit(1)
|
|
476 |
tag2symbol = ParseSymbolFile(options.input,
|
|
477 |
options.value_column,
|
|
478 |
diff --git a/src/android/gen_mozc_drawable.py b/src/android/gen_mozc_drawable.py
|
|
479 |
index f3e4cbb4..0a738f95 100644
|
|
480 |
--- a/src/android/gen_mozc_drawable.py
|
|
481 |
+++ b/src/android/gen_mozc_drawable.py
|
|
482 |
@@ -41,14 +41,14 @@ and it'd cause an crash error, unfortunately.
|
|
483 |
|
|
484 |
__author__ = "hidehiko"
|
|
485 |
|
|
486 |
-import cStringIO as StringIO
|
|
487 |
+import io
|
|
488 |
import logging
|
|
489 |
import optparse
|
|
490 |
import os
|
|
491 |
import re
|
|
492 |
import struct
|
|
493 |
import sys
|
|
494 |
-from xml.etree import cElementTree as ElementTree
|
|
495 |
+from xml.etree import ElementTree
|
|
496 |
|
|
497 |
from build_tools import util
|
|
498 |
|
|
499 |
@@ -289,7 +289,7 @@ class MozcDrawableConverter(object):
|
|
500 |
def _ConsumeFloatList(self, s, num):
|
|
501 |
"""Parses num floating values from s."""
|
|
502 |
result = []
|
|
503 |
- for _ in xrange(num):
|
|
504 |
+ for _ in range(num):
|
|
505 |
value, s = self._ConsumeFloat(s)
|
|
506 |
result.append(value)
|
|
507 |
return result, s
|
|
508 |
@@ -1035,12 +1035,12 @@ class MozcDrawableConverter(object):
|
|
509 |
|
|
510 |
# Interface for drawable conversion.
|
|
511 |
def ConvertPictureDrawable(self, path):
|
|
512 |
- output = _OutputStream(StringIO.StringIO())
|
|
513 |
+ output = _OutputStream(io.BytesIO())
|
|
514 |
self._ConvertPictureDrawableInternal(ElementTree.parse(path), output)
|
|
515 |
return output.output.getvalue()
|
|
516 |
|
|
517 |
def ConvertStateListDrawable(self, drawable_source_list):
|
|
518 |
- output = _OutputStream(StringIO.StringIO())
|
|
519 |
+ output = _OutputStream(io.BytesIO())
|
|
520 |
output.WriteByte(DRAWABLE_STATE_LIST)
|
|
521 |
output.WriteByte(len(drawable_source_list))
|
|
522 |
for (state_list, path) in drawable_source_list:
|
|
523 |
diff --git a/src/android/gen_touch_event_stats.py b/src/android/gen_touch_event_stats.py
|
|
524 |
index 4916666f..9edfc31b 100644
|
|
525 |
--- a/src/android/gen_touch_event_stats.py
|
|
526 |
+++ b/src/android/gen_touch_event_stats.py
|
|
527 |
@@ -43,7 +43,7 @@ import csv
|
|
528 |
import optparse
|
|
529 |
import os
|
|
530 |
import struct
|
|
531 |
-import urllib
|
|
532 |
+import urllib.parse
|
|
533 |
|
|
534 |
|
|
535 |
def ReadCollectedKeyboards(stream):
|
|
536 |
@@ -112,7 +112,7 @@ def WriteKeyboardData(keyboard_value, stream):
|
|
537 |
# c.f. usage_stats/usage_stats_uploader.cc
|
|
538 |
keys = ('sxa', 'sya', 'sxv', 'syv', 'dxa', 'dya', 'dxv', 'dyv')
|
|
539 |
stream.write(struct.pack('>i', len(keyboard_value)))
|
|
540 |
- for source_id, source_value in keyboard_value.iteritems():
|
|
541 |
+ for source_id, source_value in sorted(keyboard_value.items()):
|
|
542 |
stream.write(struct.pack('>i', source_id))
|
|
543 |
# Note that we are calculating
|
|
544 |
# "Average of average" and "Average of variance".
|
|
545 |
@@ -124,10 +124,10 @@ def WriteKeyboardData(keyboard_value, stream):
|
|
546 |
|
|
547 |
|
|
548 |
def WriteData(stats, output_dir):
|
|
549 |
- for base_name_orientation in stats.iterkeys():
|
|
550 |
+ for base_name_orientation in stats.keys():
|
|
551 |
with open(os.path.join(output_dir,
|
|
552 |
'%s_%s.touch_stats' % (
|
|
553 |
- urllib.unquote(base_name_orientation[0]),
|
|
554 |
+ urllib.parse.unquote(base_name_orientation[0]),
|
|
555 |
base_name_orientation[1])),
|
|
556 |
'wb') as stream:
|
|
557 |
WriteKeyboardData(stats[base_name_orientation], stream)
|
|
558 |
diff --git a/src/android/run_android_test.py b/src/android/run_android_test.py
|
|
559 |
index ebb98638..79865a51 100644
|
|
560 |
--- a/src/android/run_android_test.py
|
|
561 |
+++ b/src/android/run_android_test.py
|
|
562 |
@@ -44,8 +44,9 @@ import multiprocessing
|
|
563 |
import optparse
|
|
564 |
import os
|
|
565 |
import subprocess
|
|
566 |
+import sys
|
|
567 |
import time
|
|
568 |
-from xml.etree import cElementTree as ElementTree
|
|
569 |
+from xml.etree import ElementTree
|
|
570 |
from build_tools import android_util
|
|
571 |
from build_tools.test_tools import gtest_report
|
|
572 |
|
|
573 |
@@ -142,9 +143,9 @@ def AppendPrefixToSuiteName(in_file_name, out_file_name, prefix):
|
|
574 |
AppendPrefix(root)
|
|
575 |
for elem in root.findall('testsuite'):
|
|
576 |
AppendPrefix(elem)
|
|
577 |
- with open(out_file_name, 'w') as f:
|
|
578 |
+ with open(out_file_name, 'wb') as f:
|
|
579 |
# Note that ElementTree of 2.6 doesn't write XML declaration.
|
|
580 |
- f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
|
581 |
+ f.write(b'<?xml version="1.0" encoding="utf-8"?>\n')
|
|
582 |
f.write(ElementTree.tostring(root, 'utf-8'))
|
|
583 |
|
|
584 |
|
|
585 |
@@ -156,7 +157,7 @@ class AndroidDevice(android_util.AndroidDevice):
|
|
586 |
"""Wait until SD card is mounted."""
|
|
587 |
retry = 10
|
|
588 |
sleep = 30
|
|
589 |
- for _ in xrange(retry):
|
|
590 |
+ for _ in range(retry):
|
|
591 |
if self._RunCommand('mount').find('/sdcard') != -1:
|
|
592 |
self.GetLogger().info('SD card has been mounted.')
|
|
593 |
return
|
|
594 |
@@ -458,7 +459,7 @@ def main():
|
|
595 |
|
|
596 |
if not options.android_home:
|
|
597 |
logging.error('--android_home option must be specified.')
|
|
598 |
- os.exit(1)
|
|
599 |
+ sys.exit(1)
|
|
600 |
|
|
601 |
if options.run_native_test:
|
|
602 |
binaries = FindTestBinaries(options.test_bin_dir)
|
|
603 |
@@ -501,11 +502,11 @@ def main():
|
|
604 |
# result.get() blocks until the test terminates.
|
|
605 |
error_messages = [result.get() for result in results if result.get()]
|
|
606 |
if error_messages:
|
|
607 |
- print '[FAIL] Native tests result : Test failures are found;'
|
|
608 |
+ print('[FAIL] Native tests result : Test failures are found;')
|
|
609 |
for message in error_messages:
|
|
610 |
- print message
|
|
611 |
+ print(message)
|
|
612 |
else:
|
|
613 |
- print '[ OK ] Native tests result : Tests scceeded.'
|
|
614 |
+ print('[ OK ] Native tests result : Tests scceeded.')
|
|
615 |
|
|
616 |
|
|
617 |
if __name__ == '__main__':
|
|
618 |
diff --git a/src/base/gen_character_set.py b/src/base/gen_character_set.py
|
|
619 |
index bb39c472..7ac5b522 100644
|
|
620 |
--- a/src/base/gen_character_set.py
|
|
621 |
+++ b/src/base/gen_character_set.py
|
|
622 |
@@ -33,7 +33,6 @@ __author__ = "taku"
|
|
623 |
import itertools
|
|
624 |
import optparse
|
|
625 |
import re
|
|
626 |
-import string
|
|
627 |
import sys
|
|
628 |
|
|
629 |
|
|
630 |
@@ -89,7 +88,8 @@ class CodePointCategorizer(object):
|
|
631 |
@staticmethod
|
|
632 |
def _LoadTable(filename, column_index, pattern, validater):
|
|
633 |
result = set()
|
|
634 |
- for line in open(filename):
|
|
635 |
+ fh = open(filename)
|
|
636 |
+ for line in fh:
|
|
637 |
if line.startswith('#'):
|
|
638 |
# Skip a comment line.
|
|
639 |
continue
|
|
640 |
@@ -100,6 +100,7 @@ class CodePointCategorizer(object):
|
|
641 |
ucs = int(match.group(1), 16)
|
|
642 |
if validater(ucs):
|
|
643 |
result.add(ucs)
|
|
644 |
+ fh.close()
|
|
645 |
|
|
646 |
return result
|
|
647 |
|
|
648 |
@@ -250,7 +251,7 @@ def GenerateCategoryBitmap(category_list, name):
|
|
649 |
# (at most) four code points.
|
|
650 |
bit_list = []
|
|
651 |
for _, group in itertools.groupby(enumerate(category_list),
|
|
652 |
- lambda (codepoint, _): codepoint / 4):
|
|
653 |
+ lambda x: x[0] // 4):
|
|
654 |
# Fill bits from LSB to MSB for each group.
|
|
655 |
bits = 0
|
|
656 |
for index, (_, category) in enumerate(group):
|
|
657 |
@@ -263,7 +264,7 @@ def GenerateCategoryBitmap(category_list, name):
|
|
658 |
|
|
659 |
# Output the content. Each line would have (at most) 16 bytes.
|
|
660 |
for _, group in itertools.groupby(enumerate(bit_list),
|
|
661 |
- lambda (index, _): index / 16):
|
|
662 |
+ lambda x: x[0] // 16):
|
|
663 |
line = [' \"']
|
|
664 |
for _, bits in group:
|
|
665 |
line.append('\\x%02X' % bits)
|
|
666 |
@@ -386,7 +387,7 @@ def GenerateGetCharacterSet(category_list, bitmap_name, bitmap_size):
|
|
667 |
# Bitmap lookup.
|
|
668 |
# TODO(hidehiko): the bitmap has two huge 0-bits ranges. Reduce them.
|
|
669 |
category_map = [
|
|
670 |
- (bits, category) for category, bits in CATEGORY_BITMAP.iteritems()]
|
|
671 |
+ (bits, category) for category, bits in CATEGORY_BITMAP.items()]
|
|
672 |
category_map.sort()
|
|
673 |
|
|
674 |
lines.extend([
|
|
675 |
@@ -451,7 +452,7 @@ def main():
|
|
676 |
options.jisx0213file)
|
|
677 |
category_list = [
|
|
678 |
categorizer.GetCategory(codepoint)
|
|
679 |
- for codepoint in xrange(categorizer.MaxCodePoint() + 1)]
|
|
680 |
+ for codepoint in range(categorizer.MaxCodePoint() + 1)]
|
|
681 |
generated_character_set_header = GenerateCharacterSetHeader(category_list)
|
|
682 |
|
|
683 |
# Write the result.
|
|
684 |
diff --git a/src/base/gen_config_file_stream_data.py b/src/base/gen_config_file_stream_data.py
|
|
685 |
index 2a7af1a2..53832d18 100644
|
|
686 |
--- a/src/base/gen_config_file_stream_data.py
|
|
687 |
+++ b/src/base/gen_config_file_stream_data.py
|
|
688 |
@@ -58,7 +58,7 @@ def GenerateFileData(path):
|
|
689 |
result = []
|
|
690 |
result.append(' { "%s", "' % os.path.basename(path))
|
|
691 |
with open(path, 'rb') as stream:
|
|
692 |
- result.extend(r'\x%02X' % ord(byte) for byte in stream.read())
|
|
693 |
+ result.extend(r'\x%02X' % byte for byte in stream.read())
|
|
694 |
result.append('", %d }' % os.path.getsize(path))
|
|
695 |
|
|
696 |
return ''.join(result)
|
|
697 |
@@ -93,8 +93,8 @@ def OutputConfigFileStreamData(path_list, output):
|
|
698 |
def main():
|
|
699 |
(options, args) = ParseOptions()
|
|
700 |
if not options.output:
|
|
701 |
- print >>sys.stderr, (
|
|
702 |
- 'usage: gen_config_file_stream_data.py --output=filepath input ...')
|
|
703 |
+ print('usage: gen_config_file_stream_data.py --output=filepath input ...',
|
|
704 |
+ file=sys.stderr)
|
|
705 |
sys.exit(2)
|
|
706 |
|
|
707 |
with open(options.output, 'w') as output:
|
|
708 |
diff --git a/src/build_mozc.py b/src/build_mozc.py
|
|
709 |
index 46fa0827..89d9c939 100644
|
|
710 |
--- a/src/build_mozc.py
|
|
711 |
+++ b/src/build_mozc.py
|
|
712 |
@@ -943,7 +943,7 @@ def RunTests(target_platform, configuration, parallel_num):
|
|
713 |
logging.info('running %s...', binary)
|
|
714 |
try:
|
|
715 |
test_function(binary, gtest_report_dir, options)
|
|
716 |
- except RunOrDieError, e:
|
|
717 |
+ except RunOrDieError as e:
|
|
718 |
logging.error(e)
|
|
719 |
failed_tests.append(binary)
|
|
720 |
else:
|
|
721 |
@@ -1082,7 +1082,7 @@ def RunTestsMain(options, args):
|
|
722 |
# and '-c' and 'Release' are build options.
|
|
723 |
targets = []
|
|
724 |
build_options = []
|
|
725 |
- for i in xrange(len(args)):
|
|
726 |
+ for i in range(len(args)):
|
|
727 |
if args[i].startswith('-'):
|
|
728 |
# starting with build options
|
|
729 |
build_options = args[i:]
|
|
730 |
@@ -1190,14 +1190,14 @@ def CleanMain(options, unused_args):
|
|
731 |
|
|
732 |
def ShowHelpAndExit():
|
|
733 |
"""Shows the help message."""
|
|
734 |
- print 'Usage: build_mozc.py COMMAND [ARGS]'
|
|
735 |
- print 'Commands: '
|
|
736 |
- print ' gyp Generate project files.'
|
|
737 |
- print ' build Build the specified target.'
|
|
738 |
- print ' runtests Build all tests and run them.'
|
|
739 |
- print ' clean Clean all the build files and directories.'
|
|
740 |
- print ''
|
|
741 |
- print 'See also the comment in the script for typical usage.'
|
|
742 |
+ print('Usage: build_mozc.py COMMAND [ARGS]')
|
|
743 |
+ print('Commands: ')
|
|
744 |
+ print(' gyp Generate project files.')
|
|
745 |
+ print(' build Build the specified target.')
|
|
746 |
+ print(' runtests Build all tests and run them.')
|
|
747 |
+ print(' clean Clean all the build files and directories.')
|
|
748 |
+ print('')
|
|
749 |
+ print('See also the comment in the script for typical usage.')
|
|
750 |
sys.exit(1)
|
|
751 |
|
|
752 |
|
|
753 |
diff --git a/src/build_tools/android_util.py b/src/build_tools/android_util.py
|
|
754 |
index 5ea3da31..447ee781 100644
|
|
755 |
--- a/src/build_tools/android_util.py
|
|
756 |
+++ b/src/build_tools/android_util.py
|
|
757 |
@@ -548,7 +548,7 @@ def GetAvailableEmulatorPorts(android_home):
|
|
758 |
(devices_result, _) = process.communicate()
|
|
759 |
used_ports = set(int(port) for port
|
|
760 |
in re.findall(r'emulator-(\d+)', devices_result))
|
|
761 |
- return [port for port in xrange(5554, 5586, 2) if port not in used_ports]
|
|
762 |
+ return [port for port in range(5554, 5586, 2) if port not in used_ports]
|
|
763 |
|
|
764 |
|
|
765 |
def SetUpTestingSdkHomeDirectory(dest_android_sdk_home,
|
|
766 |
@@ -575,7 +575,7 @@ def SetUpTestingSdkHomeDirectory(dest_android_sdk_home,
|
|
767 |
'create', 'avd',
|
|
768 |
'--force',
|
|
769 |
'--sdcard', '512M',]
|
|
770 |
- for key, value in options.iteritems():
|
|
771 |
+ for key, value in options.items():
|
|
772 |
args.extend([key, value])
|
|
773 |
env = {'ANDROID_SDK_HOME': os.path.abspath(dest_android_sdk_home)}
|
|
774 |
logging.info('Creating AVD: %s', args)
|
|
775 |
@@ -615,7 +615,7 @@ def GetAvdProperties(android_sdk_home, avd_name, my_open=open):
|
|
776 |
def main():
|
|
777 |
for arg in sys.argv[1:]:
|
|
778 |
for item in sorted(GetApkProperties(arg).items()):
|
|
779 |
- print '%s: %s' % item
|
|
780 |
+ print('%s: %s' % item)
|
|
781 |
|
|
782 |
|
|
783 |
if __name__ == '__main__':
|
|
784 |
diff --git a/src/build_tools/binary_size_checker.py b/src/build_tools/binary_size_checker.py
|
|
785 |
index e53dc177..0f5e8b25 100644
|
|
786 |
--- a/src/build_tools/binary_size_checker.py
|
|
787 |
+++ b/src/build_tools/binary_size_checker.py
|
|
788 |
@@ -70,12 +70,12 @@ def CheckFileSize(filename):
|
|
789 |
actual_size = os.stat(filename).st_size
|
|
790 |
expected_size = EXPECTED_MAXIMUM_SIZES[basename]
|
|
791 |
if actual_size < expected_size * 1024 * 1024:
|
|
792 |
- print 'Pass: %s (size: %d) is smaller than expected (%d MB)' % (
|
|
793 |
- filename, actual_size, expected_size)
|
|
794 |
+ print('Pass: %s (size: %d) is smaller than expected (%d MB)' % (
|
|
795 |
+ filename, actual_size, expected_size))
|
|
796 |
return True
|
|
797 |
else:
|
|
798 |
- print 'WARNING: %s (size: %d) is larger than expected (%d MB)' % (
|
|
799 |
- filename, actual_size, expected_size)
|
|
800 |
+ print('WARNING: %s (size: %d) is larger than expected (%d MB)' % (
|
|
801 |
+ filename, actual_size, expected_size))
|
|
802 |
return False
|
|
803 |
|
|
804 |
|
|
805 |
diff --git a/src/build_tools/build_and_sign_pkg_mac.py b/src/build_tools/build_and_sign_pkg_mac.py
|
|
806 |
index 59a1f70f..1cced535 100644
|
|
807 |
--- a/src/build_tools/build_and_sign_pkg_mac.py
|
|
808 |
+++ b/src/build_tools/build_and_sign_pkg_mac.py
|
|
809 |
@@ -44,8 +44,8 @@ import os
|
|
810 |
import shutil
|
|
811 |
import sys
|
|
812 |
|
|
813 |
-from util import PrintErrorAndExit
|
|
814 |
-from util import RunOrDie
|
|
815 |
+from .util import PrintErrorAndExit
|
|
816 |
+from .util import RunOrDie
|
|
817 |
|
|
818 |
|
|
819 |
def ParseOption():
|
|
820 |
diff --git a/src/build_tools/build_breakpad.py b/src/build_tools/build_breakpad.py
|
|
821 |
index 291c8ae0..92fee9d7 100644
|
|
822 |
--- a/src/build_tools/build_breakpad.py
|
|
823 |
+++ b/src/build_tools/build_breakpad.py
|
|
824 |
@@ -54,9 +54,9 @@ def ProcessCall(command):
|
|
825 |
try:
|
|
826 |
subprocess.check_output(command)
|
|
827 |
except subprocess.CalledProcessError as e:
|
|
828 |
- print e.output
|
|
829 |
+ print(e.output)
|
|
830 |
sys.exit(e.returncode)
|
|
831 |
- print 'Done: %s' % ' '.join(command)
|
|
832 |
+ print('Done: %s' % ' '.join(command))
|
|
833 |
|
|
834 |
|
|
835 |
def Xcodebuild(projdir, target, arch, sdk, outdir):
|
|
836 |
diff --git a/src/build_tools/build_diskimage_mac.py b/src/build_tools/build_diskimage_mac.py
|
|
837 |
index f31c490b..8fa56aea 100644
|
|
838 |
--- a/src/build_tools/build_diskimage_mac.py
|
|
839 |
+++ b/src/build_tools/build_diskimage_mac.py
|
|
840 |
@@ -90,7 +90,7 @@ def main():
|
|
841 |
# setup volume directory
|
|
842 |
temp_dir = tempfile.mkdtemp()
|
|
843 |
CopyFile(path.join(build_dir, ".keystone_install"), temp_dir)
|
|
844 |
- os.chmod(path.join(temp_dir, ".keystone_install"), 0755) # rwxr-xr-x
|
|
845 |
+ os.chmod(path.join(temp_dir, ".keystone_install"), 0o755) # rwxr-xr-x
|
|
846 |
for a in args:
|
|
847 |
CopyFile(path.join(build_dir, a), temp_dir)
|
|
848 |
|
|
849 |
diff --git a/src/build_tools/change_reference_mac.py b/src/build_tools/change_reference_mac.py
|
|
850 |
index de11b7bd..6e8b1735 100644
|
|
851 |
--- a/src/build_tools/change_reference_mac.py
|
|
852 |
+++ b/src/build_tools/change_reference_mac.py
|
|
853 |
@@ -41,8 +41,8 @@ __author__ = "horo"
|
|
854 |
import optparse
|
|
855 |
import os
|
|
856 |
|
|
857 |
-from util import PrintErrorAndExit
|
|
858 |
-from util import RunOrDie
|
|
859 |
+from .util import PrintErrorAndExit
|
|
860 |
+from .util import RunOrDie
|
|
861 |
|
|
862 |
|
|
863 |
def ParseOption():
|
|
864 |
diff --git a/src/build_tools/code_generator_util.py b/src/build_tools/code_generator_util.py
|
|
865 |
index d489a7c7..80254e74 100644
|
|
866 |
--- a/src/build_tools/code_generator_util.py
|
|
867 |
+++ b/src/build_tools/code_generator_util.py
|
|
868 |
@@ -33,27 +33,26 @@
|
|
869 |
__author__ = "hidehiko"
|
|
870 |
|
|
871 |
import struct
|
|
872 |
-import types
|
|
873 |
|
|
874 |
|
|
875 |
def ToCppStringLiteral(s):
|
|
876 |
"""Returns C-style string literal, or NULL if given s is None."""
|
|
877 |
if s is None:
|
|
878 |
- return 'NULL'
|
|
879 |
+ return b'NULL'
|
|
880 |
|
|
881 |
- if all(0x20 <= ord(c) <= 0x7E for c in s):
|
|
882 |
+ if all(0x20 <= c <= 0x7E for c in s):
|
|
883 |
# All characters are in ascii code.
|
|
884 |
- return '"%s"' % s.replace('\\', r'\\').replace('"', r'\"')
|
|
885 |
+ return b'"%b"' % s.replace(b'\\', br'\\').replace(b'"', br'\"')
|
|
886 |
else:
|
|
887 |
# One or more characters are non-ascii.
|
|
888 |
- return '"%s"' % ''.join(r'\x%02X' % ord(c) for c in s)
|
|
889 |
+ return b'"%b"' % b''.join(br'\x%02X' % c for c in s)
|
|
890 |
|
|
891 |
|
|
892 |
def FormatWithCppEscape(format_text, *args):
|
|
893 |
"""Returns a string filling format with args."""
|
|
894 |
literal_list = []
|
|
895 |
for arg in args:
|
|
896 |
- if isinstance(arg, (types.StringType, types.NoneType)):
|
|
897 |
+ if isinstance(arg, (bytes, type(None))):
|
|
898 |
arg = ToCppStringLiteral(arg)
|
|
899 |
literal_list.append(arg)
|
|
900 |
|
|
901 |
@@ -95,7 +94,7 @@ def WriteCppDataArray(data, variable_name, target_compiler, stream):
|
|
902 |
if target_compiler and target_compiler.startswith('msvs'):
|
|
903 |
stream.write('const uint64 k%s_data_wordtype[] = {\n' % variable_name)
|
|
904 |
|
|
905 |
- for word_index in xrange(0, len(data), 8):
|
|
906 |
+ for word_index in range(0, len(data), 8):
|
|
907 |
word_chunk = data[word_index:word_index + 8].ljust(8, '\x00')
|
|
908 |
stream.write('0x%016X, ' % struct.unpack('<Q', word_chunk))
|
|
909 |
if (word_index / 8) % 4 == 3:
|
|
910 |
@@ -111,7 +110,7 @@ def WriteCppDataArray(data, variable_name, target_compiler, stream):
|
|
911 |
stream.write('const char k%s_data[] =\n' % variable_name)
|
|
912 |
# Output 16bytes per line.
|
|
913 |
chunk_size = 16
|
|
914 |
- for index in xrange(0, len(data), chunk_size):
|
|
915 |
+ for index in range(0, len(data), chunk_size):
|
|
916 |
chunk = data[index:index + chunk_size]
|
|
917 |
stream.write('"')
|
|
918 |
stream.writelines(r'\x%02X' % ord(c) for c in chunk)
|
|
919 |
@@ -126,36 +125,50 @@ def ToJavaStringLiteral(codepoint_list):
|
|
920 |
if type(codepoint_list) is int:
|
|
921 |
codepoint_list = (codepoint_list,)
|
|
922 |
if codepoint_list is None or len(codepoint_list) == 0:
|
|
923 |
- return 'null'
|
|
924 |
- result = r'"'
|
|
925 |
+ return b'null'
|
|
926 |
+ result = b'"'
|
|
927 |
for codepoint in codepoint_list:
|
|
928 |
- utf16_string = unichr(codepoint).encode('utf-16be')
|
|
929 |
+ utf16_string = chr(codepoint).encode('utf-16be')
|
|
930 |
if len(utf16_string) == 2:
|
|
931 |
(u0, l0) = utf16_string
|
|
932 |
- result += r'\u%02X%02X' % (ord(u0), ord(l0))
|
|
933 |
+ result += br'\u%02X%02X' % (u0, l0)
|
|
934 |
else:
|
|
935 |
(u0, l0, u1, l1) = utf16_string
|
|
936 |
- result += r'\u%02X%02X\u%02X%02X' % (ord(u0), ord(l0), ord(u1), ord(l1))
|
|
937 |
- result += r'"'
|
|
938 |
+ result += br'\u%02X%02X\u%02X%02X' % (u0, l0, u1, l1)
|
|
939 |
+ result += b'"'
|
|
940 |
return result
|
|
941 |
|
|
942 |
|
|
943 |
def SkipLineComment(stream, comment_prefix='#'):
|
|
944 |
"""Skips line comments from stream."""
|
|
945 |
for line in stream:
|
|
946 |
+ if isinstance(line, bytes):
|
|
947 |
+ if isinstance(comment_prefix, str):
|
|
948 |
+ comment_prefix = comment_prefix.encode('utf-8')
|
|
949 |
+ line_ending = b'\n'
|
|
950 |
+ else:
|
|
951 |
+ line_ending = '\n'
|
|
952 |
stripped_line = line.strip()
|
|
953 |
if stripped_line and not stripped_line.startswith(comment_prefix):
|
|
954 |
- yield line.rstrip('\n')
|
|
955 |
+ yield line.rstrip(line_ending)
|
|
956 |
|
|
957 |
|
|
958 |
def ParseColumnStream(stream, num_column=None, delimiter=None):
|
|
959 |
"""Returns parsed columns read from stream."""
|
|
960 |
if num_column is None:
|
|
961 |
for line in stream:
|
|
962 |
- yield line.rstrip('\n').split(delimiter)
|
|
963 |
+ if isinstance(line, bytes):
|
|
964 |
+ line_ending = b'\n'
|
|
965 |
+ else:
|
|
966 |
+ line_ending = '\n'
|
|
967 |
+ yield line.rstrip(line_ending).split(delimiter)
|
|
968 |
else:
|
|
969 |
for line in stream:
|
|
970 |
- yield line.rstrip('\n').split(delimiter)[:num_column]
|
|
971 |
+ if isinstance(line, bytes):
|
|
972 |
+ line_ending = b'\n'
|
|
973 |
+ else:
|
|
974 |
+ line_ending = '\n'
|
|
975 |
+ yield line.rstrip(line_ending).split(delimiter)[:num_column]
|
|
976 |
|
|
977 |
|
|
978 |
def SelectColumn(stream, column_index):
|
|
979 |
@@ -172,5 +185,5 @@ def SplitChunk(iterable, n):
|
|
980 |
grouper extends the last chunk to make it an n-element chunk by adding
|
|
981 |
appropriate value, but this returns truncated chunk.
|
|
982 |
"""
|
|
983 |
- for index in xrange(0, len(iterable), n):
|
|
984 |
+ for index in range(0, len(iterable), n):
|
|
985 |
yield iterable[index:index + n]
|
|
986 |
diff --git a/src/build_tools/codesign_mac.py b/src/build_tools/codesign_mac.py
|
|
987 |
index 9c1ba137..a558e048 100644
|
|
988 |
--- a/src/build_tools/codesign_mac.py
|
|
989 |
+++ b/src/build_tools/codesign_mac.py
|
|
990 |
@@ -46,17 +46,17 @@ import sys
|
|
991 |
|
|
992 |
def RunOrDie(command):
|
|
993 |
"""Run the command, or die if it failed."""
|
|
994 |
- print "Running: " + command
|
|
995 |
+ print("Running: " + command)
|
|
996 |
try:
|
|
997 |
output = subprocess.check_output(command, shell=True)
|
|
998 |
- print >> sys.stderr, "=========="
|
|
999 |
- print >> sys.stderr, "COMMAND: " + command
|
|
1000 |
- print >> sys.stderr, output
|
|
1001 |
+ print("==========", file=sys.stderr)
|
|
1002 |
+ print("COMMAND: " + command, file=sys.stderr)
|
|
1003 |
+ print(output, file=sys.stderr)
|
|
1004 |
except subprocess.CalledProcessError as e:
|
|
1005 |
- print >> sys.stderr, "=========="
|
|
1006 |
- print >> sys.stderr, "ERROR: " + command
|
|
1007 |
- print >> sys.stderr, e.output
|
|
1008 |
- print >> sys.stderr, "=========="
|
|
1009 |
+ print("==========", file=sys.stderr)
|
|
1010 |
+ print("ERROR: " + command, file=sys.stderr)
|
|
1011 |
+ print(e.output, file=sys.stderr)
|
|
1012 |
+ print("==========", file=sys.stderr)
|
|
1013 |
sys.exit(1)
|
|
1014 |
|
|
1015 |
|
|
1016 |
@@ -119,18 +119,18 @@ def ParseOption():
|
|
1017 |
(options, unused_args) = parser.parse_args()
|
|
1018 |
|
|
1019 |
if not options.target:
|
|
1020 |
- print "Error: --target should be specified."
|
|
1021 |
- print parser.print_help()
|
|
1022 |
+ print("Error: --target should be specified.")
|
|
1023 |
+ print(parser.print_help())
|
|
1024 |
sys.exit(1)
|
|
1025 |
|
|
1026 |
return options
|
|
1027 |
|
|
1028 |
|
|
1029 |
def DumpEnviron():
|
|
1030 |
- print "=== os.environ ==="
|
|
1031 |
+ print("=== os.environ ===")
|
|
1032 |
for key in sorted(os.environ):
|
|
1033 |
- print "%s = %s" % (key, os.getenv(key))
|
|
1034 |
- print "=================="
|
|
1035 |
+ print("%s = %s" % (key, os.getenv(key)))
|
|
1036 |
+ print("==================")
|
|
1037 |
|
|
1038 |
|
|
1039 |
def main():
|
|
1040 |
diff --git a/src/build_tools/copy_dll_and_symbol.py b/src/build_tools/copy_dll_and_symbol.py
|
|
1041 |
index 5bc0fe23..72f2788b 100644
|
|
1042 |
--- a/src/build_tools/copy_dll_and_symbol.py
|
|
1043 |
+++ b/src/build_tools/copy_dll_and_symbol.py
|
|
1044 |
@@ -38,7 +38,7 @@ import optparse
|
|
1045 |
import os
|
|
1046 |
import shutil
|
|
1047 |
|
|
1048 |
-from util import PrintErrorAndExit
|
|
1049 |
+from .util import PrintErrorAndExit
|
|
1050 |
|
|
1051 |
def ParseOption():
|
|
1052 |
"""Parse command line options."""
|
|
1053 |
@@ -98,7 +98,7 @@ def DeployMain(full_filename, src_paths, target_absdir):
|
|
1054 |
if _GetLastModifiedTime(src) <= target_file_mtime:
|
|
1055 |
# Older file found. Ignore.
|
|
1056 |
continue
|
|
1057 |
- print 'Copying %s to %s' % (src, target_file_abspath)
|
|
1058 |
+ print('Copying %s to %s' % (src, target_file_abspath))
|
|
1059 |
shutil.copy2(src, target_file_abspath)
|
|
1060 |
break
|
|
1061 |
|
|
1062 |
diff --git a/src/build_tools/copy_file.py b/src/build_tools/copy_file.py
|
|
1063 |
index 92b5ef3e..7268fd7b 100644
|
|
1064 |
--- a/src/build_tools/copy_file.py
|
|
1065 |
+++ b/src/build_tools/copy_file.py
|
|
1066 |
@@ -52,7 +52,7 @@ def _ErrorExit(message):
|
|
1067 |
Args:
|
|
1068 |
message: The error message to be printed to stderr.
|
|
1069 |
"""
|
|
1070 |
- print >>sys.stderr, message
|
|
1071 |
+ print(message, file=sys.stderr)
|
|
1072 |
sys.exit(1)
|
|
1073 |
|
|
1074 |
|
|
1075 |
diff --git a/src/build_tools/copy_qt_frameworks_mac.py b/src/build_tools/copy_qt_frameworks_mac.py
|
|
1076 |
index 2f7be942..8360e81e 100644
|
|
1077 |
--- a/src/build_tools/copy_qt_frameworks_mac.py
|
|
1078 |
+++ b/src/build_tools/copy_qt_frameworks_mac.py
|
|
1079 |
@@ -41,9 +41,9 @@ __author__ = "horo"
|
|
1080 |
import optparse
|
|
1081 |
import os
|
|
1082 |
|
|
1083 |
-from copy_file import CopyFiles
|
|
1084 |
-from util import PrintErrorAndExit
|
|
1085 |
-from util import RunOrDie
|
|
1086 |
+from .copy_file import CopyFiles
|
|
1087 |
+from .util import PrintErrorAndExit
|
|
1088 |
+from .util import RunOrDie
|
|
1089 |
|
|
1090 |
|
|
1091 |
def ParseOption():
|
|
1092 |
diff --git a/src/build_tools/embed_file.py b/src/build_tools/embed_file.py
|
|
1093 |
index 743f4f0d..9461d74b 100644
|
|
1094 |
--- a/src/build_tools/embed_file.py
|
|
1095 |
+++ b/src/build_tools/embed_file.py
|
|
1096 |
@@ -46,10 +46,10 @@ def _ParseOption():
|
|
1097 |
|
|
1098 |
def _FormatAsUint64LittleEndian(s):
|
|
1099 |
"""Formats a string as uint64 value in little endian order."""
|
|
1100 |
- for _ in xrange(len(s), 8):
|
|
1101 |
- s += '\0'
|
|
1102 |
+ for _ in range(len(s), 8):
|
|
1103 |
+ s += b'\0'
|
|
1104 |
s = s[::-1] # Reverse the string
|
|
1105 |
- return '0x%s' % binascii.b2a_hex(s)
|
|
1106 |
+ return b'0x%b' % binascii.b2a_hex(s)
|
|
1107 |
|
|
1108 |
|
|
1109 |
def main():
|
|
1110 |
@@ -57,30 +57,30 @@ def main():
|
|
1111 |
with open(opts.input, 'rb') as infile:
|
|
1112 |
with open(opts.output, 'wb') as outfile:
|
|
1113 |
outfile.write(
|
|
1114 |
- '#ifdef MOZC_EMBEDDED_FILE_%(name)s\n'
|
|
1115 |
- '#error "%(name)s was already included or defined elsewhere"\n'
|
|
1116 |
- '#else\n'
|
|
1117 |
- '#define MOZC_EMBEDDED_FILE_%(name)s\n'
|
|
1118 |
- 'const uint64 %(name)s_data[] = {\n'
|
|
1119 |
- % {'name': opts.name})
|
|
1120 |
+ b'#ifdef MOZC_EMBEDDED_FILE_%(name)b\n'
|
|
1121 |
+ b'#error "%(name)b was already included or defined elsewhere"\n'
|
|
1122 |
+ b'#else\n'
|
|
1123 |
+ b'#define MOZC_EMBEDDED_FILE_%(name)b\n'
|
|
1124 |
+ b'const uint64 %(name)b_data[] = {\n'
|
|
1125 |
+ % {b'name': opts.name.encode('utf-8')})
|
|
1126 |
|
|
1127 |
while True:
|
|
1128 |
chunk = infile.read(8)
|
|
1129 |
if not chunk:
|
|
1130 |
break
|
|
1131 |
- outfile.write(' ')
|
|
1132 |
+ outfile.write(b' ')
|
|
1133 |
outfile.write(_FormatAsUint64LittleEndian(chunk))
|
|
1134 |
- outfile.write(',\n')
|
|
1135 |
+ outfile.write(b',\n')
|
|
1136 |
|
|
1137 |
outfile.write(
|
|
1138 |
- '};\n'
|
|
1139 |
- 'const EmbeddedFile %(name)s = {\n'
|
|
1140 |
- ' %(name)s_data,\n'
|
|
1141 |
- ' %(size)d,\n'
|
|
1142 |
- '};\n'
|
|
1143 |
- '#endif // MOZC_EMBEDDED_FILE_%(name)s\n'
|
|
1144 |
- % {'name': opts.name,
|
|
1145 |
- 'size': os.stat(opts.input).st_size})
|
|
1146 |
+ b'};\n'
|
|
1147 |
+ b'const EmbeddedFile %(name)b = {\n'
|
|
1148 |
+ b' %(name)b_data,\n'
|
|
1149 |
+ b' %(size)d,\n'
|
|
1150 |
+ b'};\n'
|
|
1151 |
+ b'#endif // MOZC_EMBEDDED_FILE_%(name)b\n'
|
|
1152 |
+ % {b'name': opts.name.encode('utf-8'),
|
|
1153 |
+ b'size': os.stat(opts.input).st_size})
|
|
1154 |
|
|
1155 |
|
|
1156 |
if __name__ == '__main__':
|
|
1157 |
diff --git a/src/build_tools/embed_pathname.py b/src/build_tools/embed_pathname.py
|
|
1158 |
index d7424f38..888e704f 100644
|
|
1159 |
--- a/src/build_tools/embed_pathname.py
|
|
1160 |
+++ b/src/build_tools/embed_pathname.py
|
|
1161 |
@@ -28,7 +28,7 @@
|
|
1162 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
1163 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1164 |
|
|
1165 |
-"""A script to embed the given (relative) path name to C/C++ characters array.
|
|
1166 |
+r"""A script to embed the given (relative) path name to C/C++ characters array.
|
|
1167 |
|
|
1168 |
Example:
|
|
1169 |
./embed_pathname.py --path_to_be_embedded=d:\data\mozc
|
|
1170 |
@@ -53,7 +53,7 @@ def ParseOption():
|
|
1171 |
|
|
1172 |
(options, unused_args) = parser.parse_args()
|
|
1173 |
if not all(vars(options).values()):
|
|
1174 |
- print parser.print_help()
|
|
1175 |
+ print(parser.print_help())
|
|
1176 |
sys.exit(1)
|
|
1177 |
|
|
1178 |
return options
|
|
1179 |
@@ -63,7 +63,7 @@ def main():
|
|
1180 |
opt = ParseOption()
|
|
1181 |
path = os.path.abspath(opt.path_to_be_embedded)
|
|
1182 |
# TODO(yukawa): Consider the case of non-ASCII characters.
|
|
1183 |
- escaped_path = path.encode('string-escape')
|
|
1184 |
+ escaped_path = path.replace('\\', '\\\\')
|
|
1185 |
with open(opt.output, 'w') as output_file:
|
|
1186 |
output_file.write(
|
|
1187 |
'const char %s[] = "%s";\n' % (opt.constant_name, escaped_path))
|
|
1188 |
diff --git a/src/build_tools/ensure_gyp_module_path.py b/src/build_tools/ensure_gyp_module_path.py
|
|
1189 |
index 2ba74c9e..13344427 100644
|
|
1190 |
--- a/src/build_tools/ensure_gyp_module_path.py
|
|
1191 |
+++ b/src/build_tools/ensure_gyp_module_path.py
|
|
1192 |
@@ -48,7 +48,7 @@ def ParseOption():
|
|
1193 |
|
|
1194 |
(options, _) = parser.parse_args()
|
|
1195 |
if not options.expected:
|
|
1196 |
- print parser.print_help()
|
|
1197 |
+ print(parser.print_help())
|
|
1198 |
sys.exit(1)
|
|
1199 |
|
|
1200 |
return options
|
|
1201 |
@@ -59,20 +59,20 @@ def main():
|
|
1202 |
opt = ParseOption()
|
|
1203 |
expected_path = os.path.abspath(opt.expected)
|
|
1204 |
if not os.path.exists(expected_path):
|
|
1205 |
- print '%s does not exist.' % expected_path
|
|
1206 |
+ print('%s does not exist.' % expected_path)
|
|
1207 |
sys.exit(1)
|
|
1208 |
|
|
1209 |
try:
|
|
1210 |
import gyp # NOLINT
|
|
1211 |
except ImportError as e:
|
|
1212 |
- print 'import gyp failed: %s' % e
|
|
1213 |
+ print('import gyp failed: %s' % e)
|
|
1214 |
sys.exit(1)
|
|
1215 |
|
|
1216 |
actual_path = os.path.abspath(gyp.__path__[0])
|
|
1217 |
if expected_path != actual_path:
|
|
1218 |
- print 'Unexpected gyp module is loaded on this environment.'
|
|
1219 |
- print ' expected: %s' % expected_path
|
|
1220 |
- print ' actual : %s' % actual_path
|
|
1221 |
+ print('Unexpected gyp module is loaded on this environment.')
|
|
1222 |
+ print(' expected: %s' % expected_path)
|
|
1223 |
+ print(' actual : %s' % actual_path)
|
|
1224 |
sys.exit(1)
|
|
1225 |
|
|
1226 |
if __name__ == '__main__':
|
|
1227 |
diff --git a/src/build_tools/gen_win32_resource_header.py b/src/build_tools/gen_win32_resource_header.py
|
|
1228 |
index 313c5492..b87599f3 100644
|
|
1229 |
--- a/src/build_tools/gen_win32_resource_header.py
|
|
1230 |
+++ b/src/build_tools/gen_win32_resource_header.py
|
|
1231 |
@@ -39,7 +39,7 @@ See mozc_version.py for the detailed information for version.txt.
|
|
1232 |
__author__ = "yukawa"
|
|
1233 |
|
|
1234 |
import logging
|
|
1235 |
-import mozc_version
|
|
1236 |
+from . import mozc_version
|
|
1237 |
import optparse
|
|
1238 |
import os
|
|
1239 |
import sys
|
|
1240 |
diff --git a/src/build_tools/mozc_version.py b/src/build_tools/mozc_version.py
|
|
1241 |
index a2e93ec9..694ae4e1 100644
|
|
1242 |
--- a/src/build_tools/mozc_version.py
|
|
1243 |
+++ b/src/build_tools/mozc_version.py
|
|
1244 |
@@ -94,7 +94,7 @@ def _GetRevisionForPlatform(revision, target_platform):
|
|
1245 |
last_digit = TARGET_PLATFORM_TO_DIGIT.get(target_platform, None)
|
|
1246 |
if last_digit is None:
|
|
1247 |
logging.critical('target_platform %s is invalid. Accetable ones are %s',
|
|
1248 |
- target_platform, TARGET_PLATFORM_TO_DIGIT.keys())
|
|
1249 |
+ target_platform, list(TARGET_PLATFORM_TO_DIGIT.keys()))
|
|
1250 |
sys.exit(1)
|
|
1251 |
|
|
1252 |
if not revision:
|
|
1253 |
@@ -314,13 +314,14 @@ class MozcVersion(object):
|
|
1254 |
self._properties = {}
|
|
1255 |
if not os.path.isfile(path):
|
|
1256 |
return
|
|
1257 |
- for line in open(path):
|
|
1258 |
- matchobj = re.match(r'(\w+)=(.*)', line.strip())
|
|
1259 |
- if matchobj:
|
|
1260 |
- var = matchobj.group(1)
|
|
1261 |
- val = matchobj.group(2)
|
|
1262 |
- if var not in self._properties:
|
|
1263 |
- self._properties[var] = val
|
|
1264 |
+ with open(path) as file:
|
|
1265 |
+ for line in file:
|
|
1266 |
+ matchobj = re.match(r'(\w+)=(.*)', line.strip())
|
|
1267 |
+ if matchobj:
|
|
1268 |
+ var = matchobj.group(1)
|
|
1269 |
+ val = matchobj.group(2)
|
|
1270 |
+ if var not in self._properties:
|
|
1271 |
+ self._properties[var] = val
|
|
1272 |
|
|
1273 |
# Check mandatory properties.
|
|
1274 |
for key in VERSION_PROPERTIES:
|
|
1275 |
diff --git a/src/build_tools/redirect.py b/src/build_tools/redirect.py
|
|
1276 |
index fc78ef60..68f4eacc 100644
|
|
1277 |
--- a/src/build_tools/redirect.py
|
|
1278 |
+++ b/src/build_tools/redirect.py
|
|
1279 |
@@ -58,14 +58,15 @@ def main():
|
|
1280 |
process = subprocess.Popen(sys.argv, stdout=subprocess.PIPE,
|
|
1281 |
universal_newlines=True)
|
|
1282 |
except:
|
|
1283 |
- print '=========='
|
|
1284 |
- print ' ERROR: %s' % ' '.join(sys.argv)
|
|
1285 |
- print '=========='
|
|
1286 |
+ print('==========')
|
|
1287 |
+ print(' ERROR: %s' % ' '.join(sys.argv))
|
|
1288 |
+ print('==========')
|
|
1289 |
raise
|
|
1290 |
(stdout_content, _) = process.communicate()
|
|
1291 |
# Write the stdout content to the output file.
|
|
1292 |
output_file = open(output_file_name, 'w')
|
|
1293 |
output_file.write(stdout_content)
|
|
1294 |
+ output_file.close()
|
|
1295 |
return process.wait()
|
|
1296 |
|
|
1297 |
if __name__ == '__main__':
|
|
1298 |
diff --git a/src/build_tools/run_after_chdir.py b/src/build_tools/run_after_chdir.py
|
|
1299 |
index 9e063109..f7519c13 100644
|
|
1300 |
--- a/src/build_tools/run_after_chdir.py
|
|
1301 |
+++ b/src/build_tools/run_after_chdir.py
|
|
1302 |
@@ -57,7 +57,7 @@ def main():
|
|
1303 |
sys.argv.insert(0, sys.executable) # Inject the python interpreter path.
|
|
1304 |
# We don't capture stdout and stderr from Popen. The output will just
|
|
1305 |
# be emitted to a terminal or console.
|
|
1306 |
- print sys.argv
|
|
1307 |
+ print(sys.argv)
|
|
1308 |
sys.exit(subprocess.call(sys.argv))
|
|
1309 |
|
|
1310 |
if __name__ == '__main__':
|
|
1311 |
diff --git a/src/build_tools/serialized_string_array_builder.py b/src/build_tools/serialized_string_array_builder.py
|
|
1312 |
index f045a22c..7a2c29c6 100644
|
|
1313 |
--- a/src/build_tools/serialized_string_array_builder.py
|
|
1314 |
+++ b/src/build_tools/serialized_string_array_builder.py
|
|
1315 |
@@ -58,11 +58,11 @@ def SerializeToFile(strings, filename):
|
|
1316 |
f.write(struct.pack('<I', array_size))
|
|
1317 |
|
|
1318 |
# Offset and length array of (4 + 4) * array_size bytes.
|
|
1319 |
- for i in xrange(array_size):
|
|
1320 |
+ for i in range(array_size):
|
|
1321 |
f.write(struct.pack('<I', offsets[i]))
|
|
1322 |
f.write(struct.pack('<I', lengths[i]))
|
|
1323 |
|
|
1324 |
# Strings chunk.
|
|
1325 |
- for i in xrange(array_size):
|
|
1326 |
+ for i in range(array_size):
|
|
1327 |
f.write(strings[i])
|
|
1328 |
- f.write('\0')
|
|
1329 |
+ f.write(b'\0')
|
|
1330 |
diff --git a/src/build_tools/test_tools/gtest_report.py b/src/build_tools/test_tools/gtest_report.py
|
|
1331 |
index 3a161e1d..e01d28e7 100644
|
|
1332 |
--- a/src/build_tools/test_tools/gtest_report.py
|
|
1333 |
+++ b/src/build_tools/test_tools/gtest_report.py
|
|
1334 |
@@ -36,9 +36,9 @@ store as python object.
|
|
1335 |
|
|
1336 |
__author__ = "nona"
|
|
1337 |
|
|
1338 |
-import cStringIO as StringIO
|
|
1339 |
+import io
|
|
1340 |
import logging
|
|
1341 |
-from xml.etree import cElementTree as ElementTree
|
|
1342 |
+from xml.etree import ElementTree
|
|
1343 |
|
|
1344 |
|
|
1345 |
class Failure(object):
|
|
1346 |
@@ -87,13 +87,13 @@ class TestSuite(object):
|
|
1347 |
"""Returns summarized error report text."""
|
|
1348 |
if self.fail_num == 0:
|
|
1349 |
return ''
|
|
1350 |
- output = StringIO.StringIO()
|
|
1351 |
+ output = io.StringIO()
|
|
1352 |
for testcase in self.testcases:
|
|
1353 |
if not testcase.failures:
|
|
1354 |
continue
|
|
1355 |
- print >>output, '%s.%s:' % (self.name, testcase.name)
|
|
1356 |
+ print('%s.%s:' % (self.name, testcase.name), file=output)
|
|
1357 |
for failure in testcase.failures:
|
|
1358 |
- print >>output, failure.contents.encode('utf-8')
|
|
1359 |
+ print(failure.contents.encode('utf-8'), file=output)
|
|
1360 |
return output.getvalue()
|
|
1361 |
|
|
1362 |
@classmethod
|
|
1363 |
diff --git a/src/build_tools/test_tools/test_launcher.py b/src/build_tools/test_tools/test_launcher.py
|
|
1364 |
index 47c0a2ec..1b5cecfc 100644
|
|
1365 |
--- a/src/build_tools/test_tools/test_launcher.py
|
|
1366 |
+++ b/src/build_tools/test_tools/test_launcher.py
|
|
1367 |
@@ -101,11 +101,11 @@ class PathDeleter(object):
|
|
1368 |
time.sleep(1)
|
|
1369 |
try:
|
|
1370 |
shutil.rmtree(self._path)
|
|
1371 |
- except OSError, e:
|
|
1372 |
+ except OSError as e:
|
|
1373 |
logging.error('Failed to remove %s. error: %s', self._path, e)
|
|
1374 |
|
|
1375 |
|
|
1376 |
-def _ExecuteTest((command, gtest_report_dir)):
|
|
1377 |
+def _ExecuteTest(args):
|
|
1378 |
"""Executes tests with specified Test command.
|
|
1379 |
|
|
1380 |
Args:
|
|
1381 |
@@ -122,6 +122,7 @@ def _ExecuteTest((command, gtest_report_dir)):
|
|
1382 |
module, which is used in multiprocessing module.
|
|
1383 |
(http://docs.python.org/library/pickle.html)
|
|
1384 |
"""
|
|
1385 |
+ (command, gtest_report_dir) = args
|
|
1386 |
binary = command[0]
|
|
1387 |
binary_filename = os.path.basename(binary)
|
|
1388 |
tmp_dir = tempfile.mkdtemp()
|
|
1389 |
diff --git a/src/build_tools/tweak_data.py b/src/build_tools/tweak_data.py
|
|
1390 |
index 64d57e14..79b70c49 100644
|
|
1391 |
--- a/src/build_tools/tweak_data.py
|
|
1392 |
+++ b/src/build_tools/tweak_data.py
|
|
1393 |
@@ -55,7 +55,7 @@ def ReplaceVariables(data, environment):
|
|
1394 |
The value for the variable if the variable is defined in the
|
|
1395 |
environment. Otherwise original string is returned.
|
|
1396 |
"""
|
|
1397 |
- if environment.has_key(matchobj.group(1)):
|
|
1398 |
+ if matchobj.group(1) in environment:
|
|
1399 |
return environment[matchobj.group(1)]
|
|
1400 |
return matchobj.group(0)
|
|
1401 |
|
|
1402 |
diff --git a/src/build_tools/tweak_info_plist.py b/src/build_tools/tweak_info_plist.py
|
|
1403 |
index efa3b268..1ff91e2c 100644
|
|
1404 |
--- a/src/build_tools/tweak_info_plist.py
|
|
1405 |
+++ b/src/build_tools/tweak_info_plist.py
|
|
1406 |
@@ -42,8 +42,8 @@ import datetime
|
|
1407 |
import logging
|
|
1408 |
import optparse
|
|
1409 |
import sys
|
|
1410 |
-import mozc_version
|
|
1411 |
-import tweak_data
|
|
1412 |
+from . import mozc_version
|
|
1413 |
+from . import tweak_data
|
|
1414 |
|
|
1415 |
_COPYRIGHT_YEAR = datetime.date.today().year
|
|
1416 |
|
|
1417 |
@@ -81,7 +81,7 @@ def main():
|
|
1418 |
|
|
1419 |
version = mozc_version.MozcVersion(options.version_file)
|
|
1420 |
|
|
1421 |
- copyright_message = (u'© %d Google Inc.' % _COPYRIGHT_YEAR).encode('utf-8')
|
|
1422 |
+ copyright_message = ('© %d Google Inc.' % _COPYRIGHT_YEAR).encode('utf-8')
|
|
1423 |
long_version = version.GetVersionString()
|
|
1424 |
short_version = version.GetVersionInFormat('@MAJOR@.@MINOR@.@BUILD@')
|
|
1425 |
|
|
1426 |
diff --git a/src/build_tools/tweak_info_plist_strings.py b/src/build_tools/tweak_info_plist_strings.py
|
|
1427 |
index e34dd59a..bdd00168 100644
|
|
1428 |
--- a/src/build_tools/tweak_info_plist_strings.py
|
|
1429 |
+++ b/src/build_tools/tweak_info_plist_strings.py
|
|
1430 |
@@ -40,7 +40,7 @@ import datetime
|
|
1431 |
import logging
|
|
1432 |
import optparse
|
|
1433 |
import sys
|
|
1434 |
-import tweak_data
|
|
1435 |
+from . import tweak_data
|
|
1436 |
|
|
1437 |
_COPYRIGHT_YEAR = datetime.date.today().year
|
|
1438 |
|
|
1439 |
@@ -77,7 +77,7 @@ def main():
|
|
1440 |
if options.branding == 'GoogleJapaneseInput':
|
|
1441 |
variables = {
|
|
1442 |
'CF_BUNDLE_NAME_EN': 'Google Japanese Input',
|
|
1443 |
- 'CF_BUNDLE_NAME_JA': u'Google 日本語入力'.encode('utf-8'),
|
|
1444 |
+ 'CF_BUNDLE_NAME_JA': 'Google 日本語入力'.encode('utf-8'),
|
|
1445 |
'NS_HUMAN_READABLE_COPYRIGHT': copyright_message,
|
|
1446 |
'INPUT_MODE_ANNOTATION': 'Google',
|
|
1447 |
}
|
|
1448 |
diff --git a/src/build_tools/tweak_macinstaller_script.py b/src/build_tools/tweak_macinstaller_script.py
|
|
1449 |
index 54542cbe..daed224c 100644
|
|
1450 |
--- a/src/build_tools/tweak_macinstaller_script.py
|
|
1451 |
+++ b/src/build_tools/tweak_macinstaller_script.py
|
|
1452 |
@@ -39,7 +39,7 @@ __author__ = "mukai"
|
|
1453 |
import logging
|
|
1454 |
import optparse
|
|
1455 |
|
|
1456 |
-import mozc_version
|
|
1457 |
+from . import mozc_version
|
|
1458 |
|
|
1459 |
|
|
1460 |
def _ReplaceVariables(data, environment):
|
|
1461 |
diff --git a/src/build_tools/tweak_pkgproj.py b/src/build_tools/tweak_pkgproj.py
|
|
1462 |
index f5ff7287..84f24ffe 100644
|
|
1463 |
--- a/src/build_tools/tweak_pkgproj.py
|
|
1464 |
+++ b/src/build_tools/tweak_pkgproj.py
|
|
1465 |
@@ -45,7 +45,7 @@ import optparse
|
|
1466 |
import os
|
|
1467 |
import plistlib
|
|
1468 |
import re
|
|
1469 |
-import mozc_version
|
|
1470 |
+from . import mozc_version
|
|
1471 |
|
|
1472 |
from os import path
|
|
1473 |
|
|
1474 |
@@ -71,7 +71,7 @@ def _ReplaceVariables(data, environment):
|
|
1475 |
The value for the variable if the variable is defined in the
|
|
1476 |
environment. Otherwise original string is returned.
|
|
1477 |
"""
|
|
1478 |
- if environment.has_key(matchobj.group(1)):
|
|
1479 |
+ if matchobj.group(1) in environment:
|
|
1480 |
return environment[matchobj.group(1)]
|
|
1481 |
return matchobj.group(0)
|
|
1482 |
|
|
1483 |
diff --git a/src/build_tools/util.py b/src/build_tools/util.py
|
|
1484 |
index 85961187..f0ef68d9 100644
|
|
1485 |
--- a/src/build_tools/util.py
|
|
1486 |
+++ b/src/build_tools/util.py
|
|
1487 |
@@ -73,11 +73,11 @@ def GetNumberOfProcessors():
|
|
1488 |
return 1
|
|
1489 |
|
|
1490 |
|
|
1491 |
-class RunOrDieError(StandardError):
|
|
1492 |
+class RunOrDieError(Exception):
|
|
1493 |
"""The exception class for RunOrDie."""
|
|
1494 |
|
|
1495 |
def __init__(self, message):
|
|
1496 |
- StandardError.__init__(self, message)
|
|
1497 |
+ Exception.__init__(self, message)
|
|
1498 |
|
|
1499 |
|
|
1500 |
def RunOrDie(argv):
|
|
1501 |
@@ -105,7 +105,7 @@ def RemoveFile(file_name):
|
|
1502 |
return # Do nothing if not exist.
|
|
1503 |
if IsWindows():
|
|
1504 |
# Read-only files cannot be deleted on Windows.
|
|
1505 |
- os.chmod(file_name, 0700)
|
|
1506 |
+ os.chmod(file_name, 0o700)
|
|
1507 |
logging.debug('Removing file: %s', file_name)
|
|
1508 |
os.unlink(file_name)
|
|
1509 |
|
|
1510 |
diff --git a/src/build_tools/zlib_util.py b/src/build_tools/zlib_util.py
|
|
1511 |
index 47491480..cc6630b0 100644
|
|
1512 |
--- a/src/build_tools/zlib_util.py
|
|
1513 |
+++ b/src/build_tools/zlib_util.py
|
|
1514 |
@@ -58,7 +58,7 @@ def Decompress(input_filename, output_filename):
|
|
1515 |
|
|
1516 |
def main():
|
|
1517 |
if len(sys.argv) != 4:
|
|
1518 |
- print >>sys.stderr, 'Invalid arguments'
|
|
1519 |
+ print('Invalid arguments', file=sys.stderr)
|
|
1520 |
return
|
|
1521 |
if sys.argv[1] == 'compress':
|
|
1522 |
Compress(sys.argv[2], sys.argv[3])
|
|
1523 |
@@ -66,7 +66,7 @@ def main():
|
|
1524 |
if sys.argv[1] == 'decompress':
|
|
1525 |
Decompress(sys.argv[2], sys.argv[3])
|
|
1526 |
return
|
|
1527 |
- print >>sys.stderr, 'Unknown command:', sys.argv[1]
|
|
1528 |
+ print('Unknown command:', sys.argv[1], file=sys.stderr)
|
|
1529 |
|
|
1530 |
|
|
1531 |
if __name__ == '__main__':
|
|
1532 |
diff --git a/src/chrome/nacl/nacl_net_test_server.py b/src/chrome/nacl/nacl_net_test_server.py
|
|
1533 |
index 257fa79e..e88e10dc 100644
|
|
1534 |
--- a/src/chrome/nacl/nacl_net_test_server.py
|
|
1535 |
+++ b/src/chrome/nacl/nacl_net_test_server.py
|
|
1536 |
@@ -45,27 +45,27 @@ Example usage:
|
|
1537 |
--timeout=20
|
|
1538 |
"""
|
|
1539 |
|
|
1540 |
-import BaseHTTPServer
|
|
1541 |
+import _thread
|
|
1542 |
+import http.server
|
|
1543 |
import optparse
|
|
1544 |
import os
|
|
1545 |
import os.path
|
|
1546 |
import shutil
|
|
1547 |
-import SocketServer
|
|
1548 |
+import socketserver
|
|
1549 |
import subprocess
|
|
1550 |
import sys
|
|
1551 |
import tempfile
|
|
1552 |
-import thread
|
|
1553 |
import time
|
|
1554 |
-import urlparse
|
|
1555 |
+import urllib.parse
|
|
1556 |
|
|
1557 |
|
|
1558 |
-class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1559 |
+class RequestHandler(http.server.BaseHTTPRequestHandler):
|
|
1560 |
"""Handle the HTTP requests that arrive at the server."""
|
|
1561 |
|
|
1562 |
def do_GET(self):
|
|
1563 |
# pylint: disable=g-bad-name
|
|
1564 |
"""Handles GET request."""
|
|
1565 |
- parsed_path = urlparse.urlparse(self.path)
|
|
1566 |
+ parsed_path = urllib.parse.urlparse(self.path)
|
|
1567 |
options = {'response': 200,
|
|
1568 |
'result': '',
|
|
1569 |
'before_response_sleep': 0.0,
|
|
1570 |
@@ -77,7 +77,7 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1571 |
'data': 'DEFAULT_DATA',
|
|
1572 |
'times': 1,
|
|
1573 |
'redirect_location': ''}
|
|
1574 |
- query = urlparse.parse_qsl(parsed_path.query)
|
|
1575 |
+ query = urllib.parse.parse_qsl(parsed_path.query)
|
|
1576 |
for params in query:
|
|
1577 |
options[params[0]] = params[1]
|
|
1578 |
|
|
1579 |
@@ -113,13 +113,14 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1580 |
full_path = os.path.join(extra_dir, os.path.basename(parsed_path.path))
|
|
1581 |
if os.path.isfile(full_path):
|
|
1582 |
try:
|
|
1583 |
- data = open(full_path).read()
|
|
1584 |
+ with open(full_path) as f:
|
|
1585 |
+ data = f.read()
|
|
1586 |
self.send_response(200)
|
|
1587 |
self.send_header('Content-Length', len(data))
|
|
1588 |
self.end_headers()
|
|
1589 |
self.wfile.write(data)
|
|
1590 |
- except IOError, (errno, strerror):
|
|
1591 |
- print 'I/O error(%s): %s' % (errno, strerror)
|
|
1592 |
+ except IOError as e:
|
|
1593 |
+ print('I/O error(%s): %s' % (e.errno, e.strerror))
|
|
1594 |
return
|
|
1595 |
|
|
1596 |
try:
|
|
1597 |
@@ -143,14 +144,14 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1598 |
time.sleep(float(options['before_data_sleep']))
|
|
1599 |
self.wfile.write(options['data'])
|
|
1600 |
time.sleep(float(options['after_data_sleep']))
|
|
1601 |
- except IOError, (errno, strerror):
|
|
1602 |
- print 'I/O error(%s): %s' % (errno, strerror)
|
|
1603 |
+ except IOError as e:
|
|
1604 |
+ print('I/O error(%s): %s' % (e.errno, e.strerror))
|
|
1605 |
return
|
|
1606 |
|
|
1607 |
def do_POST(self):
|
|
1608 |
# pylint: disable=g-bad-name
|
|
1609 |
"""Handles POST request."""
|
|
1610 |
- parsed_path = urlparse.urlparse(self.path)
|
|
1611 |
+ parsed_path = urllib.parse.urlparse(self.path)
|
|
1612 |
options = {'response': 200,
|
|
1613 |
'result': '',
|
|
1614 |
'before_response_sleep': 0.0,
|
|
1615 |
@@ -159,7 +160,7 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1616 |
'after_data_sleep': 0.0,
|
|
1617 |
'content_length': '',
|
|
1618 |
'redirect_location': ''}
|
|
1619 |
- query = urlparse.parse_qsl(parsed_path.query)
|
|
1620 |
+ query = urllib.parse.parse_qsl(parsed_path.query)
|
|
1621 |
for params in query:
|
|
1622 |
options[params[0]] = params[1]
|
|
1623 |
|
|
1624 |
@@ -185,18 +186,18 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1625 |
self.wfile.write(post_data)
|
|
1626 |
time.sleep(float(options['after_data_sleep']))
|
|
1627 |
return
|
|
1628 |
- except IOError, (errno, strerror):
|
|
1629 |
- print 'I/O error(%s): %s' % (errno, strerror)
|
|
1630 |
+ except IOError as e:
|
|
1631 |
+ print('I/O error(%s): %s' % (e.errno, e.strerror))
|
|
1632 |
return
|
|
1633 |
|
|
1634 |
def do_HEAD(self):
|
|
1635 |
# pylint: disable=g-bad-name
|
|
1636 |
"""Handles HEAD request."""
|
|
1637 |
- parsed_path = urlparse.urlparse(self.path)
|
|
1638 |
+ parsed_path = urllib.parse.urlparse(self.path)
|
|
1639 |
options = {'response': 200,
|
|
1640 |
'before_response_sleep': 0.0,
|
|
1641 |
'before_head_sleep': 0.0}
|
|
1642 |
- query = urlparse.parse_qsl(parsed_path.query)
|
|
1643 |
+ query = urllib.parse.parse_qsl(parsed_path.query)
|
|
1644 |
for params in query:
|
|
1645 |
options[params[0]] = params[1]
|
|
1646 |
|
|
1647 |
@@ -210,12 +211,12 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
1648 |
for name, value in sorted(self.headers.items()):
|
|
1649 |
self.send_header('CLIENT_HEADER_%s' % name, '%s' % value)
|
|
1650 |
self.end_headers()
|
|
1651 |
- except IOError, (errno, strerror):
|
|
1652 |
- print 'I/O error(%s): %s' % (errno, strerror)
|
|
1653 |
+ except IOError as e:
|
|
1654 |
+ print('I/O error(%s): %s' % (e.errno, e.strerror))
|
|
1655 |
return
|
|
1656 |
|
|
1657 |
|
|
1658 |
-class TestServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
|
|
1659 |
+class TestServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
|
|
1660 |
def Configure(self, serving_dirs):
|
|
1661 |
self.serving_dirs = serving_dirs
|
|
1662 |
self.finished = False
|
|
1663 |
@@ -243,12 +244,12 @@ def main():
|
|
1664 |
server = TestServer(('localhost', 9999), RequestHandler)
|
|
1665 |
server.Configure(options.serving_dirs)
|
|
1666 |
host, port = server.socket.getsockname()
|
|
1667 |
- print 'Starting server %s:%s' % (host, port)
|
|
1668 |
+ print('Starting server %s:%s' % (host, port))
|
|
1669 |
|
|
1670 |
def Serve():
|
|
1671 |
while not server.finished:
|
|
1672 |
server.handle_request()
|
|
1673 |
- thread.start_new_thread(Serve, ())
|
|
1674 |
+ _thread.start_new_thread(Serve, ())
|
|
1675 |
|
|
1676 |
temp_dir = tempfile.mkdtemp()
|
|
1677 |
if options.browser_path:
|
|
1678 |
@@ -257,7 +258,7 @@ def main():
|
|
1679 |
cmd.append('--load-extension=%s' % options.load_extension)
|
|
1680 |
if options.url:
|
|
1681 |
cmd.append('http://%s:%s/%s' % (host, port, options.url))
|
|
1682 |
- print cmd
|
|
1683 |
+ print(cmd)
|
|
1684 |
browser_handle = subprocess.Popen(cmd)
|
|
1685 |
|
|
1686 |
time_started = time.time()
|
|
1687 |
diff --git a/src/chrome/nacl/pnacl_translate.py b/src/chrome/nacl/pnacl_translate.py
|
|
1688 |
index ae10b3c1..02b037d0 100644
|
|
1689 |
--- a/src/chrome/nacl/pnacl_translate.py
|
|
1690 |
+++ b/src/chrome/nacl/pnacl_translate.py
|
|
1691 |
@@ -54,11 +54,11 @@ def Translate(toolchain_root, input_file, output_base):
|
|
1692 |
for target in targets:
|
|
1693 |
cmd = (translate_command, '--allow-llvm-bitcode-input', '-arch', target[0],
|
|
1694 |
input_file, '-o', '%s_%s.nexe' % (output_base, target[1]))
|
|
1695 |
- print 'Running: ' + ' '.join(cmd)
|
|
1696 |
+ print('Running: ' + ' '.join(cmd))
|
|
1697 |
if subprocess.Popen(cmd).wait() != 0:
|
|
1698 |
- print >> sys.stderr, 'ERROR: ' + ' '.join(cmd)
|
|
1699 |
+ print('ERROR: ' + ' '.join(cmd), file=sys.stderr)
|
|
1700 |
raise RuntimeError('Translate Error')
|
|
1701 |
- print 'Done: ' + ' '.join(cmd)
|
|
1702 |
+ print('Done: ' + ' '.join(cmd))
|
|
1703 |
|
|
1704 |
|
|
1705 |
def StripAndTranslate(toolchain_root, input_file, output_base):
|
|
1706 |
@@ -68,21 +68,21 @@ def StripAndTranslate(toolchain_root, input_file, output_base):
|
|
1707 |
temp_dir = tempfile.mkdtemp()
|
|
1708 |
temp_file_base = os.path.join(temp_dir, 'stripped')
|
|
1709 |
cmd = (strip_command, input_file, '-o', temp_file_base)
|
|
1710 |
- print 'Running: ' + ' '.join(cmd)
|
|
1711 |
+ print('Running: ' + ' '.join(cmd))
|
|
1712 |
if subprocess.Popen(cmd).wait() != 0:
|
|
1713 |
- print >> sys.stderr, 'ERROR: ' + ' '.join(cmd)
|
|
1714 |
+ print('ERROR: ' + ' '.join(cmd), file=sys.stderr)
|
|
1715 |
raise RuntimeError('Strip Error')
|
|
1716 |
- print 'Done: ' + ' '.join(cmd)
|
|
1717 |
+ print('Done: ' + ' '.join(cmd))
|
|
1718 |
Translate(toolchain_root, temp_file_base, temp_file_base)
|
|
1719 |
targets = ('arm', 'x86_32', 'x86_64')
|
|
1720 |
for target in targets:
|
|
1721 |
cmd = (strip_command, '%s_%s.nexe' % (temp_file_base, target),
|
|
1722 |
'-o', '%s_%s.nexe' % (output_base, target))
|
|
1723 |
- print 'Running: ' + ' '.join(cmd)
|
|
1724 |
+ print('Running: ' + ' '.join(cmd))
|
|
1725 |
if subprocess.Popen(cmd).wait() != 0:
|
|
1726 |
- print >> sys.stderr, 'ERROR: ' + ' '.join(cmd)
|
|
1727 |
+ print('ERROR: ' + ' '.join(cmd), file=sys.stderr)
|
|
1728 |
raise RuntimeError('Strip Error')
|
|
1729 |
- print 'Done: ' + ' '.join(cmd)
|
|
1730 |
+ print('Done: ' + ' '.join(cmd))
|
|
1731 |
finally:
|
|
1732 |
shutil.rmtree(temp_dir)
|
|
1733 |
|
|
1734 |
@@ -101,15 +101,15 @@ def main():
|
|
1735 |
(options, _) = parser.parse_args()
|
|
1736 |
|
|
1737 |
if not options.toolchain_root:
|
|
1738 |
- print >> sys.stderr, 'Error: toolchain_root is not set.'
|
|
1739 |
+ print('Error: toolchain_root is not set.', file=sys.stderr)
|
|
1740 |
sys.exit(1)
|
|
1741 |
|
|
1742 |
if not options.input:
|
|
1743 |
- print >> sys.stderr, 'Error: input is not set.'
|
|
1744 |
+ print('Error: input is not set.', file=sys.stderr)
|
|
1745 |
sys.exit(1)
|
|
1746 |
|
|
1747 |
if not options.output_base:
|
|
1748 |
- print >> sys.stderr, 'Error: output_base is not set.'
|
|
1749 |
+ print('Error: output_base is not set.', file=sys.stderr)
|
|
1750 |
sys.exit(1)
|
|
1751 |
|
|
1752 |
if options.configuration == 'Release':
|
|
1753 |
diff --git a/src/chrome/nacl/run_nacl_test.py b/src/chrome/nacl/run_nacl_test.py
|
|
1754 |
index 6a7fcf2f..8a1bea19 100644
|
|
1755 |
--- a/src/chrome/nacl/run_nacl_test.py
|
|
1756 |
+++ b/src/chrome/nacl/run_nacl_test.py
|
|
1757 |
@@ -73,7 +73,7 @@ def RunCommand(options, command):
|
|
1758 |
output, _ = process.communicate()
|
|
1759 |
logging.info(output)
|
|
1760 |
if process.returncode != 0:
|
|
1761 |
- raise StandardError('Failed to run the command: ' + ' '.join(args))
|
|
1762 |
+ raise Exception('Failed to run the command: ' + ' '.join(args))
|
|
1763 |
return output
|
|
1764 |
|
|
1765 |
|
|
1766 |
diff --git a/src/client/gen_client_quality_test_data.py b/src/client/gen_client_quality_test_data.py
|
|
1767 |
index b9e13759..6c8af404 100644
|
|
1768 |
--- a/src/client/gen_client_quality_test_data.py
|
|
1769 |
+++ b/src/client/gen_client_quality_test_data.py
|
|
1770 |
@@ -28,17 +28,16 @@
|
|
1771 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
1772 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1773 |
|
|
1774 |
-import codecs
|
|
1775 |
import logging
|
|
1776 |
import sys
|
|
1777 |
|
|
1778 |
|
|
1779 |
def escape(string):
|
|
1780 |
- return ''.join('\\x%02x' % ord(char) for char in string.encode('utf-8'))
|
|
1781 |
+ return ''.join('\\x%02x' % char for char in string.encode('utf-8'))
|
|
1782 |
|
|
1783 |
|
|
1784 |
def convert_tsv(filename):
|
|
1785 |
- tsv = codecs.open(filename, 'rb', 'utf-8')
|
|
1786 |
+ tsv = open(filename, 'r', encoding='utf-8')
|
|
1787 |
for line in tsv:
|
|
1788 |
line = line.rstrip()
|
|
1789 |
if not line or line.startswith('#'):
|
|
1790 |
@@ -57,38 +56,35 @@ def convert_tsv(filename):
|
|
1791 |
expected = fields[4]
|
|
1792 |
query = fields[5]
|
|
1793 |
|
|
1794 |
- print ' // {"%s", "%s", "%s"},' % (label, expected, query)
|
|
1795 |
- print (' {"%s", "%s", "%s"},' %
|
|
1796 |
+ print(' // {"%s", "%s", "%s"},' % (label, expected, query))
|
|
1797 |
+ print(' {"%s", "%s", "%s"},' %
|
|
1798 |
(escape(label), escape(expected), escape(query)))
|
|
1799 |
tsv.close()
|
|
1800 |
|
|
1801 |
|
|
1802 |
def main():
|
|
1803 |
- sys.stdin = codecs.getreader('utf-8')(sys.stdin)
|
|
1804 |
- sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
|
|
1805 |
- sys.stderr = codecs.getwriter('utf-8')(sys.stderr)
|
|
1806 |
logging.basicConfig(level = logging.INFO)
|
|
1807 |
|
|
1808 |
- print '// Automatically generated by mozc'
|
|
1809 |
- print '#ifndef MOZC_SESSION_QUALITY_MAIN_DATA_H_'
|
|
1810 |
- print '#define MOZC_SESSION_QUALITY_MAIN_DATA_H_'
|
|
1811 |
- print ''
|
|
1812 |
- print 'namespace mozc {'
|
|
1813 |
- print 'struct TestCase {'
|
|
1814 |
- print ' const char* source;'
|
|
1815 |
- print ' const char* expected_result;'
|
|
1816 |
- print ' const char* hiragana_sentence;'
|
|
1817 |
- print '};'
|
|
1818 |
- print ''
|
|
1819 |
- print 'static TestCase test_cases[] = {'
|
|
1820 |
+ print('// Automatically generated by mozc')
|
|
1821 |
+ print('#ifndef MOZC_SESSION_QUALITY_MAIN_DATA_H_')
|
|
1822 |
+ print('#define MOZC_SESSION_QUALITY_MAIN_DATA_H_')
|
|
1823 |
+ print('')
|
|
1824 |
+ print('namespace mozc {')
|
|
1825 |
+ print('struct TestCase {')
|
|
1826 |
+ print(' const char* source;')
|
|
1827 |
+ print(' const char* expected_result;')
|
|
1828 |
+ print(' const char* hiragana_sentence;')
|
|
1829 |
+ print('};')
|
|
1830 |
+ print('')
|
|
1831 |
+ print('static TestCase test_cases[] = {')
|
|
1832 |
|
|
1833 |
for filename in sys.argv[1:]:
|
|
1834 |
convert_tsv(filename)
|
|
1835 |
|
|
1836 |
- print ' {NULL, NULL, NULL}'
|
|
1837 |
- print '};'
|
|
1838 |
- print '} // namespace mozc'
|
|
1839 |
- print '#endif // MOZC_SESSION_QUALITY_MAIN_DATA_H_'
|
|
1840 |
+ print(' {NULL, NULL, NULL}')
|
|
1841 |
+ print('};')
|
|
1842 |
+ print('} // namespace mozc')
|
|
1843 |
+ print('#endif // MOZC_SESSION_QUALITY_MAIN_DATA_H_')
|
|
1844 |
|
|
1845 |
|
|
1846 |
if __name__ == '__main__':
|
|
1847 |
diff --git a/src/composer/internal/gen_typing_model.py b/src/composer/internal/gen_typing_model.py
|
|
1848 |
index 71ba7699..8c867759 100644
|
|
1849 |
--- a/src/composer/internal/gen_typing_model.py
|
|
1850 |
+++ b/src/composer/internal/gen_typing_model.py
|
|
1851 |
@@ -54,14 +54,13 @@ Output file format:
|
|
1852 |
__author__ = "noriyukit"
|
|
1853 |
|
|
1854 |
import bisect
|
|
1855 |
-import codecs
|
|
1856 |
import collections
|
|
1857 |
import optparse
|
|
1858 |
import struct
|
|
1859 |
|
|
1860 |
UNDEFINED_COST = -1
|
|
1861 |
-MAX_UINT16 = struct.unpack('H', '\xFF\xFF')[0]
|
|
1862 |
-MAX_UINT8 = struct.unpack('B', '\xFF')[0]
|
|
1863 |
+MAX_UINT16 = struct.unpack('H', b'\xFF\xFF')[0]
|
|
1864 |
+MAX_UINT8 = struct.unpack('B', b'\xFF')[0]
|
|
1865 |
|
|
1866 |
|
|
1867 |
def ParseArgs():
|
|
1868 |
@@ -113,7 +112,7 @@ def GetMappingTable(values, mapping_table_size):
|
|
1869 |
sorted_values = list(sorted(set(values)))
|
|
1870 |
mapping_table = sorted_values[0]
|
|
1871 |
mapping_table_size_without_special_value = mapping_table_size - 1
|
|
1872 |
- span = len(sorted_values) / (mapping_table_size_without_special_value - 1)
|
|
1873 |
+ span = len(sorted_values) // (mapping_table_size_without_special_value - 1)
|
|
1874 |
mapping_table = [sorted_values[i * span]
|
|
1875 |
for i
|
|
1876 |
in range(0, mapping_table_size_without_special_value - 1)]
|
|
1877 |
@@ -150,7 +149,7 @@ def GetNearestMappingTableIndex(mapping_table, value):
|
|
1878 |
|
|
1879 |
def GetValueTable(unique_characters, mapping_table, dictionary):
|
|
1880 |
result = []
|
|
1881 |
- for key, value in dictionary.iteritems():
|
|
1882 |
+ for key, value in dictionary.items():
|
|
1883 |
index = GetIndexFromKey(unique_characters, key)
|
|
1884 |
while len(result) <= index:
|
|
1885 |
result.append(len(mapping_table) - 1)
|
|
1886 |
@@ -167,13 +166,13 @@ def WriteResult(romaji_transition_cost, output_path):
|
|
1887 |
romaji_transition_cost)
|
|
1888 |
with open(output_path, 'wb') as f:
|
|
1889 |
f.write(struct.pack('<I', len(unique_characters)))
|
|
1890 |
- f.write(''.join(unique_characters))
|
|
1891 |
+ f.write(''.join(unique_characters).encode('utf-8'))
|
|
1892 |
offset = 4 + len(unique_characters)
|
|
1893 |
|
|
1894 |
# Add padding to place value list size at 4-byte boundary.
|
|
1895 |
if offset % 4:
|
|
1896 |
padding_size = 4 - offset % 4
|
|
1897 |
- f.write('\x00' * padding_size)
|
|
1898 |
+ f.write(b'\x00' * padding_size)
|
|
1899 |
offset += padding_size
|
|
1900 |
|
|
1901 |
f.write(struct.pack('<I', len(value_list)))
|
|
1902 |
@@ -184,7 +183,7 @@ def WriteResult(romaji_transition_cost, output_path):
|
|
1903 |
# Add padding to place mapping_table at 4-byte boundary.
|
|
1904 |
if offset % 4:
|
|
1905 |
padding_size = 4 - offset % 4
|
|
1906 |
- f.write('\x00' * padding_size)
|
|
1907 |
+ f.write(b'\x00' * padding_size)
|
|
1908 |
offset += padding_size
|
|
1909 |
|
|
1910 |
for v in mapping_table:
|
|
1911 |
@@ -198,7 +197,8 @@ def main():
|
|
1912 |
# - trigram['vw']['x'] = -500 * log(P(x | 'vw'))
|
|
1913 |
unigram = {}
|
|
1914 |
trigram = collections.defaultdict(dict)
|
|
1915 |
- for line in codecs.open(options.input_path, 'r', encoding='utf-8'):
|
|
1916 |
+ input_file = open(options.input_path, 'r', encoding='utf-8')
|
|
1917 |
+ for line in input_file:
|
|
1918 |
line = line.rstrip()
|
|
1919 |
ngram, cost = line.split('\t')
|
|
1920 |
cost = int(cost)
|
|
1921 |
@@ -206,6 +206,7 @@ def main():
|
|
1922 |
unigram[ngram] = cost
|
|
1923 |
else:
|
|
1924 |
trigram[ngram[:-1]][ngram[-1]] = cost
|
|
1925 |
+ input_file.close()
|
|
1926 |
|
|
1927 |
# Calculate ngram-related cost for each 'vw' and 'x':
|
|
1928 |
# -500 * log( P('x' | 'vw') / P('x') )
|
|
1929 |
diff --git a/src/converter/gen_boundary_data.py b/src/converter/gen_boundary_data.py
|
|
1930 |
index 2a12ee57..35396695 100644
|
|
1931 |
--- a/src/converter/gen_boundary_data.py
|
|
1932 |
+++ b/src/converter/gen_boundary_data.py
|
|
1933 |
@@ -70,7 +70,8 @@ def PatternToRegexp(pattern):
|
|
1934 |
def LoadPatterns(file):
|
|
1935 |
prefix = []
|
|
1936 |
suffix = []
|
|
1937 |
- for line in open(file, 'r'):
|
|
1938 |
+ fh = open(file, 'r')
|
|
1939 |
+ for line in fh:
|
|
1940 |
if len(line) <= 1 or line[0] == '#':
|
|
1941 |
continue
|
|
1942 |
fields = line.split()
|
|
1943 |
@@ -84,8 +85,9 @@ def LoadPatterns(file):
|
|
1944 |
elif label == 'SUFFIX':
|
|
1945 |
suffix.append([re.compile(PatternToRegexp(feature)), cost])
|
|
1946 |
else:
|
|
1947 |
- print 'format error %s' % (line)
|
|
1948 |
+ print('format error %s' % (line))
|
|
1949 |
sys.exit(0)
|
|
1950 |
+ fh.close()
|
|
1951 |
return (prefix, suffix)
|
|
1952 |
|
|
1953 |
|
|
1954 |
@@ -100,19 +102,23 @@ def GetCost(patterns, feature):
|
|
1955 |
|
|
1956 |
def LoadFeatures(filename):
|
|
1957 |
features = []
|
|
1958 |
- for line in open(filename, 'r'):
|
|
1959 |
+ fh = open(filename, 'r')
|
|
1960 |
+ for line in fh:
|
|
1961 |
fields = line.split()
|
|
1962 |
features.append(fields[1])
|
|
1963 |
+ fh.close()
|
|
1964 |
return features
|
|
1965 |
|
|
1966 |
|
|
1967 |
def CountSpecialPos(filename):
|
|
1968 |
count = 0
|
|
1969 |
- for line in open(filename, 'r'):
|
|
1970 |
+ fh = open(filename, 'r')
|
|
1971 |
+ for line in fh:
|
|
1972 |
line = line.rstrip()
|
|
1973 |
if not line or line[0] == '#':
|
|
1974 |
continue
|
|
1975 |
count += 1
|
|
1976 |
+ fh.close()
|
|
1977 |
return count
|
|
1978 |
|
|
1979 |
|
|
1980 |
@@ -141,7 +147,7 @@ def main():
|
|
1981 |
f.write(struct.pack('<H', GetCost(prefix, feature)))
|
|
1982 |
f.write(struct.pack('<H', GetCost(suffix, feature)))
|
|
1983 |
|
|
1984 |
- for _ in xrange(num_special_pos):
|
|
1985 |
+ for _ in range(num_special_pos):
|
|
1986 |
f.write(struct.pack('<H', 0))
|
|
1987 |
f.write(struct.pack('<H', 0))
|
|
1988 |
|
|
1989 |
diff --git a/src/converter/gen_quality_regression_test_data.py b/src/converter/gen_quality_regression_test_data.py
|
|
1990 |
index 642d9310..68fa533a 100644
|
|
1991 |
--- a/src/converter/gen_quality_regression_test_data.py
|
|
1992 |
+++ b/src/converter/gen_quality_regression_test_data.py
|
|
1993 |
@@ -84,7 +84,7 @@ def ParseXML(file):
|
|
1994 |
else _ENABLED)
|
|
1995 |
id = issue.attributes['id'].value
|
|
1996 |
target = GetText(issue.getElementsByTagName('target'))
|
|
1997 |
- for detail in issue.getElementsByTagName(u'detail'):
|
|
1998 |
+ for detail in issue.getElementsByTagName('detail'):
|
|
1999 |
fields = []
|
|
2000 |
fields.append('mozcsu_%s' % id)
|
|
2001 |
for key in ('reading', 'output', 'actionStatus', 'rank', 'accuracy'):
|
|
2002 |
@@ -104,19 +104,19 @@ def ParseFile(file):
|
|
2003 |
|
|
2004 |
def GenerateHeader(files):
|
|
2005 |
try:
|
|
2006 |
- print 'namespace mozc{'
|
|
2007 |
- print 'struct TestCase {'
|
|
2008 |
- print ' const bool enabled;'
|
|
2009 |
- print ' const char *tsv;'
|
|
2010 |
- print '} kTestData[] = {'
|
|
2011 |
+ print('namespace mozc{')
|
|
2012 |
+ print('struct TestCase {')
|
|
2013 |
+ print(' const bool enabled;')
|
|
2014 |
+ print(' const char *tsv;')
|
|
2015 |
+ print('} kTestData[] = {')
|
|
2016 |
for file in files:
|
|
2017 |
for enabled, line in ParseFile(file):
|
|
2018 |
- print ' {%s, "%s"},' % (enabled, EscapeString(line))
|
|
2019 |
- print ' {false, nullptr},'
|
|
2020 |
- print '};'
|
|
2021 |
- print '} // namespace mozc'
|
|
2022 |
+ print(' {%s, "%s"},' % (enabled, EscapeString(line)))
|
|
2023 |
+ print(' {false, nullptr},')
|
|
2024 |
+ print('};')
|
|
2025 |
+ print('} // namespace mozc')
|
|
2026 |
except:
|
|
2027 |
- print 'cannot open %s' % (file)
|
|
2028 |
+ print('cannot open %s' % (file))
|
|
2029 |
sys.exit(1)
|
|
2030 |
|
|
2031 |
|
|
2032 |
diff --git a/src/converter/gen_segmenter_code.py b/src/converter/gen_segmenter_code.py
|
|
2033 |
index 9d1e8edf..67f48f91 100644
|
|
2034 |
--- a/src/converter/gen_segmenter_code.py
|
|
2035 |
+++ b/src/converter/gen_segmenter_code.py
|
|
2036 |
@@ -54,18 +54,22 @@ def ReadPOSID(id_file, special_pos_file):
|
|
2037 |
pos = {}
|
|
2038 |
max_id = 0
|
|
2039 |
|
|
2040 |
- for line in open(id_file, "r"):
|
|
2041 |
+ fh = open(id_file, "r")
|
|
2042 |
+ for line in fh:
|
|
2043 |
fields = line.split()
|
|
2044 |
pos[fields[1]] = fields[0]
|
|
2045 |
max_id = max(int(fields[0]), max_id)
|
|
2046 |
+ fh.close()
|
|
2047 |
|
|
2048 |
max_id = max_id + 1
|
|
2049 |
- for line in open(special_pos_file, "r"):
|
|
2050 |
+ fh = open(special_pos_file, "r")
|
|
2051 |
+ for line in fh:
|
|
2052 |
if len(line) <= 1 or line[0] == '#':
|
|
2053 |
continue
|
|
2054 |
fields = line.split()
|
|
2055 |
pos[fields[0]] = ("%d" % max_id)
|
|
2056 |
max_id = max_id + 1
|
|
2057 |
+ fh.close()
|
|
2058 |
|
|
2059 |
return pos
|
|
2060 |
|
|
2061 |
@@ -79,8 +83,7 @@ def GetRange(pos, pattern, name):
|
|
2062 |
pat = re.compile(PatternToRegexp(pattern))
|
|
2063 |
min = -1;
|
|
2064 |
max = -1;
|
|
2065 |
- keys = pos.keys()
|
|
2066 |
- keys.sort()
|
|
2067 |
+ keys = sorted(pos.keys())
|
|
2068 |
|
|
2069 |
range = []
|
|
2070 |
|
|
2071 |
@@ -107,7 +110,7 @@ def GetRange(pos, pattern, name):
|
|
2072 |
tmp.append("(%s >= %s && %s <= %s)" % (name, r[0], name, r[1]))
|
|
2073 |
|
|
2074 |
if len(tmp) == 0:
|
|
2075 |
- print "FATAL: No rule fiind %s" % (pattern)
|
|
2076 |
+ print("FATAL: No rule fiind %s" % (pattern))
|
|
2077 |
sys.exit(-1)
|
|
2078 |
|
|
2079 |
return " || ".join(tmp)
|
|
2080 |
@@ -115,19 +118,21 @@ def GetRange(pos, pattern, name):
|
|
2081 |
def main():
|
|
2082 |
pos = ReadPOSID(sys.argv[1], sys.argv[2])
|
|
2083 |
|
|
2084 |
- print HEADER % (len(pos.keys()), len(pos.keys()))
|
|
2085 |
+ print(HEADER % (len(pos.keys()), len(pos.keys())))
|
|
2086 |
|
|
2087 |
- for line in open(sys.argv[3], "r"):
|
|
2088 |
+ fh = open(sys.argv[3], "r")
|
|
2089 |
+ for line in fh:
|
|
2090 |
if len(line) <= 1 or line[0] == '#':
|
|
2091 |
continue
|
|
2092 |
(l, r, result) = line.split()
|
|
2093 |
result = result.lower()
|
|
2094 |
lcond = GetRange(pos, l, "rid") or "true";
|
|
2095 |
rcond = GetRange(pos, r, "lid") or "true";
|
|
2096 |
- print " // %s %s %s" % (l, r, result)
|
|
2097 |
- print " if ((%s) && (%s)) { return %s; }" % (lcond, rcond, result)
|
|
2098 |
+ print(" // %s %s %s" % (l, r, result))
|
|
2099 |
+ print(" if ((%s) && (%s)) { return %s; }" % (lcond, rcond, result))
|
|
2100 |
+ fh.close()
|
|
2101 |
|
|
2102 |
- print FOOTER
|
|
2103 |
+ print(FOOTER)
|
|
2104 |
|
|
2105 |
if __name__ == "__main__":
|
|
2106 |
main()
|
|
2107 |
diff --git a/src/data/test/calculator/gen_test.py b/src/data/test/calculator/gen_test.py
|
|
2108 |
index 863630e2..ce8e729a 100644
|
|
2109 |
--- a/src/data/test/calculator/gen_test.py
|
|
2110 |
+++ b/src/data/test/calculator/gen_test.py
|
|
2111 |
@@ -105,7 +105,6 @@
|
|
2112 |
# current script puts parentheses as carefully and safely as possible. If
|
|
2113 |
# such a case happens, it's really tough to track bugs...
|
|
2114 |
|
|
2115 |
-import codecs
|
|
2116 |
import logging
|
|
2117 |
import math
|
|
2118 |
import optparse
|
|
2119 |
@@ -636,24 +635,24 @@ class TestCaseGenerator(object):
|
|
2120 |
"""
|
|
2121 |
|
|
2122 |
# Character map used to generate test expression including Japanese.
|
|
2123 |
- _EQUIVALENT_CHARS = {'+': ['+', u'+'],
|
|
2124 |
- '-': ['-', u'−', u'ー'],
|
|
2125 |
- '*': ['*', u'*'],
|
|
2126 |
- '/': ['/', u'/', u'・'],
|
|
2127 |
+ _EQUIVALENT_CHARS = {'+': ['+', '+'],
|
|
2128 |
+ '-': ['-', '−', 'ー'],
|
|
2129 |
+ '*': ['*', '*'],
|
|
2130 |
+ '/': ['/', '/', '・'],
|
|
2131 |
'^': ['^'],
|
|
2132 |
- '%': ['%', u'%'],
|
|
2133 |
- '(': ['(', u'('],
|
|
2134 |
- ')': [')', u')'],
|
|
2135 |
- '0': ['0', u'0'],
|
|
2136 |
- '1': ['1', u'1'],
|
|
2137 |
- '2': ['2', u'2'],
|
|
2138 |
- '3': ['3', u'3'],
|
|
2139 |
- '4': ['4', u'4'],
|
|
2140 |
- '5': ['5', u'5'],
|
|
2141 |
- '6': ['6', u'6'],
|
|
2142 |
- '7': ['7', u'7'],
|
|
2143 |
- '8': ['8', u'8'],
|
|
2144 |
- '9': ['9', u'9']}
|
|
2145 |
+ '%': ['%', '%'],
|
|
2146 |
+ '(': ['(', '('],
|
|
2147 |
+ ')': [')', ')'],
|
|
2148 |
+ '0': ['0', '0'],
|
|
2149 |
+ '1': ['1', '1'],
|
|
2150 |
+ '2': ['2', '2'],
|
|
2151 |
+ '3': ['3', '3'],
|
|
2152 |
+ '4': ['4', '4'],
|
|
2153 |
+ '5': ['5', '5'],
|
|
2154 |
+ '6': ['6', '6'],
|
|
2155 |
+ '7': ['7', '7'],
|
|
2156 |
+ '8': ['8', '8'],
|
|
2157 |
+ '9': ['9', '9']}
|
|
2158 |
|
|
2159 |
def __init__(self, test_filename, py_filename = '', cc_filename = ''):
|
|
2160 |
"""
|
|
2161 |
@@ -666,7 +665,7 @@ class TestCaseGenerator(object):
|
|
2162 |
# Initialize output file
|
|
2163 |
self._test_filename = test_filename
|
|
2164 |
if test_filename:
|
|
2165 |
- self._test_file = codecs.getwriter('utf-8')(open(test_filename, 'wb'))
|
|
2166 |
+ self._test_file = open(test_filename, 'w', encoding='utf-8')
|
|
2167 |
else:
|
|
2168 |
# Replace the generating function by a dummy
|
|
2169 |
self.add_test_case_for = lambda expr: None
|
|
2170 |
@@ -674,7 +673,7 @@ class TestCaseGenerator(object):
|
|
2171 |
|
|
2172 |
# Initialize python code
|
|
2173 |
if py_filename:
|
|
2174 |
- self._py_file = codecs.getwriter('utf-8')(open(py_filename, 'wb'))
|
|
2175 |
+ self._py_file = open(py_filename, 'w', encoding='utf-8')
|
|
2176 |
self._py_file.write('import math\n\n')
|
|
2177 |
else:
|
|
2178 |
self._add_py_code_for = lambda py_expr, expected: None
|
|
2179 |
@@ -682,7 +681,7 @@ class TestCaseGenerator(object):
|
|
2180 |
|
|
2181 |
# Initialize cc code
|
|
2182 |
if cc_filename:
|
|
2183 |
- self._cc_file = codecs.getwriter('utf-8')(open(cc_filename, 'wb'))
|
|
2184 |
+ self._cc_file = open(cc_filename, 'w', encoding='utf-8')
|
|
2185 |
self._cc_file.write('// Automatically generated by '
|
|
2186 |
'mozc/src/data/test/calculator/gen_test.py\n\n'
|
|
2187 |
'#include <cmath>\n'
|
|
2188 |
@@ -716,7 +715,7 @@ class TestCaseGenerator(object):
|
|
2189 |
@staticmethod
|
|
2190 |
def _mix_japanese_string(string):
|
|
2191 |
"""Randomly transforms half-width characters to full-width."""
|
|
2192 |
- result = u''
|
|
2193 |
+ result = ''
|
|
2194 |
for char in string:
|
|
2195 |
if char in TestCaseGenerator._EQUIVALENT_CHARS:
|
|
2196 |
equiv_chars = TestCaseGenerator._EQUIVALENT_CHARS[char]
|
|
2197 |
@@ -727,7 +726,7 @@ class TestCaseGenerator(object):
|
|
2198 |
|
|
2199 |
def add_test_case_for(self, expr):
|
|
2200 |
"""Appends the code that checks whether the evaluation result of given
|
|
2201 |
- expr coincides with the epxected result.
|
|
2202 |
+ expr coincides with the expected result.
|
|
2203 |
|
|
2204 |
Args:
|
|
2205 |
expr: Expr object
|
|
2206 |
@@ -749,24 +748,24 @@ class TestCaseGenerator(object):
|
|
2207 |
raise FatalError('Expression tree evaluation error')
|
|
2208 |
|
|
2209 |
self._num_computable_cases += 1
|
|
2210 |
- self._test_file.write(u'%s=%.8g\n' % (test_expr, value))
|
|
2211 |
+ self._test_file.write('%s=%.8g\n' % (test_expr, value))
|
|
2212 |
self._add_py_code_for(py_expr, value)
|
|
2213 |
self._add_cc_code_for(expr.build_cc_expr(), value)
|
|
2214 |
except EvalError:
|
|
2215 |
- self._test_file.write(u'%s=\n' % test_expr)
|
|
2216 |
+ self._test_file.write('%s=\n' % test_expr)
|
|
2217 |
self._add_cc_code_for(expr.build_cc_expr(), None)
|
|
2218 |
|
|
2219 |
self._num_total_cases += 1
|
|
2220 |
|
|
2221 |
def _add_py_code_for(self, py_expr, expected):
|
|
2222 |
"""Appends python code that checks whether the evaluation result of given
|
|
2223 |
- expr coincides with the epxected result.
|
|
2224 |
+ expr coincides with the expected result.
|
|
2225 |
|
|
2226 |
If expected is None, it indicates that the evaluation of expr results in
|
|
2227 |
error (like overflow and division-by-zero). Currently, just generates
|
|
2228 |
comments for such cases.
|
|
2229 |
|
|
2230 |
- In generated scrpt, the accuracy is verified either in absolute error or
|
|
2231 |
+ In generated script, the accuracy is verified either in absolute error or
|
|
2232 |
relative error, because there's a possibility that different machines
|
|
2233 |
generate different values due to precision. For example, if the expected
|
|
2234 |
value is very large, we cannot expect that error is less than a certain
|
|
2235 |
@@ -777,21 +776,21 @@ class TestCaseGenerator(object):
|
|
2236 |
expected: expected value of the expression (float)
|
|
2237 |
"""
|
|
2238 |
if expected:
|
|
2239 |
- self._py_file.write('expr = u"%s"\n' % py_expr)
|
|
2240 |
+ self._py_file.write('expr = "%s"\n' % py_expr)
|
|
2241 |
self._py_file.write('expected = %s\n' % repr(expected))
|
|
2242 |
self._py_file.write('val = eval(expr)\n')
|
|
2243 |
self._py_file.write('err = abs(val - expected)\n')
|
|
2244 |
self._py_file.write('if (err > 1e-8 and\n')
|
|
2245 |
self._py_file.write(' err > 1e-2 * abs(expected)):\n')
|
|
2246 |
- self._py_file.write(' print repr(val), "!=", repr(expected)\n')
|
|
2247 |
- self._py_file.write(' print "expr =", expr\n\n')
|
|
2248 |
+ self._py_file.write(' print("%r != %r" % (val, expected))\n')
|
|
2249 |
+ self._py_file.write(' print("expr = %s" % expr)\n\n')
|
|
2250 |
else:
|
|
2251 |
self._py_file.write('# Incomputable\n'
|
|
2252 |
'# %s\n\n' % py_expr)
|
|
2253 |
|
|
2254 |
def _add_cc_code_for(self, cc_expr, expected):
|
|
2255 |
"""Appends the code that checks whether the evaluation result of given
|
|
2256 |
- expr coincides with the epxected result.
|
|
2257 |
+ expr coincides with the expected result.
|
|
2258 |
|
|
2259 |
If expected is None, it indicates that the evaluation of expr results in
|
|
2260 |
error (like overflow and division-by-zero). Currently, just generates
|
|
2261 |
@@ -851,9 +850,6 @@ def parse_options():
|
|
2262 |
|
|
2263 |
|
|
2264 |
def main():
|
|
2265 |
- sys.stdin = codecs.getreader('utf-8')(sys.stdin)
|
|
2266 |
- sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
|
|
2267 |
- sys.stderr = codecs.getwriter('utf-8')(sys.stderr)
|
|
2268 |
random.seed()
|
|
2269 |
logging.basicConfig(level = logging.INFO,
|
|
2270 |
format = '%(levelname)s: %(message)s')
|
|
2271 |
diff --git a/src/data_manager/gen_connection_data.py b/src/data_manager/gen_connection_data.py
|
|
2272 |
index c3fb0952..4f9282b2 100644
|
|
2273 |
--- a/src/data_manager/gen_connection_data.py
|
|
2274 |
+++ b/src/data_manager/gen_connection_data.py
|
|
2275 |
@@ -32,8 +32,7 @@
|
|
2276 |
|
|
2277 |
__author__ = "hidehiko"
|
|
2278 |
|
|
2279 |
-import cStringIO as StringIO
|
|
2280 |
-import itertools
|
|
2281 |
+import io
|
|
2282 |
import logging
|
|
2283 |
import optparse
|
|
2284 |
import os
|
|
2285 |
@@ -45,7 +44,7 @@ from build_tools import code_generator_util
|
|
2286 |
INVALID_COST = 30000
|
|
2287 |
INVALID_1BYTE_COST = 255
|
|
2288 |
RESOLUTION_FOR_1BYTE = 64
|
|
2289 |
-FILE_MAGIC = '\xAB\xCD'
|
|
2290 |
+FILE_MAGIC = b'\xAB\xCD'
|
|
2291 |
|
|
2292 |
FALSE_VALUES = ['f', 'false', '0']
|
|
2293 |
TRUE_VALUES = ['t', 'true', '1']
|
|
2294 |
@@ -79,28 +78,28 @@ def ParseConnectionFile(text_connection_file, pos_size, special_pos_size):
|
|
2295 |
# The result is a square matrix.
|
|
2296 |
mat_size = pos_size + special_pos_size
|
|
2297 |
|
|
2298 |
- matrix = [[0] * mat_size for _ in xrange(mat_size)]
|
|
2299 |
+ matrix = [[0] * mat_size for _ in range(mat_size)]
|
|
2300 |
with open(text_connection_file) as stream:
|
|
2301 |
stream = code_generator_util.SkipLineComment(stream)
|
|
2302 |
# The first line contains the matrix column/row size.
|
|
2303 |
- size = stream.next().rstrip()
|
|
2304 |
+ size = next(stream).rstrip()
|
|
2305 |
assert (int(size) == pos_size), '%s != %d' % (size, pos_size)
|
|
2306 |
|
|
2307 |
for array_index, cost in enumerate(stream):
|
|
2308 |
cost = int(cost.rstrip())
|
|
2309 |
- rid = array_index / pos_size
|
|
2310 |
+ rid = array_index // pos_size
|
|
2311 |
lid = array_index % pos_size
|
|
2312 |
if rid == 0 and lid == 0:
|
|
2313 |
cost = 0
|
|
2314 |
matrix[rid][lid] = cost
|
|
2315 |
|
|
2316 |
# Fill INVALID_COST in matrix elements for special POS.
|
|
2317 |
- for rid in xrange(pos_size, mat_size):
|
|
2318 |
- for lid in xrange(1, mat_size): # Skip EOS
|
|
2319 |
+ for rid in range(pos_size, mat_size):
|
|
2320 |
+ for lid in range(1, mat_size): # Skip EOS
|
|
2321 |
matrix[rid][lid] = INVALID_COST
|
|
2322 |
|
|
2323 |
- for lid in xrange(pos_size, mat_size):
|
|
2324 |
- for rid in xrange(1, mat_size): # Skip BOS
|
|
2325 |
+ for lid in range(pos_size, mat_size):
|
|
2326 |
+ for rid in range(1, mat_size): # Skip BOS
|
|
2327 |
matrix[rid][lid] = INVALID_COST
|
|
2328 |
|
|
2329 |
return matrix
|
|
2330 |
@@ -116,7 +115,7 @@ def CreateModeValueList(matrix):
|
|
2331 |
# Heuristically, we do not compress INVALID_COST.
|
|
2332 |
continue
|
|
2333 |
m[cost] = m.get(cost, 0) + 1
|
|
2334 |
- mode_value = max(m.iteritems(), key=lambda (_, count): count)[0]
|
|
2335 |
+ mode_value = max(m.items(), key=lambda x: x[1])[0]
|
|
2336 |
result.append(mode_value)
|
|
2337 |
return result
|
|
2338 |
|
|
2339 |
@@ -126,8 +125,8 @@ def CompressMatrixByModeValue(matrix, mode_value_list):
|
|
2340 |
# list, and fill None into the matrix if it equals to the corresponding
|
|
2341 |
# mode value.
|
|
2342 |
assert len(matrix) == len(mode_value_list)
|
|
2343 |
- for row, mode_value in itertools.izip(matrix, mode_value_list):
|
|
2344 |
- for index in xrange(len(row)):
|
|
2345 |
+ for row, mode_value in zip(matrix, mode_value_list):
|
|
2346 |
+ for index in range(len(row)):
|
|
2347 |
if row[index] == mode_value:
|
|
2348 |
row[index] = None
|
|
2349 |
|
|
2350 |
@@ -179,7 +178,7 @@ def BuildBinaryData(matrix, mode_value_list, use_1byte_cost):
|
|
2351 |
resolution = RESOLUTION_FOR_1BYTE
|
|
2352 |
else:
|
|
2353 |
resolution = 1
|
|
2354 |
- stream = StringIO.StringIO()
|
|
2355 |
+ stream = io.BytesIO()
|
|
2356 |
|
|
2357 |
# Output header.
|
|
2358 |
stream.write(FILE_MAGIC)
|
|
2359 |
@@ -194,7 +193,7 @@ def BuildBinaryData(matrix, mode_value_list, use_1byte_cost):
|
|
2360 |
|
|
2361 |
# 4 bytes alignment.
|
|
2362 |
if len(mode_value_list) % 2:
|
|
2363 |
- stream.write('\x00\x00')
|
|
2364 |
+ stream.write(b'\x00\x00')
|
|
2365 |
|
|
2366 |
# Process each row:
|
|
2367 |
for row in matrix:
|
|
2368 |
@@ -218,7 +217,7 @@ def BuildBinaryData(matrix, mode_value_list, use_1byte_cost):
|
|
2369 |
if cost == INVALID_COST:
|
|
2370 |
cost = INVALID_1BYTE_COST
|
|
2371 |
else:
|
|
2372 |
- cost /= resolution
|
|
2373 |
+ cost //= resolution
|
|
2374 |
assert cost != INVALID_1BYTE_COST
|
|
2375 |
values.append(cost)
|
|
2376 |
|
|
2377 |
@@ -237,7 +236,7 @@ def BuildBinaryData(matrix, mode_value_list, use_1byte_cost):
|
|
2378 |
values_size = len(values) * 2
|
|
2379 |
|
|
2380 |
# Output the bits for a row.
|
|
2381 |
- stream.write(struct.pack('<HH', len(compact_bits) / 8, values_size))
|
|
2382 |
+ stream.write(struct.pack('<HH', len(compact_bits) // 8, values_size))
|
|
2383 |
OutputBitList(chunk_bits, stream)
|
|
2384 |
OutputBitList(compact_bits, stream)
|
|
2385 |
if use_1byte_cost:
|
|
2386 |
diff --git a/src/dictionary/gen_pos_map.py b/src/dictionary/gen_pos_map.py
|
|
2387 |
index 443e006e..88bee592 100644
|
|
2388 |
--- a/src/dictionary/gen_pos_map.py
|
|
2389 |
+++ b/src/dictionary/gen_pos_map.py
|
|
2390 |
@@ -39,7 +39,7 @@ import sys
|
|
2391 |
from build_tools import code_generator_util
|
|
2392 |
|
|
2393 |
|
|
2394 |
-HEADER = """// Copyright 2009 Google Inc. All Rights Reserved.
|
|
2395 |
+HEADER = b"""// Copyright 2009 Google Inc. All Rights Reserved.
|
|
2396 |
// Author: keni
|
|
2397 |
|
|
2398 |
#ifndef MOZC_DICTIONARY_POS_MAP_H_
|
|
2399 |
@@ -48,13 +48,13 @@ HEADER = """// Copyright 2009 Google Inc. All Rights Reserved.
|
|
2400 |
// POS conversion rules
|
|
2401 |
const POSMap kPOSMap[] = {
|
|
2402 |
"""
|
|
2403 |
-FOOTER = """};
|
|
2404 |
+FOOTER = b"""};
|
|
2405 |
|
|
2406 |
#endif // MOZC_DICTIONARY_POS_MAP_H_
|
|
2407 |
"""
|
|
2408 |
|
|
2409 |
def ParseUserPos(user_pos_file):
|
|
2410 |
- with open(user_pos_file, 'r') as stream:
|
|
2411 |
+ with open(user_pos_file, 'rb') as stream:
|
|
2412 |
stream = code_generator_util.SkipLineComment(stream)
|
|
2413 |
stream = code_generator_util.ParseColumnStream(stream, num_column=2)
|
|
2414 |
return dict((key, enum_value) for key, enum_value in stream)
|
|
2415 |
@@ -64,7 +64,7 @@ def GeneratePosMap(third_party_pos_map_file, user_pos_file):
|
|
2416 |
user_pos_map = ParseUserPos(user_pos_file)
|
|
2417 |
|
|
2418 |
result = {}
|
|
2419 |
- with open(third_party_pos_map_file, 'r') as stream:
|
|
2420 |
+ with open(third_party_pos_map_file, 'rb') as stream:
|
|
2421 |
stream = code_generator_util.SkipLineComment(stream)
|
|
2422 |
for columns in code_generator_util.ParseColumnStream(stream, num_column=2):
|
|
2423 |
third_party_pos_name, mozc_pos = (columns + [None])[:2]
|
|
2424 |
@@ -78,7 +78,7 @@ def GeneratePosMap(third_party_pos_map_file, user_pos_file):
|
|
2425 |
result[third_party_pos_name] = mozc_pos
|
|
2426 |
|
|
2427 |
# Create mozc_pos to mozc_pos map.
|
|
2428 |
- for key, value in user_pos_map.iteritems():
|
|
2429 |
+ for key, value in user_pos_map.items():
|
|
2430 |
if key in result:
|
|
2431 |
assert (result[key] == value)
|
|
2432 |
continue
|
|
2433 |
@@ -94,10 +94,10 @@ def OutputPosMap(pos_map, output):
|
|
2434 |
if value is None:
|
|
2435 |
# Invalid PosType.
|
|
2436 |
value = (
|
|
2437 |
- 'static_cast< ::mozc::user_dictionary::UserDictionary::PosType>(-1)')
|
|
2438 |
+ b'static_cast< ::mozc::user_dictionary::UserDictionary::PosType>(-1)')
|
|
2439 |
else:
|
|
2440 |
- value = '::mozc::user_dictionary::UserDictionary::' + value
|
|
2441 |
- output.write(' { %s, %s },\n' % (key, value))
|
|
2442 |
+ value = b'::mozc::user_dictionary::UserDictionary::' + value
|
|
2443 |
+ output.write(b' { %s, %s },\n' % (key, value))
|
|
2444 |
output.write(FOOTER)
|
|
2445 |
|
|
2446 |
|
|
2447 |
@@ -121,7 +121,7 @@ def main():
|
|
2448 |
pos_map = GeneratePosMap(options.third_party_pos_map_file,
|
|
2449 |
options.user_pos_file)
|
|
2450 |
|
|
2451 |
- with open(options.output, 'w') as stream:
|
|
2452 |
+ with open(options.output, 'wb') as stream:
|
|
2453 |
OutputPosMap(pos_map, stream)
|
|
2454 |
|
|
2455 |
|
|
2456 |
diff --git a/src/dictionary/gen_pos_rewrite_rule.py b/src/dictionary/gen_pos_rewrite_rule.py
|
|
2457 |
index f8d00198..49b71caa 100644
|
|
2458 |
--- a/src/dictionary/gen_pos_rewrite_rule.py
|
|
2459 |
+++ b/src/dictionary/gen_pos_rewrite_rule.py
|
|
2460 |
@@ -46,29 +46,34 @@ def IsPrefix(str, key):
|
|
2461 |
|
|
2462 |
|
|
2463 |
def LoadRewriteMapRule(filename):
|
|
2464 |
- fh = open(filename)
|
|
2465 |
+ fh = open(filename, 'rb')
|
|
2466 |
rule = []
|
|
2467 |
for line in fh:
|
|
2468 |
- line = line.rstrip('\n')
|
|
2469 |
- if not line or line.startswith('#'):
|
|
2470 |
+ line = line.rstrip(b'\n')
|
|
2471 |
+ if not line or line.startswith(b'#'):
|
|
2472 |
continue
|
|
2473 |
fields = line.split()
|
|
2474 |
rule.append([fields[0], fields[1]])
|
|
2475 |
+ fh.close()
|
|
2476 |
return rule
|
|
2477 |
|
|
2478 |
|
|
2479 |
def ReadPOSID(id_file, special_pos_file):
|
|
2480 |
pos_list = []
|
|
2481 |
|
|
2482 |
- for line in open(id_file, 'r'):
|
|
2483 |
+ fh = open(id_file, 'rb')
|
|
2484 |
+ for line in fh:
|
|
2485 |
fields = line.split()
|
|
2486 |
pos_list.append(fields[1])
|
|
2487 |
+ fh.close()
|
|
2488 |
|
|
2489 |
- for line in open(special_pos_file, 'r'):
|
|
2490 |
- if len(line) <= 1 or line[0] == '#':
|
|
2491 |
+ fh = open(special_pos_file, 'rb')
|
|
2492 |
+ for line in fh:
|
|
2493 |
+ if len(line) <= 1 or line[0:1] == b'#':
|
|
2494 |
continue
|
|
2495 |
fields = line.split()
|
|
2496 |
pos_list.append(fields[0])
|
|
2497 |
+ fh.close()
|
|
2498 |
|
|
2499 |
return pos_list
|
|
2500 |
|
|
2501 |
@@ -112,7 +117,7 @@ def main():
|
|
2502 |
ids.append(id)
|
|
2503 |
|
|
2504 |
with open(opts.output, 'wb') as f:
|
|
2505 |
- f.write(''.join(chr(id) for id in ids))
|
|
2506 |
+ f.write(''.join(chr(id) for id in ids).encode('utf-8'))
|
|
2507 |
|
|
2508 |
|
|
2509 |
if __name__ == '__main__':
|
|
2510 |
diff --git a/src/dictionary/gen_suffix_data.py b/src/dictionary/gen_suffix_data.py
|
|
2511 |
index 0dc0b011..4facb615 100644
|
|
2512 |
--- a/src/dictionary/gen_suffix_data.py
|
|
2513 |
+++ b/src/dictionary/gen_suffix_data.py
|
|
2514 |
@@ -52,10 +52,10 @@ def main():
|
|
2515 |
opts = _ParseOptions()
|
|
2516 |
|
|
2517 |
result = []
|
|
2518 |
- with open(opts.input, 'r') as stream:
|
|
2519 |
+ with open(opts.input, 'rb') as stream:
|
|
2520 |
for line in stream:
|
|
2521 |
- line = line.rstrip('\r\n')
|
|
2522 |
- fields = line.split('\t')
|
|
2523 |
+ line = line.rstrip(b'\r\n')
|
|
2524 |
+ fields = line.split(b'\t')
|
|
2525 |
key = fields[0]
|
|
2526 |
lid = int(fields[1])
|
|
2527 |
rid = int(fields[2])
|
|
2528 |
@@ -63,7 +63,7 @@ def main():
|
|
2529 |
value = fields[4]
|
|
2530 |
|
|
2531 |
if key == value:
|
|
2532 |
- value = ''
|
|
2533 |
+ value = b''
|
|
2534 |
|
|
2535 |
result.append((key, value, lid, rid, cost))
|
|
2536 |
|
|
2537 |
diff --git a/src/dictionary/gen_user_pos_data.py b/src/dictionary/gen_user_pos_data.py
|
|
2538 |
index 58c83c42..0c1d9c3d 100644
|
|
2539 |
--- a/src/dictionary/gen_user_pos_data.py
|
|
2540 |
+++ b/src/dictionary/gen_user_pos_data.py
|
|
2541 |
@@ -64,7 +64,7 @@ def OutputUserPosData(user_pos_data, output_token_array, output_string_array):
|
|
2542 |
f.write(struct.pack('<H', conjugation_id))
|
|
2543 |
|
|
2544 |
serialized_string_array_builder.SerializeToFile(
|
|
2545 |
- sorted(string_index.iterkeys()), output_string_array)
|
|
2546 |
+ sorted(x.encode('utf-8') for x in string_index.keys()), output_string_array)
|
|
2547 |
|
|
2548 |
|
|
2549 |
def ParseOptions():
|
|
2550 |
@@ -100,7 +100,7 @@ def main():
|
|
2551 |
|
|
2552 |
if options.output_pos_list:
|
|
2553 |
serialized_string_array_builder.SerializeToFile(
|
|
2554 |
- [pos for (pos, _) in user_pos.data], options.output_pos_list)
|
|
2555 |
+ [pos.encode('utf-8') for (pos, _) in user_pos.data], options.output_pos_list)
|
|
2556 |
|
|
2557 |
|
|
2558 |
if __name__ == '__main__':
|
|
2559 |
diff --git a/src/dictionary/gen_zip_code_seed.py b/src/dictionary/gen_zip_code_seed.py
|
|
2560 |
index 0265d318..e5818e38 100644
|
|
2561 |
--- a/src/dictionary/gen_zip_code_seed.py
|
|
2562 |
+++ b/src/dictionary/gen_zip_code_seed.py
|
|
2563 |
@@ -83,7 +83,7 @@ class ZipEntry(object):
|
|
2564 |
address = unicodedata.normalize('NFKC', self.address)
|
|
2565 |
line = '\t'.join([zip_code, '0', '0', str(ZIP_CODE_COST),
|
|
2566 |
address, ZIP_CODE_LABEL])
|
|
2567 |
- print line.encode('utf-8')
|
|
2568 |
+ print(line.encode('utf-8'))
|
|
2569 |
|
|
2570 |
|
|
2571 |
def ProcessZipCodeCSV(file_name):
|
|
2572 |
@@ -105,26 +105,26 @@ def ProcessJigyosyoCSV(file_name):
|
|
2573 |
|
|
2574 |
def ReadZipCodeEntries(zip_code, level1, level2, level3):
|
|
2575 |
"""Read zip code entries."""
|
|
2576 |
- return [ZipEntry(zip_code, u''.join([level1, level2, town]))
|
|
2577 |
+ return [ZipEntry(zip_code, ''.join([level1, level2, town]))
|
|
2578 |
for town in ParseTownName(level3)]
|
|
2579 |
|
|
2580 |
|
|
2581 |
def ReadJigyosyoEntry(zip_code, level1, level2, level3, name):
|
|
2582 |
"""Read jigyosyo entry."""
|
|
2583 |
return ZipEntry(zip_code,
|
|
2584 |
- u''.join([level1, level2, level3, u' ', name]))
|
|
2585 |
+ ''.join([level1, level2, level3, ' ', name]))
|
|
2586 |
|
|
2587 |
|
|
2588 |
def ParseTownName(level3):
|
|
2589 |
"""Parse town name."""
|
|
2590 |
- if level3.find(u'以下に掲載がない場合') != -1:
|
|
2591 |
+ if level3.find('以下に掲載がない場合') != -1:
|
|
2592 |
return ['']
|
|
2593 |
|
|
2594 |
assert CanParseAddress(level3), ('failed to be merged %s'
|
|
2595 |
% level3.encode('utf-8'))
|
|
2596 |
|
|
2597 |
# We ignore additional information here.
|
|
2598 |
- level3 = re.sub(u'(.*)', u'', level3, re.U)
|
|
2599 |
+ level3 = re.sub('(.*)', '', level3, re.U)
|
|
2600 |
|
|
2601 |
# For 地割, we have these cases.
|
|
2602 |
# XX1地割
|
|
2603 |
@@ -134,7 +134,7 @@ def ParseTownName(level3):
|
|
2604 |
# XX第1地割、XX第2地割、
|
|
2605 |
# XX第1地割〜XX第2地割、
|
|
2606 |
# We simply use XX for them.
|
|
2607 |
- chiwari_match = re.match(u'(\D*?)第?\d+地割.*', level3, re.U)
|
|
2608 |
+ chiwari_match = re.match('(\D*?)第?\d+地割.*', level3, re.U)
|
|
2609 |
if chiwari_match:
|
|
2610 |
town = chiwari_match.group(1)
|
|
2611 |
return [town]
|
|
2612 |
@@ -144,21 +144,21 @@ def ParseTownName(level3):
|
|
2613 |
# -> XX町YY and (XX町)ZZ
|
|
2614 |
# YY、ZZ
|
|
2615 |
# -> YY and ZZ
|
|
2616 |
- chou_match = re.match(u'(.*町)?(.*)', level3, re.U)
|
|
2617 |
+ chou_match = re.match('(.*町)?(.*)', level3, re.U)
|
|
2618 |
if chou_match:
|
|
2619 |
- chou = u''
|
|
2620 |
+ chou = ''
|
|
2621 |
if chou_match.group(1):
|
|
2622 |
chou = chou_match.group(1)
|
|
2623 |
rests = chou_match.group(2)
|
|
2624 |
- return [chou + rest for rest in rests.split(u'、')]
|
|
2625 |
+ return [chou + rest for rest in rests.split('、')]
|
|
2626 |
|
|
2627 |
return [level3]
|
|
2628 |
|
|
2629 |
|
|
2630 |
def CanParseAddress(address):
|
|
2631 |
"""Return true for valid address."""
|
|
2632 |
- return (address.find(u'(') == -1 or
|
|
2633 |
- address.find(u')') != -1)
|
|
2634 |
+ return (address.find('(') == -1 or
|
|
2635 |
+ address.find(')') != -1)
|
|
2636 |
|
|
2637 |
|
|
2638 |
def ParseOptions():
|
|
2639 |
diff --git a/src/dictionary/zip_code_util.py b/src/dictionary/zip_code_util.py
|
|
2640 |
index de6e084f..32ae7526 100644
|
|
2641 |
--- a/src/dictionary/zip_code_util.py
|
|
2642 |
+++ b/src/dictionary/zip_code_util.py
|
|
2643 |
@@ -86,11 +86,11 @@ class SpecialMergeZip(object):
|
|
2644 |
|
|
2645 |
|
|
2646 |
_SPECIAL_CASES = [
|
|
2647 |
- SpecialMergeZip(u'5900111', u'大阪府', u'堺市中区', [u'三原台']),
|
|
2648 |
- SpecialMergeZip(u'8710046', u'大分県', u'中津市',
|
|
2649 |
- [u'金谷', u'西堀端', u'東堀端', u'古金谷']),
|
|
2650 |
- SpecialMergeZip(u'9218046', u'石川県', u'金沢市',
|
|
2651 |
- [u'大桑町', u'三小牛町']),
|
|
2652 |
+ SpecialMergeZip('5900111', '大阪府', '堺市中区', ['三原台']),
|
|
2653 |
+ SpecialMergeZip('8710046', '大分県', '中津市',
|
|
2654 |
+ ['金谷', '西堀端', '東堀端', '古金谷']),
|
|
2655 |
+ SpecialMergeZip('9218046', '石川県', '金沢市',
|
|
2656 |
+ ['大桑町', '三小牛町']),
|
|
2657 |
]
|
|
2658 |
|
|
2659 |
|
|
2660 |
diff --git a/src/gui/character_pad/data/gen_cp932_map.py b/src/gui/character_pad/data/gen_cp932_map.py
|
|
2661 |
index 8f8b05a5..b7365d25 100644
|
|
2662 |
--- a/src/gui/character_pad/data/gen_cp932_map.py
|
|
2663 |
+++ b/src/gui/character_pad/data/gen_cp932_map.py
|
|
2664 |
@@ -32,7 +32,6 @@ __author__ = "taku"
|
|
2665 |
|
|
2666 |
import re
|
|
2667 |
import sys
|
|
2668 |
-import string
|
|
2669 |
|
|
2670 |
kUnicodePat = re.compile(r'0x[0-9A-Fa-f]{2,4}')
|
|
2671 |
def IsValidUnicode(n):
|
|
2672 |
@@ -42,28 +41,29 @@ def main():
|
|
2673 |
fh = open(sys.argv[1])
|
|
2674 |
result = {}
|
|
2675 |
for line in fh.readlines():
|
|
2676 |
- if line[0] is '#':
|
|
2677 |
+ if line[0] == '#':
|
|
2678 |
continue
|
|
2679 |
- array = string.split(line)
|
|
2680 |
+ array = line.split()
|
|
2681 |
sjis = array[0]
|
|
2682 |
ucs2 = array[1]
|
|
2683 |
if eval(sjis) < 32 or not IsValidUnicode(ucs2):
|
|
2684 |
continue
|
|
2685 |
result.setdefault(ucs2, sjis)
|
|
2686 |
+ fh.close()
|
|
2687 |
|
|
2688 |
keys = sorted(result.keys())
|
|
2689 |
|
|
2690 |
- print "struct CP932MapData {"
|
|
2691 |
- print " unsigned int ucs4;"
|
|
2692 |
- print " unsigned short int sjis;"
|
|
2693 |
- print "};"
|
|
2694 |
- print ""
|
|
2695 |
- print "static const size_t kCP932MapDataSize = %d;" % (len(keys))
|
|
2696 |
- print "static const CP932MapData kCP932MapData[] = {"
|
|
2697 |
+ print("struct CP932MapData {")
|
|
2698 |
+ print(" unsigned int ucs4;")
|
|
2699 |
+ print(" unsigned short int sjis;")
|
|
2700 |
+ print("};")
|
|
2701 |
+ print("")
|
|
2702 |
+ print("static const size_t kCP932MapDataSize = %d;" % (len(keys)))
|
|
2703 |
+ print("static const CP932MapData kCP932MapData[] = {")
|
|
2704 |
for n in keys:
|
|
2705 |
- print " { %s, %s }," % (n ,result[n])
|
|
2706 |
- print " { 0, 0 }";
|
|
2707 |
- print "};"
|
|
2708 |
+ print(" { %s, %s }," % (n ,result[n]))
|
|
2709 |
+ print(" { 0, 0 }");
|
|
2710 |
+ print("};")
|
|
2711 |
|
|
2712 |
if __name__ == "__main__":
|
|
2713 |
main()
|
|
2714 |
diff --git a/src/gui/character_pad/data/gen_local_character_map.py b/src/gui/character_pad/data/gen_local_character_map.py
|
|
2715 |
index 3e550575..3e30bd99 100644
|
|
2716 |
--- a/src/gui/character_pad/data/gen_local_character_map.py
|
|
2717 |
+++ b/src/gui/character_pad/data/gen_local_character_map.py
|
|
2718 |
@@ -30,7 +30,6 @@
|
|
2719 |
|
|
2720 |
__author__ = "taku"
|
|
2721 |
|
|
2722 |
-import string
|
|
2723 |
import re
|
|
2724 |
import sys
|
|
2725 |
|
|
2726 |
@@ -43,9 +42,9 @@ def LoadJISX0201(filename):
|
|
2727 |
fh = open(filename)
|
|
2728 |
result = []
|
|
2729 |
for line in fh.readlines():
|
|
2730 |
- if line[0] is '#':
|
|
2731 |
+ if line[0] == '#':
|
|
2732 |
continue
|
|
2733 |
- array = string.split(line)
|
|
2734 |
+ array = line.split()
|
|
2735 |
jis = array[0].replace('0x', '')
|
|
2736 |
ucs2 = array[1].replace('0x', '')
|
|
2737 |
if len(jis) == 2:
|
|
2738 |
@@ -53,6 +52,7 @@ def LoadJISX0201(filename):
|
|
2739 |
|
|
2740 |
if IsValidUnicode(ucs2):
|
|
2741 |
result.append([jis, ucs2])
|
|
2742 |
+ fh.close()
|
|
2743 |
|
|
2744 |
return ["JISX0201", result]
|
|
2745 |
|
|
2746 |
@@ -60,13 +60,14 @@ def LoadJISX0208(filename):
|
|
2747 |
fh = open(filename)
|
|
2748 |
result = []
|
|
2749 |
for line in fh.readlines():
|
|
2750 |
- if line[0] is '#':
|
|
2751 |
+ if line[0] == '#':
|
|
2752 |
continue
|
|
2753 |
array = line.split()
|
|
2754 |
jis = array[1].replace('0x', '')
|
|
2755 |
ucs2 = array[2].replace('0x', '')
|
|
2756 |
if IsValidUnicode(ucs2):
|
|
2757 |
result.append([jis, ucs2])
|
|
2758 |
+ fh.close()
|
|
2759 |
|
|
2760 |
return ["JISX0208", result]
|
|
2761 |
|
|
2762 |
@@ -74,13 +75,14 @@ def LoadJISX0212(filename):
|
|
2763 |
fh = open(filename)
|
|
2764 |
result = []
|
|
2765 |
for line in fh.readlines():
|
|
2766 |
- if line[0] is '#':
|
|
2767 |
+ if line[0] == '#':
|
|
2768 |
continue
|
|
2769 |
array = line.split()
|
|
2770 |
jis = array[0].replace('0x', '')
|
|
2771 |
ucs2 = array[1].replace('0x', '')
|
|
2772 |
if IsValidUnicode(ucs2):
|
|
2773 |
result.append([jis, ucs2])
|
|
2774 |
+ fh.close()
|
|
2775 |
|
|
2776 |
return ["JISX0212", result]
|
|
2777 |
|
|
2778 |
@@ -88,7 +90,7 @@ def LoadCP932(filename):
|
|
2779 |
fh = open(filename)
|
|
2780 |
result = []
|
|
2781 |
for line in fh.readlines():
|
|
2782 |
- if line[0] is '#':
|
|
2783 |
+ if line[0] == '#':
|
|
2784 |
continue
|
|
2785 |
array = line.split()
|
|
2786 |
sjis = array[0].replace('0x', '')
|
|
2787 |
@@ -100,19 +102,20 @@ def LoadCP932(filename):
|
|
2788 |
|
|
2789 |
if IsValidUnicode(ucs2):
|
|
2790 |
result.append([sjis, ucs2])
|
|
2791 |
+ fh.close()
|
|
2792 |
|
|
2793 |
return ["CP932", result]
|
|
2794 |
|
|
2795 |
def Output(arg):
|
|
2796 |
name = arg[0]
|
|
2797 |
result = arg[1]
|
|
2798 |
- print "static const size_t k%sMapSize = %d;" % (name, len(result))
|
|
2799 |
- print "static const mozc::gui::CharacterPalette::LocalCharacterMap k%sMap[] = {" % (name)
|
|
2800 |
+ print("static const size_t k%sMapSize = %d;" % (name, len(result)))
|
|
2801 |
+ print("static const mozc::gui::CharacterPalette::LocalCharacterMap k%sMap[] = {" % (name))
|
|
2802 |
for n in result:
|
|
2803 |
- print " { 0x%s, 0x%s }," % (n[0] ,n[1])
|
|
2804 |
- print " { 0, 0 }";
|
|
2805 |
- print "};"
|
|
2806 |
- print ""
|
|
2807 |
+ print(" { 0x%s, 0x%s }," % (n[0] ,n[1]))
|
|
2808 |
+ print(" { 0, 0 }");
|
|
2809 |
+ print("};")
|
|
2810 |
+ print("")
|
|
2811 |
|
|
2812 |
if __name__ == "__main__":
|
|
2813 |
Output(LoadJISX0201(sys.argv[1]))
|
|
2814 |
diff --git a/src/gui/character_pad/data/gen_unicode_blocks.py b/src/gui/character_pad/data/gen_unicode_blocks.py
|
|
2815 |
index 32cd633a..d9a17995 100644
|
|
2816 |
--- a/src/gui/character_pad/data/gen_unicode_blocks.py
|
|
2817 |
+++ b/src/gui/character_pad/data/gen_unicode_blocks.py
|
|
2818 |
@@ -33,13 +33,13 @@ __author__ = "taku"
|
|
2819 |
import sys
|
|
2820 |
import re
|
|
2821 |
|
|
2822 |
-re = re.compile('^(.....?)\.\.(.....?); (.+)')
|
|
2823 |
+re = re.compile(r'^(.....?)\.\.(.....?); (.+)')
|
|
2824 |
|
|
2825 |
def main():
|
|
2826 |
- print "static const mozc::gui::CharacterPalette::UnicodeBlock kUnicodeBlockTable[] = {"
|
|
2827 |
+ print("static const mozc::gui::CharacterPalette::UnicodeBlock kUnicodeBlockTable[] = {")
|
|
2828 |
fh = open(sys.argv[1])
|
|
2829 |
for line in fh.readlines():
|
|
2830 |
- if line[0] is '#':
|
|
2831 |
+ if line[0] == '#':
|
|
2832 |
continue
|
|
2833 |
m = re.match(line)
|
|
2834 |
if m is not None:
|
|
2835 |
@@ -47,11 +47,12 @@ def main():
|
|
2836 |
end = int(m.group(2), 16)
|
|
2837 |
name = m.group(3)
|
|
2838 |
if start <= 0x2FFFF and end <= 0x2FFFF:
|
|
2839 |
- print " { \"%s\", { %d, %d } }," % (name, start, end)
|
|
2840 |
+ print(" { \"%s\", { %d, %d } }," % (name, start, end))
|
|
2841 |
+ fh.close()
|
|
2842 |
|
|
2843 |
- print " { NULL, { 0, 0 } }"
|
|
2844 |
- print "};"
|
|
2845 |
- print ""
|
|
2846 |
+ print(" { NULL, { 0, 0 } }")
|
|
2847 |
+ print("};")
|
|
2848 |
+ print("")
|
|
2849 |
|
|
2850 |
if __name__ == "__main__":
|
|
2851 |
main()
|
|
2852 |
diff --git a/src/gui/character_pad/data/gen_unicode_data.py b/src/gui/character_pad/data/gen_unicode_data.py
|
|
2853 |
index c5bdbf46..431fd951 100644
|
|
2854 |
--- a/src/gui/character_pad/data/gen_unicode_data.py
|
|
2855 |
+++ b/src/gui/character_pad/data/gen_unicode_data.py
|
|
2856 |
@@ -46,18 +46,19 @@ def main():
|
|
2857 |
code = int(code, 16)
|
|
2858 |
if code < 0x2FFFF:
|
|
2859 |
results.append(" { %d, \"%s\" }," % (code, desc))
|
|
2860 |
+ fh.close()
|
|
2861 |
|
|
2862 |
- print "struct UnicodeData {";
|
|
2863 |
- print " char32 ucs4;";
|
|
2864 |
- print " const char *description;";
|
|
2865 |
- print "};";
|
|
2866 |
- print ""
|
|
2867 |
- print "static const size_t kUnicodeDataSize = %d;" % (len(results))
|
|
2868 |
- print "static const UnicodeData kUnicodeData[] = {";
|
|
2869 |
+ print("struct UnicodeData {");
|
|
2870 |
+ print(" char32 ucs4;");
|
|
2871 |
+ print(" const char *description;");
|
|
2872 |
+ print("};");
|
|
2873 |
+ print("")
|
|
2874 |
+ print("static const size_t kUnicodeDataSize = %d;" % (len(results)))
|
|
2875 |
+ print("static const UnicodeData kUnicodeData[] = {");
|
|
2876 |
for line in results:
|
|
2877 |
- print line;
|
|
2878 |
- print " { 0, NULL }";
|
|
2879 |
- print "};";
|
|
2880 |
+ print(line);
|
|
2881 |
+ print(" { 0, NULL }");
|
|
2882 |
+ print("};");
|
|
2883 |
|
|
2884 |
if __name__ == "__main__":
|
|
2885 |
main()
|
|
2886 |
diff --git a/src/gui/character_pad/data/gen_unihan_data.py b/src/gui/character_pad/data/gen_unihan_data.py
|
|
2887 |
index 411ba69a..b59e147b 100644
|
|
2888 |
--- a/src/gui/character_pad/data/gen_unihan_data.py
|
|
2889 |
+++ b/src/gui/character_pad/data/gen_unihan_data.py
|
|
2890 |
@@ -31,35 +31,34 @@
|
|
2891 |
__author__ = "taku"
|
|
2892 |
|
|
2893 |
import re
|
|
2894 |
-import string
|
|
2895 |
import sys
|
|
2896 |
rs = {}
|
|
2897 |
|
|
2898 |
def Escape(n):
|
|
2899 |
- if n is not "NULL":
|
|
2900 |
+ if n != "NULL":
|
|
2901 |
return "\"%s\"" % (n)
|
|
2902 |
else:
|
|
2903 |
return "NULL"
|
|
2904 |
|
|
2905 |
def GetCode(n):
|
|
2906 |
- if n is not "NULL":
|
|
2907 |
- n = string.replace(n, '0-', 'JIS X 0208: 0x')
|
|
2908 |
- n = string.replace(n, '1-', 'JIS X 0212: 0x')
|
|
2909 |
- n = string.replace(n, '3-', 'JIS X 0213: 0x')
|
|
2910 |
- n = string.replace(n, '4-', 'JIS X 0213: 0x')
|
|
2911 |
- n = string.replace(n, 'A-', 'Vendors Ideographs: 0x')
|
|
2912 |
- n = string.replace(n, '3A', 'JIS X 0213 2000: 0x')
|
|
2913 |
+ if n != "NULL":
|
|
2914 |
+ n = n.replace('0-', 'JIS X 0208: 0x')
|
|
2915 |
+ n = n.replace('1-', 'JIS X 0212: 0x')
|
|
2916 |
+ n = n.replace('3-', 'JIS X 0213: 0x')
|
|
2917 |
+ n = n.replace('4-', 'JIS X 0213: 0x')
|
|
2918 |
+ n = n.replace('A-', 'Vendors Ideographs: 0x')
|
|
2919 |
+ n = n.replace('3A', 'JIS X 0213 2000: 0x')
|
|
2920 |
return "\"%s\"" % n
|
|
2921 |
else:
|
|
2922 |
return "NULL"
|
|
2923 |
|
|
2924 |
def GetRadical(n):
|
|
2925 |
pat = re.compile(r'^(\d+)\.')
|
|
2926 |
- if n is not "NULL":
|
|
2927 |
+ if n != "NULL":
|
|
2928 |
m = pat.match(n)
|
|
2929 |
if m:
|
|
2930 |
result = rs[m.group(1)]
|
|
2931 |
- return "\"%s\"" % (result.encode('string_escape'))
|
|
2932 |
+ return "\"%s\"" % result
|
|
2933 |
else:
|
|
2934 |
return "NULL"
|
|
2935 |
else:
|
|
2936 |
@@ -73,6 +72,7 @@ def main():
|
|
2937 |
id = array[1]
|
|
2938 |
radical = array[2]
|
|
2939 |
rs[id] = radical
|
|
2940 |
+ fh.close()
|
|
2941 |
|
|
2942 |
dic = {}
|
|
2943 |
pat = re.compile(r'^U\+(\S+)\s+(kTotalStrokes|kJapaneseKun|kJapaneseOn|kRSUnicode|kIRG_JSource)\t(.+)')
|
|
2944 |
@@ -86,23 +86,24 @@ def main():
|
|
2945 |
n = int(m.group(1), 16)
|
|
2946 |
if n <= 65536:
|
|
2947 |
dic.setdefault(key, {}).setdefault(field, value)
|
|
2948 |
+ fh.close()
|
|
2949 |
|
|
2950 |
keys = sorted(dic.keys())
|
|
2951 |
|
|
2952 |
- print "struct UnihanData {";
|
|
2953 |
- print " unsigned int ucs4;";
|
|
2954 |
+ print("struct UnihanData {");
|
|
2955 |
+ print(" unsigned int ucs4;");
|
|
2956 |
# Since the total strokes defined in Unihan data is Chinese-based
|
|
2957 |
# number, we can't use it.
|
|
2958 |
# print " unsigned char total_strokes;";
|
|
2959 |
- print " const char *japanese_kun;";
|
|
2960 |
- print " const char *japanese_on;";
|
|
2961 |
+ print(" const char *japanese_kun;");
|
|
2962 |
+ print(" const char *japanese_on;");
|
|
2963 |
# Since the radical information defined in Unihan data is Chinese-based
|
|
2964 |
# number, we can't use it.
|
|
2965 |
# print " const char *radical;";
|
|
2966 |
- print " const char *IRG_jsource;";
|
|
2967 |
- print "};"
|
|
2968 |
- print "static const size_t kUnihanDataSize = %d;" % (len(keys))
|
|
2969 |
- print "static const UnihanData kUnihanData[] = {"
|
|
2970 |
+ print(" const char *IRG_jsource;");
|
|
2971 |
+ print("};")
|
|
2972 |
+ print("static const size_t kUnihanDataSize = %d;" % (len(keys)))
|
|
2973 |
+ print("static const UnihanData kUnihanData[] = {")
|
|
2974 |
|
|
2975 |
for key in keys:
|
|
2976 |
total_strokes = dic[key].get("kTotalStrokes", "0")
|
|
2977 |
@@ -111,9 +112,9 @@ def main():
|
|
2978 |
rad = GetRadical(dic[key].get("kRSUnicode", "NULL"))
|
|
2979 |
code = GetCode(dic[key].get("kIRG_JSource", "NULL"))
|
|
2980 |
# print " { 0x%s, %s, %s, %s, %s, %s }," % (key, total_strokes, kun, on, rad, code)
|
|
2981 |
- print " { 0x%s, %s, %s, %s }," % (key, kun, on, code)
|
|
2982 |
+ print(" { 0x%s, %s, %s, %s }," % (key, kun, on, code))
|
|
2983 |
|
|
2984 |
- print "};"
|
|
2985 |
+ print("};")
|
|
2986 |
|
|
2987 |
if __name__ == "__main__":
|
|
2988 |
main()
|
|
2989 |
diff --git a/src/mac/generate_mapping.py b/src/mac/generate_mapping.py
|
|
2990 |
index 75d4888b..733f94ed 100644
|
|
2991 |
--- a/src/mac/generate_mapping.py
|
|
2992 |
+++ b/src/mac/generate_mapping.py
|
|
2993 |
@@ -31,6 +31,7 @@
|
|
2994 |
__author__ = "mukai"
|
|
2995 |
|
|
2996 |
import optparse
|
|
2997 |
+import sys
|
|
2998 |
|
|
2999 |
class Mapping(object):
|
|
3000 |
def __init__(self, options):
|
|
3001 |
@@ -40,26 +41,26 @@ class Mapping(object):
|
|
3002 |
self._filename = options.filename
|
|
3003 |
|
|
3004 |
def PrintLine(self, line):
|
|
3005 |
- columns = line.strip().split('\t')
|
|
3006 |
+ columns = line.strip().split(b'\t')
|
|
3007 |
if len(columns) != 2:
|
|
3008 |
return
|
|
3009 |
(key, value) = columns
|
|
3010 |
mapname = self._mapname
|
|
3011 |
- if key.startswith('Shift '):
|
|
3012 |
+ if key.startswith(b'Shift '):
|
|
3013 |
mapname += 'Shift'
|
|
3014 |
- key = key[len('Shift '):len(key)]
|
|
3015 |
+ key = key[len(b'Shift '):len(key)]
|
|
3016 |
|
|
3017 |
- if self._key_type == 'unsigned short' and not key.startswith('kVK_'):
|
|
3018 |
- key = 'kVK_ANSI_' + key
|
|
3019 |
+ if self._key_type == 'unsigned short' and not key.startswith(b'kVK_'):
|
|
3020 |
+ key = b'kVK_ANSI_' + key
|
|
3021 |
|
|
3022 |
if self._result_type == 'const char *':
|
|
3023 |
- value = '"%s"' % ''.join(['\\x%x' % ord(c) for c in value])
|
|
3024 |
+ value = b'"%b"' % b''.join([b'\\x%x' % c for c in value])
|
|
3025 |
elif self._result_type == 'KeyEvent::SpecialKey':
|
|
3026 |
- value = 'KeyEvent::' + value
|
|
3027 |
- print ' (*k%s)[%s] = %s;' % (mapname, key, value)
|
|
3028 |
+ value = b'KeyEvent::' + value
|
|
3029 |
+ print(' (*k%s)[%s] = %s;' % (mapname, key.decode('utf-8'), value.decode('utf-8')))
|
|
3030 |
|
|
3031 |
def PrintHeader(self):
|
|
3032 |
- print """// Copyright 2009 Google Inc. All Rights Reserved.
|
|
3033 |
+ print("""// Copyright 2009 Google Inc. All Rights Reserved.
|
|
3034 |
// Author: mukai
|
|
3035 |
//
|
|
3036 |
// This file is automatically generated by
|
|
3037 |
@@ -87,17 +88,18 @@ void Init%(mapname)s() {
|
|
3038 |
}
|
|
3039 |
""" % {'key_type': self._key_type,
|
|
3040 |
'mapname': self._mapname,
|
|
3041 |
- 'result_type': self._result_type }
|
|
3042 |
+ 'result_type': self._result_type })
|
|
3043 |
|
|
3044 |
def PrintFooter(self):
|
|
3045 |
- print """}
|
|
3046 |
+ print("""}
|
|
3047 |
} // namespace
|
|
3048 |
-""" % {'mapname': self._mapname}
|
|
3049 |
+""" % {'mapname': self._mapname})
|
|
3050 |
|
|
3051 |
def Print(self):
|
|
3052 |
self.PrintHeader()
|
|
3053 |
- for line in file(self._filename):
|
|
3054 |
- self.PrintLine(line)
|
|
3055 |
+ with open(self._filename, 'rb') as file:
|
|
3056 |
+ for line in file:
|
|
3057 |
+ self.PrintLine(line)
|
|
3058 |
self.PrintFooter()
|
|
3059 |
|
|
3060 |
def ParseOption():
|
|
3061 |
@@ -110,14 +112,14 @@ def ParseOption():
|
|
3062 |
(options, unused_args) = parser.parse_args()
|
|
3063 |
|
|
3064 |
if not options.mapname:
|
|
3065 |
- print "Error: the output map name should be specified."
|
|
3066 |
+ print("Error: the output map name should be specified.")
|
|
3067 |
sys.exit(2)
|
|
3068 |
if not options.key_type:
|
|
3069 |
options.key_type = 'unsigned short'
|
|
3070 |
if not options.result_type:
|
|
3071 |
- print "Error: the result type of the output map should be speicified."
|
|
3072 |
+ print("Error: the result type of the output map should be specified.")
|
|
3073 |
if not options.filename:
|
|
3074 |
- print "Error: the file name is not specified."
|
|
3075 |
+ print("Error: the file name is not specified.")
|
|
3076 |
return options
|
|
3077 |
|
|
3078 |
def main():
|
|
3079 |
diff --git a/src/prediction/gen_zero_query_data.py b/src/prediction/gen_zero_query_data.py
|
|
3080 |
index 1ffb2fbb..26726185 100644
|
|
3081 |
--- a/src/prediction/gen_zero_query_data.py
|
|
3082 |
+++ b/src/prediction/gen_zero_query_data.py
|
|
3083 |
@@ -59,20 +59,20 @@ def ParseCodePoint(s):
|
|
3084 |
Returns:
|
|
3085 |
A integer indicating parsed pua.
|
|
3086 |
"""
|
|
3087 |
- if not s or s[0] == '>':
|
|
3088 |
+ if not s or s[0:1] == b'>':
|
|
3089 |
return 0
|
|
3090 |
return int(s, 16)
|
|
3091 |
|
|
3092 |
|
|
3093 |
def NormalizeString(string):
|
|
3094 |
return unicodedata.normalize(
|
|
3095 |
- 'NFKC', string.decode('utf-8')).encode('utf-8').replace('~', '〜')
|
|
3096 |
+ 'NFKC', string.decode('utf-8')).replace('~', '〜').encode('utf-8')
|
|
3097 |
|
|
3098 |
|
|
3099 |
def RemoveTrailingNumber(string):
|
|
3100 |
if not string:
|
|
3101 |
- return ''
|
|
3102 |
- return re.sub(r'^([^0-9]+)[0-9]+$', r'\1', string)
|
|
3103 |
+ return b''
|
|
3104 |
+ return re.sub(br'^([^0-9]+)[0-9]+$', r'\1', string)
|
|
3105 |
|
|
3106 |
|
|
3107 |
def GetReadingsFromDescription(description):
|
|
3108 |
@@ -84,19 +84,19 @@ def GetReadingsFromDescription(description):
|
|
3109 |
# - ビル・建物
|
|
3110 |
# \xE3\x83\xBB : "・"
|
|
3111 |
return [RemoveTrailingNumber(token) for token
|
|
3112 |
- in re.split(r'(?:\(|\)|/|\xE3\x83\xBB)+', normalized)]
|
|
3113 |
+ in re.split(br'(?:\(|\)|/|\xE3\x83\xBB)+', normalized)]
|
|
3114 |
|
|
3115 |
|
|
3116 |
def ReadEmojiTsv(stream):
|
|
3117 |
"""Reads emoji data from stream and returns zero query data."""
|
|
3118 |
zero_query_dict = defaultdict(list)
|
|
3119 |
stream = code_generator_util.SkipLineComment(stream)
|
|
3120 |
- for columns in code_generator_util.ParseColumnStream(stream, delimiter='\t'):
|
|
3121 |
+ for columns in code_generator_util.ParseColumnStream(stream, delimiter=b'\t'):
|
|
3122 |
if len(columns) != 13:
|
|
3123 |
- logging.critical('format error: %s', '\t'.join(columns))
|
|
3124 |
+ logging.critical('format error: %s', b'\t'.join(columns))
|
|
3125 |
sys.exit(1)
|
|
3126 |
|
|
3127 |
- code_points = columns[0].split(' ')
|
|
3128 |
+ code_points = columns[0].split(b' ')
|
|
3129 |
|
|
3130 |
# Emoji code point.
|
|
3131 |
emoji = columns[1]
|
|
3132 |
@@ -114,12 +114,12 @@ def ReadEmojiTsv(stream):
|
|
3133 |
# - Composite emoji which has multiple code point.
|
|
3134 |
# NOTE: Some Unicode 6.0 emoji don't have PUA, and it is also omitted.
|
|
3135 |
# TODO(hsumita): Check the availability of such emoji and enable it.
|
|
3136 |
- logging.info('Skip %s', ' '.join(code_points))
|
|
3137 |
+ logging.info('Skip %s', b' '.join(code_points))
|
|
3138 |
continue
|
|
3139 |
|
|
3140 |
reading_list = []
|
|
3141 |
# \xe3\x80\x80 is a full-width space
|
|
3142 |
- for reading in re.split(r'(?: |\xe3\x80\x80)+', NormalizeString(readings)):
|
|
3143 |
+ for reading in re.split(br'(?: |\xe3\x80\x80)+', NormalizeString(readings)):
|
|
3144 |
if not reading:
|
|
3145 |
continue
|
|
3146 |
reading_list.append(reading)
|
|
3147 |
@@ -158,15 +158,15 @@ def ReadZeroQueryRuleData(input_stream):
|
|
3148 |
zero_query_dict = defaultdict(list)
|
|
3149 |
|
|
3150 |
for line in input_stream:
|
|
3151 |
- if line.startswith('#'):
|
|
3152 |
+ if line.startswith(b'#'):
|
|
3153 |
continue
|
|
3154 |
- line = line.rstrip('\r\n')
|
|
3155 |
+ line = line.rstrip(b'\r\n')
|
|
3156 |
if not line:
|
|
3157 |
continue
|
|
3158 |
|
|
3159 |
- tokens = line.split('\t')
|
|
3160 |
+ tokens = line.split(b'\t')
|
|
3161 |
key = tokens[0]
|
|
3162 |
- values = tokens[1].split(',')
|
|
3163 |
+ values = tokens[1].split(b',')
|
|
3164 |
|
|
3165 |
for value in values:
|
|
3166 |
zero_query_dict[key].append(
|
|
3167 |
@@ -179,16 +179,16 @@ def ReadEmoticonTsv(stream):
|
|
3168 |
"""Reads emoticon data from stream and returns zero query data."""
|
|
3169 |
zero_query_dict = defaultdict(list)
|
|
3170 |
stream = code_generator_util.SkipLineComment(stream)
|
|
3171 |
- for columns in code_generator_util.ParseColumnStream(stream, delimiter='\t'):
|
|
3172 |
+ for columns in code_generator_util.ParseColumnStream(stream, delimiter=b'\t'):
|
|
3173 |
if len(columns) != 3:
|
|
3174 |
- logging.critical('format error: %s', '\t'.join(columns))
|
|
3175 |
+ logging.critical('format error: %s', b'\t'.join(columns))
|
|
3176 |
sys.exit(1)
|
|
3177 |
|
|
3178 |
emoticon = columns[0]
|
|
3179 |
readings = columns[2]
|
|
3180 |
|
|
3181 |
# \xe3\x80\x80 is a full-width space
|
|
3182 |
- for reading in re.split(r'(?: |\xe3\x80\x80)+', readings.strip()):
|
|
3183 |
+ for reading in re.split(br'(?: |\xe3\x80\x80)+', readings.strip()):
|
|
3184 |
if not reading:
|
|
3185 |
continue
|
|
3186 |
zero_query_dict[reading].append(
|
|
3187 |
@@ -202,9 +202,9 @@ def ReadSymbolTsv(stream):
|
|
3188 |
"""Reads emoji data from stream and returns zero query data."""
|
|
3189 |
zero_query_dict = defaultdict(list)
|
|
3190 |
stream = code_generator_util.SkipLineComment(stream)
|
|
3191 |
- for columns in code_generator_util.ParseColumnStream(stream, delimiter='\t'):
|
|
3192 |
+ for columns in code_generator_util.ParseColumnStream(stream, delimiter=b'\t'):
|
|
3193 |
if len(columns) < 3:
|
|
3194 |
- logging.warning('format error: %s', '\t'.join(columns))
|
|
3195 |
+ logging.warning('format error: %s', b'\t'.join(columns))
|
|
3196 |
continue
|
|
3197 |
|
|
3198 |
symbol = columns[1]
|
|
3199 |
@@ -222,7 +222,7 @@ def ReadSymbolTsv(stream):
|
|
3200 |
continue
|
|
3201 |
|
|
3202 |
# \xe3\x80\x80 is a full-width space
|
|
3203 |
- for reading in re.split(r'(?: |\xe3\x80\x80)+', readings.strip()):
|
|
3204 |
+ for reading in re.split(br'(?: |\xe3\x80\x80)+', readings.strip()):
|
|
3205 |
if not reading:
|
|
3206 |
continue
|
|
3207 |
zero_query_dict[reading].append(
|
|
3208 |
@@ -247,7 +247,7 @@ def ReadSymbolTsv(stream):
|
|
3209 |
|
|
3210 |
def IsValidKeyForZeroQuery(key):
|
|
3211 |
"""Returns if the key is valid for zero query trigger."""
|
|
3212 |
- is_ascii = all(ord(char) < 128 for char in key)
|
|
3213 |
+ is_ascii = all(char < 128 for char in key)
|
|
3214 |
return not is_ascii
|
|
3215 |
|
|
3216 |
|
|
3217 |
@@ -301,13 +301,13 @@ def ParseOptions():
|
|
3218 |
|
|
3219 |
def main():
|
|
3220 |
options = ParseOptions()
|
|
3221 |
- with open(options.input_rule, 'r') as input_stream:
|
|
3222 |
+ with open(options.input_rule, 'rb') as input_stream:
|
|
3223 |
zero_query_rule_dict = ReadZeroQueryRuleData(input_stream)
|
|
3224 |
- with open(options.input_symbol, 'r') as input_stream:
|
|
3225 |
+ with open(options.input_symbol, 'rb') as input_stream:
|
|
3226 |
zero_query_symbol_dict = ReadSymbolTsv(input_stream)
|
|
3227 |
- with open(options.input_emoji, 'r') as input_stream:
|
|
3228 |
+ with open(options.input_emoji, 'rb') as input_stream:
|
|
3229 |
zero_query_emoji_dict = ReadEmojiTsv(input_stream)
|
|
3230 |
- with open(options.input_emoticon, 'r') as input_stream:
|
|
3231 |
+ with open(options.input_emoticon, 'rb') as input_stream:
|
|
3232 |
zero_query_emoticon_dict = ReadEmoticonTsv(input_stream)
|
|
3233 |
|
|
3234 |
merged_zero_query_dict = MergeZeroQueryData(
|
|
3235 |
diff --git a/src/prediction/gen_zero_query_number_data.py b/src/prediction/gen_zero_query_number_data.py
|
|
3236 |
index 1fe3e4e8..5596e34e 100644
|
|
3237 |
--- a/src/prediction/gen_zero_query_number_data.py
|
|
3238 |
+++ b/src/prediction/gen_zero_query_number_data.py
|
|
3239 |
@@ -41,15 +41,15 @@ def ReadZeroQueryNumberData(input_stream):
|
|
3240 |
zero_query_dict = defaultdict(list)
|
|
3241 |
|
|
3242 |
for line in input_stream:
|
|
3243 |
- if line.startswith('#'):
|
|
3244 |
+ if line.startswith(b'#'):
|
|
3245 |
continue
|
|
3246 |
- line = line.rstrip('\r\n')
|
|
3247 |
+ line = line.rstrip(b'\r\n')
|
|
3248 |
if not line:
|
|
3249 |
continue
|
|
3250 |
|
|
3251 |
- tokens = line.split('\t')
|
|
3252 |
+ tokens = line.split(b'\t')
|
|
3253 |
key = tokens[0]
|
|
3254 |
- values = tokens[1].split(',')
|
|
3255 |
+ values = tokens[1].split(b',')
|
|
3256 |
|
|
3257 |
for value in values:
|
|
3258 |
zero_query_dict[key].append(
|
|
3259 |
@@ -71,7 +71,7 @@ def ParseOption():
|
|
3260 |
|
|
3261 |
def main():
|
|
3262 |
options = ParseOption()
|
|
3263 |
- with open(options.input, 'r') as input_stream:
|
|
3264 |
+ with open(options.input, 'rb') as input_stream:
|
|
3265 |
zero_query_dict = ReadZeroQueryNumberData(input_stream)
|
|
3266 |
util.WriteZeroQueryData(zero_query_dict,
|
|
3267 |
options.output_token_array,
|
|
3268 |
diff --git a/src/prediction/gen_zero_query_util.py b/src/prediction/gen_zero_query_util.py
|
|
3269 |
index 733ca2f4..098387a4 100644
|
|
3270 |
--- a/src/prediction/gen_zero_query_util.py
|
|
3271 |
+++ b/src/prediction/gen_zero_query_util.py
|
|
3272 |
@@ -69,7 +69,7 @@ def WriteZeroQueryData(zero_query_dict, output_token_array,
|
|
3273 |
output_string_array):
|
|
3274 |
# Collect all the strings and assing index in ascending order
|
|
3275 |
string_index = {}
|
|
3276 |
- for key, entry_list in zero_query_dict.iteritems():
|
|
3277 |
+ for key, entry_list in zero_query_dict.items():
|
|
3278 |
string_index[key] = 0
|
|
3279 |
for entry in entry_list:
|
|
3280 |
string_index[entry.value] = 0
|
|
3281 |
diff --git a/src/rewriter/gen_counter_suffix_array.py b/src/rewriter/gen_counter_suffix_array.py
|
|
3282 |
index 4f4dd597..98e10cf5 100644
|
|
3283 |
--- a/src/rewriter/gen_counter_suffix_array.py
|
|
3284 |
+++ b/src/rewriter/gen_counter_suffix_array.py
|
|
3285 |
@@ -43,7 +43,7 @@ def ReadCounterSuffixPosIds(id_file):
|
|
3286 |
with codecs.open(id_file, 'r', encoding='utf-8') as stream:
|
|
3287 |
stream = code_generator_util.ParseColumnStream(stream, num_column=2)
|
|
3288 |
for pos_id, pos_name in stream:
|
|
3289 |
- if pos_name.startswith(u'名詞,接尾,助数詞'):
|
|
3290 |
+ if pos_name.startswith('名詞,接尾,助数詞'):
|
|
3291 |
pos_ids.add(pos_id)
|
|
3292 |
return pos_ids
|
|
3293 |
|
|
3294 |
diff --git a/src/rewriter/gen_emoji_rewriter_data.py b/src/rewriter/gen_emoji_rewriter_data.py
|
|
3295 |
index 210d5af6..be5a94cb 100644
|
|
3296 |
--- a/src/rewriter/gen_emoji_rewriter_data.py
|
|
3297 |
+++ b/src/rewriter/gen_emoji_rewriter_data.py
|
|
3298 |
@@ -74,19 +74,19 @@ def ParseCodePoint(s):
|
|
3299 |
the glyph (in other words, it has alternative (primary) code point, which
|
|
3300 |
doesn't lead '>' and that's why we'll ignore it).
|
|
3301 |
"""
|
|
3302 |
- if not s or s[0] == '>':
|
|
3303 |
+ if not s or s[0:1] == b'>':
|
|
3304 |
return None
|
|
3305 |
return int(s, 16)
|
|
3306 |
|
|
3307 |
|
|
3308 |
-_FULLWIDTH_RE = re.compile(ur'[!-~]') # U+FF01 - U+FF5E
|
|
3309 |
+_FULLWIDTH_RE = re.compile(r'[!-~]') # U+FF01 - U+FF5E
|
|
3310 |
|
|
3311 |
|
|
3312 |
def NormalizeString(string):
|
|
3313 |
"""Normalize full width ascii characters to half width characters."""
|
|
3314 |
- offset = ord(u'A') - ord(u'A')
|
|
3315 |
- return _FULLWIDTH_RE.sub(lambda x: unichr(ord(x.group(0)) - offset),
|
|
3316 |
- unicode(string, 'utf-8')).encode('utf-8')
|
|
3317 |
+ offset = ord('A') - ord('A')
|
|
3318 |
+ return _FULLWIDTH_RE.sub(lambda x: chr(ord(x.group(0)) - offset),
|
|
3319 |
+ string.decode('utf-8')).encode('utf-8')
|
|
3320 |
|
|
3321 |
|
|
3322 |
def ReadEmojiTsv(stream):
|
|
3323 |
@@ -96,14 +96,14 @@ def ReadEmojiTsv(stream):
|
|
3324 |
token_dict = defaultdict(list)
|
|
3325 |
|
|
3326 |
stream = code_generator_util.SkipLineComment(stream)
|
|
3327 |
- for columns in code_generator_util.ParseColumnStream(stream, delimiter='\t'):
|
|
3328 |
+ for columns in code_generator_util.ParseColumnStream(stream, delimiter=b'\t'):
|
|
3329 |
if len(columns) != 13:
|
|
3330 |
- logging.critical('format error: %s', '\t'.join(columns))
|
|
3331 |
+ logging.critical('format error: %s', b'\t'.join(columns))
|
|
3332 |
sys.exit(1)
|
|
3333 |
|
|
3334 |
- code_points = columns[0].split(' ')
|
|
3335 |
+ code_points = columns[0].split(b' ')
|
|
3336 |
# Emoji code point.
|
|
3337 |
- emoji = columns[1] if columns[1] else ''
|
|
3338 |
+ emoji = columns[1] if columns[1] else b''
|
|
3339 |
android_pua = ParseCodePoint(columns[2])
|
|
3340 |
docomo_pua = ParseCodePoint(columns[3])
|
|
3341 |
softbank_pua = ParseCodePoint(columns[4])
|
|
3342 |
@@ -112,10 +112,10 @@ def ReadEmojiTsv(stream):
|
|
3343 |
readings = columns[6]
|
|
3344 |
|
|
3345 |
# [7]: Name defined in Unicode. It is ignored in current implementation.
|
|
3346 |
- utf8_description = columns[8] if columns[8] else ''
|
|
3347 |
- docomo_description = columns[9] if columns[9] else ''
|
|
3348 |
- softbank_description = columns[10] if columns[10] else ''
|
|
3349 |
- kddi_description = columns[11] if columns[11] else ''
|
|
3350 |
+ utf8_description = columns[8] if columns[8] else b''
|
|
3351 |
+ docomo_description = columns[9] if columns[9] else b''
|
|
3352 |
+ softbank_description = columns[10] if columns[10] else b''
|
|
3353 |
+ kddi_description = columns[11] if columns[11] else b''
|
|
3354 |
|
|
3355 |
if not android_pua or len(code_points) > 1:
|
|
3356 |
# Skip some emoji, which is not supported on old devices.
|
|
3357 |
@@ -123,7 +123,7 @@ def ReadEmojiTsv(stream):
|
|
3358 |
# - Composite emoji which has multiple code point.
|
|
3359 |
# NOTE: Some Unicode 6.0 emoji don't have PUA, and it is also omitted.
|
|
3360 |
# TODO(hsumita): Check the availability of such emoji and enable it.
|
|
3361 |
- logging.info('Skip %s', ' '.join(code_points))
|
|
3362 |
+ logging.info('Skip %s', b' '.join(code_points))
|
|
3363 |
continue
|
|
3364 |
|
|
3365 |
# Check consistency between carrier PUA codes and descriptions for Android
|
|
3366 |
@@ -132,7 +132,7 @@ def ReadEmojiTsv(stream):
|
|
3367 |
(bool(softbank_pua) != bool(softbank_description)) or
|
|
3368 |
(bool(kddi_pua) != bool(kddi_description))):
|
|
3369 |
logging.warning('carrier PUA and description conflict: %s',
|
|
3370 |
- '\t'.join(columns))
|
|
3371 |
+ b'\t'.join(columns))
|
|
3372 |
continue
|
|
3373 |
|
|
3374 |
# Check if the character is usable on Android.
|
|
3375 |
@@ -140,7 +140,7 @@ def ReadEmojiTsv(stream):
|
|
3376 |
android_pua = 0 # Replace None with 0.
|
|
3377 |
|
|
3378 |
if not emoji and not android_pua:
|
|
3379 |
- logging.info('Skip: %s', '\t'.join(columns))
|
|
3380 |
+ logging.info('Skip: %s', b'\t'.join(columns))
|
|
3381 |
continue
|
|
3382 |
|
|
3383 |
index = len(emoji_data_list)
|
|
3384 |
@@ -149,7 +149,7 @@ def ReadEmojiTsv(stream):
|
|
3385 |
kddi_description))
|
|
3386 |
|
|
3387 |
# \xe3\x80\x80 is a full-width space
|
|
3388 |
- for reading in re.split(r'(?: |\xe3\x80\x80)+', readings.strip()):
|
|
3389 |
+ for reading in re.split(br'(?: |\xe3\x80\x80)+', readings.strip()):
|
|
3390 |
if reading:
|
|
3391 |
token_dict[NormalizeString(reading)].append(index)
|
|
3392 |
|
|
3393 |
@@ -159,7 +159,7 @@ def ReadEmojiTsv(stream):
|
|
3394 |
def OutputData(emoji_data_list, token_dict,
|
|
3395 |
token_array_file, string_array_file):
|
|
3396 |
"""Output token and string arrays to files."""
|
|
3397 |
- sorted_token_dict = sorted(token_dict.iteritems())
|
|
3398 |
+ sorted_token_dict = sorted(token_dict.items())
|
|
3399 |
|
|
3400 |
strings = {}
|
|
3401 |
for reading, _ in sorted_token_dict:
|
|
3402 |
@@ -171,7 +171,7 @@ def OutputData(emoji_data_list, token_dict,
|
|
3403 |
strings[docomo_description] = 0
|
|
3404 |
strings[softbank_description] = 0
|
|
3405 |
strings[kddi_description] = 0
|
|
3406 |
- sorted_strings = sorted(strings.iterkeys())
|
|
3407 |
+ sorted_strings = sorted(strings.keys())
|
|
3408 |
for index, s in enumerate(sorted_strings):
|
|
3409 |
strings[s] = index
|
|
3410 |
|
|
3411 |
@@ -205,7 +205,7 @@ def ParseOptions():
|
|
3412 |
|
|
3413 |
def main():
|
|
3414 |
options = ParseOptions()
|
|
3415 |
- with open(options.input, 'r') as input_stream:
|
|
3416 |
+ with open(options.input, 'rb') as input_stream:
|
|
3417 |
(emoji_data_list, token_dict) = ReadEmojiTsv(input_stream)
|
|
3418 |
|
|
3419 |
OutputData(emoji_data_list, token_dict,
|
|
3420 |
diff --git a/src/rewriter/gen_reading_correction_data.py b/src/rewriter/gen_reading_correction_data.py
|
|
3421 |
index 97a09b9b..99997ed7 100644
|
|
3422 |
--- a/src/rewriter/gen_reading_correction_data.py
|
|
3423 |
+++ b/src/rewriter/gen_reading_correction_data.py
|
|
3424 |
@@ -63,7 +63,7 @@ def ParseOptions():
|
|
3425 |
def WriteData(input_path, output_value_array_path, output_error_array_path,
|
|
3426 |
output_correction_array_path):
|
|
3427 |
outputs = []
|
|
3428 |
- with open(input_path) as input_stream:
|
|
3429 |
+ with open(input_path, 'rb') as input_stream:
|
|
3430 |
input_stream = code_generator_util.SkipLineComment(input_stream)
|
|
3431 |
input_stream = code_generator_util.ParseColumnStream(input_stream,
|
|
3432 |
num_column=3)
|
|
3433 |
@@ -73,7 +73,7 @@ def WriteData(input_path, output_value_array_path, output_error_array_path,
|
|
3434 |
|
|
3435 |
# In order to lookup the entries via |error| with binary search,
|
|
3436 |
# sort outputs here.
|
|
3437 |
- outputs.sort(lambda x, y: cmp(x[1], y[1]) or cmp(x[0], y[0]))
|
|
3438 |
+ outputs.sort(key=lambda x: (x[1], x[0]))
|
|
3439 |
|
|
3440 |
serialized_string_array_builder.SerializeToFile(
|
|
3441 |
[value for (value, _, _) in outputs], output_value_array_path)
|
|
3442 |
diff --git a/src/rewriter/gen_single_kanji_rewriter_data.py b/src/rewriter/gen_single_kanji_rewriter_data.py
|
|
3443 |
index 5c87006d..97c5b491 100644
|
|
3444 |
--- a/src/rewriter/gen_single_kanji_rewriter_data.py
|
|
3445 |
+++ b/src/rewriter/gen_single_kanji_rewriter_data.py
|
|
3446 |
@@ -52,7 +52,7 @@ def ReadSingleKanji(stream):
|
|
3447 |
stream = code_generator_util.ParseColumnStream(stream, num_column=2)
|
|
3448 |
outputs = list(stream)
|
|
3449 |
# For binary search by |key|, sort outputs here.
|
|
3450 |
- outputs.sort(lambda x, y: cmp(x[0], y[0]))
|
|
3451 |
+ outputs.sort(key=lambda x: x[0])
|
|
3452 |
|
|
3453 |
return outputs
|
|
3454 |
|
|
3455 |
@@ -72,7 +72,7 @@ def ReadVariant(stream):
|
|
3456 |
variant_items.append([target, original, len(variant_types) - 1])
|
|
3457 |
|
|
3458 |
# For binary search by |target|, sort variant items here.
|
|
3459 |
- variant_items.sort(lambda x, y: cmp(x[0], y[0]))
|
|
3460 |
+ variant_items.sort(key=lambda x: x[0])
|
|
3461 |
|
|
3462 |
return (variant_types, variant_items)
|
|
3463 |
|
|
3464 |
@@ -151,10 +151,10 @@ def _ParseOptions():
|
|
3465 |
def main():
|
|
3466 |
options = _ParseOptions()
|
|
3467 |
|
|
3468 |
- with open(options.single_kanji_file, 'r') as single_kanji_stream:
|
|
3469 |
+ with open(options.single_kanji_file, 'rb') as single_kanji_stream:
|
|
3470 |
single_kanji = ReadSingleKanji(single_kanji_stream)
|
|
3471 |
|
|
3472 |
- with open(options.variant_file, 'r') as variant_stream:
|
|
3473 |
+ with open(options.variant_file, 'rb') as variant_stream:
|
|
3474 |
variant_info = ReadVariant(variant_stream)
|
|
3475 |
|
|
3476 |
WriteSingleKanji(single_kanji,
|
|
3477 |
diff --git a/src/session/gen_session_stress_test_data.py b/src/session/gen_session_stress_test_data.py
|
|
3478 |
index 1e27d52f..b3f86c27 100644
|
|
3479 |
--- a/src/session/gen_session_stress_test_data.py
|
|
3480 |
+++ b/src/session/gen_session_stress_test_data.py
|
|
3481 |
@@ -50,24 +50,26 @@ def escape_string(s):
|
|
3482 |
"""
|
|
3483 |
result = ''
|
|
3484 |
for c in s:
|
|
3485 |
- hexstr = hex(ord(c))
|
|
3486 |
+ hexstr = hex(c)
|
|
3487 |
# because hexstr contains '0x', remove the prefix and add our prefix
|
|
3488 |
result += '\\x' + hexstr[2:]
|
|
3489 |
return result
|
|
3490 |
|
|
3491 |
def GenerateHeader(file):
|
|
3492 |
try:
|
|
3493 |
- print "const char *kTestSentences[] = {"
|
|
3494 |
- for line in open(file, "r"):
|
|
3495 |
- if line.startswith('#'):
|
|
3496 |
+ print("const char *kTestSentences[] = {")
|
|
3497 |
+ fh = open(file, "rb")
|
|
3498 |
+ for line in fh:
|
|
3499 |
+ if line.startswith(b'#'):
|
|
3500 |
continue
|
|
3501 |
- line = line.rstrip('\r\n')
|
|
3502 |
+ line = line.rstrip(b'\r\n')
|
|
3503 |
if not line:
|
|
3504 |
continue
|
|
3505 |
- print " \"%s\"," % escape_string(line)
|
|
3506 |
- print "};"
|
|
3507 |
+ print(" \"%s\"," % escape_string(line))
|
|
3508 |
+ fh.close()
|
|
3509 |
+ print("};")
|
|
3510 |
except:
|
|
3511 |
- print "cannot open %s" % (file)
|
|
3512 |
+ print("cannot open %s" % (file))
|
|
3513 |
sys.exit(1)
|
|
3514 |
|
|
3515 |
def main():
|
|
3516 |
diff --git a/src/unix/ibus/gen_mozc_xml.py b/src/unix/ibus/gen_mozc_xml.py
|
|
3517 |
index 4a450408..f3b2718b 100644
|
|
3518 |
--- a/src/unix/ibus/gen_mozc_xml.py
|
|
3519 |
+++ b/src/unix/ibus/gen_mozc_xml.py
|
|
3520 |
@@ -74,7 +74,7 @@ CPP_FOOTER = """} // namespace
|
|
3521 |
|
|
3522 |
|
|
3523 |
def OutputXmlElement(param_dict, element_name, value):
|
|
3524 |
- print ' <%s>%s</%s>' % (element_name, (value % param_dict), element_name)
|
|
3525 |
+ print(' <%s>%s</%s>' % (element_name, (value % param_dict), element_name))
|
|
3526 |
|
|
3527 |
|
|
3528 |
def OutputXml(param_dict, component, engine_common, engines, setup_arg):
|
|
3529 |
@@ -90,26 +90,26 @@ def OutputXml(param_dict, component, engine_common, engines, setup_arg):
|
|
3530 |
engines: A dictionary from a property name to a list of property values of
|
|
3531 |
engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
|
|
3532 |
"""
|
|
3533 |
- print '<component>'
|
|
3534 |
- for key in component:
|
|
3535 |
+ print('<component>')
|
|
3536 |
+ for key in sorted(component):
|
|
3537 |
OutputXmlElement(param_dict, key, component[key])
|
|
3538 |
- print '<engines>'
|
|
3539 |
+ print('<engines>')
|
|
3540 |
for i in range(len(engines['name'])):
|
|
3541 |
- print '<engine>'
|
|
3542 |
- for key in engine_common:
|
|
3543 |
+ print('<engine>')
|
|
3544 |
+ for key in sorted(engine_common):
|
|
3545 |
OutputXmlElement(param_dict, key, engine_common[key])
|
|
3546 |
if setup_arg:
|
|
3547 |
OutputXmlElement(param_dict, 'setup', ' '.join(setup_arg))
|
|
3548 |
- for key in engines:
|
|
3549 |
+ for key in sorted(engines):
|
|
3550 |
OutputXmlElement(param_dict, key, engines[key][i])
|
|
3551 |
- print '</engine>'
|
|
3552 |
- print '</engines>'
|
|
3553 |
- print '</component>'
|
|
3554 |
+ print('</engine>')
|
|
3555 |
+ print('</engines>')
|
|
3556 |
+ print('</component>')
|
|
3557 |
|
|
3558 |
|
|
3559 |
def OutputCppVariable(param_dict, prefix, variable_name, value):
|
|
3560 |
- print 'const char k%s%s[] = "%s";' % (prefix, variable_name.capitalize(),
|
|
3561 |
- (value % param_dict))
|
|
3562 |
+ print('const char k%s%s[] = "%s";' % (prefix, variable_name.capitalize(),
|
|
3563 |
+ (value % param_dict)))
|
|
3564 |
|
|
3565 |
|
|
3566 |
def OutputCpp(param_dict, component, engine_common, engines):
|
|
3567 |
@@ -122,18 +122,18 @@ def OutputCpp(param_dict, component, engine_common, engines):
|
|
3568 |
engines: ditto.
|
|
3569 |
"""
|
|
3570 |
guard_name = 'MOZC_UNIX_IBUS_MAIN_H_'
|
|
3571 |
- print CPP_HEADER % (guard_name, guard_name)
|
|
3572 |
- for key in component:
|
|
3573 |
+ print(CPP_HEADER % (guard_name, guard_name))
|
|
3574 |
+ for key in sorted(component):
|
|
3575 |
OutputCppVariable(param_dict, 'Component', key, component[key])
|
|
3576 |
- for key in engine_common:
|
|
3577 |
+ for key in sorted(engine_common):
|
|
3578 |
OutputCppVariable(param_dict, 'Engine', key, engine_common[key])
|
|
3579 |
- for key in engines:
|
|
3580 |
- print 'const char* kEngine%sArray[] = {' % key.capitalize()
|
|
3581 |
+ for key in sorted(engines):
|
|
3582 |
+ print('const char* kEngine%sArray[] = {' % key.capitalize())
|
|
3583 |
for i in range(len(engines[key])):
|
|
3584 |
- print '"%s",' % (engines[key][i] % param_dict)
|
|
3585 |
- print '};'
|
|
3586 |
- print 'const size_t kEngineArrayLen = %s;' % len(engines['name'])
|
|
3587 |
- print CPP_FOOTER % guard_name
|
|
3588 |
+ print('"%s",' % (engines[key][i] % param_dict))
|
|
3589 |
+ print('};')
|
|
3590 |
+ print('const size_t kEngineArrayLen = %s;' % len(engines['name']))
|
|
3591 |
+ print(CPP_FOOTER % guard_name)
|
|
3592 |
|
|
3593 |
|
|
3594 |
def CheckIBusVersion(options, minimum_version):
|
|
3595 |
diff --git a/src/usage_stats/gen_stats_list.py b/src/usage_stats/gen_stats_list.py
|
|
3596 |
index 00051dfd..b63e1bc9 100644
|
|
3597 |
--- a/src/usage_stats/gen_stats_list.py
|
|
3598 |
+++ b/src/usage_stats/gen_stats_list.py
|
|
3599 |
@@ -37,23 +37,24 @@ import sys
|
|
3600 |
|
|
3601 |
def GetStatsNameList(filename):
|
|
3602 |
stats = []
|
|
3603 |
- for line in open(filename, 'r'):
|
|
3604 |
- stat = line.strip()
|
|
3605 |
- if not stat or stat[0] == '#':
|
|
3606 |
- continue
|
|
3607 |
- stats.append(stat)
|
|
3608 |
+ with open(filename, 'r') as file:
|
|
3609 |
+ for line in file:
|
|
3610 |
+ stat = line.strip()
|
|
3611 |
+ if not stat or stat[0] == '#':
|
|
3612 |
+ continue
|
|
3613 |
+ stats.append(stat)
|
|
3614 |
return stats
|
|
3615 |
|
|
3616 |
|
|
3617 |
def main():
|
|
3618 |
stats_list = GetStatsNameList(sys.argv[1])
|
|
3619 |
- print '// This header file is generated by gen_stats_list.py'
|
|
3620 |
+ print('// This header file is generated by gen_stats_list.py')
|
|
3621 |
for stats in stats_list:
|
|
3622 |
- print 'const char k%s[] = "%s";' % (stats, stats)
|
|
3623 |
- print 'const char *kStatsList[] = {'
|
|
3624 |
+ print('const char k%s[] = "%s";' % (stats, stats))
|
|
3625 |
+ print('const char *kStatsList[] = {')
|
|
3626 |
for stats in stats_list:
|
|
3627 |
- print ' k%s,' % (stats)
|
|
3628 |
- print '};'
|
|
3629 |
+ print(' k%s,' % (stats))
|
|
3630 |
+ print('};')
|
|
3631 |
|
|
3632 |
|
|
3633 |
if __name__ == '__main__':
|
|
3634 |
diff --git a/src/win32/installer/postbuilds_win.py b/src/win32/installer/postbuilds_win.py
|
|
3635 |
index f37f1c36..a7ef4152 100644
|
|
3636 |
--- a/src/win32/installer/postbuilds_win.py
|
|
3637 |
+++ b/src/win32/installer/postbuilds_win.py
|
|
3638 |
@@ -28,7 +28,7 @@
|
|
3639 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
3640 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
3641 |
|
|
3642 |
-"""Script post-prosessing executables for Windows.
|
|
3643 |
+"""Script post-processing executables for Windows.
|
|
3644 |
|
|
3645 |
postbuilds_win.py --targetpath=my_binary.exe
|
|
3646 |
"""
|
|
3647 |
@@ -66,11 +66,11 @@ def ParseOption():
|
|
3648 |
open(abs_touch_file_path, 'w').close()
|
|
3649 |
|
|
3650 |
|
|
3651 |
-class RunOrDieError(StandardError):
|
|
3652 |
+class RunOrDieError(Exception):
|
|
3653 |
"""The exception class for RunOrDie."""
|
|
3654 |
|
|
3655 |
def __init__(self, message):
|
|
3656 |
- StandardError.__init__(self, message)
|
|
3657 |
+ Exception.__init__(self, message)
|
|
3658 |
|
|
3659 |
|
|
3660 |
def RunOrDie(argv):
|
|
3661 |
@@ -94,15 +94,15 @@ def RunOrDie(argv):
|
|
3662 |
|
|
3663 |
def PrintErrorAndExit(error_message):
|
|
3664 |
"""Prints the error message and exists."""
|
|
3665 |
- print error_message
|
|
3666 |
+ print(error_message)
|
|
3667 |
sys.exit(1)
|
|
3668 |
|
|
3669 |
|
|
3670 |
def ShowHelpAndExit():
|
|
3671 |
"""Shows the help message."""
|
|
3672 |
- print 'Usage: postbuilds_win.py [ARGS]'
|
|
3673 |
- print 'This script only supports Windows'
|
|
3674 |
- print 'See also the comment in the script for typical usage.'
|
|
3675 |
+ print('Usage: postbuilds_win.py [ARGS]')
|
|
3676 |
+ print('This script only supports Windows')
|
|
3677 |
+ print('See also the comment in the script for typical usage.')
|
|
3678 |
sys.exit(1)
|
|
3679 |
|
|
3680 |
|
|
3681 |
@@ -110,7 +110,7 @@ def main():
|
|
3682 |
opts = ParseOption()
|
|
3683 |
|
|
3684 |
if not opts.targetpath:
|
|
3685 |
- print '--targetpath is not specified'
|
|
3686 |
+ print('--targetpath is not specified')
|
|
3687 |
sys.exit(1)
|
|
3688 |
|
|
3689 |
if IsWindows():
|
|
3690 |
--
|
|
3691 |
2.26.1
|
|
3692 |
|