Update bindings

This commit is contained in:
Andrew Resch 2008-10-28 22:20:46 +00:00
commit 12a6be4e20
6 changed files with 117 additions and 59 deletions

View file

@ -56,7 +56,9 @@ void bind_alert()
.def("message", &alert::message, alert_msg_doc)
.def("what", &alert::what)
.def("category", &alert::category)
#ifndef TORRENT_NO_DEPRECATE
.def("severity", &alert::severity, alert_severity_doc)
#endif
.def("__str__", &alert::message, alert_msg_doc)
;
@ -79,8 +81,10 @@ void bind_alert()
.value("status_notification", alert::status_notification)
.value("progress_notification", alert::progress_notification)
.value("ip_block_notification", alert::ip_block_notification)
.value("performance_warning", alert::performance_warning)
.value("all_categories", alert::all_categories)
;
}
class_<torrent_alert, bases<alert>, noncopyable>(
@ -350,4 +354,16 @@ void bind_alert()
"save_resume_data_failed_alert", no_init
);
class_<performance_alert, bases<torrent_alert>, noncopyable>(
"performance_alert", no_init
)
.def_readonly("warning_code", &performance_alert::warning_code)
;
enum_<performance_alert::performance_warning_t>("performance_warning_t")
.value("outstanding_disk_buffer_limit_reached", performance_alert::outstanding_disk_buffer_limit_reached)
.value("outstanding_request_limit_reached", performance_alert::outstanding_request_limit_reached)
;
}

View file

@ -9,6 +9,7 @@
#include <libtorrent/extensions/ut_pex.hpp>
#include <libtorrent/extensions/metadata_transfer.hpp>
#include <libtorrent/extensions/ut_metadata.hpp>
#include <libtorrent/extensions/smart_ban.hpp>
#include <boost/python.hpp>
#include "gil.hpp"
@ -123,6 +124,10 @@ boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
return create_ut_pex_plugin(t, NULL);
}
boost::shared_ptr<torrent_plugin> create_smart_ban_plugin_wrapper(torrent* t) {
return create_smart_ban_plugin(t, NULL);
}
void bind_extensions()
{
class_<
@ -160,6 +165,7 @@ void bind_extensions()
def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
def("create_metadata_plugin", create_metadata_plugin_wrapper);
def("create_ut_metadata_plugin", create_ut_metadata_plugin_wrapper);
def("create_smart_ban_plugin", create_smart_ban_plugin_wrapper);
}

View file

@ -13,16 +13,21 @@ namespace
{
void add_rule(ip_filter& filter, std::string start, std::string end, int flags)
{
return filter.add_rule(address_v4::from_string(start), address_v4::from_string(end), flags);
return filter.add_rule(address::from_string(start), address::from_string(end), flags);
}
int _access(ip_filter& filter, std::string addr)
{
return filter.access(address::from_string(addr));
}
}
void bind_ip_filter()
{
class_<ip_filter>("ip_filter")
.def("add_rule", &add_rule)
.def("access", allow_threads(&ip_filter::access))
.def_readonly("export_filter", allow_threads(&ip_filter::export_filter))
.def("add_rule", add_rule)
.def("access", _access)
.def("export_filter", allow_threads(&ip_filter::export_filter))
;
}

View file

@ -105,6 +105,16 @@ namespace
s.add_extension(invoke_extension_factory(e));
}
#ifndef TORRENT_NO_DEPRECATE
torrent_handle add_torrent_depr(session& s, torrent_info const& ti
, boost::filesystem::path const& save, entry const& resume
, storage_mode_t storage_mode, bool paused)
{
allow_threading_guard guard;
return s.add_torrent(ti, save, resume, storage_mode, paused, default_storage_constructor);
}
#endif
torrent_handle add_torrent(session& s, dict params)
{
add_torrent_params p;
@ -136,9 +146,13 @@ namespace
std::memcpy(&resume_buf[0], &resume[0], resume.size());
p.resume_data = &resume_buf;
}
if (params.has_key("storage_mode"))
p.storage_mode = extract<storage_mode_t>(params["storage_mode"]);
if (params.has_key("paused"))
p.paused = params["paused"];
if (params.has_key("auto_managed"))
p.auto_managed = params["auto_managed"];
if (params.has_key("duplicate_is_error"))
p.duplicate_is_error = params["duplicate_is_error"];
return s.add_torrent(p);
@ -288,7 +302,18 @@ void bind_session()
.def("set_dht_proxy", allow_threads(&session::set_dht_proxy))
#endif
.def("add_torrent", &add_torrent, session_add_torrent_doc)
#ifndef TORRENT_NO_DEPRECATE
.def(
"add_torrent", &add_torrent_depr
, (
arg("resume_data") = entry(), arg("storage_mode") = storage_mode_sparse,
arg("paused") = false
)
, session_add_torrent_doc
)
#endif
.def("remove_torrent", allow_threads(&session::remove_torrent), arg("option") = session::none
, session_remove_torrent_doc)
.def(
"set_download_rate_limit", allow_threads(&session::set_download_rate_limit)
@ -336,10 +361,12 @@ void bind_session()
#endif
.def("load_state", allow_threads(&session::load_state))
.def("state", allow_threads(&session::state))
#ifndef TORRENT_NO_DEPRECATE
.def(
"set_severity_level", allow_threads(&session::set_severity_level)
, session_set_severity_level_doc
)
#endif
.def("set_alert_mask", allow_threads(&session::set_alert_mask))
.def("pop_alert", allow_threads(&session::pop_alert), session_pop_alert_doc)
.def("add_extension", &add_extension)
@ -362,5 +389,3 @@ void bind_session()
register_ptr_to_python<std::auto_ptr<alert> >();
}

View file

@ -295,9 +295,11 @@ void bind_torrent_handle()
.def("resolve_countries", _(resolve_countries1))
#endif
// deprecated
#ifndef TORRENT_NO_DEPRECATE
.def("filter_piece", _(&torrent_handle::filter_piece))
.def("is_piece_filtered", _(&torrent_handle::is_piece_filtered))
.def("write_resume_data", _(&torrent_handle::write_resume_data))
#endif
.def("piece_availability", piece_availability)
.def("piece_priority", _(piece_priority0))
.def("piece_priority", _(piece_priority1))
@ -306,7 +308,6 @@ void bind_torrent_handle()
.def("prioritize_files", prioritize_files)
.def("file_priorities", file_priorities)
.def("use_interface", &torrent_handle::use_interface)
.def("write_resume_data", _(&torrent_handle::write_resume_data))
.def("save_resume_data", _(&torrent_handle::save_resume_data))
.def("force_reannounce", _(force_reannounce0))
.def("force_reannounce", force_reannounce)
@ -331,4 +332,3 @@ void bind_torrent_handle()
.def("rename_file", _(&torrent_handle::rename_file))
;
}

View file

@ -67,6 +67,10 @@ namespace
std::string result(ti.metadata().get(), ti.metadata_size());
return result;
}
torrent_info construct0(std::string path) {
return torrent_info(fs::path(path));
}
} // namespace unnamed
void bind_torrent_info()
@ -74,9 +78,12 @@ void bind_torrent_info()
return_value_policy<copy_const_reference> copy;
class_<torrent_info, boost::intrusive_ptr<torrent_info> >("torrent_info", no_init)
#ifndef TORRENT_NO_DEPRECATE
.def(init<entry const&>())
#endif
.def(init<sha1_hash const&>())
.def(init<char const*, int>())
.def(init<boost::filesystem::path>())
.def("add_tracker", &torrent_info::add_tracker, (arg("url"), arg("tier")=0))
.def("add_url_seed", &torrent_info::add_url_seed)
@ -87,8 +94,9 @@ void bind_torrent_info()
.def("total_size", &torrent_info::total_size)
.def("piece_length", &torrent_info::piece_length)
.def("num_pieces", &torrent_info::num_pieces)
#ifndef TORRENT_NO_DEPRECATE
.def("info_hash", &torrent_info::info_hash, copy)
#endif
.def("hash_for_piece", &torrent_info::hash_for_piece)
.def("piece_size", &torrent_info::piece_size)
@ -123,5 +131,3 @@ void bind_torrent_info()
.def_readwrite("tier", &announce_entry::tier)
;
}