updated python bindings

This commit is contained in:
Arvid Norberg 2009-05-14 17:24:17 +00:00
parent e3f1b5a905
commit 391bd37113
2 changed files with 95 additions and 239 deletions

View File

@ -9,44 +9,6 @@
using namespace boost::python;
using namespace libtorrent;
extern char const* alert_doc;
extern char const* alert_msg_doc;
extern char const* alert_severity_doc;
extern char const* torrent_alert_doc;
extern char const* tracker_alert_doc;
extern char const* tracker_error_alert_doc;
extern char const* tracker_warning_alert_doc;
extern char const* tracker_reply_alert_doc;
extern char const* tracker_announce_alert_doc;
extern char const* hash_failed_alert_doc;
extern char const* peer_ban_alert_doc;
extern char const* peer_error_alert_doc;
extern char const* invalid_request_alert_doc;
extern char const* peer_request_doc;
extern char const* torrent_finished_alert_doc;
extern char const* piece_finished_alert_doc;
extern char const* block_finished_alert_doc;
extern char const* block_downloading_alert_doc;
extern char const* storage_moved_alert_doc;
extern char const* torrent_deleted_alert_doc;
extern char const* torrent_paused_alert_doc;
extern char const* torrent_checked_alert_doc;
extern char const* url_seed_alert_doc;
extern char const* file_error_alert_doc;
extern char const* metadata_failed_alert_doc;
extern char const* metadata_received_alert_doc;
extern char const* listen_failed_alert_doc;
extern char const* listen_succeeded_alert_doc;
extern char const* portmap_error_alert_doc;
extern char const* portmap_alert_doc;
extern char const* fastresume_rejected_alert_doc;
extern char const* peer_blocked_alert_doc;
extern char const* scrape_reply_alert_doc;
extern char const* scrape_failed_alert_doc;
extern char const* udp_error_alert_doc;
extern char const* external_ip_alert_doc;
extern char const* save_resume_data_alert_doc;
std::string get_buffer(read_piece_alert const& rpa)
{
return rpa.buffer ? std::string(rpa.buffer.get(), rpa.size)
@ -58,14 +20,14 @@ void bind_alert()
using boost::noncopyable;
{
scope alert_scope = class_<alert, noncopyable>("alert", alert_doc, no_init)
.def("message", &alert::message, alert_msg_doc)
scope alert_scope = class_<alert, noncopyable>("alert", no_init)
.def("message", &alert::message)
.def("what", &alert::what)
.def("category", &alert::category)
#ifndef TORRENT_NO_DEPRECATE
.def("severity", &alert::severity, alert_severity_doc)
.def("severity", &alert::severity)
#endif
.def("__str__", &alert::message, alert_msg_doc)
.def("__str__", &alert::message)
;
#ifndef TORRENT_NO_DEPRECATE
@ -96,13 +58,13 @@ void bind_alert()
}
class_<torrent_alert, bases<alert>, noncopyable>(
"torrent_alert", torrent_alert_doc, no_init
"torrent_alert", no_init
)
.def_readonly("handle", &torrent_alert::handle)
;
class_<tracker_alert, bases<torrent_alert>, noncopyable>(
"tracker_alert", tracker_alert_doc, no_init
"tracker_alert", no_init
)
.def_readonly("url", &tracker_alert::url)
;
@ -122,7 +84,7 @@ void bind_alert()
.def_readonly("pid", &peer_alert::pid)
;
class_<tracker_error_alert, bases<tracker_alert>, noncopyable>(
"tracker_error_alert", tracker_error_alert_doc, no_init
"tracker_error_alert", no_init
)
.def_readonly("msg", &tracker_error_alert::msg)
.def_readonly("times_in_row", &tracker_error_alert::times_in_row)
@ -130,40 +92,40 @@ void bind_alert()
;
class_<tracker_warning_alert, bases<tracker_alert>, noncopyable>(
"tracker_warning_alert", tracker_warning_alert_doc, no_init
"tracker_warning_alert", no_init
);
class_<tracker_reply_alert, bases<tracker_alert>, noncopyable>(
"tracker_reply_alert", tracker_reply_alert_doc, no_init
"tracker_reply_alert", no_init
)
.def_readonly("num_peers", &tracker_reply_alert::num_peers)
;
class_<tracker_announce_alert, bases<tracker_alert>, noncopyable>(
"tracker_announce_alert", tracker_announce_alert_doc, no_init
"tracker_announce_alert", no_init
);
class_<hash_failed_alert, bases<torrent_alert>, noncopyable>(
"hash_failed_alert", hash_failed_alert_doc, no_init
"hash_failed_alert", no_init
)
.def_readonly("piece_index", &hash_failed_alert::piece_index)
;
class_<peer_ban_alert, bases<peer_alert>, noncopyable>(
"peer_ban_alert", peer_ban_alert_doc, no_init
"peer_ban_alert", no_init
);
class_<peer_error_alert, bases<peer_alert>, noncopyable>(
"peer_error_alert", peer_error_alert_doc, no_init
"peer_error_alert", no_init
);
class_<invalid_request_alert, bases<peer_alert>, noncopyable>(
"invalid_request_alert", invalid_request_alert_doc, no_init
"invalid_request_alert", no_init
)
.def_readonly("request", &invalid_request_alert::request)
;
class_<peer_request>("peer_request", peer_request_doc)
class_<peer_request>("peer_request")
.def_readonly("piece", &peer_request::piece)
.def_readonly("start", &peer_request::start)
.def_readonly("length", &peer_request::length)
@ -171,24 +133,24 @@ void bind_alert()
;
class_<torrent_finished_alert, bases<torrent_alert>, noncopyable>(
"torrent_finished_alert", torrent_finished_alert_doc, no_init
"torrent_finished_alert", no_init
);
class_<piece_finished_alert, bases<torrent_alert>, noncopyable>(
"piece_finished_alert", piece_finished_alert_doc, no_init
"piece_finished_alert", no_init
)
.def_readonly("piece_index", &piece_finished_alert::piece_index)
;
class_<block_finished_alert, bases<peer_alert>, noncopyable>(
"block_finished_alert", block_finished_alert_doc, no_init
"block_finished_alert", no_init
)
.def_readonly("block_index", &block_finished_alert::block_index)
.def_readonly("piece_index", &block_finished_alert::piece_index)
;
class_<block_downloading_alert, bases<peer_alert>, noncopyable>(
"block_downloading_alert", block_downloading_alert_doc, no_init
"block_downloading_alert", no_init
)
.def_readonly("peer_speedmsg", &block_downloading_alert::peer_speedmsg)
.def_readonly("block_index", &block_downloading_alert::block_index)
@ -196,60 +158,66 @@ void bind_alert()
;
class_<storage_moved_alert, bases<torrent_alert>, noncopyable>(
"storage_moved_alert", storage_moved_alert_doc, no_init
"storage_moved_alert", no_init
);
class_<storage_moved_failed_alert, bases<torrent_alert>, noncopyable>(
"storage_moved_failed_alert", no_init
)
.def_readonly("error", &storage_moved_failed_alert::error)
;
class_<torrent_deleted_alert, bases<torrent_alert>, noncopyable>(
"torrent_deleted_alert", torrent_deleted_alert_doc, no_init
"torrent_deleted_alert", no_init
);
class_<torrent_paused_alert, bases<torrent_alert>, noncopyable>(
"torrent_paused_alert", torrent_paused_alert_doc, no_init
"torrent_paused_alert", no_init
);
class_<torrent_checked_alert, bases<torrent_alert>, noncopyable>(
"torrent_checked_alert", torrent_checked_alert_doc, no_init
"torrent_checked_alert", no_init
);
class_<url_seed_alert, bases<torrent_alert>, noncopyable>(
"url_seed_alert", url_seed_alert_doc, no_init
"url_seed_alert", no_init
)
.def_readonly("url", &url_seed_alert::url)
;
class_<file_error_alert, bases<torrent_alert>, noncopyable>(
"file_error_alert", file_error_alert_doc, no_init
"file_error_alert", no_init
)
.def_readonly("file", &file_error_alert::file)
;
class_<metadata_failed_alert, bases<torrent_alert>, noncopyable>(
"metadata_failed_alert", metadata_failed_alert_doc, no_init
"metadata_failed_alert", no_init
);
class_<metadata_received_alert, bases<torrent_alert>, noncopyable>(
"metadata_received_alert", metadata_received_alert_doc, no_init
"metadata_received_alert", no_init
);
class_<listen_failed_alert, bases<alert>, noncopyable>(
"listen_failed_alert", listen_failed_alert_doc, no_init
"listen_failed_alert", no_init
);
class_<listen_succeeded_alert, bases<alert>, noncopyable>(
"listen_succeeded_alert", listen_succeeded_alert_doc, no_init
"listen_succeeded_alert", no_init
)
.def_readonly("endpoint", &listen_succeeded_alert::endpoint)
;
class_<portmap_error_alert, bases<alert>, noncopyable>(
"portmap_error_alert", portmap_error_alert_doc, no_init
"portmap_error_alert", no_init
)
.def_readonly("mapping", &portmap_error_alert::mapping)
.def_readonly("type", &portmap_error_alert::type)
;
class_<portmap_alert, bases<alert>, noncopyable>(
"portmap_alert", portmap_alert_doc, no_init
"portmap_alert", no_init
)
.def_readonly("mapping", &portmap_alert::mapping)
.def_readonly("external_port", &portmap_alert::external_port)
@ -257,40 +225,40 @@ void bind_alert()
;
class_<fastresume_rejected_alert, bases<torrent_alert>, noncopyable>(
"fastresume_rejected_alert", fastresume_rejected_alert_doc, no_init
"fastresume_rejected_alert", no_init
);
class_<peer_blocked_alert, bases<alert>, noncopyable>(
"peer_blocked_alert", peer_blocked_alert_doc, no_init
"peer_blocked_alert", no_init
)
.def_readonly("ip", &peer_blocked_alert::ip)
;
class_<scrape_reply_alert, bases<tracker_alert>, noncopyable>(
"scrape_reply_alert", scrape_reply_alert_doc, no_init
"scrape_reply_alert", no_init
)
.def_readonly("incomplete", &scrape_reply_alert::incomplete)
.def_readonly("complete", &scrape_reply_alert::complete)
;
class_<scrape_failed_alert, bases<tracker_alert>, noncopyable>(
"scrape_failed_alert", scrape_failed_alert_doc, no_init
"scrape_failed_alert", no_init
);
class_<udp_error_alert, bases<alert>, noncopyable>(
"udp_error_alert", udp_error_alert_doc, no_init
"udp_error_alert", no_init
)
.def_readonly("endpoint", &udp_error_alert::endpoint)
;
class_<external_ip_alert, bases<alert>, noncopyable>(
"external_ip_alert", external_ip_alert_doc, no_init
"external_ip_alert", no_init
)
.def_readonly("external_address", &external_ip_alert::external_address)
;
class_<save_resume_data_alert, bases<torrent_alert>, noncopyable>(
"save_resume_data_alert", save_resume_data_alert_doc, no_init
"save_resume_data_alert", no_init
)
.def_readonly("resume_data", &save_resume_data_alert::resume_data)
;
@ -306,7 +274,7 @@ void bind_alert()
"file_rename_failed_alert", no_init
)
.def_readonly("index", &file_rename_failed_alert::index)
.def_readonly("msg", &file_rename_failed_alert::msg)
.def_readonly("error", &file_rename_failed_alert::error)
;
class_<torrent_resumed_alert, bases<torrent_alert>, noncopyable>(

View File

@ -12,54 +12,6 @@
using namespace boost::python;
using namespace libtorrent;
extern char const* session_status_doc;
extern char const* session_status_has_incoming_connections_doc;
extern char const* session_status_upload_rate_doc;
extern char const* session_status_download_rate_doc;
extern char const* session_status_payload_upload_rate_doc;
extern char const* session_status_payload_download_rate_doc;
extern char const* session_status_total_download_doc;
extern char const* session_status_total_upload_doc;
extern char const* session_status_total_payload_download_doc;
extern char const* session_status_total_payload_upload_doc;
extern char const* session_status_num_peers_doc;
extern char const* session_status_dht_nodes_doc;
extern char const* session_status_cache_nodes_doc;
extern char const* session_status_dht_torrents_doc;
extern char const* session_doc;
extern char const* session_init_doc;
extern char const* session_listen_on_doc;
extern char const* session_is_listening_doc;
extern char const* session_listen_port_doc;
extern char const* session_status_m_doc;
extern char const* session_start_dht_doc;
extern char const* session_stop_dht_doc;
extern char const* session_dht_state_doc;
extern char const* session_add_dht_router_doc;
extern char const* session_add_torrent_doc;
extern char const* session_remove_torrent_doc;
extern char const* session_set_download_rate_limit_doc;
extern char const* session_download_rate_limit_doc;
extern char const* session_set_upload_rate_limit_doc;
extern char const* session_upload_rate_limit_doc;
extern char const* session_set_max_uploads_doc;
extern char const* session_set_max_connections_doc;
extern char const* session_set_max_half_open_connections_doc;
extern char const* session_num_connections_doc;
extern char const* session_set_settings_doc;
extern char const* session_set_pe_settings_doc;
extern char const* session_get_pe_settings_doc;
extern char const* session_set_severity_level_doc;
extern char const* session_pop_alert_doc;
extern char const* session_start_upnp_doc;
extern char const* session_start_lsd_doc;
extern char const* session_stop_lsd_doc;
extern char const* session_stop_upnp_doc;
extern char const* session_start_natpmp_doc;
extern char const* session_stop_natpmp_doc;
extern char const* session_set_ip_filter_doc;
namespace
{
@ -205,60 +157,21 @@ namespace
void bind_session()
{
class_<session_status>("session_status", session_status_doc)
.def_readonly(
"has_incoming_connections", &session_status::has_incoming_connections
, session_status_has_incoming_connections_doc
)
.def_readonly(
"upload_rate", &session_status::upload_rate
, session_status_upload_rate_doc
)
.def_readonly(
"download_rate", &session_status::download_rate
, session_status_download_rate_doc
)
.def_readonly(
"payload_upload_rate", &session_status::payload_upload_rate
, session_status_payload_upload_rate_doc
)
.def_readonly(
"payload_download_rate", &session_status::payload_download_rate
, session_status_payload_download_rate_doc
)
.def_readonly(
"total_download", &session_status::total_download
, session_status_total_download_doc
)
.def_readonly(
"total_upload", &session_status::total_upload
, session_status_total_upload_doc
)
.def_readonly(
"total_payload_download", &session_status::total_payload_download
, session_status_total_payload_download_doc
)
.def_readonly(
"total_payload_upload", &session_status::total_payload_upload
, session_status_total_payload_upload_doc
)
.def_readonly(
"num_peers", &session_status::num_peers
, session_status_num_peers_doc
)
class_<session_status>("session_status")
.def_readonly("has_incoming_connections", &session_status::has_incoming_connections)
.def_readonly("upload_rate", &session_status::upload_rate)
.def_readonly("download_rate", &session_status::download_rate)
.def_readonly("payload_upload_rate", &session_status::payload_upload_rate)
.def_readonly("payload_download_rate", &session_status::payload_download_rate)
.def_readonly("total_download", &session_status::total_download)
.def_readonly("total_upload", &session_status::total_upload)
.def_readonly("total_payload_download", &session_status::total_payload_download)
.def_readonly("total_payload_upload", &session_status::total_payload_upload)
.def_readonly("num_peers", &session_status::num_peers)
#ifndef TORRENT_DISABLE_DHT
.def_readonly(
"dht_nodes", &session_status::dht_nodes
, session_status_dht_nodes_doc
)
.def_readonly(
"dht_cache_nodes", &session_status::dht_node_cache
, session_status_cache_nodes_doc
)
.def_readonly(
"dht_torrents", &session_status::dht_torrents
, session_status_dht_torrents_doc
)
.def_readonly("dht_nodes", &session_status::dht_nodes)
.def_readonly("dht_cache_nodes", &session_status::dht_node_cache)
.def_readonly("dht_torrents", &session_status::dht_torrents)
#endif
;
@ -278,86 +191,64 @@ void bind_session()
.value("start_default_features", session::start_default_features)
;
class_<session, boost::noncopyable>("session", session_doc, no_init)
class_<session, boost::noncopyable>("session", no_init)
.def(
init<fingerprint, int>((
arg("fingerprint")=fingerprint("LT",0,1,0,0)
, arg("flags")=session::start_default_features | session::add_default_plugins)
, session_init_doc)
, arg("flags")=session::start_default_features | session::add_default_plugins))
)
.def(
"listen_on", &listen_on
, (arg("min"), "max", arg("interface") = (char const*)0)
, session_listen_on_doc
)
.def("outgoing_ports", &outgoing_ports)
.def("is_listening", allow_threads(&session::is_listening), session_is_listening_doc)
.def("listen_port", allow_threads(&session::listen_port), session_listen_port_doc)
.def("status", allow_threads(&session::status), session_status_m_doc)
.def("is_listening", allow_threads(&session::is_listening))
.def("listen_port", allow_threads(&session::listen_port))
.def("status", allow_threads(&session::status))
#ifndef TORRENT_DISABLE_DHT
.def(
"add_dht_router", &add_dht_router
, (arg("router"), "port")
, session_add_dht_router_doc
)
.def("start_dht", allow_threads(&session::start_dht), session_start_dht_doc)
.def("stop_dht", allow_threads(&session::stop_dht), session_stop_dht_doc)
.def("dht_state", allow_threads(&session::dht_state), session_dht_state_doc)
.def("start_dht", allow_threads(&session::start_dht))
.def("stop_dht", allow_threads(&session::stop_dht))
.def("dht_state", allow_threads(&session::dht_state))
.def("set_dht_proxy", allow_threads(&session::set_dht_proxy))
.def("dht_proxy", allow_threads(&session::dht_proxy), return_value_policy<copy_const_reference>())
#endif
.def("add_torrent", &add_torrent, session_add_torrent_doc)
.def("add_torrent", &add_torrent)
#ifndef TORRENT_NO_DEPRECATE
.def(
"add_torrent", &add_torrent_depr
, (
arg("resume_data") = entry(), arg("storage_mode") = storage_mode_sparse,
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
)
.def("set_local_download_rate_limit", allow_threads(&session::set_local_download_rate_limit))
.def("local_download_rate_limit", allow_threads(&session::local_download_rate_limit))
, session_remove_torrent_doc)
.def(
"set_download_rate_limit", allow_threads(&session::set_download_rate_limit)
, session_set_download_rate_limit_doc
)
.def(
"download_rate_limit", allow_threads(&session::download_rate_limit)
, session_download_rate_limit_doc
)
.def("set_local_upload_rate_limit", allow_threads(&session::set_local_upload_rate_limit))
.def("local_upload_rate_limit", allow_threads(&session::local_upload_rate_limit))
.def(
"set_upload_rate_limit", allow_threads(&session::set_upload_rate_limit)
, session_set_upload_rate_limit_doc
)
.def(
"upload_rate_limit", allow_threads(&session::upload_rate_limit)
, session_upload_rate_limit_doc
)
.def("set_download_rate_limit", allow_threads(&session::set_download_rate_limit))
.def("download_rate_limit", allow_threads(&session::download_rate_limit))
.def(
"set_max_uploads", allow_threads(&session::set_max_uploads)
, session_set_max_uploads_doc
)
.def(
"set_max_connections", allow_threads(&session::set_max_connections)
, session_set_max_connections_doc
)
.def(
"set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections)
, session_set_max_half_open_connections_doc
)
.def(
"num_connections", allow_threads(&session::num_connections)
, session_num_connections_doc
)
.def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc)
.def("set_upload_rate_limit", allow_threads(&session::set_upload_rate_limit))
.def("upload_rate_limit", allow_threads(&session::upload_rate_limit))
.def("set_max_uploads", allow_threads(&session::set_max_uploads))
.def("set_max_connections", allow_threads(&session::set_max_connections))
.def("set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections))
.def("num_connections", allow_threads(&session::num_connections))
.def("set_settings", allow_threads(&session::set_settings))
.def("settings", allow_threads(&session::settings), return_value_policy<copy_const_reference>())
#ifndef TORRENT_DISABLE_ENCRYPTION
.def("set_pe_settings", allow_threads(&session::set_pe_settings), session_set_pe_settings_doc)
.def("set_pe_settings", allow_threads(&session::set_pe_settings))
.def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>())
#endif
#ifndef TORRENT_DISABLE_GEO_IP
@ -367,13 +258,10 @@ void bind_session()
.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
)
.def("set_severity_level", allow_threads(&session::set_severity_level))
#endif
.def("set_alert_mask", allow_threads(&session::set_alert_mask))
.def("pop_alert", allow_threads(&session::pop_alert), session_pop_alert_doc)
.def("pop_alert", allow_threads(&session::pop_alert))
.def("add_extension", &add_extension)
.def("set_peer_proxy", allow_threads(&session::set_peer_proxy))
.def("set_tracker_proxy", allow_threads(&session::set_tracker_proxy))
@ -381,13 +269,13 @@ void bind_session()
.def("peer_proxy", allow_threads(&session::peer_proxy), return_value_policy<copy_const_reference>())
.def("tracker_proxy", allow_threads(&session::tracker_proxy), return_value_policy<copy_const_reference>())
.def("web_seed_proxy", allow_threads(&session::web_seed_proxy), return_value_policy<copy_const_reference>())
.def("start_upnp", &start_upnp, session_start_upnp_doc)
.def("stop_upnp", allow_threads(&session::stop_upnp), session_stop_upnp_doc)
.def("start_lsd", allow_threads(&session::start_lsd), session_start_lsd_doc)
.def("stop_lsd", allow_threads(&session::stop_lsd), session_stop_lsd_doc)
.def("start_natpmp", &start_natpmp, session_start_natpmp_doc)
.def("stop_natpmp", allow_threads(&session::stop_natpmp), session_stop_natpmp_doc)
.def("set_ip_filter", allow_threads(&session::set_ip_filter), session_set_ip_filter_doc)
.def("start_upnp", &start_upnp)
.def("stop_upnp", allow_threads(&session::stop_upnp))
.def("start_lsd", allow_threads(&session::start_lsd))
.def("stop_lsd", allow_threads(&session::stop_lsd))
.def("start_natpmp", &start_natpmp)
.def("stop_natpmp", allow_threads(&session::stop_natpmp))
.def("set_ip_filter", allow_threads(&session::set_ip_filter))
.def("find_torrent", allow_threads(&session::find_torrent))
.def("get_torrents", &get_torrents)
.def("pause", allow_threads(&session::pause))