Package: sunpinyin / 3.0.0~rc1+ds1-3

python3.patch Patch series | download
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
Description: Use python3
Origin: upstream,
 https://github.com/sunpinyin/sunpinyin/commit/f16a9b5704702a5303a4b951c66dc068c19469a0
 https://github.com/sunpinyin/sunpinyin/commit/409345202251af6dfae26705b7c4c9ff65dfbb75
 https://github.com/sunpinyin/sunpinyin/pull/97
Bug: https://github.com/sunpinyin/sunpinyin/issues/94

--- a/SConstruct
+++ b/SConstruct
@@ -227,7 +227,7 @@
 def PassVariables(envvar, env):
     for (x, y) in envvar:
         if x in os.environ:
-            print 'Warning: you\'ve set %s in the environmental variable!' % x
+            print('Warning: you\'ve set %s in the environmental variable!' % x)
             env[y] = os.environ[x]
 
 env = CreateEnvironment()
@@ -299,11 +299,11 @@
 
 def CheckPython(context):
     context.Message('Checking for Python library...')
-    ret = context.TryAction('python-config --prefix')[0]
+    ret = context.TryAction('python3-config --prefix')[0]
     context.Result(ret)
     if ret:
-        context.env.MergeFlags(['!python-config --includes',
-                                '!python-config --libs'])
+        context.env.MergeFlags(['!python3-config --includes',
+                                '!python3-config --libs'])
     return ret
 
 
@@ -429,9 +429,7 @@
     '@PREFIX@': env['PREFIX'],
     '@LIBDIR@': env['LIBDIR'],
     '@VERSION@': version,
-    '@CFLAGS@': reduce(lambda a, b: a + ' ' + b,
-                       map(lambda x: '-I$${includedir}' + x[3:],
-                           sorted(allinc()))),
+    '@CFLAGS@': ' '.join(['-I$${includedir}' + x[3:] for x in sorted(allinc())]),
 })
 
 libname_default = '%ssunpinyin%s' % (env.subst('${SHLIBPREFIX}'),
--- a/python/imdict.py
+++ b/python/imdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python 
+#!/usr/bin/python3
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 # 
--- a/python/importer/import_fcitx_userdict.py
+++ b/python/importer/import_fcitx_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os, sys
 import codecs
--- a/python/importer/import_fit_userdict.py
+++ b/python/importer/import_fit_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os
 import sqlite3 as sqlite
--- a/python/importer/import_google_userdict.py
+++ b/python/importer/import_google_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os, sys
 import codecs
@@ -23,7 +23,7 @@
 
 def main ():
     if len (sys.argv) != 2:
-        print "Please specify the Google Pinyin exported user dict file!"
+        print("Please specify the Google Pinyin exported user dict file!")
         exit (1)
 
     google_user_dict = load_google_user_dict(sys.argv[1])
--- a/python/importer/import_qim_userdict.py
+++ b/python/importer/import_qim_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os, sys
 import codecs
@@ -18,7 +18,7 @@
 
 def main ():
     if len (sys.argv) != 2:
-        print "Please specify the QIM exported user dict file!"
+        print("Please specify the QIM exported user dict file!")
         exit (1)
 
     qim_user_dict = load_qim_user_dict(sys.argv[1])
--- a/python/importer/import_qq_userdict.py
+++ b/python/importer/import_qq_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os, sys
 import codecs
@@ -21,7 +21,7 @@
 
 def main ():
     if len (sys.argv) != 2:
-        print "Please specify the QQ PinYin exported user dict file!"
+        print("Please specify the QQ PinYin exported user dict file!")
         exit (1)
 
     qq_user_dict = load_qq_user_dict(sys.argv[1])
--- a/python/importer/import_sogou_celldict.py
+++ b/python/importer/import_sogou_celldict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 # thanks for the reverse engineering efforts of following projects/peoples:
 # http://code.google.com/p/imewlconverter
@@ -71,7 +71,7 @@
 
 def main ():
     if len (sys.argv) != 2:
-        print "Please specify the Sogou PinYin Cell dict file!"
+        print("Please specify the Sogou PinYin Cell dict file!")
         exit (1)
 
     generator = get_word_from_sogou_cell_dict (sys.argv[1])
--- a/python/importer/import_sogou_userdict.py
+++ b/python/importer/import_sogou_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os, sys
 import codecs
@@ -19,7 +19,7 @@
 
 def main ():
     if len (sys.argv) != 2:
-        print "Please specify the Sogou PinYin exported user dict file!"
+        print("Please specify the Sogou PinYin exported user dict file!")
         exit (1)
 
     sogou_user_dict = load_sogou_user_dict(sys.argv[1])
--- a/python/importer/import_ziguang_userdict.py
+++ b/python/importer/import_ziguang_userdict.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import os, sys
 import codecs
@@ -21,7 +21,7 @@
 
 def main ():
     if len (sys.argv) != 2:
-        print "Please specify the ZiGuang PinYin exported user dict file!"
+        print("Please specify the ZiGuang PinYin exported user dict file!")
         exit (1)
 
     ziguang_user_dict = load_ziguang_user_dict(sys.argv[1])
--- a/python/importer/importer.py
+++ b/python/importer/importer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 import os, sys
 import struct
 import sqlite3 as sqlite
@@ -72,15 +72,15 @@
         try:
             syllables = [valid_syllables[s] for s in pystr.split("'")]
         except:
-            print "[%s] has un-recognized syllables, ignoring this record!" % pystr
+            print("[%s] has un-recognized syllables, ignoring this record!" % pystr)
             continue
 
         if len (syllables) < 2 or len (syllables) > 6:
-            print "[%s] is too long or too short for sunpinyin userdict" % utf8str
+            print("[%s] is too long or too short for sunpinyin userdict" % utf8str)
             continue
 
         if utf8str in sysdict:
-            #print "[%s] is already in sunpinyin's sysdict" % utf8str
+            #print("[%s] is already in sunpinyin's sysdict" % utf8str)
             continue
 
         record = [0]*14
@@ -102,7 +102,7 @@
                     """
             try:
                 db.execute (sqlstring, record)
-                #print "[%s] is imported into sunpinyin's userdict" % utf8str
+                #print("[%s] is imported into sunpinyin's userdict" % utf8str)
 
                 batch_count += 1
                 if batch_count == 100:
@@ -110,7 +110,7 @@
                     batch_count = 0
 
             except:
-                #print "[%s] is already in sunpinyin's userdict" % utf8str
+                #print("[%s] is already in sunpinyin's userdict" % utf8str)
                 pass
 
     db.commit()
@@ -130,7 +130,7 @@
         f    = record[8:14]
         str  = record[-1]
         syls = [initials[i[x]] + finals[f[x]] for x in range(l)]
-        print str.encode ('UTF-8'), id, "'".join(syls) 
+        print(str.encode ('UTF-8'), id, "'".join(syls))
         
 if __name__ == "__main__":
     export_sunpinyin_user_dict ()
--- a/python/mmseg.py
+++ b/python/mmseg.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 # 
@@ -45,7 +45,7 @@
 from utils import read_ch_sentences
 
 def usage():
-    print '''
+    print('''
 Usage:
 mmseg.py -d dict_file [-f (text|bin)] [-i] [-s STOK_ID] [-a AMBI_ID] corpus_file
 
@@ -65,7 +65,7 @@
     The sequence ABC will not be segmented, in binary mode, the AMBI-ID 
     is written out; in text mode, <ambi>ABC</ambi> will be output. Default 
     is 9.
-'''
+''')
 
 options={'show-id':       False, 
          'format' :       'bin', 
@@ -75,8 +75,8 @@
 def parse_options(args):
     try:
         opts, args = getopt.getopt(args, "hid:f:s:a:", ["help", "show-id", "dict=", "format=", "stok-id=", "ambi-id="])
-    except getopt.GetoptError, err:
-        print str(err) 
+    except getopt.GetoptError as err:
+        print(str(err))
         sys.exit(1)
 
     for opt,val in opts:
@@ -114,7 +114,7 @@
 
 def process_file(file, dict):
     for line in read_ch_sentences(file):
-        print >> sys.stderr, line.encode('UTF-8')
+        print(line.encode('UTF-8'), file=sys.stderr)
         length = len(line)
         i = 0
         while (i < length):
--- a/python/pinyin_data.py
+++ b/python/pinyin_data.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python 
+#!/usr/bin/python3
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 # 
--- a/python/pinyin_info_gen.py
+++ b/python/pinyin_info_gen.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python 
+#!/usr/bin/python3
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 # 
@@ -38,60 +38,60 @@
 from pinyin_data import *
 
 def fmt_str_array (name, var) :
-    print 'static const char *%s[] = { %s };' % (name, ', '.join ('"%s"' % s for s in var))
+    print('static const char *%s[] = { %s };' % (name, ', '.join ('"%s"' % s for s in var)))
 
 def fmt_array_size (name):
-    print 'static const unsigned num_%s = sizeof(%s) / sizeof(*%s);' % (name, name, name)
+    print('static const unsigned num_%s = sizeof(%s) / sizeof(*%s);' % (name, name, name))
 
 def fmt_str_pair_array (name, var) :
-    print 'static const char *%s[] = {' % name
+    print('static const char *%s[] = {' % name)
     for s1, s2 in var:
-        print '    %-7s %s' % ('"%s",' % s1, '"%s",' % s2)
-    print '};'
+        print('    %-7s %s' % ('"%s",' % s1, '"%s",' % s2))
+    print('};')
 
 def fmt_pair_array_size (name):
-    print 'static const unsigned num_%s = sizeof(%s) / sizeof(*%s) / 2;' % (name, name, name)
+    print('static const unsigned num_%s = sizeof(%s) / sizeof(*%s) / 2;' % (name, name, name))
 
 fmt_str_array ('initials', initials)
 fmt_array_size ('initials')
-print ''
+print('')
 
 fmt_str_array('finals', finals)
 fmt_array_size ('finals')
-print ''
+print('')
 
 fmt_str_array('fuzzy_finals', inner_fuzzy_finals)
 fmt_array_size ('fuzzy_finals')
-print ''
+print('')
 
 fmt_str_pair_array ('fuzzy_pairs', fuzzy_pairs)
 fmt_pair_array_size ('fuzzy_pairs')
-print ''
+print('')
 
 fmt_str_pair_array ('auto_correction_pairs', sorted(auto_correction_pairs.items()))
 fmt_pair_array_size ('auto_correction_pairs')
-print ''
+print('')
 
-print 'static const unsigned fuzzy_finals_map [] = {'
+print('static const unsigned fuzzy_finals_map [] = {')
 for s in inner_fuzzy_finals:
-    print '    %-7s %-7s %-7s /* %-4s -> %-4s len %d */' % ('0x%02x,' % finals.index(s), '0x%02x,' % valid_syllables[s[1:]], '%d,' % (len(s)-1,),  s, s[1:], len(s)-1)
-print '};\n'
+    print('    %-7s %-7s %-7s /* %-4s -> %-4s len %d */' % ('0x%02x,' % finals.index(s), '0x%02x,' % valid_syllables[s[1:]], '%d,' % (len(s)-1,),  s, s[1:], len(s)-1))
+print('};\n')
 
-print 'static const TPyTabEntry pinyin_table[] = {'
+print('static const TPyTabEntry pinyin_table[] = {')
 for syllable, hex_syllable in sorted(valid_syllables.items()):
-    print '    { %-9s %s },' % ('"%s",' % syllable, '0x%05x' % hex_syllable)
-print '};\n'
+    print('    { %-9s %s },' % ('"%s",' % syllable, '0x%05x' % hex_syllable))
+print('};\n')
 
-print 'static const unsigned fuzzy_pre_syllables [] = {'
+print('static const unsigned fuzzy_pre_syllables [] = {')
 for s in fuzzy_pre_syllables:
-    print '    %-11s %-7s %-11s /* %s */' % ('0x%05x,' % valid_syllables[s[:-1]], "'%s'," % s[-1], '0x%05x,' % valid_syllables[s], s)
-print '    0x0,'
-print '};\n'
+    print('    %-11s %-7s %-11s /* %s */' % ('0x%05x,' % valid_syllables[s[:-1]], "'%s'," % s[-1], '0x%05x,' % valid_syllables[s], s))
+print('    0x0,')
+print('};\n')
 
-print 'static const unsigned fuzzy_pro_syllables [] = {'
+print('static const unsigned fuzzy_pro_syllables [] = {')
 for s in fuzzy_pro_syllables:
-    print '    %-11s %-7s %-11s /* %s */' % ('0x%05x,' % valid_syllables[s], "'%s'," % s[0], '0x%05x,' % valid_syllables[s[1:]], s)
-print '    0x0,'
-print '};\n'
+    print('    %-11s %-7s %-11s /* %s */' % ('0x%05x,' % valid_syllables[s], "'%s'," % s[0], '0x%05x,' % valid_syllables[s[1:]], s))
+print('    0x0,')
+print('};\n')
 
 # -*- indent-tabs-mode: nil -*- vim:et:ts=4
--- a/python/pytrie.pyx
+++ b/python/pytrie.pyx
@@ -92,7 +92,7 @@
     def get_words (self):
         words = []
         cdef CPinyinTrie_TWord *p= <CPinyinTrie_TWord*> self.pnode.getWordIdPtr ()
-        for i in xrange (self.pnode.m_nWordId):
+        for i in range (self.pnode.m_nWordId):
             words.append (WordInfo(p[i].m_id, p[i].m_bSeen, p[i].m_cost, p[i].m_len, p[i].m_csLevel))
         return words 
 
--- a/python/quanpin_trie_gen.py
+++ b/python/quanpin_trie_gen.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python 
+#!/usr/bin/python3
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 # 
--- a/python/test.py
+++ b/python/test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 # -*- coding: UTF-8 -*-
 
 from pyslm import Slm, SlmState
@@ -10,21 +10,21 @@
         return
 
     pr, result = slm.transfer (SlmState(0,0), 58614)
-    print "pr =", pr, "\tresult = %s" % result
+    print("pr =", pr, "\tresult = %s" % result)
     
     pr, result = slm.transfer (result, 75956)
-    print "pr =", pr, "\tresult = %s" % result
+    print("pr =", pr, "\tresult = %s" % result)
     
     pr, result = slm.transfer (result, 84582)
-    print "pr =", pr, "\tresult = %s" % result
+    print("pr =", pr, "\tresult = %s" % result)
     
     his = slm.history_state_of (result)
-    print "his = %s" % his
+    print("his = %s" % his)
     
     slm.historify (result)
-    print "result = %s" % result
+    print("result = %s" % result)
 
-    print 'last_word_id =', slm.last_word_id (result)
+    print('last_word_id =', slm.last_word_id (result))
 
     slm.free ()
 
@@ -36,12 +36,12 @@
     root = trie.get_root_node ()
     node = trie.transfer (root, 0x1000)
     for w in node.get_words ():
-        print w
+        print(w)
 
-    print trie.is_valid (node, False, 0)
-    print trie[10000]
+    print(trie.is_valid (node, False, 0))
+    print(trie[10000])
 
-    print trie.get_symbol_id (u'。')
+    print(trie.get_symbol_id (u'。'))
     trie.free ()
 
 test_pyslm()
--- a/python/trie.py
+++ b/python/trie.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 # 
@@ -161,7 +161,7 @@
                 if progress_cb:
                     progress_cb ()
 
-        for i in xrange (self.chr_encoder (max(trie.root.trans))+1):
+        for i in range (self.chr_encoder (max(trie.root.trans))+1):
             if self.check[i] == -1:
                 self.check[i] = 0
 
@@ -272,7 +272,7 @@
         v, l = match_longest (datrie, s+'b')
         assert (len(s) == l and valid_syllables[s] == v)
 
-    print 'test executed successfully'
+    print('test executed successfully')
 
 if __name__ == "__main__":
     test ()
--- a/python/utils.py
+++ b/python/utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python 
+#!/usr/bin/python3
 # -*- coding: UTF-8 -*-
 
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
@@ -202,7 +202,7 @@
         self.__realsize += 1
 
     def __iter__(self):
-        for i in xrange(0, self.__realsize):
+        for i in range(0, self.__realsize):
             yield self.__access(i)
 
     def truncate(self, tsize):
--- a/src/SConscript
+++ b/src/SConscript
@@ -53,7 +53,7 @@
 })
 env.Command('sunpinyin-dictgen', 'sunpinyin-dictgen.mk', [
     Copy("$TARGET", "$SOURCE"),
-    Chmod("$TARGET", 0755),
+    Chmod("$TARGET", 0o755),
 ])
 
 # -*- indent-tabs-mode: nil -*- vim:et:ts=4