diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2014-02-05 17:14:49 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2014-02-05 17:14:49 +0900 |
commit | e1781553312d54e835a59e7443d0a95ecbba7c1e (patch) | |
tree | d6fb807ebba131523d0978366fc05a4a338ea82f | |
parent | 1ae9a571c009d96b95da0c53ca6460d41ff067e7 (diff) | |
download | ibus-anthy-e1781553312d54e835a59e7443d0a95ecbba7c1e.tar.gz |
Enabled python3 in data/zipcode-textdic.py
-rwxr-xr-x | data/zipcode-textdic.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/data/zipcode-textdic.py b/data/zipcode-textdic.py index 2864f85..6fa50d6 100755 --- a/data/zipcode-textdic.py +++ b/data/zipcode-textdic.py @@ -7,21 +7,26 @@ # include too many and unnecessary candidates. # Also wish to install the filename of 'zipcode.t' to simplify enigne. +# for python2 +from __future__ import print_function + +import codecs import sys if len(sys.argv) < 2: - print >> sys.stderr, 'usage: %s /usr/share/anthy/zipcode.t' % sys.argv[0] + print('usage: %s /usr/share/anthy/zipcode.t' % sys.argv[0], + file=sys.stderr) exit(-1) anthy_zipfile = sys.argv[1] try: - contents = unicode(open(anthy_zipfile).read(), 'euc_jp').encode('utf-8') -except UnicodeDecodeError, e: - print >> sys.stderr, 'Your file is not eucJP? %s' % anthy_zipfile + contents = codecs.open(anthy_zipfile, 'r', 'euc_jp').read() +except UnicodeDecodeError as e: + print('Your file is not eucJP? %s' % anthy_zipfile, file=sys.stderr) contents = open(anthy_zipfile).read() -output_zipfile = open('zipcode.t', 'w') +output_zipfile = codecs.open('zipcode.t', 'w', 'utf-8') output_zipfile.write('# copied %s with UTF-8.\n#\n' % anthy_zipfile) for line in contents.split('\n'): @@ -33,19 +38,25 @@ for line in contents.split('\n'): if len(words) < 3: continue - if len(words[0]) < 1 or ord(unicode(words[0], 'utf-8')[0]) > 0xff: + if len(words[0]) < 1 or ord(words[0][0]) > 0xff: mbcs_addr = words[0] else: uni_addr = '' i = 0 for word in words[0]: # Convert ASCII number char to wide number char. - uni_addr += unichr(0xfee0 + ord(word)) + if sys.version < '3': + uni_addr += unichr(0xfee0 + ord(word)) + else: + uni_addr += chr(0xfee0 + ord(word)) if i == 2: # Insert wide hyphen - uni_addr += unichr(0x30fc) + if sys.version < '3': + uni_addr += unichr(0x30fc) + else: + uni_addr += chr(0x30fc) i += 1 - mbcs_addr = uni_addr.encode('utf-8') + mbcs_addr = uni_addr output_zipfile.write('%s %s %s\n' % \ (mbcs_addr, '#T35*500', words[2])) |