equal
deleted
inserted
replaced
1 #!/usr/bin/env python |
1 #!/usr/bin/env python3 |
2 # vim: set fileencoding=utf-8 : |
2 # vim: set fileencoding=utf-8 : |
3 |
3 |
4 """\ |
4 """\ |
5 YML 2 compiler version 5.10 |
5 YML 2 compiler version 6.0 |
6 Copyleft (c), 2009-2018, Volker Birk http://fdik.org/yml/ |
6 Copyleft (c), 2009-2019, Volker Birk http://fdik.org/yml/ |
7 |
7 |
8 """ |
8 """ |
9 |
9 |
10 import sys, os, codecs, locale |
10 import sys, os, codecs, locale |
11 import fileinput, unicodedata |
11 import fileinput, unicodedata |
22 if isinstance(msg, BaseException): |
22 if isinstance(msg, BaseException): |
23 try: |
23 try: |
24 msg = str(msg) + "\n" |
24 msg = str(msg) + "\n" |
25 except: |
25 except: |
26 msg = u(msg) + u"\n" |
26 msg = u(msg) + u"\n" |
27 if type(msg) is unicode: |
27 if type(msg) is bytes: |
28 msg = codecs.encode(msg, sys.stderr.encoding) |
28 msg = codecs.encode(msg, sys.stderr.encoding) |
29 sys.stderr.write(msg) |
29 sys.stderr.write(msg) |
30 |
30 |
31 optParser = OptionParser() |
31 optParser = OptionParser() |
32 optParser.add_option("-C", "--old-syntax", action="store_true", dest="old_syntax", |
32 optParser.add_option("-C", "--old-syntax", action="store_true", dest="old_syntax", |
74 result = backend.finish(result) |
74 result = backend.finish(result) |
75 if options.normalization != "none": |
75 if options.normalization != "none": |
76 result = unicodedata.normalize(options.normalization, result) |
76 result = unicodedata.normalize(options.normalization, result) |
77 |
77 |
78 if options.outputFile and options.outputFile != "-": |
78 if options.outputFile and options.outputFile != "-": |
79 outfile = open(options.outputFile, "w") |
79 outfile = open(options.outputFile, "wb") |
80 outfile.write(codecs.encode(result, options.encoding)) |
80 outfile.write(codecs.encode(result, options.encoding)) |
81 outfile.close() |
81 outfile.close() |
82 else: |
82 else: |
83 print(codecs.encode(result, options.encoding)) |
83 sys.stdout.buffer.write(codecs.encode(result, options.encoding)) |
|
84 print() |
84 |
85 |
85 except KeyboardInterrupt: |
86 except KeyboardInterrupt: |
86 w("\n") |
87 w("\n") |
87 sys.exit(1) |
88 sys.exit(1) |
88 except KeyError as msg: |
89 except KeyError as msg: |