Skip to content

Commit

Permalink
Fix Usages of removed from/tostring for Python 3.9 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kistelini authored Jan 11, 2021
1 parent c08e07f commit cff55ba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions mymcplus/ps2mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ def unpack_32bit_array(s):
def pack_32bit_array(a):
a = a[:]
a.byteswap()
return a.tostring()
return a.tobytes()
else:
def unpack_32bit_array(s):
#if isinstance(s, str):
# a = array.array('L')
# a.fromstring(s)
# a.frombytes(s)
# return a
return array.array('I', s)

def pack_32bit_array(a):
return a.tostring()
return a.tobytes()

def unpack_superblock(s):
sb = struct.unpack("<28s12sHHHHLLLLLL8x128s128sbbxx", s)
Expand Down
8 changes: 4 additions & 4 deletions mymcplus/ps2mc_ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _ecc_calculate(s):

if not isinstance(s, array.array):
a = array.array('B')
a.fromstring(s)
a.frombytes(s)
s = a
column_parity = 0x77
line_parity_0 = 0x7F
Expand All @@ -95,7 +95,7 @@ def _ecc_check(s, ecc):
return ECC_CHECK_OK

#print
#_print_bin(0, s.tostring())
#_print_bin(0, s.tobytes())
#print "computed %02x %02x %02x" % tuple(computed)
#print "actual %02x %02x %02x" % tuple(ecc)

Expand Down Expand Up @@ -148,15 +148,15 @@ def ecc_check_page(page, spare):
chunks = []
for i in range(div_round_up(len(page), 128)):
a = array.array('B')
a.fromstring(page[i * 128 : i * 128 + 128])
a.frombytes(page[i * 128 : i * 128 + 128])
chunks.append((a, list(spare[i * 3 : i * 3 + 3])))

r = [ecc_check(s, ecc)
for (s, ecc) in chunks]
ret = ECC_CHECK_OK
if ECC_CHECK_CORRECTED in r:
# rebuild sector and spare from the corrected versions
page = b"".join([a[0].tostring() for a in chunks])
page = b"".join([a[0].tobytes() for a in chunks])
spare = bytes([a[1][i]
for a in chunks
for i in range(3)])
Expand Down
4 changes: 2 additions & 2 deletions mymcplus/save/lzari.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def bit_array_to_string(a):
remainder = len(a) % 8
if remainder != 0:
a.fromlist([0] * (8 - remainder))
s = a.tostring()
s = a.tobytes()
s = binascii.unhexlify(s.translate(_tr_rev_2))
s = binascii.unhexlify(s.translate(_tr_rev_4))
return binascii.unhexlify(s.translate(_tr_rev_16))
Expand Down Expand Up @@ -632,7 +632,7 @@ def decode(self, src, out_length, progress = None):
self.in_iter = None
if progress:
sys.stderr.write("%s100%%\n" % progress)
return out.tostring()
return out.tobytes()

if mymcsup == None:
def decode(src, out_length, progress = None):
Expand Down
6 changes: 3 additions & 3 deletions test/test_ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_ecc_check_ok():
res = ps2mc_ecc.ecc_check(s, ecc)

assert res == ps2mc_ecc.ECC_CHECK_OK
assert s.tostring() == bytes(_data)
assert s.tobytes() == bytes(_data)
assert ecc == _ecc


Expand All @@ -65,7 +65,7 @@ def test_ecc_check_correct_data():
res = ps2mc_ecc.ecc_check(s, ecc)

assert res == ps2mc_ecc.ECC_CHECK_CORRECTED
assert s.tostring() == bytes(_data)
assert s.tobytes() == bytes(_data)
assert ecc == _ecc


Expand All @@ -79,7 +79,7 @@ def test_ecc_check_correct_ecc():
res = ps2mc_ecc.ecc_check(s, ecc)

assert res == ps2mc_ecc.ECC_CHECK_CORRECTED
assert s.tostring() == bytes(_data)
assert s.tobytes() == bytes(_data)
assert ecc == _ecc


Expand Down

0 comments on commit cff55ba

Please sign in to comment.