From 96ba53d916d24182993d75d6d20169c68096fdab Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 24 Jun 2024 15:50:45 -0700 Subject: [PATCH] Handle another fix after 57119c1b300d8f7b1cc87c6aea9b1bf5a294d87f --- modules/block_requests.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/block_requests.py b/modules/block_requests.py index 1bfa9a99..778b9f5a 100644 --- a/modules/block_requests.py +++ b/modules/block_requests.py @@ -43,6 +43,9 @@ def my_open(*args, **kwargs): with original_open(*args, **kwargs) as f: file_contents = f.read() + if len(args) > 1 and args[1] == 'rb': + file_contents = file_contents.decode('utf-8') + file_contents = file_contents.replace('\t\t', '') file_contents = file_contents.replace('cdnjs.cloudflare.com', '127.0.0.1') file_contents = file_contents.replace( @@ -55,7 +58,12 @@ def my_open(*args, **kwargs): '\n ' ) - return io.StringIO(file_contents) + if len(args) > 1 and args[1] == 'rb': + file_contents = file_contents.encode('utf-8') + return io.BytesIO(file_contents) + else: + return io.StringIO(file_contents) + else: return original_open(*args, **kwargs)