mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 20:14:13 +00:00
[Common] Decode byte strings for TorrentInfo
This commit is contained in:
parent
bbd2661acb
commit
9ad2f50fa4
@ -33,11 +33,11 @@ class UICommonTestCase(unittest.TestCase):
|
||||
ti = TorrentInfo(filename)
|
||||
|
||||
files = ti.files_tree['unicode_filenames']
|
||||
self.assertTrue(b'\xe3\x83\x86\xe3\x82\xaf\xe3\x82\xb9\xe3\x83\xbb\xe3\x83'
|
||||
b'\x86\xe3\x82\xaf\xe3\x82\xb5\xe3\x83\xb3.mkv' in files)
|
||||
self.assertTrue(b'\xd0\x9c\xd0\xb8\xd1\x85\xd0\xb0\xd0\xb8\xd0\xbb \xd0\x93'
|
||||
b'\xd0\xbe\xd1\x80\xd0\xb1\xd0\xb0\xd1\x87\xd1\x91\xd0\xb2.mkv' in files)
|
||||
self.assertTrue(b"Alisher ibn G'iyosiddin Navoiy.mkv" in files)
|
||||
self.assertTrue(b'Ascii title.mkv' in files)
|
||||
self.assertTrue(b'\xe0\xa6\xb8\xe0\xa7\x81\xe0\xa6\x95\xe0\xa7\x81\xe0\xa6'
|
||||
b'\xae\xe0\xa6\xbe\xe0\xa6\xb0 \xe0\xa6\xb0\xe0\xa6\xbe\xe0\xa7\x9f.mkv' in files)
|
||||
self.assertTrue((b'\xe3\x83\x86\xe3\x82\xaf\xe3\x82\xb9\xe3\x83\xbb\xe3\x83'
|
||||
b'\x86\xe3\x82\xaf\xe3\x82\xb5\xe3\x83\xb3.mkv').decode('utf8') in files)
|
||||
self.assertTrue((b'\xd0\x9c\xd0\xb8\xd1\x85\xd0\xb0\xd0\xb8\xd0\xbb \xd0\x93'
|
||||
b'\xd0\xbe\xd1\x80\xd0\xb1\xd0\xb0\xd1\x87\xd1\x91\xd0\xb2.mkv').decode('utf8') in files)
|
||||
self.assertTrue(b"Alisher ibn G'iyosiddin Navoiy.mkv".decode('utf8') in files)
|
||||
self.assertTrue(b'Ascii title.mkv'.decode('utf8') in files)
|
||||
self.assertTrue((b'\xe0\xa6\xb8\xe0\xa7\x81\xe0\xa6\x95\xe0\xa7\x81\xe0\xa6\xae\xe0\xa6\xbe'
|
||||
b'\xe0\xa6\xb0 \xe0\xa6\xb0\xe0\xa6\xbe\xe0\xa7\x9f.mkv').decode('utf8') in files)
|
||||
|
@ -20,7 +20,7 @@ from hashlib import sha1 as sha
|
||||
|
||||
import deluge.configmanager
|
||||
from deluge import bencode
|
||||
from deluge.common import utf8_encoded
|
||||
from deluge.common import decode_string
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -166,9 +166,9 @@ class TorrentInfo(object):
|
||||
# Check if 'name.utf-8' is in the torrent and if not try to decode the string
|
||||
# using the encoding found.
|
||||
if 'name.utf-8' in self.__m_metadata['info']:
|
||||
self.__m_name = utf8_encoded(self.__m_metadata['info']['name.utf-8'])
|
||||
self.__m_name = decode_string(self.__m_metadata['info']['name.utf-8'])
|
||||
else:
|
||||
self.__m_name = utf8_encoded(self.__m_metadata['info']['name'], self.encoding)
|
||||
self.__m_name = decode_string(self.__m_metadata['info']['name'], self.encoding)
|
||||
|
||||
# Get list of files from torrent info
|
||||
paths = {}
|
||||
@ -180,11 +180,10 @@ class TorrentInfo(object):
|
||||
|
||||
for index, f in enumerate(self.__m_metadata['info']['files']):
|
||||
if 'path.utf-8' in f:
|
||||
path = os.path.join(prefix, *f['path.utf-8'])
|
||||
path = decode_string(os.path.join(prefix, *f['path.utf-8']))
|
||||
del f['path.utf-8']
|
||||
else:
|
||||
path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f['path']),
|
||||
self.encoding)), self.encoding)
|
||||
path = os.path.join(prefix, decode_string(os.path.join(*f['path']), self.encoding))
|
||||
f['path'] = path
|
||||
f['index'] = index
|
||||
if 'sha1' in f and len(f['sha1']) == 20:
|
||||
|
Loading…
x
Reference in New Issue
Block a user