Disk image filenames should be str, not encoded bytes

This commit is contained in:
Rob McMullen 2018-06-24 09:51:46 -07:00
parent 8747e7e26b
commit 7e3159b175

View File

@ -130,11 +130,10 @@ class DiskImageBase(object):
return Directory return Directory
def set_filename(self, filename): def set_filename(self, filename):
if type(filename) is not bytes: filename = filename.encode("utf-8") if '.' in filename:
if b'.' in filename: self.filename, self.ext = filename.rsplit('.', 1)
self.filename, self.ext = filename.rsplit(b'.', 1)
else: else:
self.filename, self.ext = filename, b'' self.filename, self.ext = filename, ''
def dir(self): def dir(self):
lines = [] lines = []
@ -180,10 +179,9 @@ class DiskImageBase(object):
if not filename: if not filename:
filename = self.filename filename = self.filename
if self.ext: if self.ext:
filename += b'.' + self.ext filename += '.' + self.ext
if not filename: if not filename:
raise RuntimeError("No filename specified for save!") raise RuntimeError("No filename specified for save!")
if type(filename) is not bytes: filename = filename.encode("utf-8")
data = self.bytes[:] data = self.bytes[:]
with open(filename, "wb") as fh: with open(filename, "wb") as fh:
data.tofile(fh) data.tofile(fh)