py3port: binary, text-mode file reads and writes

This commit is contained in:
The MMGen Project 2018-10-31 16:18:50 +00:00
commit 793c808797
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 4 additions and 2 deletions

View file

@ -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))

View file

@ -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