app-i18n/mozc: Initial commit - add fcitx5 support
[gentoo-zh.git] / app-i18n / mozc / files / mozc-2.23.2815.102-python-3_2.patch
blob456e8368049ac6bd5310e0d2ed9566105eb1bcf3
1 https://github.com/google/mozc/issues/462
3 --- /src/build_tools/redirect.py
4 +++ /src/build_tools/redirect.py
5 @@ -58,14 +58,15 @@
6 process = subprocess.Popen(sys.argv, stdout=subprocess.PIPE,
7 universal_newlines=True)
8 except:
9 - print '=========='
10 - print ' ERROR: %s' % ' '.join(sys.argv)
11 - print '=========='
12 + print('==========')
13 + print(' ERROR: %s' % ' '.join(sys.argv))
14 + print('==========')
15 raise
16 (stdout_content, _) = process.communicate()
17 # Write the stdout content to the output file.
18 output_file = open(output_file_name, 'w')
19 output_file.write(stdout_content)
20 + output_file.close()
21 return process.wait()
23 if __name__ == '__main__':
24 --- /src/build_tools/run_after_chdir.py
25 +++ /src/build_tools/run_after_chdir.py
26 @@ -57,7 +57,7 @@
27 sys.argv.insert(0, sys.executable) # Inject the python interpreter path.
28 # We don't capture stdout and stderr from Popen. The output will just
29 # be emitted to a terminal or console.
30 - print sys.argv
31 + print(sys.argv)
32 sys.exit(subprocess.call(sys.argv))
34 if __name__ == '__main__':
35 --- /src/build_tools/serialized_string_array_builder.py
36 +++ /src/build_tools/serialized_string_array_builder.py
37 @@ -58,11 +58,11 @@
38 f.write(struct.pack('<I', array_size))
40 # Offset and length array of (4 + 4) * array_size bytes.
41 - for i in xrange(array_size):
42 + for i in range(array_size):
43 f.write(struct.pack('<I', offsets[i]))
44 f.write(struct.pack('<I', lengths[i]))
46 # Strings chunk.
47 - for i in xrange(array_size):
48 + for i in range(array_size):
49 f.write(strings[i])
50 - f.write('\0')
51 + f.write(b'\0')
52 --- /src/build_tools/test_tools/gtest_report.py
53 +++ /src/build_tools/test_tools/gtest_report.py
54 @@ -36,9 +36,9 @@
56 __author__ = "nona"
58 -import cStringIO as StringIO
59 +import io
60 import logging
61 -from xml.etree import cElementTree as ElementTree
62 +from xml.etree import ElementTree
65 class Failure(object):
66 @@ -87,13 +87,13 @@
67 """Returns summarized error report text."""
68 if self.fail_num == 0:
69 return ''
70 - output = StringIO.StringIO()
71 + output = io.StringIO()
72 for testcase in self.testcases:
73 if not testcase.failures:
74 continue
75 - print >>output, '%s.%s:' % (self.name, testcase.name)
76 + print('%s.%s:' % (self.name, testcase.name), file=output)
77 for failure in testcase.failures:
78 - print >>output, failure.contents.encode('utf-8')
79 + print(failure.contents.encode('utf-8'), file=output)
80 return output.getvalue()
82 @classmethod
83 --- /src/build_tools/test_tools/test_launcher.py
84 +++ /src/build_tools/test_tools/test_launcher.py
85 @@ -101,11 +101,11 @@
86 time.sleep(1)
87 try:
88 shutil.rmtree(self._path)
89 - except OSError, e:
90 + except OSError as e:
91 logging.error('Failed to remove %s. error: %s', self._path, e)
94 -def _ExecuteTest((command, gtest_report_dir)):
95 +def _ExecuteTest(args):
96 """Executes tests with specified Test command.
98 Args:
99 @@ -122,6 +122,7 @@
100 module, which is used in multiprocessing module.
101 (http://docs.python.org/library/pickle.html)
103 + (command, gtest_report_dir) = args
104 binary = command[0]
105 binary_filename = os.path.basename(binary)
106 tmp_dir = tempfile.mkdtemp()
107 --- /src/build_tools/tweak_data.py
108 +++ /src/build_tools/tweak_data.py
109 @@ -55,7 +55,7 @@
110 The value for the variable if the variable is defined in the
111 environment. Otherwise original string is returned.
113 - if environment.has_key(matchobj.group(1)):
114 + if matchobj.group(1) in environment:
115 return environment[matchobj.group(1)]
116 return matchobj.group(0)
118 --- /src/build_tools/tweak_info_plist.py
119 +++ /src/build_tools/tweak_info_plist.py
120 @@ -42,8 +42,8 @@
121 import logging
122 import optparse
123 import sys
124 -import mozc_version
125 -import tweak_data
126 +from . import mozc_version
127 +from . import tweak_data
129 _COPYRIGHT_YEAR = datetime.date.today().year
131 @@ -81,7 +81,7 @@
133 version = mozc_version.MozcVersion(options.version_file)
135 - copyright_message = (u'© %d Google Inc.' % _COPYRIGHT_YEAR).encode('utf-8')
136 + copyright_message = ('© %d Google Inc.' % _COPYRIGHT_YEAR).encode('utf-8')
137 long_version = version.GetVersionString()
138 short_version = version.GetVersionInFormat('@MAJOR@.@MINOR@.@BUILD@')
140 --- /src/build_tools/tweak_info_plist_strings.py
141 +++ /src/build_tools/tweak_info_plist_strings.py
142 @@ -40,7 +40,7 @@
143 import logging
144 import optparse
145 import sys
146 -import tweak_data
147 +from . import tweak_data
149 _COPYRIGHT_YEAR = datetime.date.today().year
151 @@ -77,7 +77,7 @@
152 if options.branding == 'GoogleJapaneseInput':
153 variables = {
154 'CF_BUNDLE_NAME_EN': 'Google Japanese Input',
155 - 'CF_BUNDLE_NAME_JA': u'Google 日本語入力'.encode('utf-8'),
156 + 'CF_BUNDLE_NAME_JA': 'Google 日本語入力'.encode('utf-8'),
157 'NS_HUMAN_READABLE_COPYRIGHT': copyright_message,
158 'INPUT_MODE_ANNOTATION': 'Google',
160 --- /src/build_tools/tweak_macinstaller_script.py
161 +++ /src/build_tools/tweak_macinstaller_script.py
162 @@ -39,7 +39,7 @@
163 import logging
164 import optparse
166 -import mozc_version
167 +from . import mozc_version
170 def _ReplaceVariables(data, environment):
171 --- /src/build_tools/tweak_pkgproj.py
172 +++ /src/build_tools/tweak_pkgproj.py
173 @@ -45,7 +45,7 @@
174 import os
175 import plistlib
176 import re
177 -import mozc_version
178 +from . import mozc_version
180 from os import path
182 @@ -71,7 +71,7 @@
183 The value for the variable if the variable is defined in the
184 environment. Otherwise original string is returned.
186 - if environment.has_key(matchobj.group(1)):
187 + if matchobj.group(1) in environment:
188 return environment[matchobj.group(1)]
189 return matchobj.group(0)
191 --- /src/build_tools/util.py
192 +++ /src/build_tools/util.py
193 @@ -73,11 +73,11 @@
194 return 1
197 -class RunOrDieError(StandardError):
198 +class RunOrDieError(Exception):
199 """The exception class for RunOrDie."""
201 def __init__(self, message):
202 - StandardError.__init__(self, message)
203 + Exception.__init__(self, message)
206 def RunOrDie(argv):
207 @@ -105,7 +105,7 @@
208 return # Do nothing if not exist.
209 if IsWindows():
210 # Read-only files cannot be deleted on Windows.
211 - os.chmod(file_name, 0700)
212 + os.chmod(file_name, 0o700)
213 logging.debug('Removing file: %s', file_name)
214 os.unlink(file_name)
216 --- /src/build_tools/zlib_util.py
217 +++ /src/build_tools/zlib_util.py
218 @@ -58,7 +58,7 @@
220 def main():
221 if len(sys.argv) != 4:
222 - print >>sys.stderr, 'Invalid arguments'
223 + print('Invalid arguments', file=sys.stderr)
224 return
225 if sys.argv[1] == 'compress':
226 Compress(sys.argv[2], sys.argv[3])
227 @@ -66,7 +66,7 @@
228 if sys.argv[1] == 'decompress':
229 Decompress(sys.argv[2], sys.argv[3])
230 return
231 - print >>sys.stderr, 'Unknown command:', sys.argv[1]
232 + print('Unknown command:', sys.argv[1], file=sys.stderr)
235 if __name__ == '__main__':
236 --- /src/composer/internal/gen_typing_model.py
237 +++ /src/composer/internal/gen_typing_model.py
238 @@ -54,14 +54,13 @@
239 __author__ = "noriyukit"
241 import bisect
242 -import codecs
243 import collections
244 import optparse
245 import struct
247 UNDEFINED_COST = -1
248 -MAX_UINT16 = struct.unpack('H', '\xFF\xFF')[0]
249 -MAX_UINT8 = struct.unpack('B', '\xFF')[0]
250 +MAX_UINT16 = struct.unpack('H', b'\xFF\xFF')[0]
251 +MAX_UINT8 = struct.unpack('B', b'\xFF')[0]
254 def ParseArgs():
255 @@ -113,7 +112,7 @@
256 sorted_values = list(sorted(set(values)))
257 mapping_table = sorted_values[0]
258 mapping_table_size_without_special_value = mapping_table_size - 1
259 - span = len(sorted_values) / (mapping_table_size_without_special_value - 1)
260 + span = len(sorted_values) // (mapping_table_size_without_special_value - 1)
261 mapping_table = [sorted_values[i * span]
262 for i
263 in range(0, mapping_table_size_without_special_value - 1)]
264 @@ -150,7 +149,7 @@
266 def GetValueTable(unique_characters, mapping_table, dictionary):
267 result = []
268 - for key, value in dictionary.iteritems():
269 + for key, value in dictionary.items():
270 index = GetIndexFromKey(unique_characters, key)
271 while len(result) <= index:
272 result.append(len(mapping_table) - 1)
273 @@ -167,13 +166,13 @@
274 romaji_transition_cost)
275 with open(output_path, 'wb') as f:
276 f.write(struct.pack('<I', len(unique_characters)))
277 - f.write(''.join(unique_characters))
278 + f.write(''.join(unique_characters).encode('utf-8'))
279 offset = 4 + len(unique_characters)
281 # Add padding to place value list size at 4-byte boundary.
282 if offset % 4:
283 padding_size = 4 - offset % 4
284 - f.write('\x00' * padding_size)
285 + f.write(b'\x00' * padding_size)
286 offset += padding_size
288 f.write(struct.pack('<I', len(value_list)))
289 @@ -184,7 +183,7 @@
290 # Add padding to place mapping_table at 4-byte boundary.
291 if offset % 4:
292 padding_size = 4 - offset % 4
293 - f.write('\x00' * padding_size)
294 + f.write(b'\x00' * padding_size)
295 offset += padding_size
297 for v in mapping_table:
298 @@ -198,7 +197,8 @@
299 # - trigram['vw']['x'] = -500 * log(P(x | 'vw'))
300 unigram = {}
301 trigram = collections.defaultdict(dict)
302 - for line in codecs.open(options.input_path, 'r', encoding='utf-8'):
303 + input_file = open(options.input_path, 'r', encoding='utf-8')
304 + for line in input_file:
305 line = line.rstrip()
306 ngram, cost = line.split('\t')
307 cost = int(cost)
308 @@ -206,6 +206,7 @@
309 unigram[ngram] = cost
310 else:
311 trigram[ngram[:-1]][ngram[-1]] = cost
312 + input_file.close()
314 # Calculate ngram-related cost for each 'vw' and 'x':
315 # -500 * log( P('x' | 'vw') / P('x') )
316 --- /src/converter/gen_boundary_data.py
317 +++ /src/converter/gen_boundary_data.py
318 @@ -70,7 +70,8 @@
319 def LoadPatterns(file):
320 prefix = []
321 suffix = []
322 - for line in open(file, 'r'):
323 + fh = open(file, 'r')
324 + for line in fh:
325 if len(line) <= 1 or line[0] == '#':
326 continue
327 fields = line.split()
328 @@ -84,8 +85,9 @@
329 elif label == 'SUFFIX':
330 suffix.append([re.compile(PatternToRegexp(feature)), cost])
331 else:
332 - print 'format error %s' % (line)
333 + print('format error %s' % (line))
334 sys.exit(0)
335 + fh.close()
336 return (prefix, suffix)
339 @@ -100,19 +102,23 @@
341 def LoadFeatures(filename):
342 features = []
343 - for line in open(filename, 'r'):
344 + fh = open(filename, 'r')
345 + for line in fh:
346 fields = line.split()
347 features.append(fields[1])
348 + fh.close()
349 return features
352 def CountSpecialPos(filename):
353 count = 0
354 - for line in open(filename, 'r'):
355 + fh = open(filename, 'r')
356 + for line in fh:
357 line = line.rstrip()
358 if not line or line[0] == '#':
359 continue
360 count += 1
361 + fh.close()
362 return count
365 @@ -141,7 +147,7 @@
366 f.write(struct.pack('<H', GetCost(prefix, feature)))
367 f.write(struct.pack('<H', GetCost(suffix, feature)))
369 - for _ in xrange(num_special_pos):
370 + for _ in range(num_special_pos):
371 f.write(struct.pack('<H', 0))
372 f.write(struct.pack('<H', 0))
374 --- /src/converter/gen_quality_regression_test_data.py
375 +++ /src/converter/gen_quality_regression_test_data.py
376 @@ -84,7 +84,7 @@
377 else _ENABLED)
378 id = issue.attributes['id'].value
379 target = GetText(issue.getElementsByTagName('target'))
380 - for detail in issue.getElementsByTagName(u'detail'):
381 + for detail in issue.getElementsByTagName('detail'):
382 fields = []
383 fields.append('mozcsu_%s' % id)
384 for key in ('reading', 'output', 'actionStatus', 'rank', 'accuracy'):
385 @@ -104,19 +104,19 @@
387 def GenerateHeader(files):
388 try:
389 - print 'namespace mozc{'
390 - print 'struct TestCase {'
391 - print ' const bool enabled;'
392 - print ' const char *tsv;'
393 - print '} kTestData[] = {'
394 + print('namespace mozc{')
395 + print('struct TestCase {')
396 + print(' const bool enabled;')
397 + print(' const char *tsv;')
398 + print('} kTestData[] = {')
399 for file in files:
400 for enabled, line in ParseFile(file):
401 - print ' {%s, "%s"},' % (enabled, EscapeString(line))
402 - print ' {false, nullptr},'
403 - print '};'
404 - print '} // namespace mozc'
405 + print(' {%s, "%s"},' % (enabled, EscapeString(line)))
406 + print(' {false, nullptr},')
407 + print('};')
408 + print('} // namespace mozc')
409 except:
410 - print 'cannot open %s' % (file)
411 + print('cannot open %s' % (file))
412 sys.exit(1)
415 --- /src/converter/gen_segmenter_code.py
416 +++ /src/converter/gen_segmenter_code.py
417 @@ -54,18 +54,22 @@
418 pos = {}
419 max_id = 0
421 - for line in open(id_file, "r"):
422 + fh = open(id_file, "r")
423 + for line in fh:
424 fields = line.split()
425 pos[fields[1]] = fields[0]
426 max_id = max(int(fields[0]), max_id)
427 + fh.close()
429 max_id = max_id + 1
430 - for line in open(special_pos_file, "r"):
431 + fh = open(special_pos_file, "r")
432 + for line in fh:
433 if len(line) <= 1 or line[0] == '#':
434 continue
435 fields = line.split()
436 pos[fields[0]] = ("%d" % max_id)
437 max_id = max_id + 1
438 + fh.close()
440 return pos
442 @@ -79,8 +83,7 @@
443 pat = re.compile(PatternToRegexp(pattern))
444 min = -1;
445 max = -1;
446 - keys = pos.keys()
447 - keys.sort()
448 + keys = sorted(pos.keys())
450 range = []
452 @@ -107,7 +110,7 @@
453 tmp.append("(%s >= %s && %s <= %s)" % (name, r[0], name, r[1]))
455 if len(tmp) == 0:
456 - print "FATAL: No rule fiind %s" % (pattern)
457 + print("FATAL: No rule fiind %s" % (pattern))
458 sys.exit(-1)
460 return " || ".join(tmp)
461 @@ -115,19 +118,21 @@
462 def main():
463 pos = ReadPOSID(sys.argv[1], sys.argv[2])
465 - print HEADER % (len(pos.keys()), len(pos.keys()))
466 + print(HEADER % (len(pos.keys()), len(pos.keys())))
468 - for line in open(sys.argv[3], "r"):
469 + fh = open(sys.argv[3], "r")
470 + for line in fh:
471 if len(line) <= 1 or line[0] == '#':
472 continue
473 (l, r, result) = line.split()
474 result = result.lower()
475 lcond = GetRange(pos, l, "rid") or "true";
476 rcond = GetRange(pos, r, "lid") or "true";
477 - print " // %s %s %s" % (l, r, result)
478 - print " if ((%s) && (%s)) { return %s; }" % (lcond, rcond, result)
479 + print(" // %s %s %s" % (l, r, result))
480 + print(" if ((%s) && (%s)) { return %s; }" % (lcond, rcond, result))
481 + fh.close()
483 - print FOOTER
484 + print(FOOTER)
486 if __name__ == "__main__":
487 main()
488 --- /src/data_manager/gen_connection_data.py
489 +++ /src/data_manager/gen_connection_data.py
490 @@ -32,8 +32,7 @@
492 __author__ = "hidehiko"
494 -import cStringIO as StringIO
495 -import itertools
496 +import io
497 import logging
498 import optparse
499 import os
500 @@ -45,7 +44,7 @@
501 INVALID_COST = 30000
502 INVALID_1BYTE_COST = 255
503 RESOLUTION_FOR_1BYTE = 64
504 -FILE_MAGIC = '\xAB\xCD'
505 +FILE_MAGIC = b'\xAB\xCD'
507 FALSE_VALUES = ['f', 'false', '0']
508 TRUE_VALUES = ['t', 'true', '1']
509 @@ -79,28 +78,28 @@
510 # The result is a square matrix.
511 mat_size = pos_size + special_pos_size
513 - matrix = [[0] * mat_size for _ in xrange(mat_size)]
514 + matrix = [[0] * mat_size for _ in range(mat_size)]
515 with open(text_connection_file) as stream:
516 stream = code_generator_util.SkipLineComment(stream)
517 # The first line contains the matrix column/row size.
518 - size = stream.next().rstrip()
519 + size = next(stream).rstrip()
520 assert (int(size) == pos_size), '%s != %d' % (size, pos_size)
522 for array_index, cost in enumerate(stream):
523 cost = int(cost.rstrip())
524 - rid = array_index / pos_size
525 + rid = array_index // pos_size
526 lid = array_index % pos_size
527 if rid == 0 and lid == 0:
528 cost = 0
529 matrix[rid][lid] = cost
531 # Fill INVALID_COST in matrix elements for special POS.
532 - for rid in xrange(pos_size, mat_size):
533 - for lid in xrange(1, mat_size): # Skip EOS
534 + for rid in range(pos_size, mat_size):
535 + for lid in range(1, mat_size): # Skip EOS
536 matrix[rid][lid] = INVALID_COST
538 - for lid in xrange(pos_size, mat_size):
539 - for rid in xrange(1, mat_size): # Skip BOS
540 + for lid in range(pos_size, mat_size):
541 + for rid in range(1, mat_size): # Skip BOS
542 matrix[rid][lid] = INVALID_COST
544 return matrix
545 @@ -116,7 +115,7 @@
546 # Heuristically, we do not compress INVALID_COST.
547 continue
548 m[cost] = m.get(cost, 0) + 1
549 - mode_value = max(m.iteritems(), key=lambda (_, count): count)[0]
550 + mode_value = max(m.items(), key=lambda x: x[1])[0]
551 result.append(mode_value)
552 return result
554 @@ -126,8 +125,8 @@
555 # list, and fill None into the matrix if it equals to the corresponding
556 # mode value.
557 assert len(matrix) == len(mode_value_list)
558 - for row, mode_value in itertools.izip(matrix, mode_value_list):
559 - for index in xrange(len(row)):
560 + for row, mode_value in zip(matrix, mode_value_list):
561 + for index in range(len(row)):
562 if row[index] == mode_value:
563 row[index] = None
565 @@ -179,7 +178,7 @@
566 resolution = RESOLUTION_FOR_1BYTE
567 else:
568 resolution = 1
569 - stream = StringIO.StringIO()
570 + stream = io.BytesIO()
572 # Output header.
573 stream.write(FILE_MAGIC)
574 @@ -194,7 +193,7 @@
576 # 4 bytes alignment.
577 if len(mode_value_list) % 2:
578 - stream.write('\x00\x00')
579 + stream.write(b'\x00\x00')
581 # Process each row:
582 for row in matrix:
583 @@ -218,7 +217,7 @@
584 if cost == INVALID_COST:
585 cost = INVALID_1BYTE_COST
586 else:
587 - cost /= resolution
588 + cost //= resolution
589 assert cost != INVALID_1BYTE_COST
590 values.append(cost)
592 @@ -237,7 +236,7 @@
593 values_size = len(values) * 2
595 # Output the bits for a row.
596 - stream.write(struct.pack('<HH', len(compact_bits) / 8, values_size))
597 + stream.write(struct.pack('<HH', len(compact_bits) // 8, values_size))
598 OutputBitList(chunk_bits, stream)
599 OutputBitList(compact_bits, stream)
600 if use_1byte_cost: