Browse Source

py3port: binary, text-mode file reads and writes

MMGen 6 years ago
parent
commit
793c808797
2 changed files with 4 additions and 2 deletions
  1. 1 1
      mmgen/opts.py
  2. 3 1
      mmgen/util.py

+ 1 - 1
mmgen/opts.py

@@ -104,7 +104,7 @@ def get_cfg_template_data():
 				+ (['share'],['local','share'])[g.platform=='linux']
 				+ [g.proj_name.lower(),os.path.basename(g.cfg_file)]))
 	try:
-		with open(cfg_template,'rb') as f:
+		with open(cfg_template,'r') as f:
 			return f.read()
 	except:
 		msg("WARNING: configuration template not found at '{}'".format(cfg_template))

+ 3 - 1
mmgen/util.py

@@ -678,7 +678,9 @@ def get_data_from_file(infile,desc='data',dash=False,silent=False,binary=False,r
 	data = f.read()
 	f.close()
 	if require_utf8:
-		try: data = data.decode()
+		try:
+			if binary: data = data.decode()
+			else: data.encode()
 		except: die(1,'{} data must be UTF-8 encoded.'.format(capfirst(desc)))
 	return data