py3port: binary, text-mode file reads and writes
This commit is contained in:
parent
a97995c6cb
commit
793c808797
2 changed files with 4 additions and 2 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue