]> git.phdru.name Git - extfs.d.git/blobdiff - torrent
Feat(torrent): Try harder to guess encoding
[extfs.d.git] / torrent
diff --git a/torrent b/torrent
index ba725c965aed4ac000d185a2ba481f19066e59b9..a0f827ef91f7ad213d7ab70445e9ef0e54e6175a 100755 (executable)
--- a/torrent
+++ b/torrent
@@ -317,11 +317,16 @@ def decode_torrent():
             encoding = encoding.decode('ascii')
         elif codepage:
             encoding = codepage.decode('ascii')
-
-    if PY3 and encoding:
+        else:
+            for encoding in ('ascii', 'utf-8', default_encoding):
+                try:
+                    return decode_dict(torrent, encoding)
+                except UnicodeDecodeError:
+                    pass
+            torrent_error('UnicodeDecodeError')
         return decode_dict(torrent, encoding)
-    else:
-        return torrent
+
+    return torrent
 
 
 def decode_datetime_asc(dt):