fix: Indexing `bytes` produces `int` on python3 for `pssh-box.py` (#1228)

Fixes #1227
This commit is contained in:
Allan Lei 2023-07-13 00:03:43 +08:00 committed by GitHub
parent ac47e529ad
commit d9d3c7f8be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -20,6 +20,17 @@ import os
import struct import struct
import sys import sys
def to_code_point(value):
"""
Return the unicode code point with `int` passthrough
"""
if isinstance(value, int):
return value
return ord(value)
_script_dir = os.path.dirname(os.path.realpath(__file__)) _script_dir = os.path.dirname(os.path.realpath(__file__))
_proto_path = os.path.join(_script_dir, 'pyproto') _proto_path = os.path.join(_script_dir, 'pyproto')
_widevine_proto_path = os.path.join(_proto_path, 'packager/media/base') _widevine_proto_path = os.path.join(_proto_path, 'packager/media/base')
@ -64,9 +75,9 @@ class BinaryReader(object):
ret = 0 ret = 0
for i in range(0, size): for i in range(0, size):
if self.little_endian: if self.little_endian:
ret |= (ord(data[i]) << (8 * i)) ret |= (to_code_point(data[i]) << (8 * i))
else: else:
ret |= (ord(data[i]) << (8 * (size - i - 1))) ret |= (to_code_point(data[i]) << (8 * (size - i - 1)))
return ret return ret