at 18.03-beta 2.4 kB view raw
1From 0cc9e68de1181d950d4185bf3a87b69a87e4358f Mon Sep 17 00:00:00 2001 2From: "James D. Trotter" <james@simula.no> 3Date: Mon, 14 Aug 2017 16:43:53 +0200 4Subject: [PATCH] Use a UTF-8 encoding to avoid errors with decoding non-ascii 5 characters 6 7--- 8 cmake/scripts/generate-swig-interface.py | 6 +++--- 9 utils/pylit/pylit.py | 10 +++++++--- 10 2 files changed, 10 insertions(+), 6 deletions(-) 11 12diff --git a/cmake/scripts/generate-swig-interface.py b/cmake/scripts/generate-swig-interface.py 13index 843a49229..7b85453d0 100644 14--- a/cmake/scripts/generate-swig-interface.py 15+++ b/cmake/scripts/generate-swig-interface.py 16@@ -212,10 +212,10 @@ def extract_swig_modules_dependencies(module_to_submodules, submodule_info): 17 continue 18 19 # Read code 20- with open(header_file) as f: 21- code = f.read() 22- 23 try: 24+ with open(header_file, encoding='utf-8') as f: 25+ code = f.read() 26+ 27 # Extract type info 28 used_types, declared_types = parse_and_extract_type_info(code) 29 except Exception as e: 30diff --git a/utils/pylit/pylit.py b/utils/pylit/pylit.py 31index bcd8ec5e0..8c2964fbd 100755 32--- a/utils/pylit/pylit.py 33+++ b/utils/pylit/pylit.py 34@@ -1496,7 +1496,7 @@ def open_streams(infile = '-', outfile = '-', overwrite='update', **keyw): 35 if infile == '-': 36 in_stream = sys.stdin 37 else: 38- in_stream = open(infile, 'r') 39+ in_stream = open(infile, 'r', encoding='utf-8') 40 41 if outfile == '-': 42 out_stream = sys.stdout 43@@ -1505,7 +1505,7 @@ def open_streams(infile = '-', outfile = '-', overwrite='update', **keyw): 44 elif overwrite == 'update' and is_newer(outfile, infile): 45 raise IOError((1, "Output file is newer than input file!", outfile)) 46 else: 47- out_stream = open(outfile, 'w') 48+ out_stream = open(outfile, 'w', encoding='utf-8') 49 return (in_stream, out_stream) 50 51 # is_newer 52@@ -1731,7 +1731,11 @@ def main(args=sys.argv[1:], **defaults): 53 54 # Convert and write to out_stream:: 55 56- out_stream.write(str(converter)) 57+ try: 58+ out_stream.write(str(converter)) 59+ except Exception as e: 60+ print("Failed to write extract to", out_stream.name) 61+ raise 62 63 if out_stream is not sys.stdout: 64 print("extract written to", out_stream.name) 65-- 662.14.0 67