From 568ab7342bd21f4392b620cab3c97f76b6710944 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 9 Aug 2023 21:02:47 +0300 Subject: [PATCH] Fix(torrent): Process torrent file as binary --- eff_bdecode.py | 4 ++-- torrent | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eff_bdecode.py b/eff_bdecode.py index fe1c4c2..2f8fc5e 100644 --- a/eff_bdecode.py +++ b/eff_bdecode.py @@ -27,7 +27,7 @@ from functools import partial import re -def tokenize(text, match=re.compile("([idel])|(\\d+):|(-?\\d+)").match): +def tokenize(text, match=re.compile(b"([idel])|(\\d+):|(-?\\d+)").match): i = 0 while i < len(text): m = match(text, i) @@ -38,7 +38,7 @@ def tokenize(text, match=re.compile("([idel])|(\\d+):|(-?\\d+)").match): yield text[i:i+int(s)] i = i + int(s) else: - yield s + yield s.decode('ascii') def decode_item(next_, token): diff --git a/torrent b/torrent index 6363242..550ad72 100755 --- a/torrent +++ b/torrent @@ -265,7 +265,7 @@ def torrent_error(error_str): def decode_torrent(): try: - torrent_file = open(sys.argv[2], 'r') + torrent_file = open(sys.argv[2], 'rb') data = torrent_file.read() torrent_file.close() return decode(data) -- 2.39.5