Fix python3 in pssh-box

The script now works with both python 2 and python 3 (tested with python 2.7 and python 3.8.6).

Fixes #833.
This commit is contained in:
pszemus 2020-12-11 18:43:29 +01:00 committed by GitHub
parent 346c844e42
commit c6b01f90ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -124,7 +124,7 @@ class Pssh(object):
lines.extend([' ' + x for x in extra]) lines.extend([' ' + x for x in extra])
# pylint: disable=broad-except # pylint: disable=broad-except
except Exception as e: except Exception as e:
lines.append(' ERROR: ' + e.message) lines.append(' ERROR: ' + str(e))
else: else:
lines.extend([ lines.extend([
' Raw Data (base64):', ' Raw Data (base64):',
@ -141,14 +141,14 @@ def _split_list_on(elems, sep):
def _create_bin_int(value): def _create_bin_int(value):
"""Creates a 4-byte binary string from the given integer.""" """Creates a binary string as 4-byte array from the given integer."""
return (chr(value >> 24) + chr((value >> 16) & 0xff) + return (chr(value >> 24) + chr((value >> 16) & 0xff) +
chr((value >> 8) & 0xff) + chr(value & 0xff)) chr((value >> 8) & 0xff) + chr(value & 0xff)).encode()
def _create_uuid(data): def _create_uuid(data):
"""Creates a human readable UUID string from the given binary string.""" """Creates a human readable UUID string from the given binary string."""
ret = base64.b16encode(data).lower() ret = base64.b16encode(data).decode().lower()
return (ret[:8] + '-' + ret[8:12] + '-' + ret[12:16] + '-' + ret[16:20] + return (ret[:8] + '-' + ret[8:12] + '-' + ret[12:16] + '-' + ret[16:20] +
'-' + ret[20:]) '-' + ret[20:])
@ -180,7 +180,7 @@ def _parse_widevine_data(data):
if wv.HasField('provider'): if wv.HasField('provider'):
ret.append('Provider: ' + wv.provider) ret.append('Provider: ' + wv.provider)
if wv.HasField('content_id'): if wv.HasField('content_id'):
ret.append('Content ID: ' + base64.b16encode(wv.content_id)) ret.append('Content ID: ' + base64.b16encode(wv.content_id).decode())
if wv.HasField('policy'): if wv.HasField('policy'):
ret.append('Policy: ' + wv.policy) ret.append('Policy: ' + wv.policy)
if wv.HasField('crypto_period_index'): if wv.HasField('crypto_period_index'):
@ -423,11 +423,11 @@ def main(all_args):
for box in boxes: for box in boxes:
print(box.human_string()) print(box.human_string())
else: else:
box_data = ''.join([x.binary_string() for x in boxes]) box_data = b''.join([x.binary_string() for x in boxes])
if output_format == 'hex': if output_format == 'hex':
print(base64.b16encode(box_data)) print(base64.b16encode(box_data).decode())
else: else:
print(base64.b64encode(box_data)) print(base64.b64encode(box_data).decode())
if __name__ == '__main__': if __name__ == '__main__':