]> git.phdru.name Git - extfs.d.git/commitdiff
Fix(torrent): Process torrent file as binary
authorOleg Broytman <phd@phdru.name>
Wed, 9 Aug 2023 18:02:47 +0000 (21:02 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 13 Aug 2023 13:08:26 +0000 (16:08 +0300)
eff_bdecode.py
torrent

index fe1c4c245e54fa076c2f076c10b330de756f1b77..2f8fc5eb1d3caa9f3d384cbcfe9f455d7bb90950 100644 (file)
@@ -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 63632420629529168b7325423f6b2df8413a57e1..550ad72ebf9c1f459e12a5cfa7b0eccf19bb2207 100755 (executable)
--- 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)