From dcb8b3a217afe59b368c8ffa4f93d1d6e3d174b2 Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Mon, 14 Mar 2016 21:42:31 -0700 Subject: [PATCH] switch to codecs.open and expect UTF-8 data --- tldp/doctypes/common.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tldp/doctypes/common.py b/tldp/doctypes/common.py index e90024b..f2bc48b 100644 --- a/tldp/doctypes/common.py +++ b/tldp/doctypes/common.py @@ -7,6 +7,7 @@ import os import sys import stat import errno +import codecs import shutil import logging import inspect @@ -202,12 +203,13 @@ class BaseDoctype(object): s = script.format(output=output, source=source, config=config) tf = ntf(dir=logdir, prefix=prefix, suffix='.sh', delete=False) - if preamble: - tf.write(preamble) - tf.write(s) - if postamble: - tf.write(postamble) tf.close() + with codecs.open(tf.name, 'w', encoding='utf-8') as f: + if preamble: + f.write(preamble) + f.write(s) + if postamble: + f.write(postamble) mode = stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR os.chmod(tf.name, mode) @@ -215,7 +217,7 @@ class BaseDoctype(object): cmd = [tf.name] result = execute(cmd, logdir=logdir) if result != 0: - with open(tf.name) as f: + with codecs.open(tf.name, encoding='utf-8') as f: for line in f: logger.info("Script: %s", line.rstrip()) return False