Skip to content

Commit 64d5432

Browse files
itsybitsypixelmborgerson
authored andcommitted
Change bytes literals to bytearray
1 parent d927c05 commit 64d5432

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

xbe/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ def off_to_addr(off: int) -> int:
10521052
raw_off = round_up(self.header.headers_size)
10531053

10541054
# Construct section data
1055-
section_data = b""
1055+
section_data = bytearray()
10561056
for name in sorted(
10571057
self.sections, key=lambda x: cast(int, self.sections[x].header.virtual_addr)
10581058
):
@@ -1062,23 +1062,23 @@ def off_to_addr(off: int) -> int:
10621062
"Expected %#x for %s, got %#x", s.header.raw_addr, name, raw_off
10631063
)
10641064
s.header.raw_addr = raw_off
1065-
section_data += s.data
1065+
section_data.extend(s.data)
10661066
raw_off += len(s.data)
10671067

10681068
# Align to 4k
10691069
new_offset = round_up(raw_off)
1070-
section_data += bytes(new_offset - raw_off)
1070+
section_data.extend(bytes(new_offset - raw_off))
10711071
raw_off = new_offset
10721072

10731073
#
10741074
# Construct headers
10751075
#
1076-
headers_data = b""
1076+
headers_data = bytearray()
10771077

10781078
def do_append(data: bytes) -> int:
10791079
nonlocal raw_off, headers_data
10801080
old_off = raw_off
1081-
headers_data += data
1081+
headers_data.extend(data)
10821082
raw_off += len(data)
10831083
return off_to_addr(old_off)
10841084

@@ -1204,20 +1204,20 @@ def do_append(data: bytes) -> int:
12041204
)
12051205

12061206
# Construct final image
1207-
output = b""
1208-
output += bytes(self.header)
1209-
output += bytes(self.cert)
1207+
output = bytearray()
1208+
output.extend(bytes(self.header))
1209+
output.extend(bytes(self.cert))
12101210
for name, s in self.sections.items():
12111211
log.info("Writing section %s at %#x", name, len(output))
1212-
output += bytes(s.header)
1213-
output += headers_data
1214-
output += section_data
1212+
output.extend(bytes(s.header))
1213+
output.extend(headers_data)
1214+
output.extend(section_data)
12151215

12161216
# MS XBEs seem to always add an extra page if the last page is completely filled
12171217
# FIXME: Why?
12181218
if output[-1] != 0:
1219-
output += bytes(0x1000)
1220-
return output
1219+
output.extend(bytes(0x1000))
1220+
return bytes(output)
12211221

12221222
@classmethod
12231223
def from_file(cls, path: str) -> "Xbe":

0 commit comments

Comments
 (0)