From 134fa7b0fbebeca26abc1f9e9a3839608b8d21e8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 19 Oct 2012 05:18:48 +0000 Subject: [PATCH] merged python fix from RC_0_16 --- ChangeLog | 1 + bindings/python/src/magnet_uri.cpp | 6 ++--- bindings/python/src/session.cpp | 43 +++++++++++++++++------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0770d95df..0e1e1a205 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * added missing async_add_torrent to python bindings * raised the limit for bottled http downloads to 2 MiB * add support for magnet links and URLs in python example client * fixed typo in python bindings' add_torrent_params diff --git a/bindings/python/src/magnet_uri.cpp b/bindings/python/src/magnet_uri.cpp index ea4dbcb57..4998c6a02 100644 --- a/bindings/python/src/magnet_uri.cpp +++ b/bindings/python/src/magnet_uri.cpp @@ -12,8 +12,7 @@ using namespace boost::python; using namespace libtorrent; extern void dict_to_add_torrent_params(dict params - , add_torrent_params& p, std::vector& rd - , std::list& storage); + , add_torrent_params& p, std::vector& rd); namespace { @@ -23,8 +22,7 @@ namespace { add_torrent_params p; std::vector resume_buf; - std::list string_storage; - dict_to_add_torrent_params(params, p, resume_buf, string_storage); + dict_to_add_torrent_params(params, p, resume_buf); allow_threading_guard guard; diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 21cc4fe8d..b62a6388a 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -162,7 +162,7 @@ namespace } void dict_to_add_torrent_params(dict params, add_torrent_params& p - , std::vector& rd, std::list& string_storage) + , std::vector& rd) { // torrent_info objects are always held by an intrusive_ptr in the python binding if (params.has_key("ti") && params.get("ti") != boost::python::object()) @@ -171,10 +171,7 @@ namespace if (params.has_key("info_hash")) p.info_hash = extract(params["info_hash"]); if (params.has_key("name")) - { - string_storage.push_back(extract(params["name"])); - p.name = string_storage.back().c_str(); - } + p.name = extract(params["name"]); p.save_path = extract(params["save_path"]); if (params.has_key("resume_data")) @@ -205,10 +202,7 @@ namespace #ifndef TORRENT_NO_DEPRECATE std::string url; if (params.has_key("tracker_url")) - { - string_storage.push_back(extract(params["tracker_url"])); - p.tracker_url = string_storage.back().c_str(); - } + p.trackers.push_back(extract(params["tracker_url"])); if (params.has_key("seed_mode")) p.seed_mode = params["seed_mode"]; if (params.has_key("upload_mode")) @@ -248,8 +242,7 @@ namespace { add_torrent_params p; std::vector resume_buf; - std::list string_buf; - dict_to_add_torrent_params(params, p, resume_buf, string_buf); + dict_to_add_torrent_params(params, p, resume_buf); allow_threading_guard guard; @@ -261,9 +254,24 @@ namespace #endif } + void async_add_torrent(session& s, dict params) + { + add_torrent_params p; + std::vector resume_buf; + dict_to_add_torrent_params(params, p, resume_buf); + + allow_threading_guard guard; + +#ifndef BOOST_NO_EXCEPTIONS + s.async_add_torrent(p); +#else + error_code ec; + s.async_add_torrent(p, ec); +#endif + } + void dict_to_feed_settings(dict params, feed_settings& feed - , std::vector& resume_buf - , std::list& string_storage) + , std::vector& resume_buf) { if (params.has_key("auto_download")) feed.auto_download = extract(params["auto_download"]); @@ -273,7 +281,7 @@ namespace feed.url = extract(params["url"]); if (params.has_key("add_args")) dict_to_add_torrent_params(dict(params["add_args"]), feed.add_args - , resume_buf, string_storage); + , resume_buf); } feed_handle add_feed(session& s, dict params) @@ -282,8 +290,7 @@ namespace // this static here is a bit of a hack. It will // probably work for the most part static std::vector resume_buf; - std::list string_storage; - dict_to_feed_settings(params, feed, resume_buf, string_storage); + dict_to_feed_settings(params, feed, resume_buf); allow_threading_guard guard; return s.add_feed(feed); @@ -330,8 +337,7 @@ namespace { feed_settings feed; static std::vector resume_buf; - std::list string_storage; - dict_to_feed_settings(sett, feed, resume_buf, string_storage); + dict_to_feed_settings(sett, feed, resume_buf); h.set_settings(feed); } @@ -556,6 +562,7 @@ void bind_session() #endif #endif .def("add_torrent", &add_torrent) + .def("async_add_torrent", &async_add_torrent) #ifndef BOOST_NO_EXCEPTIONS #ifndef TORRENT_NO_DEPRECATE .def(