fix add_torrent_params field in add_torrent_alert. include more fields in dict -> add_torrent_param converter for add_torrent/async_add_torrent

This commit is contained in:
arvidn 2017-01-15 21:14:24 -05:00 committed by Arvid Norberg
parent d4672f41ba
commit 450a8fb170
3 changed files with 20 additions and 47 deletions

View File

@ -45,32 +45,6 @@ list get_status_from_update_alert(state_update_alert const& alert)
return result;
}
dict get_params(add_torrent_alert const& alert)
{
add_torrent_params const& p = alert.params;
dict ret;
ret["ti"] = p.ti;
ret["info_hash"] = p.info_hash;
ret["name"] = p.name;
ret["save_path"] = p.save_path;
ret["storage_mode"] = p.storage_mode;
list trackers;
for (std::vector<std::string>::const_iterator i = p.trackers.begin();
i != p.trackers.end(); ++i)
{
trackers.append(*i);
}
ret["trackers"] = trackers;
// TODO: dht_nodes
ret["flags"] = p.flags;
ret["trackerid"] = p.trackerid;
ret["url"] = p.url;
#ifndef TORRENT_NO_DEPRECATE
ret["uuid"] = p.uuid;
#endif
return ret;
}
list dht_stats_active_requests(dht_stats_alert const& a)
{
list result;
@ -822,7 +796,7 @@ void bind_alert()
class_<add_torrent_alert, bases<torrent_alert>, noncopyable>(
"add_torrent_alert", no_init)
.def_readonly("error", &add_torrent_alert::error)
.add_property("params", &get_params)
.add_property("params", &add_torrent_alert::params)
;
#ifndef TORRENT_NO_DEPRECATE

View File

@ -236,20 +236,15 @@ namespace
p.storage_mode = extract<storage_mode_t>(params["storage_mode"]);
if (params.has_key("trackers"))
{
list l = extract<list>(params["trackers"]);
int const n = int(boost::python::len(l));
for(int i = 0; i < n; i++)
p.trackers.push_back(extract<std::string>(l[i]));
}
p.trackers = extract<std::vector<std::string>>(params["trackers"]);
if (params.has_key("dht_nodes"))
{
list l = extract<list>(params["dht_nodes"]);
int const n = int(boost::python::len(l));
for(int i = 0; i < n; i++)
p.dht_nodes.push_back(extract<std::pair<std::string, int>>(l[i]));
}
p.dht_nodes = extract<std::vector<std::pair<std::string, int>>>(params["dht_nodes"]);
if (params.has_key("http_seeds"))
p.http_seeds = extract<std::vector<std::string>>(params["http_seeds"]);
if (params.has_key("peers"))
p.peers = extract<std::vector<tcp::endpoint>>(params["peers"]);
if (params.has_key("banned_peers"))
p.banned_peers = extract<std::vector<tcp::endpoint>>(params["banned_peers"]);
if (params.has_key("flags"))
p.flags = extract<std::uint64_t>(params["flags"]);
if (params.has_key("trackerid"))
@ -262,13 +257,7 @@ namespace
#endif
if (params.has_key("file_priorities"))
{
list l = extract<list>(params["file_priorities"]);
int const n = int(boost::python::len(l));
for(int i = 0; i < n; i++)
p.file_priorities.push_back(extract<std::uint8_t>(l[i]));
p.file_priorities.clear();
}
p.file_priorities = extract<std::vector<std::uint8_t>>(params["file_priorities"]);
}
namespace

View File

@ -252,6 +252,16 @@ class test_session(unittest.TestCase):
self.assertTrue(isinstance(a.values, dict))
self.assertTrue(len(a.values) > 0)
def test_add_torrent(self):
s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, 'enable_dht': False})
h = s.add_torrent({'ti': lt.torrent_info('base.torrent'),
'save_path': '.',
'dht_nodes': [('1.2.3.4', 6881), ('4.3.2.1', 6881)],
'http_seeds': ['http://test.com/seed'],
'peers': [('5.6.7.8', 6881)],
'banned_peers': [('8.7.6.5', 6881)],
'file_priorities': [1,1,1,2,0]})
def test_unknown_settings(self):
try:
s = lt.session({'unexpected-key-name': 42})