X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=development%2Ftools%2Funicodesymbols.py;h=7338d2f0d56570d2d3ec1dd626958fc9c403b34d;hb=e798db5739871aaa29f95de321c52f19058064c9;hp=e63c0be36bda49ff6c2186833198ad2981f8972f;hpb=1a2af1197e20aa8adaaa7a8f2d62d9c4c0d3136c;p=lyx.git diff --git a/development/tools/unicodesymbols.py b/development/tools/unicodesymbols.py old mode 100644 new mode 100755 index e63c0be36b..7338d2f0d5 --- a/development/tools/unicodesymbols.py +++ b/development/tools/unicodesymbols.py @@ -12,7 +12,9 @@ # This script reads a unicode symbol file and completes it in the given range +from __future__ import print_function import os, re, string, sys, unicodedata +import io def usage(prog_name): return ("Usage: %s start stop inputfile outputfile\n" % prog_name + @@ -26,9 +28,7 @@ def error(message): def trim_eol(line): " Remove end of line char(s)." - if line[-2:-1] == '\r': - return line[:-2] - elif line[-1:] == '\r' or line[-1:] == '\n': + if line[-1:] == '\n': return line[:-1] else: # file with no EOL in last line @@ -55,9 +55,9 @@ def read(input): def write(output, lines): - " Write output file with native lineendings." + " Write output file." for line in lines: - output.write(line[1] + os.linesep) + output.write(line[1] + '\n') def complete(lines, start, stop): @@ -65,11 +65,14 @@ def complete(lines, start, stop): for i in range(start, stop): # This catches both comments (lines[l][0] == -1) and code points less than i while l < len(lines) and lines[l][0] < i: -# print lines[l] +# print(lines[l]) l = l + 1 continue if l >= len(lines) or lines[l][0] != i: - c = unichr(i) + if sys.version_info[0] < 3: + c = unichr(i) + else: + c = chr(i) name = unicodedata.name(c, "") if name != "": if unicodedata.combining(c): @@ -78,7 +81,7 @@ def complete(lines, start, stop): combining = "" line = [i, '#0x%04x "" "" "%s" "" "" # %s' % (i, combining, name)] lines.insert(l, line) -# print lines[l] +# print(lines[l]) l = l + 1 @@ -89,8 +92,8 @@ def main(argv): input = sys.stdin output = sys.stdout elif len(argv) == 5: - input = open(argv[3], 'rb') - output = open(argv[4], 'wb') + input = io.open(argv[3], 'r', encoding='utf_8') + output = io.open(argv[4], 'w', encoding='utf_8') else: error(usage(argv[0])) if argv[1][:2] == "0x":