summaryrefslogtreecommitdiff
path: root/app-i18n/mozc/files/mozc-2.23.2815.102-python-3_3.patch
blob: a5c5a2dc8038db657c2ac12be89a4b9eeb5e734e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
https://github.com/google/mozc/issues/462

--- /src/dictionary/gen_pos_map.py
+++ /src/dictionary/gen_pos_map.py
@@ -39,7 +39,7 @@
 from build_tools import code_generator_util
 
 
-HEADER = """// Copyright 2009 Google Inc. All Rights Reserved.
+HEADER = b"""// Copyright 2009 Google Inc. All Rights Reserved.
 // Author: keni
 
 #ifndef MOZC_DICTIONARY_POS_MAP_H_
@@ -48,13 +48,13 @@
 // POS conversion rules
 const POSMap kPOSMap[] = {
 """
-FOOTER = """};
+FOOTER = b"""};
 
 #endif  // MOZC_DICTIONARY_POS_MAP_H_
 """
 
 def ParseUserPos(user_pos_file):
-  with open(user_pos_file, 'r') as stream:
+  with open(user_pos_file, 'rb') as stream:
     stream = code_generator_util.SkipLineComment(stream)
     stream = code_generator_util.ParseColumnStream(stream, num_column=2)
     return dict((key, enum_value) for key, enum_value in stream)
@@ -64,7 +64,7 @@
   user_pos_map = ParseUserPos(user_pos_file)
 
   result = {}
-  with open(third_party_pos_map_file, 'r') as stream:
+  with open(third_party_pos_map_file, 'rb') as stream:
     stream = code_generator_util.SkipLineComment(stream)
     for columns in code_generator_util.ParseColumnStream(stream, num_column=2):
       third_party_pos_name, mozc_pos = (columns + [None])[:2]
@@ -78,7 +78,7 @@
       result[third_party_pos_name] = mozc_pos
 
   # Create mozc_pos to mozc_pos map.
-  for key, value in user_pos_map.iteritems():
+  for key, value in user_pos_map.items():
     if key in result:
       assert (result[key] == value)
       continue
@@ -94,10 +94,10 @@
     if value is None:
       # Invalid PosType.
       value = (
-          'static_cast< ::mozc::user_dictionary::UserDictionary::PosType>(-1)')
+          b'static_cast< ::mozc::user_dictionary::UserDictionary::PosType>(-1)')
     else:
-      value = '::mozc::user_dictionary::UserDictionary::' + value
-    output.write('  { %s, %s },\n' % (key, value))
+      value = b'::mozc::user_dictionary::UserDictionary::' + value
+    output.write(b'  { %s, %s },\n' % (key, value))
   output.write(FOOTER)
 
 
@@ -121,7 +121,7 @@
   pos_map = GeneratePosMap(options.third_party_pos_map_file,
                            options.user_pos_file)
 
-  with open(options.output, 'w') as stream:
+  with open(options.output, 'wb') as stream:
     OutputPosMap(pos_map, stream)
 
 
--- /src/dictionary/gen_pos_rewrite_rule.py
+++ /src/dictionary/gen_pos_rewrite_rule.py
@@ -46,29 +46,34 @@
 
 
 def LoadRewriteMapRule(filename):
-  fh = open(filename)
+  fh = open(filename, 'rb')
   rule = []
   for line in fh:
-    line = line.rstrip('\n')
-    if not line or line.startswith('#'):
+    line = line.rstrip(b'\n')
+    if not line or line.startswith(b'#'):
       continue
     fields = line.split()
     rule.append([fields[0], fields[1]])
+  fh.close()
   return rule
 
 
 def ReadPOSID(id_file, special_pos_file):
   pos_list = []
 
-  for line in open(id_file, 'r'):
+  fh = open(id_file, 'rb')
+  for line in fh:
     fields = line.split()
     pos_list.append(fields[1])
+  fh.close()
 
-  for line in open(special_pos_file, 'r'):
-    if len(line) <= 1 or line[0] == '#':
+  fh = open(special_pos_file, 'rb')
+  for line in fh:
+    if len(line) <= 1 or line[0:1] == b'#':
       continue
     fields = line.split()
     pos_list.append(fields[0])
+  fh.close()
 
   return pos_list
 
@@ -112,7 +117,7 @@
     ids.append(id)
 
   with open(opts.output, 'wb') as f:
-    f.write(''.join(chr(id) for id in ids))
+    f.write(''.join(chr(id) for id in ids).encode('utf-8'))
 
 
 if __name__ == '__main__':
--- /src/dictionary/gen_suffix_data.py
+++ /src/dictionary/gen_suffix_data.py
@@ -52,10 +52,10 @@
   opts = _ParseOptions()
 
   result = []
-  with open(opts.input, 'r') as stream:
+  with open(opts.input, 'rb') as stream:
     for line in stream:
-      line = line.rstrip('\r\n')
-      fields = line.split('\t')
+      line = line.rstrip(b'\r\n')
+      fields = line.split(b'\t')
       key = fields[0]
       lid = int(fields[1])
       rid = int(fields[2])
@@ -63,7 +63,7 @@
       value = fields[4]
 
       if key == value:
-        value = ''
+        value = b''
 
       result.append((key, value, lid, rid, cost))
 
--- /src/dictionary/gen_user_pos_data.py
+++ /src/dictionary/gen_user_pos_data.py
@@ -64,7 +64,7 @@
         f.write(struct.pack('<H', conjugation_id))
 
   serialized_string_array_builder.SerializeToFile(
-      sorted(string_index.iterkeys()), output_string_array)
+      sorted(x.encode('utf-8') for x in string_index.keys()), output_string_array)
 
 
 def ParseOptions():
@@ -100,7 +100,7 @@
 
   if options.output_pos_list:
     serialized_string_array_builder.SerializeToFile(
-        [pos for (pos, _) in user_pos.data], options.output_pos_list)
+        [pos.encode('utf-8') for (pos, _) in user_pos.data], options.output_pos_list)
 
 
 if __name__ == '__main__':
--- /src/dictionary/gen_zip_code_seed.py
+++ /src/dictionary/gen_zip_code_seed.py
@@ -83,7 +83,7 @@
     address = unicodedata.normalize('NFKC', self.address)
     line = '\t'.join([zip_code, '0', '0', str(ZIP_CODE_COST),
                       address, ZIP_CODE_LABEL])
-    print line.encode('utf-8')
+    print(line.encode('utf-8'))
 
 
 def ProcessZipCodeCSV(file_name):
@@ -105,26 +105,26 @@
 
 def ReadZipCodeEntries(zip_code, level1, level2, level3):
   """Read zip code entries."""
-  return [ZipEntry(zip_code, u''.join([level1, level2, town]))
+  return [ZipEntry(zip_code, ''.join([level1, level2, town]))
           for town in ParseTownName(level3)]
 
 
 def ReadJigyosyoEntry(zip_code, level1, level2, level3, name):
   """Read jigyosyo entry."""
   return ZipEntry(zip_code,
-                  u''.join([level1, level2, level3, u' ', name]))
+                  ''.join([level1, level2, level3, ' ', name]))
 
 
 def ParseTownName(level3):
   """Parse town name."""
-  if level3.find(u'以下に掲載がない場合') != -1:
+  if level3.find('以下に掲載がない場合') != -1:
     return ['']
 
   assert CanParseAddress(level3), ('failed to be merged %s'
                                    % level3.encode('utf-8'))
 
   # We ignore additional information here.
-  level3 = re.sub(u'(.*)', u'', level3, re.U)
+  level3 = re.sub('(.*)', '', level3, re.U)
 
   # For 地割, we have these cases.
   #  XX1地割
@@ -134,7 +134,7 @@
   #  XX第1地割、XX第2地割、
   #  XX第1地割〜XX第2地割、
   # We simply use XX for them.
-  chiwari_match = re.match(u'(\D*?)第?\d+地割.*', level3, re.U)
+  chiwari_match = re.match('(\D*?)第?\d+地割.*', level3, re.U)
   if chiwari_match:
     town = chiwari_match.group(1)
     return [town]
@@ -144,21 +144,21 @@
   #   -> XX町YY and (XX町)ZZ
   #  YY、ZZ
   #   -> YY and ZZ
-  chou_match = re.match(u'(.*町)?(.*)', level3, re.U)
+  chou_match = re.match('(.*町)?(.*)', level3, re.U)
   if chou_match:
-    chou = u''
+    chou = ''
     if chou_match.group(1):
       chou = chou_match.group(1)
     rests = chou_match.group(2)
-    return [chou + rest for rest in rests.split(u'、')]
+    return [chou + rest for rest in rests.split('、')]
 
   return [level3]
 
 
 def CanParseAddress(address):
   """Return true for valid address."""
-  return (address.find(u'(') == -1 or
-          address.find(u')') != -1)
+  return (address.find('(') == -1 or
+          address.find(')') != -1)
 
 
 def ParseOptions():
--- /src/dictionary/zip_code_util.py
+++ /src/dictionary/zip_code_util.py
@@ -86,11 +86,11 @@
 
 
 _SPECIAL_CASES = [
-    SpecialMergeZip(u'5900111', u'大阪府', u'堺市中区', [u'三原台']),
-    SpecialMergeZip(u'8710046', u'大分県', u'中津市',
-                    [u'金谷', u'西堀端', u'東堀端', u'古金谷']),
-    SpecialMergeZip(u'9218046', u'石川県', u'金沢市',
-                    [u'大桑町', u'三小牛町']),
+    SpecialMergeZip('5900111', '大阪府', '堺市中区', ['三原台']),
+    SpecialMergeZip('8710046', '大分県', '中津市',
+                    ['金谷', '西堀端', '東堀端', '古金谷']),
+    SpecialMergeZip('9218046', '石川県', '金沢市',
+                    ['大桑町', '三小牛町']),
     ]
 
 
--- /src/gui/character_pad/data/gen_cp932_map.py
+++ /src/gui/character_pad/data/gen_cp932_map.py
@@ -32,7 +32,6 @@
 
 import re
 import sys
-import string
 
 kUnicodePat = re.compile(r'0x[0-9A-Fa-f]{2,4}')
 def IsValidUnicode(n):
@@ -42,28 +41,29 @@
   fh = open(sys.argv[1])
   result = {}
   for line in fh.readlines():
-    if line[0] is '#':
+    if line[0] == '#':
       continue
-    array = string.split(line)
+    array = line.split()
     sjis = array[0]
     ucs2 = array[1]
     if eval(sjis) < 32 or not IsValidUnicode(ucs2):
       continue
     result.setdefault(ucs2, sjis)
+  fh.close()
 
   keys = sorted(result.keys())
 
-  print "struct CP932MapData {"
-  print "  unsigned int ucs4;"
-  print "  unsigned short int sjis;"
-  print "};"
-  print ""
-  print "static const size_t kCP932MapDataSize = %d;" % (len(keys))
-  print "static const CP932MapData kCP932MapData[] = {"
+  print("struct CP932MapData {")
+  print("  unsigned int ucs4;")
+  print("  unsigned short int sjis;")
+  print("};")
+  print("")
+  print("static const size_t kCP932MapDataSize = %d;" % (len(keys)))
+  print("static const CP932MapData kCP932MapData[] = {")
   for n in keys:
-    print "  { %s, %s }," % (n ,result[n])
-  print "  { 0, 0 }";
-  print "};"
+    print("  { %s, %s }," % (n ,result[n]))
+  print("  { 0, 0 }");
+  print("};")
 
 if __name__ == "__main__":
   main()
--- /src/gui/character_pad/data/gen_local_character_map.py
+++ /src/gui/character_pad/data/gen_local_character_map.py
@@ -30,7 +30,6 @@
 
 __author__ = "taku"
 
-import string
 import re
 import sys
 
@@ -43,9 +42,9 @@
   fh = open(filename)
   result = []
   for line in fh.readlines():
-    if line[0] is '#':
+    if line[0] == '#':
       continue
-    array = string.split(line)
+    array = line.split()
     jis = array[0].replace('0x', '')
     ucs2 = array[1].replace('0x', '')
     if len(jis) == 2:
@@ -53,6 +52,7 @@
 
     if IsValidUnicode(ucs2):
       result.append([jis, ucs2])
+  fh.close()
 
   return ["JISX0201", result]
 
@@ -60,13 +60,14 @@
   fh = open(filename)
   result = []
   for line in fh.readlines():
-    if line[0] is '#':
+    if line[0] == '#':
       continue
     array = line.split()
     jis = array[1].replace('0x', '')
     ucs2 = array[2].replace('0x', '')
     if IsValidUnicode(ucs2):
       result.append([jis, ucs2])
+  fh.close()
 
   return ["JISX0208", result]
 
@@ -74,13 +75,14 @@
   fh = open(filename)
   result = []
   for line in fh.readlines():
-    if line[0] is '#':
+    if line[0] == '#':
       continue
     array = line.split()
     jis = array[0].replace('0x', '')
     ucs2 = array[1].replace('0x', '')
     if IsValidUnicode(ucs2):
       result.append([jis, ucs2])
+  fh.close()
 
   return ["JISX0212", result]
 
@@ -88,7 +90,7 @@
   fh = open(filename)
   result = []
   for line in fh.readlines():
-    if line[0] is '#':
+    if line[0] == '#':
       continue
     array = line.split()
     sjis = array[0].replace('0x', '')
@@ -100,19 +102,20 @@
 
     if IsValidUnicode(ucs2):
       result.append([sjis, ucs2])
+  fh.close()
 
   return ["CP932", result]
 
 def Output(arg):
   name = arg[0]
   result = arg[1]
-  print "static const size_t k%sMapSize = %d;" % (name, len(result))
-  print "static const mozc::gui::CharacterPalette::LocalCharacterMap k%sMap[] = {" % (name)
+  print("static const size_t k%sMapSize = %d;" % (name, len(result)))
+  print("static const mozc::gui::CharacterPalette::LocalCharacterMap k%sMap[] = {" % (name))
   for n in result:
-    print "  { 0x%s, 0x%s }," % (n[0] ,n[1])
-  print "  { 0, 0 }";
-  print "};"
-  print ""
+    print("  { 0x%s, 0x%s }," % (n[0] ,n[1]))
+  print("  { 0, 0 }");
+  print("};")
+  print("")
 
 if __name__ == "__main__":
   Output(LoadJISX0201(sys.argv[1]))
--- /src/gui/character_pad/data/gen_unicode_blocks.py
+++ /src/gui/character_pad/data/gen_unicode_blocks.py
@@ -33,13 +33,13 @@
 import sys
 import re
 
-re = re.compile('^(.....?)\.\.(.....?); (.+)')
+re = re.compile(r'^(.....?)\.\.(.....?); (.+)')
 
 def main():
-  print "static const mozc::gui::CharacterPalette::UnicodeBlock kUnicodeBlockTable[] = {"
+  print("static const mozc::gui::CharacterPalette::UnicodeBlock kUnicodeBlockTable[] = {")
   fh = open(sys.argv[1])
   for line in fh.readlines():
-    if line[0] is '#':
+    if line[0] == '#':
       continue
     m = re.match(line)
     if m is not None:
@@ -47,11 +47,12 @@
       end   = int(m.group(2), 16)
       name = m.group(3)
       if start <= 0x2FFFF and end <= 0x2FFFF:
-        print "  { \"%s\", { %d, %d } }," % (name, start, end)
+        print("  { \"%s\", { %d, %d } }," % (name, start, end))
+  fh.close()
 
-  print "  { NULL, { 0, 0 } }"
-  print "};"
-  print ""
+  print("  { NULL, { 0, 0 } }")
+  print("};")
+  print("")
 
 if __name__ == "__main__":
   main()
--- /src/gui/character_pad/data/gen_unicode_data.py
+++ /src/gui/character_pad/data/gen_unicode_data.py
@@ -46,18 +46,19 @@
     code = int(code, 16)
     if code < 0x2FFFF:
       results.append("  { %d, \"%s\" }," % (code, desc))
+  fh.close()
 
-  print "struct UnicodeData {";
-  print "  char32 ucs4;";
-  print "  const char *description;";
-  print "};";
-  print ""
-  print "static const size_t kUnicodeDataSize = %d;" % (len(results))
-  print "static const UnicodeData kUnicodeData[] = {";
+  print("struct UnicodeData {");
+  print("  char32 ucs4;");
+  print("  const char *description;");
+  print("};");
+  print("")
+  print("static const size_t kUnicodeDataSize = %d;" % (len(results)))
+  print("static const UnicodeData kUnicodeData[] = {");
   for line in results:
-    print line;
-  print "  { 0, NULL }";
-  print "};";
+    print(line);
+  print("  { 0, NULL }");
+  print("};");
 
 if __name__ == "__main__":
   main()
--- /src/gui/character_pad/data/gen_unihan_data.py
+++ /src/gui/character_pad/data/gen_unihan_data.py
@@ -31,35 +31,34 @@
 __author__ = "taku"
 
 import re
-import string
 import sys
 rs = {}
 
 def Escape(n):
-  if n is not "NULL":
+  if n != "NULL":
     return "\"%s\"" % (n)
   else:
     return "NULL"
 
 def GetCode(n):
-  if n is not "NULL":
-    n = string.replace(n, '0-', 'JIS X 0208: 0x')
-    n = string.replace(n, '1-', 'JIS X 0212: 0x')
-    n = string.replace(n, '3-', 'JIS X 0213: 0x')
-    n = string.replace(n, '4-', 'JIS X 0213: 0x')
-    n = string.replace(n, 'A-', 'Vendors Ideographs: 0x')
-    n = string.replace(n, '3A', 'JIS X 0213 2000: 0x')
+  if n != "NULL":
+    n = n.replace('0-', 'JIS X 0208: 0x')
+    n = n.replace('1-', 'JIS X 0212: 0x')
+    n = n.replace('3-', 'JIS X 0213: 0x')
+    n = n.replace('4-', 'JIS X 0213: 0x')
+    n = n.replace('A-', 'Vendors Ideographs: 0x')
+    n = n.replace('3A', 'JIS X 0213 2000: 0x')
     return "\"%s\"" % n
   else:
     return "NULL"
 
 def GetRadical(n):
   pat = re.compile(r'^(\d+)\.')
-  if n is not "NULL":
+  if n != "NULL":
     m = pat.match(n)
     if m:
       result = rs[m.group(1)]
-      return  "\"%s\"" % (result.encode('string_escape'))
+      return "\"%s\"" % result
     else:
       return "NULL"
   else:
@@ -73,6 +72,7 @@
     id = array[1]
     radical = array[2]
     rs[id] = radical
+  fh.close()
 
   dic = {}
   pat = re.compile(r'^U\+(\S+)\s+(kTotalStrokes|kJapaneseKun|kJapaneseOn|kRSUnicode|kIRG_JSource)\t(.+)')
@@ -86,23 +86,24 @@
       n = int(m.group(1), 16)
       if n <= 65536:
         dic.setdefault(key, {}).setdefault(field, value)
+  fh.close()
 
   keys = sorted(dic.keys())
 
-  print "struct UnihanData {";
-  print "  unsigned int ucs4;";
+  print("struct UnihanData {");
+  print("  unsigned int ucs4;");
 # Since the total strokes defined in Unihan data is Chinese-based
 # number, we can't use it.
 #  print "  unsigned char total_strokes;";
-  print "  const char *japanese_kun;";
-  print "  const char *japanese_on;";
+  print("  const char *japanese_kun;");
+  print("  const char *japanese_on;");
 # Since the radical information defined in Unihan data is Chinese-based
 # number, we can't use it.
 #  print "  const char *radical;";
-  print "  const char *IRG_jsource;";
-  print "};"
-  print "static const size_t kUnihanDataSize = %d;" % (len(keys))
-  print "static const UnihanData kUnihanData[] = {"
+  print("  const char *IRG_jsource;");
+  print("};")
+  print("static const size_t kUnihanDataSize = %d;" % (len(keys)))
+  print("static const UnihanData kUnihanData[] = {")
 
   for key in keys:
     total_strokes = dic[key].get("kTotalStrokes", "0")
@@ -111,9 +112,9 @@
     rad = GetRadical(dic[key].get("kRSUnicode", "NULL"))
     code = GetCode(dic[key].get("kIRG_JSource", "NULL"))
 #    print " { 0x%s, %s, %s, %s, %s, %s }," % (key, total_strokes, kun, on, rad, code)
-    print " { 0x%s, %s, %s, %s }," % (key, kun, on, code)
+    print(" { 0x%s, %s, %s, %s }," % (key, kun, on, code))
 
-  print "};"
+  print("};")
 
 if __name__ == "__main__":
   main()