From c30f390fed9e3b5d2b379851ce92634caaf0654e Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Sun, 7 May 2017 19:33:38 -0700 Subject: [PATCH] All tests passing for python 3 --- atrcopy/ataridos.py | 18 +++++++++--------- atrcopy/diskimages.py | 6 +++--- atrcopy/dos33.py | 5 +++-- test/test_add_file.py | 1 + 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/atrcopy/ataridos.py b/atrcopy/ataridos.py index b78ae03..871f5e8 100644 --- a/atrcopy/ataridos.py +++ b/atrcopy/ataridos.py @@ -94,8 +94,8 @@ class AtariDosDirent(Dirent): self.deleted = False self.num_sectors = 0 self.starting_sector = 0 - self.basename = "" - self.ext = "" + self.basename = b'' + self.ext = b'' self.is_sane = True self.current_sector = 0 self.current_read = 0 @@ -103,14 +103,14 @@ class AtariDosDirent(Dirent): self.parse_raw_dirent(image, bytes) def __str__(self): - return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, self.summary, self.starting_sector, self.basename, self.ext, self.num_sectors) + return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, self.summary, self.starting_sector, str(self.basename), str(self.ext), self.num_sectors) def __eq__(self, other): return self.__class__ == other.__class__ and self.filename == other.filename and self.starting_sector == other.starting_sector and self.num_sectors == other.num_sectors @property def filename(self): - ext = ("." + self.ext) if self.ext else "" + ext = (b'.' + self.ext) if self.ext else b'' return self.basename + ext @property @@ -138,10 +138,10 @@ class AtariDosDirent(Dirent): def extra_metadata(self, image): return self.verbose_info - def parse_raw_dirent(self, image, bytes): - if bytes is None: + def parse_raw_dirent(self, image, data): + if data is None: return - values = bytes.view(dtype=self.format)[0] + values = data.view(dtype=self.format)[0] flag = values[0] self.flag = flag self.opened_output = (flag&0x01) > 0 @@ -153,8 +153,8 @@ class AtariDosDirent(Dirent): self.deleted = (flag&0x80) > 0 self.num_sectors = int(values[1]) self.starting_sector = int(values[2]) - self.basename = str(values[3]).rstrip() - self.ext = str(values[4]).rstrip() + self.basename = bytes(values[3]).rstrip() + self.ext = bytes(values[4]).rstrip() self.is_sane = self.sanity_check(image) def encode_dirent(self): diff --git a/atrcopy/diskimages.py b/atrcopy/diskimages.py index 3b86dd8..af77572 100644 --- a/atrcopy/diskimages.py +++ b/atrcopy/diskimages.py @@ -183,9 +183,9 @@ class DiskImageBase(object): if not filename: raise RuntimeError("No filename specified for save!") if type(filename) is not bytes: filename = filename.encode("utf-8") - bytes = self.bytes[:] + data = self.bytes[:] with open(filename, "wb") as fh: - bytes.tofile(fh) + data.tofile(fh) def assert_valid_sector(self, sector): if not self.header.sector_is_valid(sector): @@ -279,7 +279,7 @@ class DiskImageBase(object): for dirent in self.files: if filename == dirent.filename: return dirent - raise FileNotFound("%s not found on disk" % filename) + raise FileNotFound("%s not found on disk" % str(filename)) def find_file(self, filename): dirent = self.find_dirent(filename) diff --git a/atrcopy/dos33.py b/atrcopy/dos33.py index d2efc52..2309769 100644 --- a/atrcopy/dos33.py +++ b/atrcopy/dos33.py @@ -171,7 +171,7 @@ class Dos33Dirent(Dirent): self.deleted = False self.track = 0 self.sector = 0 - self.filename = "" + self.filename = b'' self.num_sectors = 0 self.is_sane = True self.current_sector_index = 0 @@ -353,7 +353,8 @@ class Dos33Dirent(Dirent): return self.filename def set_values(self, filename, filetype, index): - self.filename = "%-30s" % filename[0:30] + if type(filename) is not bytes: filename = filename.encode("utf-8") + self.filename = b'%-30s' % filename[0:30] self._file_type = self.text_to_type.get(filetype, 0x04) self.locked = False self.deleted = False diff --git a/test/test_add_file.py b/test/test_add_file.py index ffd679f..d755234 100644 --- a/test/test_add_file.py +++ b/test/test_add_file.py @@ -18,6 +18,7 @@ class BaseFilesystemModifyTest(object): self.image = self.diskimage_type(rawdata) def check_entries(self, entries, prefix=b"TEST", save=None): + if type(prefix) is not bytes: prefix = prefix.encode("utf-8") orig_num_files = len(self.image.files) filenames = [] count = 1