mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 08:58:38 +00:00
[Common] Decode byte strings for TorrentInfo
This commit is contained in:
parent
bbd2661acb
commit
9ad2f50fa4
2 changed files with 13 additions and 14 deletions
|
@ -33,11 +33,11 @@ class UICommonTestCase(unittest.TestCase):
|
||||||
ti = TorrentInfo(filename)
|
ti = TorrentInfo(filename)
|
||||||
|
|
||||||
files = ti.files_tree['unicode_filenames']
|
files = ti.files_tree['unicode_filenames']
|
||||||
self.assertTrue(b'\xe3\x83\x86\xe3\x82\xaf\xe3\x82\xb9\xe3\x83\xbb\xe3\x83'
|
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)
|
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'
|
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)
|
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" in files)
|
self.assertTrue(b"Alisher ibn G'iyosiddin Navoiy.mkv".decode('utf8') in files)
|
||||||
self.assertTrue(b'Ascii title.mkv' 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'
|
self.assertTrue((b'\xe0\xa6\xb8\xe0\xa7\x81\xe0\xa6\x95\xe0\xa7\x81\xe0\xa6\xae\xe0\xa6\xbe'
|
||||||
b'\xae\xe0\xa6\xbe\xe0\xa6\xb0 \xe0\xa6\xb0\xe0\xa6\xbe\xe0\xa7\x9f.mkv' in files)
|
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
|
import deluge.configmanager
|
||||||
from deluge import bencode
|
from deluge import bencode
|
||||||
from deluge.common import utf8_encoded
|
from deluge.common import decode_string
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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
|
# Check if 'name.utf-8' is in the torrent and if not try to decode the string
|
||||||
# using the encoding found.
|
# using the encoding found.
|
||||||
if 'name.utf-8' in self.__m_metadata['info']:
|
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:
|
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
|
# Get list of files from torrent info
|
||||||
paths = {}
|
paths = {}
|
||||||
|
@ -180,11 +180,10 @@ class TorrentInfo(object):
|
||||||
|
|
||||||
for index, f in enumerate(self.__m_metadata['info']['files']):
|
for index, f in enumerate(self.__m_metadata['info']['files']):
|
||||||
if 'path.utf-8' in f:
|
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']
|
del f['path.utf-8']
|
||||||
else:
|
else:
|
||||||
path = utf8_encoded(os.path.join(prefix, utf8_encoded(os.path.join(*f['path']),
|
path = os.path.join(prefix, decode_string(os.path.join(*f['path']), self.encoding))
|
||||||
self.encoding)), self.encoding)
|
|
||||||
f['path'] = path
|
f['path'] = path
|
||||||
f['index'] = index
|
f['index'] = index
|
||||||
if 'sha1' in f and len(f['sha1']) == 20:
|
if 'sha1' in f and len(f['sha1']) == 20:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue