mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 15:08:40 +00:00
[#3204|Core] Fix unicode get_name unicode error
The recent change to torrent.get_name does not handle non-ascii paths on Python 2. - Add a decode_bytes to resolve the issue. - Add tests. - Refactor to reduce nesting.
This commit is contained in:
parent
9ab2a50097
commit
b834e33568
3 changed files with 18 additions and 15 deletions
|
@ -933,23 +933,18 @@ class Torrent(object):
|
||||||
str: the name of the torrent.
|
str: the name of the torrent.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.options['name']:
|
if self.options['name']:
|
||||||
# Use the top-level folder as torrent name.
|
return self.options['name']
|
||||||
if self.has_metadata:
|
|
||||||
handle_name = (
|
|
||||||
self.torrent_info.file_at(0)
|
|
||||||
.path.replace('\\', '/', 1)
|
|
||||||
.split('/', 1)[0]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
handle_name = self.handle.name()
|
|
||||||
|
|
||||||
if handle_name:
|
if self.has_metadata:
|
||||||
name = decode_bytes(handle_name)
|
# Use the top-level folder as torrent name.
|
||||||
else:
|
filename = decode_bytes(self.torrent_info.file_at(0).path)
|
||||||
name = self.torrent_id
|
name = filename.replace('\\', '/', 1).split('/', 1)[0]
|
||||||
else:
|
else:
|
||||||
name = self.options['name']
|
name = decode_bytes(self.handle.name())
|
||||||
|
|
||||||
|
if not name:
|
||||||
|
name = self.torrent_id
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
1
deluge/tests/data/unicode_file.torrent
Normal file
1
deluge/tests/data/unicode_file.torrent
Normal file
|
@ -0,0 +1 @@
|
||||||
|
d13:creation datei1540200743e8:encoding5:UTF-84:infod6:lengthi0e4:name35:সুকুমার রায়.mkv12:piece lengthi32768e6:pieces0:7:privatei0eee
|
|
@ -297,3 +297,10 @@ class TorrentTestCase(BaseTestCase):
|
||||||
result = self.torrent.get_eta()
|
result = self.torrent.get_eta()
|
||||||
self.assertEqual(result, 100)
|
self.assertEqual(result, 100)
|
||||||
self.assertIsInstance(result, int)
|
self.assertIsInstance(result, int)
|
||||||
|
|
||||||
|
def test_get_name_unicode(self):
|
||||||
|
"""Test retrieving a unicode torrent name from libtorrent."""
|
||||||
|
atp = self.get_torrent_atp('unicode_file.torrent')
|
||||||
|
handle = self.session.add_torrent(atp)
|
||||||
|
self.torrent = Torrent(handle, {})
|
||||||
|
self.assertEqual(self.torrent.get_name(), 'সুকুমার রায়.mkv')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue