From d9d3c7f8be13e493a99b2ff4b72a402c441c1666 Mon Sep 17 00:00:00 2001 From: Allan Lei Date: Thu, 13 Jul 2023 00:03:43 +0800 Subject: [PATCH] fix: Indexing `bytes` produces `int` on python3 for `pssh-box.py` (#1228) Fixes #1227 --- packager/tools/pssh/pssh-box.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packager/tools/pssh/pssh-box.py b/packager/tools/pssh/pssh-box.py index 7c2b20ffa0..45306247d1 100755 --- a/packager/tools/pssh/pssh-box.py +++ b/packager/tools/pssh/pssh-box.py @@ -20,6 +20,17 @@ import os import struct 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__)) _proto_path = os.path.join(_script_dir, 'pyproto') _widevine_proto_path = os.path.join(_proto_path, 'packager/media/base') @@ -64,9 +75,9 @@ class BinaryReader(object): ret = 0 for i in range(0, size): if self.little_endian: - ret |= (ord(data[i]) << (8 * i)) + ret |= (to_code_point(data[i]) << (8 * i)) else: - ret |= (ord(data[i]) << (8 * (size - i - 1))) + ret |= (to_code_point(data[i]) << (8 * (size - i - 1))) return ret