toolsutils.py
changeset 10966 8909593f46d4
parent 10688 fa29f3628a1b
--- a/toolsutils.py	Thu Dec 10 18:00:41 2015 +0100
+++ b/toolsutils.py	Thu Dec 10 17:57:55 2015 +0100
@@ -22,6 +22,7 @@
 
 # XXX move most of this in logilab.common (shellutils ?)
 
+import io
 import os, sys
 import subprocess
 from os import listdir, makedirs, environ, chmod, walk, remove
@@ -153,10 +154,10 @@
                 shutil.copyfile(fpath, tfpath)
 
 def fill_templated_file(fpath, tfpath, context):
-    fobj = open(tfpath, 'w')
-    templated = open(fpath).read()
-    fobj.write(templated % context)
-    fobj.close()
+    with io.open(fpath, encoding='ascii') as fobj:
+        template = fobj.read()
+    with io.open(tfpath, 'w', encoding='ascii') as fobj:
+        fobj.write(template % context)
 
 def restrict_perms_to_user(filepath, log=None):
     """set -rw------- permission on the given file"""