diff --git a/sasmodels/generate.py b/sasmodels/generate.py index e0c32ea2..3014dd9b 100644 --- a/sasmodels/generate.py +++ b/sasmodels/generate.py @@ -661,7 +661,7 @@ def load_template(filename): path = joinpath(DATA_PATH, filename) mtime = getmtime(path) if filename not in _template_cache or mtime > _template_cache[filename][0]: - with open(path) as fid: + with open(path, encoding="utf-8") as fid: _template_cache[filename] = (mtime, fid.read(), path) return _template_cache[filename][1], path @@ -945,7 +945,10 @@ def _add_source(source, code, path, lineno=1): source.append(code) def read_text(f): - with open(f) as fid: + """ + Read a source file. Sources are UTF-8. + """ + with open(f, encoding="utf-8") as fid: return fid.read() def make_source(model_info): diff --git a/sasmodels/gengauss.py b/sasmodels/gengauss.py index 2ef06313..22227896 100755 --- a/sasmodels/gengauss.py +++ b/sasmodels/gengauss.py @@ -20,7 +20,7 @@ def gengauss(n, path): else: array_size = n - with open(path, "w") as fid: + with open(path, "w", encoding="utf-8") as fid: fid.write(f"""\ // Generated by sasmodels.gengauss.gengauss({n}) diff --git a/sasmodels/kerneldll.py b/sasmodels/kerneldll.py index 216b668d..2653c1ef 100644 --- a/sasmodels/kerneldll.py +++ b/sasmodels/kerneldll.py @@ -293,12 +293,12 @@ def make_dll(source, model_info, dtype=F64, system=False): basename = splitext(os.path.basename(dll))[0] + "_" system_fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) logging.debug("make_dll: writing C for dll: %s", filename) - with os.fdopen(system_fd, "w") as file_handle: + with os.fdopen(system_fd, "w", encoding="utf-8") as file_handle: file_handle.write(source) else: filename = splitext(dll)[0] + ".c" logging.debug("make_dll: writing C for system dll: %s", filename) - with open(filename, 'w') as file_handle: + with open(filename, 'w', encoding="utf-8") as file_handle: file_handle.write(source) compile_model(source=filename, output=dll) # Comment the following to keep the generated C file. diff --git a/sasmodels/rst2html.py b/sasmodels/rst2html.py index cd71c3ee..971c2e51 100644 --- a/sasmodels/rst2html.py +++ b/sasmodels/rst2html.py @@ -145,7 +145,7 @@ def load_rst_as_html(filename): # type: (str) -> str """Load rst from file and convert to html""" from os.path import expanduser - with open(expanduser(filename)) as fid: + with open(expanduser(filename), encoding="utf-8") as fid: rst = fid.read() html = rst2html(rst) return html