mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-24 02:11:06 +00:00
[GTK] Fix unable to prefetch magnet in thinclient
A UnicodeDecodeError is raised in transfer module when attempting to prefetch a magnet. This is result of passing a Python dict containing text bytes and raw bytes that cannot be decoded as utf-8 in rencode when recieving the message. This could be handled in rencode by returning raw bytes if decoding fails (perhaps with a strict mode?) however better to follow convention of encoding raw bytes in base64 in API calls. Fixed by retaining bencoding and encoding with base64 when sending result. Resolves: https://github.com/deluge-torrent/deluge/pull/334
This commit is contained in:
parent
79b7e6093f
commit
e50927f575
@ -432,12 +432,14 @@ class Core(component.Component):
|
||||
|
||||
Used by UIs to get magnet files for selection before adding to session.
|
||||
|
||||
The metadata is bencoded and for transfer base64 encoded.
|
||||
|
||||
Args:
|
||||
magnet (str): The magnet URI.
|
||||
timeout (int): Number of seconds to wait before canceling request.
|
||||
|
||||
Returns:
|
||||
Deferred: A tuple of (torrent_id (str), metadata (dict)) for the magnet.
|
||||
Deferred: A tuple of (torrent_id (str), metadata (str)) for the magnet.
|
||||
|
||||
"""
|
||||
|
||||
|
@ -13,6 +13,7 @@ import operator
|
||||
import os
|
||||
import pickle
|
||||
import time
|
||||
from base64 import b64encode
|
||||
from collections import namedtuple
|
||||
from tempfile import gettempdir
|
||||
|
||||
@ -396,12 +397,12 @@ class TorrentManager(component.Component):
|
||||
else:
|
||||
self.session.remove_torrent(torrent_handle, 1)
|
||||
|
||||
metadata = None
|
||||
metadata = b''
|
||||
if isinstance(torrent_info, lt.torrent_info):
|
||||
log.debug('prefetch metadata received')
|
||||
metadata = lt.bdecode(torrent_info.metadata())
|
||||
metadata = torrent_info.metadata()
|
||||
|
||||
return torrent_id, metadata
|
||||
return torrent_id, b64encode(metadata)
|
||||
|
||||
def _build_torrent_options(self, options):
|
||||
"""Load default options and update if needed."""
|
||||
|
@ -317,7 +317,7 @@ class CoreTestCase(BaseTestCase):
|
||||
def test_prefetch_metadata_existing(self):
|
||||
"""Check another call with same magnet returns existing deferred."""
|
||||
magnet = 'magnet:?xt=urn:btih:ab570cdd5a17ea1b61e970bb72047de141bce173'
|
||||
expected = ('ab570cdd5a17ea1b61e970bb72047de141bce173', None)
|
||||
expected = ('ab570cdd5a17ea1b61e970bb72047de141bce173', b'')
|
||||
|
||||
def on_result(result):
|
||||
self.assertEqual(result, expected)
|
||||
|
@ -15,6 +15,7 @@ from twisted.internet import defer, task
|
||||
from twisted.trial import unittest
|
||||
|
||||
from deluge import component
|
||||
from deluge.bencode import bencode
|
||||
from deluge.common import windows_check
|
||||
from deluge.core.core import Core
|
||||
from deluge.core.rpcserver import RPCServer
|
||||
@ -82,6 +83,8 @@ class TorrentmanagerTestCase(BaseTestCase):
|
||||
|
||||
expected = (
|
||||
'ab570cdd5a17ea1b61e970bb72047de141bce173',
|
||||
b64encode(
|
||||
bencode(
|
||||
{
|
||||
b'piece length': 32768,
|
||||
b'sha1': (
|
||||
@ -109,7 +112,9 @@ class TorrentmanagerTestCase(BaseTestCase):
|
||||
b'length': 307949,
|
||||
b'name.utf-8': b'azcvsupdater_2.6.2.jar',
|
||||
b'ed2k': b'>p\xefl\xfa]\x95K\x1b^\xc2\\;;e\xb7',
|
||||
},
|
||||
}
|
||||
)
|
||||
),
|
||||
)
|
||||
self.assertEqual(expected, self.successResultOf(d))
|
||||
|
||||
@ -117,7 +122,7 @@ class TorrentmanagerTestCase(BaseTestCase):
|
||||
magnet = 'magnet:?xt=urn:btih:ab570cdd5a17ea1b61e970bb72047de141bce173'
|
||||
d = self.tm.prefetch_metadata(magnet, 30)
|
||||
self.clock.advance(30)
|
||||
expected = ('ab570cdd5a17ea1b61e970bb72047de141bce173', None)
|
||||
expected = ('ab570cdd5a17ea1b61e970bb72047de141bce173', b'')
|
||||
return d.addCallback(self.assertEqual, expected)
|
||||
|
||||
@pytest.mark.todo
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
from base64 import b64encode
|
||||
from base64 import b64decode, b64encode
|
||||
from xml.sax.saxutils import escape as xml_escape
|
||||
from xml.sax.saxutils import unescape as xml_unescape
|
||||
|
||||
@ -16,6 +16,7 @@ from gi.repository import Gtk
|
||||
from gi.repository.GObject import TYPE_INT64, TYPE_UINT64
|
||||
|
||||
import deluge.component as component
|
||||
from deluge.bencode import bdecode
|
||||
from deluge.common import (
|
||||
create_magnet_uri,
|
||||
decode_bytes,
|
||||
@ -268,6 +269,7 @@ class AddTorrentDialog(component.Component):
|
||||
return
|
||||
|
||||
if metadata:
|
||||
metadata = bdecode(b64decode(metadata))
|
||||
info = TorrentInfo.from_metadata(metadata, [[t] for t in trackers])
|
||||
self.files[info_hash] = info.files
|
||||
self.infos[info_hash] = info.filedata
|
||||
|
Loading…
x
Reference in New Issue
Block a user