mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 09:28:41 +00:00
[Common] Fix incorrect path in TorrentInfo
Refactoring for Python 3 did not account for the `self._files` using an updated info_dict so simplify code by updating in the files for loop. Added test that TorrentInfo.files returns the correct structure.
This commit is contained in:
parent
10d39c83cb
commit
55aee2b00f
2 changed files with 50 additions and 42 deletions
|
@ -8,6 +8,7 @@
|
||||||
#
|
#
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from six import assertCountEqual
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from deluge.common import windows_check
|
from deluge.common import windows_check
|
||||||
|
@ -32,29 +33,45 @@ class UICommonTestCase(unittest.TestCase):
|
||||||
if windows_check():
|
if windows_check():
|
||||||
raise unittest.SkipTest('on windows KeyError: unicode_filenames')
|
raise unittest.SkipTest('on windows KeyError: unicode_filenames')
|
||||||
filename = common.get_test_data_file('unicode_filenames.torrent')
|
filename = common.get_test_data_file('unicode_filenames.torrent')
|
||||||
ti = TorrentInfo(filename)
|
filepath1 = '\u30c6\u30af\u30b9\u30fb\u30c6\u30af\u30b5\u30f3.mkv'
|
||||||
|
filepath2 = (
|
||||||
|
'\u041c\u0438\u0445\u0430\u0438\u043b \u0413\u043e'
|
||||||
|
'\u0440\u0431\u0430\u0447\u0451\u0432.mkv'
|
||||||
|
)
|
||||||
|
filepath3 = "Alisher ibn G'iyosiddin Navoiy.mkv"
|
||||||
|
filepath4 = 'Ascii title.mkv'
|
||||||
|
filepath5 = '\u09b8\u09c1\u0995\u09c1\u09ae\u09be\u09b0 \u09b0\u09be\u09df.mkv'
|
||||||
|
|
||||||
files = ti.files_tree['unicode_filenames']
|
ti = TorrentInfo(filename)
|
||||||
self.assertTrue(
|
files_tree = ti.files_tree['unicode_filenames']
|
||||||
(
|
self.assertIn(filepath1, files_tree)
|
||||||
b'\xe3\x83\x86\xe3\x82\xaf\xe3\x82\xb9\xe3\x83\xbb\xe3\x83'
|
self.assertIn(filepath2, files_tree)
|
||||||
b'\x86\xe3\x82\xaf\xe3\x82\xb5\xe3\x83\xb3.mkv'
|
self.assertIn(filepath3, files_tree)
|
||||||
).decode('utf8')
|
self.assertIn(filepath4, files_tree)
|
||||||
in files
|
self.assertIn(filepath5, files_tree)
|
||||||
)
|
|
||||||
self.assertTrue(
|
result_files = [
|
||||||
(
|
{
|
||||||
b'\xd0\x9c\xd0\xb8\xd1\x85\xd0\xb0\xd0\xb8\xd0\xbb \xd0\x93'
|
'download': True,
|
||||||
b'\xd0\xbe\xd1\x80\xd0\xb1\xd0\xb0\xd1\x87\xd1\x91\xd0\xb2.mkv'
|
'path': 'unicode_filenames/' + filepath3,
|
||||||
).decode('utf8')
|
'size': 126158658,
|
||||||
in files
|
},
|
||||||
)
|
{
|
||||||
self.assertTrue(b"Alisher ibn G'iyosiddin Navoiy.mkv".decode('utf8') in files)
|
'download': True,
|
||||||
self.assertTrue(b'Ascii title.mkv'.decode('utf8') in files)
|
'path': 'unicode_filenames/' + filepath4,
|
||||||
self.assertTrue(
|
'size': 189321363,
|
||||||
(
|
},
|
||||||
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'
|
'download': True,
|
||||||
).decode('utf8')
|
'path': 'unicode_filenames/' + filepath2,
|
||||||
in files
|
'size': 106649699,
|
||||||
)
|
},
|
||||||
|
{
|
||||||
|
'download': True,
|
||||||
|
'path': 'unicode_filenames/' + filepath5,
|
||||||
|
'size': 21590269,
|
||||||
|
},
|
||||||
|
{'download': True, 'path': 'unicode_filenames/' + filepath1, 'size': 1771},
|
||||||
|
]
|
||||||
|
|
||||||
|
assertCountEqual(self, ti.files, result_files)
|
||||||
|
|
|
@ -221,6 +221,7 @@ class TorrentInfo(object):
|
||||||
self._name = decode_bytes(info_dict['name'], encoding)
|
self._name = decode_bytes(info_dict['name'], encoding)
|
||||||
|
|
||||||
# Get list of files from torrent info
|
# Get list of files from torrent info
|
||||||
|
self._files = []
|
||||||
if 'files' in info_dict:
|
if 'files' in info_dict:
|
||||||
paths = {}
|
paths = {}
|
||||||
dirs = {}
|
dirs = {}
|
||||||
|
@ -238,9 +239,12 @@ class TorrentInfo(object):
|
||||||
if prefix:
|
if prefix:
|
||||||
path = os.path.join(prefix, path)
|
path = os.path.join(prefix, path)
|
||||||
|
|
||||||
|
self._files.append(
|
||||||
|
{'path': path, 'size': f['length'], 'download': True}
|
||||||
|
)
|
||||||
|
|
||||||
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:
|
||||||
f['sha1'] = hexlify(f['sha1']).decode()
|
f['sha1'] = hexlify(f['sha1']).decode()
|
||||||
if 'ed2k' in f and len(f['ed2k']) == 16:
|
if 'ed2k' in f and len(f['ed2k']) == 16:
|
||||||
|
@ -277,6 +281,9 @@ class TorrentInfo(object):
|
||||||
file_tree.walk(walk)
|
file_tree.walk(walk)
|
||||||
self._files_tree = file_tree.get_tree()
|
self._files_tree = file_tree.get_tree()
|
||||||
else:
|
else:
|
||||||
|
self._files.append(
|
||||||
|
{'path': self._name, 'size': info_dict['length'], 'download': True}
|
||||||
|
)
|
||||||
if filetree == 2:
|
if filetree == 2:
|
||||||
self._files_tree = {
|
self._files_tree = {
|
||||||
'contents': {
|
'contents': {
|
||||||
|
@ -291,22 +298,6 @@ class TorrentInfo(object):
|
||||||
else:
|
else:
|
||||||
self._files_tree = {self._name: (0, info_dict['length'], True)}
|
self._files_tree = {self._name: (0, info_dict['length'], True)}
|
||||||
|
|
||||||
self._files = []
|
|
||||||
if 'files' in info_dict:
|
|
||||||
prefix = ''
|
|
||||||
if len(info_dict['files']) > 1:
|
|
||||||
prefix = self._name
|
|
||||||
|
|
||||||
for f in info_dict['files']:
|
|
||||||
path_list = [k.decode(encoding) for k in f[b'path']]
|
|
||||||
self._files.append(
|
|
||||||
{'path': path_list, 'size': f[b'length'], 'download': True}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._files.append(
|
|
||||||
{'path': self._name, 'size': info_dict['length'], 'download': True}
|
|
||||||
)
|
|
||||||
|
|
||||||
def as_dict(self, *keys):
|
def as_dict(self, *keys):
|
||||||
"""The torrent info as a dictionary, filtered by keys.
|
"""The torrent info as a dictionary, filtered by keys.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue