Skip to content

Commit

Permalink
qcow2_format.py: make printable data an extension class member
Browse files Browse the repository at this point in the history
Let us differ binary data type from string one for the extension data
variable and keep the string as the QcowHeaderExtension class member.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <1596742557-320265-3-git-send-email-andrey.shinkevich@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
a-shinkevich authored and ebblake committed Aug 21, 2020
1 parent bf654b3 commit 4539b36
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/qemu-iotests/qcow2_format.py
Expand Up @@ -165,6 +165,13 @@ def __init__(self, magic=None, length=None, data=None, fd=None):
self.data = fd.read(padded)
assert self.data is not None

data_str = self.data[:self.length]
if all(c in string.printable.encode('ascii') for c in data_str):
data_str = f"'{ data_str.decode('ascii') }'"
else:
data_str = '<binary>'
self.data_str = data_str

if self.magic == QCOW2_EXT_MAGIC_BITMAPS:
self.obj = Qcow2BitmapExt(data=self.data)
else:
Expand All @@ -174,12 +181,7 @@ def dump(self):
super().dump()

if self.obj is None:
data = self.data[:self.length]
if all(c in string.printable.encode('ascii') for c in data):
data = f"'{ data.decode('ascii') }'"
else:
data = '<binary>'
print(f'{"data":<25} {data}')
print(f'{"data":<25} {self.data_str}')
else:
self.obj.dump()

Expand Down

0 comments on commit 4539b36

Please sign in to comment.