net-misc/rustdesk: update deps
[gentoo-zh.git] / app-i18n / mozc / files / mozc-2.23.2815.102-python-3_1.patch
blob2b9bbd720cde61c0d752945a9221bd49083fa0b6
1 https://github.com/google/mozc/issues/462
3 --- /src/base/gen_character_set.py
4 +++ /src/base/gen_character_set.py
5 @@ -33,7 +33,6 @@
6 import itertools
7 import optparse
8 import re
9 -import string
10 import sys
13 @@ -89,7 +88,8 @@
14 @staticmethod
15 def _LoadTable(filename, column_index, pattern, validater):
16 result = set()
17 - for line in open(filename):
18 + fh = open(filename)
19 + for line in fh:
20 if line.startswith('#'):
21 # Skip a comment line.
22 continue
23 @@ -100,6 +100,7 @@
24 ucs = int(match.group(1), 16)
25 if validater(ucs):
26 result.add(ucs)
27 + fh.close()
29 return result
31 @@ -250,7 +251,7 @@
32 # (at most) four code points.
33 bit_list = []
34 for _, group in itertools.groupby(enumerate(category_list),
35 - lambda (codepoint, _): codepoint / 4):
36 + lambda x: x[0] // 4):
37 # Fill bits from LSB to MSB for each group.
38 bits = 0
39 for index, (_, category) in enumerate(group):
40 @@ -263,7 +264,7 @@
42 # Output the content. Each line would have (at most) 16 bytes.
43 for _, group in itertools.groupby(enumerate(bit_list),
44 - lambda (index, _): index / 16):
45 + lambda x: x[0] // 16):
46 line = [' \"']
47 for _, bits in group:
48 line.append('\\x%02X' % bits)
49 @@ -386,7 +387,7 @@
50 # Bitmap lookup.
51 # TODO(hidehiko): the bitmap has two huge 0-bits ranges. Reduce them.
52 category_map = [
53 - (bits, category) for category, bits in CATEGORY_BITMAP.iteritems()]
54 + (bits, category) for category, bits in CATEGORY_BITMAP.items()]
55 category_map.sort()
57 lines.extend([
58 @@ -451,7 +452,7 @@
59 options.jisx0213file)
60 category_list = [
61 categorizer.GetCategory(codepoint)
62 - for codepoint in xrange(categorizer.MaxCodePoint() + 1)]
63 + for codepoint in range(categorizer.MaxCodePoint() + 1)]
64 generated_character_set_header = GenerateCharacterSetHeader(category_list)
66 # Write the result.
67 --- /src/base/gen_config_file_stream_data.py
68 +++ /src/base/gen_config_file_stream_data.py
69 @@ -58,7 +58,7 @@
70 result = []
71 result.append(' { "%s", "' % os.path.basename(path))
72 with open(path, 'rb') as stream:
73 - result.extend(r'\x%02X' % ord(byte) for byte in stream.read())
74 + result.extend(r'\x%02X' % byte for byte in stream.read())
75 result.append('", %d }' % os.path.getsize(path))
77 return ''.join(result)
78 @@ -93,8 +93,8 @@
79 def main():
80 (options, args) = ParseOptions()
81 if not options.output:
82 - print >>sys.stderr, (
83 - 'usage: gen_config_file_stream_data.py --output=filepath input ...')
84 + print('usage: gen_config_file_stream_data.py --output=filepath input ...',
85 + file=sys.stderr)
86 sys.exit(2)
88 with open(options.output, 'w') as output:
89 --- /src/build_mozc.py
90 +++ /src/build_mozc.py
91 @@ -943,7 +943,7 @@
92 logging.info('running %s...', binary)
93 try:
94 test_function(binary, gtest_report_dir, options)
95 - except RunOrDieError, e:
96 + except RunOrDieError as e:
97 logging.error(e)
98 failed_tests.append(binary)
99 else:
100 @@ -1082,7 +1082,7 @@
101 # and '-c' and 'Release' are build options.
102 targets = []
103 build_options = []
104 - for i in xrange(len(args)):
105 + for i in range(len(args)):
106 if args[i].startswith('-'):
107 # starting with build options
108 build_options = args[i:]
109 @@ -1190,14 +1190,14 @@
111 def ShowHelpAndExit():
112 """Shows the help message."""
113 - print 'Usage: build_mozc.py COMMAND [ARGS]'
114 - print 'Commands: '
115 - print ' gyp Generate project files.'
116 - print ' build Build the specified target.'
117 - print ' runtests Build all tests and run them.'
118 - print ' clean Clean all the build files and directories.'
119 - print ''
120 - print 'See also the comment in the script for typical usage.'
121 + print('Usage: build_mozc.py COMMAND [ARGS]')
122 + print('Commands: ')
123 + print(' gyp Generate project files.')
124 + print(' build Build the specified target.')
125 + print(' runtests Build all tests and run them.')
126 + print(' clean Clean all the build files and directories.')
127 + print('')
128 + print('See also the comment in the script for typical usage.')
129 sys.exit(1)
132 --- /src/build_tools/android_util.py
133 +++ /src/build_tools/android_util.py
134 @@ -548,7 +548,7 @@
135 (devices_result, _) = process.communicate()
136 used_ports = set(int(port) for port
137 in re.findall(r'emulator-(\d+)', devices_result))
138 - return [port for port in xrange(5554, 5586, 2) if port not in used_ports]
139 + return [port for port in range(5554, 5586, 2) if port not in used_ports]
142 def SetUpTestingSdkHomeDirectory(dest_android_sdk_home,
143 @@ -575,7 +575,7 @@
144 'create', 'avd',
145 '--force',
146 '--sdcard', '512M',]
147 - for key, value in options.iteritems():
148 + for key, value in options.items():
149 args.extend([key, value])
150 env = {'ANDROID_SDK_HOME': os.path.abspath(dest_android_sdk_home)}
151 logging.info('Creating AVD: %s', args)
152 @@ -615,7 +615,7 @@
153 def main():
154 for arg in sys.argv[1:]:
155 for item in sorted(GetApkProperties(arg).items()):
156 - print '%s: %s' % item
157 + print('%s: %s' % item)
160 if __name__ == '__main__':
161 --- /src/build_tools/binary_size_checker.py
162 +++ /src/build_tools/binary_size_checker.py
163 @@ -70,12 +70,12 @@
164 actual_size = os.stat(filename).st_size
165 expected_size = EXPECTED_MAXIMUM_SIZES[basename]
166 if actual_size < expected_size * 1024 * 1024:
167 - print 'Pass: %s (size: %d) is smaller than expected (%d MB)' % (
168 - filename, actual_size, expected_size)
169 + print('Pass: %s (size: %d) is smaller than expected (%d MB)' % (
170 + filename, actual_size, expected_size))
171 return True
172 else:
173 - print 'WARNING: %s (size: %d) is larger than expected (%d MB)' % (
174 - filename, actual_size, expected_size)
175 + print('WARNING: %s (size: %d) is larger than expected (%d MB)' % (
176 + filename, actual_size, expected_size))
177 return False
180 --- /src/build_tools/build_and_sign_pkg_mac.py
181 +++ /src/build_tools/build_and_sign_pkg_mac.py
182 @@ -44,8 +44,8 @@
183 import shutil
184 import sys
186 -from util import PrintErrorAndExit
187 -from util import RunOrDie
188 +from .util import PrintErrorAndExit
189 +from .util import RunOrDie
192 def ParseOption():
193 --- /src/build_tools/build_breakpad.py
194 +++ /src/build_tools/build_breakpad.py
195 @@ -54,9 +54,9 @@
196 try:
197 subprocess.check_output(command)
198 except subprocess.CalledProcessError as e:
199 - print e.output
200 + print(e.output)
201 sys.exit(e.returncode)
202 - print 'Done: %s' % ' '.join(command)
203 + print('Done: %s' % ' '.join(command))
206 def Xcodebuild(projdir, target, arch, sdk, outdir):
207 --- /src/build_tools/build_diskimage_mac.py
208 +++ /src/build_tools/build_diskimage_mac.py
209 @@ -90,7 +90,7 @@
210 # setup volume directory
211 temp_dir = tempfile.mkdtemp()
212 CopyFile(path.join(build_dir, ".keystone_install"), temp_dir)
213 - os.chmod(path.join(temp_dir, ".keystone_install"), 0755) # rwxr-xr-x
214 + os.chmod(path.join(temp_dir, ".keystone_install"), 0o755) # rwxr-xr-x
215 for a in args:
216 CopyFile(path.join(build_dir, a), temp_dir)
218 --- /src/build_tools/change_reference_mac.py
219 +++ /src/build_tools/change_reference_mac.py
220 @@ -41,8 +41,8 @@
221 import optparse
222 import os
224 -from util import PrintErrorAndExit
225 -from util import RunOrDie
226 +from .util import PrintErrorAndExit
227 +from .util import RunOrDie
230 def ParseOption():
231 --- /src/build_tools/code_generator_util.py
232 +++ /src/build_tools/code_generator_util.py
233 @@ -33,27 +33,26 @@
234 __author__ = "hidehiko"
236 import struct
237 -import types
240 def ToCppStringLiteral(s):
241 """Returns C-style string literal, or NULL if given s is None."""
242 if s is None:
243 - return 'NULL'
244 + return b'NULL'
246 - if all(0x20 <= ord(c) <= 0x7E for c in s):
247 + if all(0x20 <= c <= 0x7E for c in s):
248 # All characters are in ascii code.
249 - return '"%s"' % s.replace('\\', r'\\').replace('"', r'\"')
250 + return b'"%b"' % s.replace(b'\\', br'\\').replace(b'"', br'\"')
251 else:
252 # One or more characters are non-ascii.
253 - return '"%s"' % ''.join(r'\x%02X' % ord(c) for c in s)
254 + return b'"%b"' % b''.join(br'\x%02X' % c for c in s)
257 def FormatWithCppEscape(format_text, *args):
258 """Returns a string filling format with args."""
259 literal_list = []
260 for arg in args:
261 - if isinstance(arg, (types.StringType, types.NoneType)):
262 + if isinstance(arg, (bytes, type(None))):
263 arg = ToCppStringLiteral(arg)
264 literal_list.append(arg)
266 @@ -95,7 +94,7 @@
267 if target_compiler and target_compiler.startswith('msvs'):
268 stream.write('const uint64 k%s_data_wordtype[] = {\n' % variable_name)
270 - for word_index in xrange(0, len(data), 8):
271 + for word_index in range(0, len(data), 8):
272 word_chunk = data[word_index:word_index + 8].ljust(8, '\x00')
273 stream.write('0x%016X, ' % struct.unpack('<Q', word_chunk))
274 if (word_index / 8) % 4 == 3:
275 @@ -111,7 +110,7 @@
276 stream.write('const char k%s_data[] =\n' % variable_name)
277 # Output 16bytes per line.
278 chunk_size = 16
279 - for index in xrange(0, len(data), chunk_size):
280 + for index in range(0, len(data), chunk_size):
281 chunk = data[index:index + chunk_size]
282 stream.write('"')
283 stream.writelines(r'\x%02X' % ord(c) for c in chunk)
284 @@ -126,36 +125,50 @@
285 if type(codepoint_list) is int:
286 codepoint_list = (codepoint_list,)
287 if codepoint_list is None or len(codepoint_list) == 0:
288 - return 'null'
289 - result = r'"'
290 + return b'null'
291 + result = b'"'
292 for codepoint in codepoint_list:
293 - utf16_string = unichr(codepoint).encode('utf-16be')
294 + utf16_string = chr(codepoint).encode('utf-16be')
295 if len(utf16_string) == 2:
296 (u0, l0) = utf16_string
297 - result += r'\u%02X%02X' % (ord(u0), ord(l0))
298 + result += br'\u%02X%02X' % (u0, l0)
299 else:
300 (u0, l0, u1, l1) = utf16_string
301 - result += r'\u%02X%02X\u%02X%02X' % (ord(u0), ord(l0), ord(u1), ord(l1))
302 - result += r'"'
303 + result += br'\u%02X%02X\u%02X%02X' % (u0, l0, u1, l1)
304 + result += b'"'
305 return result
308 def SkipLineComment(stream, comment_prefix='#'):
309 """Skips line comments from stream."""
310 for line in stream:
311 + if isinstance(line, bytes):
312 + if isinstance(comment_prefix, str):
313 + comment_prefix = comment_prefix.encode('utf-8')
314 + line_ending = b'\n'
315 + else:
316 + line_ending = '\n'
317 stripped_line = line.strip()
318 if stripped_line and not stripped_line.startswith(comment_prefix):
319 - yield line.rstrip('\n')
320 + yield line.rstrip(line_ending)
323 def ParseColumnStream(stream, num_column=None, delimiter=None):
324 """Returns parsed columns read from stream."""
325 if num_column is None:
326 for line in stream:
327 - yield line.rstrip('\n').split(delimiter)
328 + if isinstance(line, bytes):
329 + line_ending = b'\n'
330 + else:
331 + line_ending = '\n'
332 + yield line.rstrip(line_ending).split(delimiter)
333 else:
334 for line in stream:
335 - yield line.rstrip('\n').split(delimiter)[:num_column]
336 + if isinstance(line, bytes):
337 + line_ending = b'\n'
338 + else:
339 + line_ending = '\n'
340 + yield line.rstrip(line_ending).split(delimiter)[:num_column]
343 def SelectColumn(stream, column_index):
344 @@ -172,5 +185,5 @@
345 grouper extends the last chunk to make it an n-element chunk by adding
346 appropriate value, but this returns truncated chunk.
348 - for index in xrange(0, len(iterable), n):
349 + for index in range(0, len(iterable), n):
350 yield iterable[index:index + n]
351 --- /src/build_tools/codesign_mac.py
352 +++ /src/build_tools/codesign_mac.py
353 @@ -46,17 +46,17 @@
355 def RunOrDie(command):
356 """Run the command, or die if it failed."""
357 - print "Running: " + command
358 + print("Running: " + command)
359 try:
360 output = subprocess.check_output(command, shell=True)
361 - print >> sys.stderr, "=========="
362 - print >> sys.stderr, "COMMAND: " + command
363 - print >> sys.stderr, output
364 + print("==========", file=sys.stderr)
365 + print("COMMAND: " + command, file=sys.stderr)
366 + print(output, file=sys.stderr)
367 except subprocess.CalledProcessError as e:
368 - print >> sys.stderr, "=========="
369 - print >> sys.stderr, "ERROR: " + command
370 - print >> sys.stderr, e.output
371 - print >> sys.stderr, "=========="
372 + print("==========", file=sys.stderr)
373 + print("ERROR: " + command, file=sys.stderr)
374 + print(e.output, file=sys.stderr)
375 + print("==========", file=sys.stderr)
376 sys.exit(1)
379 @@ -119,18 +119,18 @@
380 (options, unused_args) = parser.parse_args()
382 if not options.target:
383 - print "Error: --target should be specified."
384 - print parser.print_help()
385 + print("Error: --target should be specified.")
386 + print(parser.print_help())
387 sys.exit(1)
389 return options
392 def DumpEnviron():
393 - print "=== os.environ ==="
394 + print("=== os.environ ===")
395 for key in sorted(os.environ):
396 - print "%s = %s" % (key, os.getenv(key))
397 - print "=================="
398 + print("%s = %s" % (key, os.getenv(key)))
399 + print("==================")
402 def main():
403 --- /src/build_tools/copy_dll_and_symbol.py
404 +++ /src/build_tools/copy_dll_and_symbol.py
405 @@ -38,7 +38,7 @@
406 import os
407 import shutil
409 -from util import PrintErrorAndExit
410 +from .util import PrintErrorAndExit
412 def ParseOption():
413 """Parse command line options."""
414 @@ -98,7 +98,7 @@
415 if _GetLastModifiedTime(src) <= target_file_mtime:
416 # Older file found. Ignore.
417 continue
418 - print 'Copying %s to %s' % (src, target_file_abspath)
419 + print('Copying %s to %s' % (src, target_file_abspath))
420 shutil.copy2(src, target_file_abspath)
421 break
423 --- /src/build_tools/copy_file.py
424 +++ /src/build_tools/copy_file.py
425 @@ -52,7 +52,7 @@
426 Args:
427 message: The error message to be printed to stderr.
429 - print >>sys.stderr, message
430 + print(message, file=sys.stderr)
431 sys.exit(1)
434 --- /src/build_tools/copy_qt_frameworks_mac.py
435 +++ /src/build_tools/copy_qt_frameworks_mac.py
436 @@ -41,9 +41,9 @@
437 import optparse
438 import os
440 -from copy_file import CopyFiles
441 -from util import PrintErrorAndExit
442 -from util import RunOrDie
443 +from .copy_file import CopyFiles
444 +from .util import PrintErrorAndExit
445 +from .util import RunOrDie
448 def ParseOption():
449 --- /src/build_tools/embed_file.py
450 +++ /src/build_tools/embed_file.py
451 @@ -46,10 +46,10 @@
453 def _FormatAsUint64LittleEndian(s):
454 """Formats a string as uint64 value in little endian order."""
455 - for _ in xrange(len(s), 8):
456 - s += '\0'
457 + for _ in range(len(s), 8):
458 + s += b'\0'
459 s = s[::-1] # Reverse the string
460 - return '0x%s' % binascii.b2a_hex(s)
461 + return b'0x%b' % binascii.b2a_hex(s)
464 def main():
465 @@ -57,30 +57,30 @@
466 with open(opts.input, 'rb') as infile:
467 with open(opts.output, 'wb') as outfile:
468 outfile.write(
469 - '#ifdef MOZC_EMBEDDED_FILE_%(name)s\n'
470 - '#error "%(name)s was already included or defined elsewhere"\n'
471 - '#else\n'
472 - '#define MOZC_EMBEDDED_FILE_%(name)s\n'
473 - 'const uint64 %(name)s_data[] = {\n'
474 - % {'name': opts.name})
475 + b'#ifdef MOZC_EMBEDDED_FILE_%(name)b\n'
476 + b'#error "%(name)b was already included or defined elsewhere"\n'
477 + b'#else\n'
478 + b'#define MOZC_EMBEDDED_FILE_%(name)b\n'
479 + b'const uint64 %(name)b_data[] = {\n'
480 + % {b'name': opts.name.encode('utf-8')})
482 while True:
483 chunk = infile.read(8)
484 if not chunk:
485 break
486 - outfile.write(' ')
487 + outfile.write(b' ')
488 outfile.write(_FormatAsUint64LittleEndian(chunk))
489 - outfile.write(',\n')
490 + outfile.write(b',\n')
492 outfile.write(
493 - '};\n'
494 - 'const EmbeddedFile %(name)s = {\n'
495 - ' %(name)s_data,\n'
496 - ' %(size)d,\n'
497 - '};\n'
498 - '#endif // MOZC_EMBEDDED_FILE_%(name)s\n'
499 - % {'name': opts.name,
500 - 'size': os.stat(opts.input).st_size})
501 + b'};\n'
502 + b'const EmbeddedFile %(name)b = {\n'
503 + b' %(name)b_data,\n'
504 + b' %(size)d,\n'
505 + b'};\n'
506 + b'#endif // MOZC_EMBEDDED_FILE_%(name)b\n'
507 + % {b'name': opts.name.encode('utf-8'),
508 + b'size': os.stat(opts.input).st_size})
511 if __name__ == '__main__':
512 --- /src/build_tools/embed_pathname.py
513 +++ /src/build_tools/embed_pathname.py
514 @@ -28,7 +28,7 @@
515 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
516 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
518 -"""A script to embed the given (relative) path name to C/C++ characters array.
519 +r"""A script to embed the given (relative) path name to C/C++ characters array.
521 Example:
522 ./embed_pathname.py --path_to_be_embedded=d:\data\mozc
523 @@ -53,7 +53,7 @@
525 (options, unused_args) = parser.parse_args()
526 if not all(vars(options).values()):
527 - print parser.print_help()
528 + print(parser.print_help())
529 sys.exit(1)
531 return options
532 @@ -63,7 +63,7 @@
533 opt = ParseOption()
534 path = os.path.abspath(opt.path_to_be_embedded)
535 # TODO(yukawa): Consider the case of non-ASCII characters.
536 - escaped_path = path.encode('string-escape')
537 + escaped_path = path.replace('\\', '\\\\')
538 with open(opt.output, 'w') as output_file:
539 output_file.write(
540 'const char %s[] = "%s";\n' % (opt.constant_name, escaped_path))
541 --- /src/build_tools/ensure_gyp_module_path.py
542 +++ /src/build_tools/ensure_gyp_module_path.py
543 @@ -48,7 +48,7 @@
545 (options, _) = parser.parse_args()
546 if not options.expected:
547 - print parser.print_help()
548 + print(parser.print_help())
549 sys.exit(1)
551 return options
552 @@ -59,20 +59,20 @@
553 opt = ParseOption()
554 expected_path = os.path.abspath(opt.expected)
555 if not os.path.exists(expected_path):
556 - print '%s does not exist.' % expected_path
557 + print('%s does not exist.' % expected_path)
558 sys.exit(1)
560 try:
561 import gyp # NOLINT
562 except ImportError as e:
563 - print 'import gyp failed: %s' % e
564 + print('import gyp failed: %s' % e)
565 sys.exit(1)
567 actual_path = os.path.abspath(gyp.__path__[0])
568 if expected_path != actual_path:
569 - print 'Unexpected gyp module is loaded on this environment.'
570 - print ' expected: %s' % expected_path
571 - print ' actual : %s' % actual_path
572 + print('Unexpected gyp module is loaded on this environment.')
573 + print(' expected: %s' % expected_path)
574 + print(' actual : %s' % actual_path)
575 sys.exit(1)
577 if __name__ == '__main__':
578 --- /src/build_tools/gen_win32_resource_header.py
579 +++ /src/build_tools/gen_win32_resource_header.py
580 @@ -39,7 +39,7 @@
581 __author__ = "yukawa"
583 import logging
584 -import mozc_version
585 +from . import mozc_version
586 import optparse
587 import os
588 import sys
589 --- /src/build_tools/mozc_version.py
590 +++ /src/build_tools/mozc_version.py
591 @@ -94,7 +94,7 @@
592 last_digit = TARGET_PLATFORM_TO_DIGIT.get(target_platform, None)
593 if last_digit is None:
594 logging.critical('target_platform %s is invalid. Accetable ones are %s',
595 - target_platform, TARGET_PLATFORM_TO_DIGIT.keys())
596 + target_platform, list(TARGET_PLATFORM_TO_DIGIT.keys()))
597 sys.exit(1)
599 if not revision:
600 @@ -314,13 +314,14 @@
601 self._properties = {}
602 if not os.path.isfile(path):
603 return
604 - for line in open(path):
605 - matchobj = re.match(r'(\w+)=(.*)', line.strip())
606 - if matchobj:
607 - var = matchobj.group(1)
608 - val = matchobj.group(2)
609 - if var not in self._properties:
610 - self._properties[var] = val
611 + with open(path) as file:
612 + for line in file:
613 + matchobj = re.match(r'(\w+)=(.*)', line.strip())
614 + if matchobj:
615 + var = matchobj.group(1)
616 + val = matchobj.group(2)
617 + if var not in self._properties:
618 + self._properties[var] = val
620 # Check mandatory properties.
621 for key in VERSION_PROPERTIES: