Fixed ImageHandler to be compatible with python3.
This change is still compatible with Python 2.
Bug: 151336743
Test: atest --host libavb_host_unittest
Test: atest --host aftltool_test
Test: ./aftltool_integration_test.py
Change-Id: I7dcb27c8c0149c1ff74479165a5e67550a0c0517
diff --git a/avbtool b/avbtool
index 427d4e0..a8cfc26 100755
--- a/avbtool
+++ b/avbtool
@@ -656,10 +656,10 @@
output_offset: Offset in de-sparsified file.
output_size: Number of bytes in output.
input_offset: Offset in sparse file if TYPE_RAW otherwise None.
- fill_data: Blob with data to fill if TYPE_FILL otherwise None.
+ fill_data: Blob as bytes with data to fill if TYPE_FILL otherwise None.
Raises:
- ValueError: If data is not well-formed.
+ ValueError: If given chunk parameters are invalid.
"""
self.chunk_type = chunk_type
self.chunk_offset = chunk_offset
@@ -901,7 +901,7 @@
The length of the given data must be a multiple of the block size.
Arguments:
- data: Data to append.
+ data: Data to append as bytes.
"""
assert len(data) % self.block_size == 0
@@ -967,7 +967,7 @@
RuntimeError: If the given offset is negative.
"""
if offset < 0:
- raise RuntimeError('Seeking with negative offset: %d' % offset)
+ raise RuntimeError('Seeking with negative offset: {}'.format(offset))
self._file_pos = offset
def read(self, size):
@@ -983,8 +983,7 @@
size: Number of bytes to read.
Returns:
- The data.
-
+ The data as bytes.
"""
if not self.is_sparse:
self._image.seek(self._file_pos)
@@ -1011,7 +1010,7 @@
data.extend(all_data[offset_mod:(offset_mod + chunk_pos_to_go)])
else:
assert chunk.chunk_type == ImageChunk.TYPE_DONT_CARE
- data.extend('\0' * chunk_pos_to_go)
+ data.extend(b'\0' * chunk_pos_to_go)
to_go -= chunk_pos_to_go
self._file_pos += chunk_pos_to_go
@@ -1020,7 +1019,7 @@
if chunk_idx >= len(self._chunks):
break
- return data
+ return bytes(data)
def tell(self):
"""Returns the file cursor position for reading from unsparsified file.