python bindings updates. Thanks andar

This commit is contained in:
Arvid Norberg 2007-10-15 05:37:35 +00:00
parent 1699fa4652
commit ba48c629fb
6 changed files with 215 additions and 98 deletions

View File

@ -12,24 +12,33 @@ using namespace libtorrent;
extern char const* alert_doc;
extern char const* alert_msg_doc;
extern char const* alert_severity_doc;
extern char const* listen_failed_alert_doc;
extern char const* file_error_alert_doc;
extern char const* tracker_announce_alert_doc;
extern char const* torrent_alert_doc;
extern char const* tracker_alert_doc;
extern char const* tracker_reply_alert_doc;
extern char const* tracker_warning_alert_doc;
extern char const* url_seed_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* torrent_paused_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_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;
void bind_alert()
{
@ -58,60 +67,43 @@ void bind_alert()
;
}
class_<listen_failed_alert, bases<alert>, noncopyable>(
"listen_failed_alert", listen_failed_alert_doc, no_init
);
class_<file_error_alert, bases<alert>, noncopyable>(
"file_error_alert", file_error_alert_doc, no_init
class_<torrent_alert, bases<alert>, noncopyable>(
"torrent_alert", torrent_alert_doc, no_init
)
.def_readonly("handle", &file_error_alert::handle)
.def_readonly("handle", &torrent_alert::handle)
;
class_<tracker_announce_alert, bases<alert>, noncopyable>(
"tracker_announce_alert", tracker_announce_alert_doc, no_init
)
.def_readonly("handle", &tracker_announce_alert::handle)
;
class_<tracker_alert, bases<alert>, noncopyable>(
class_<tracker_alert, bases<torrent_alert>, noncopyable>(
"tracker_alert", tracker_alert_doc, no_init
)
.def_readonly("handle", &tracker_alert::handle)
.def_readonly("times_in_row", &tracker_alert::times_in_row)
.def_readonly("status_code", &tracker_alert::status_code)
;
class_<tracker_reply_alert, bases<alert>, noncopyable>(
class_<tracker_warning_alert, bases<torrent_alert>, noncopyable>(
"tracker_warning_alert", tracker_warning_alert_doc, no_init
);
class_<tracker_reply_alert, bases<torrent_alert>, noncopyable>(
"tracker_reply_alert", tracker_reply_alert_doc, no_init
)
.def_readonly("handle", &tracker_reply_alert::handle)
.def_readonly("num_peers", &tracker_reply_alert::num_peers)
;
class_<tracker_warning_alert, bases<alert>, noncopyable>(
"tracker_warning_alert", tracker_warning_alert_doc, no_init
)
.def_readonly("handle", &tracker_warning_alert::handle)
;
class_<tracker_announce_alert, bases<torrent_alert>, noncopyable>(
"tracker_announce_alert", tracker_announce_alert_doc, no_init
);
class_<url_seed_alert, bases<alert>, noncopyable>(
"url_seed_alert", url_seed_alert_doc, no_init
)
.def_readonly("url", &url_seed_alert::url)
;
class_<hash_failed_alert, bases<alert>, noncopyable>(
class_<hash_failed_alert, bases<torrent_alert>, noncopyable>(
"hash_failed_alert", hash_failed_alert_doc, no_init
)
.def_readonly("handle", &hash_failed_alert::handle)
.def_readonly("piece_index", &hash_failed_alert::piece_index)
;
class_<peer_ban_alert, bases<alert>, noncopyable>(
class_<peer_ban_alert, bases<torrent_alert>, noncopyable>(
"peer_ban_alert", peer_ban_alert_doc, no_init
)
.def_readonly("ip", &peer_ban_alert::ip)
.def_readonly("handle", &peer_ban_alert::handle)
;
class_<peer_error_alert, bases<alert>, noncopyable>(
@ -121,10 +113,9 @@ void bind_alert()
.def_readonly("pid", &peer_error_alert::pid)
;
class_<invalid_request_alert, bases<alert>, noncopyable>(
class_<invalid_request_alert, bases<torrent_alert>, noncopyable>(
"invalid_request_alert", invalid_request_alert_doc, no_init
)
.def_readonly("handle", &invalid_request_alert::handle)
.def_readonly("ip", &invalid_request_alert::ip)
.def_readonly("request", &invalid_request_alert::request)
.def_readonly("pid", &invalid_request_alert::pid)
@ -137,39 +128,86 @@ void bind_alert()
.def(self == self)
;
class_<torrent_finished_alert, bases<alert>, noncopyable>(
class_<torrent_finished_alert, bases<torrent_alert>, noncopyable>(
"torrent_finished_alert", torrent_finished_alert_doc, no_init
);
class_<piece_finished_alert, bases<torrent_alert>, noncopyable>(
"piece_finished_alert", piece_finished_alert_doc, no_init
)
.def_readonly("handle", &torrent_finished_alert::handle)
.def_readonly("piece_index", &piece_finished_alert::piece_index)
;
class_<torrent_paused_alert, bases<alert>, noncopyable>(
"torrent_paused_alert", torrent_paused_alert_doc, no_init
class_<block_finished_alert, bases<torrent_alert>, noncopyable>(
"block_finished_alert", block_finished_alert_doc, no_init
)
.def_readonly("handle", &torrent_paused_alert::handle)
.def_readonly("block_index", &block_finished_alert::block_index)
.def_readonly("piece_index", &block_finished_alert::piece_index)
;
class_<storage_moved_alert, bases<alert>, noncopyable>(
class_<block_downloading_alert, bases<torrent_alert>, noncopyable>(
"block_downloading_alert", block_downloading_alert_doc, no_init
)
.def_readonly("peer_speedmsg", &block_downloading_alert::peer_speedmsg)
.def_readonly("block_index", &block_downloading_alert::block_index)
.def_readonly("piece_index", &block_downloading_alert::piece_index)
;
class_<storage_moved_alert, bases<torrent_alert>, noncopyable>(
"storage_moved_alert", storage_moved_alert_doc, no_init
);
class_<torrent_paused_alert, bases<torrent_alert>, noncopyable>(
"torrent_paused_alert", torrent_paused_alert_doc, no_init
);
class_<torrent_checked_alert, bases<torrent_alert>, noncopyable>(
"torrent_checked_alert", torrent_checked_alert_doc, no_init
);
class_<url_seed_alert, bases<torrent_alert>, noncopyable>(
"url_seed_alert", url_seed_alert_doc, no_init
)
.def_readonly("handle", &storage_moved_alert::handle)
.def_readonly("url", &url_seed_alert::url)
;
class_<metadata_failed_alert, bases<alert>, noncopyable>(
class_<file_error_alert, bases<torrent_alert>, noncopyable>(
"file_error_alert", file_error_alert_doc, no_init
);
class_<metadata_failed_alert, bases<torrent_alert>, noncopyable>(
"metadata_failed_alert", metadata_failed_alert_doc, no_init
)
.def_readonly("handle", &metadata_failed_alert::handle)
;
);
class_<metadata_received_alert, bases<alert>, noncopyable>(
class_<metadata_received_alert, bases<torrent_alert>, noncopyable>(
"metadata_received_alert", metadata_received_alert_doc, no_init
)
.def_readonly("handle", &metadata_received_alert::handle)
;
);
class_<fastresume_rejected_alert, bases<alert>, noncopyable>(
"fastresume_rejected_alert", fastresume_rejected_alert_doc, no_init
class_<listen_failed_alert, bases<alert>, noncopyable>(
"listen_failed_alert", listen_failed_alert_doc, no_init
);
class_<listen_succeeded_alert, bases<alert>, noncopyable>(
"listen_succeeded_alert", listen_succeeded_alert_doc, no_init
)
.def_readonly("handle", &fastresume_rejected_alert::handle)
.def_readonly("endpoint", &listen_succeeded_alert::endpoint)
;
class_<portmap_error_alert, bases<alert>, noncopyable>(
"portmap_error_alert", portmap_error_alert_doc, no_init
);
class_<portmap_alert, bases<alert>, noncopyable>(
"portmap_alert", portmap_alert_doc, no_init
);
class_<fastresume_rejected_alert, bases<torrent_alert>, noncopyable>(
"fastresume_rejected_alert", fastresume_rejected_alert_doc, no_init
);
class_<peer_blocked_alert, bases<alert>, noncopyable>(
"peer_blocked_alert", peer_blocked_alert_doc, no_init
)
.def_readonly("ip", &peer_blocked_alert::ip)
;
}

View File

@ -153,14 +153,26 @@ char const* session_set_max_half_open_connections_doc =
"-1 as the limit, means to have no limit. When limiting the number of\n"
"simultaneous connection attempts, peers will be put in a queue waiting\n"
"for their turn to get connected.";
char const* session_num_connections_doc =
"";
char const* session_set_settings_doc =
"";
char const* session_set_pe_settings_doc =
"";
char const* session_get_pe_settings_doc =
"";
char const* session_set_severity_level_doc =
"";
char const* session_pop_alert_doc =
"";
char const* session_start_upnp_doc =
"";
char const* session_stop_upnp_doc =
"";
char const* session_start_natpmp_doc =
"";
char const* session_stop_natpmp_doc =
"";
// -- alert -----------------------------------------------------------------
char const* alert_doc =
@ -172,19 +184,8 @@ char const* alert_msg_doc =
char const* alert_severity_doc =
"Returns the severity level for this alert, one of `alert.severity_levels`.";
char const* listen_failed_alert_doc =
"This alert is generated when none of the ports, given in the\n"
"port range, to `session` can be opened for listening. This alert\n"
"is generated as severity level `alert.severity_levels.fatal`.";
char const* file_error_alert_doc =
"If the storage fails to read or write files that it needs access\n"
"to, this alert is generated and the torrent is paused. It is\n"
"generated as severity level `alert.severity_levels.fatal`.";
char const* tracker_announce_alert_doc =
"This alert is generated each time a tracker announce is sent\n"
"(or attempted to be sent). It is generated at severity level `alert.severity_levels.info`.";
char const* torrent_alert_doc =
"";
char const* tracker_alert_doc =
"This alert is generated on tracker time outs, premature\n"
@ -193,21 +194,21 @@ char const* tracker_alert_doc =
"the tracker belongs to. This alert is generated as severity level\n"
"`alert.severity_levels.warning`.";
char const* tracker_reply_alert_doc =
"This alert is only for informational purpose. It is generated when\n"
"a tracker announce succeeds. It is generated with severity level\n"
"`alert.severity_levels.info`.";
char const* tracker_warning_alert_doc =
"This alert is triggered if the tracker reply contains a warning\n"
"field. Usually this means that the tracker announce was successful\n"
", but the tracker has a message to the client. The message string in\n"
"the alert will contain the warning message from the tracker. It is\n"
"generated with severity level `alert.severity_levels.warning`.";
char const* tracker_reply_alert_doc =
"This alert is only for informational purpose. It is generated when\n"
"a tracker announce succeeds. It is generated with severity level\n"
"`alert.severity_levels.info`.";
char const* url_seed_alert_doc =
"This alert is generated when a HTTP seed name lookup fails. This\n"
"alert is generated as severity level `alert.severity_levels.warning`.";
char const* tracker_announce_alert_doc =
"This alert is generated each time a tracker announce is sent\n"
"(or attempted to be sent). It is generated at severity level `alert.severity_levels.info`.";
char const* hash_failed_alert_doc =
"This alert is generated when a finished piece fails its hash check.\n"
@ -246,17 +247,38 @@ char const* torrent_finished_alert_doc =
"It contains a `torrent_handle` to the torrent in question. This alert\n"
"is generated as severity level `alert.severity_levels.info`.";
char const* torrent_paused_alert_doc =
"This alert is generated when a torrent switches from being a\n"
"active to paused.\n"
"It contains a `torrent_handle` to the torrent in question. This alert\n"
"is generated as severity level `alert.severity_levels.warning`.";
char const* piece_finished_alert_doc =
"";
char const* block_finished_alert_doc =
"";
char const* block_downloading_alert_doc =
"";
char const* storage_moved_alert_doc =
"This alert is generated when a torrent moves storage.\n"
"It contains a `torrent_handle` to the torrent in question. This alert\n"
"is generated as severity level `alert.severity_levels.warning`.";
char const* torrent_paused_alert_doc =
"This alert is generated when a torrent switches from being a\n"
"active to paused.\n"
"It contains a `torrent_handle` to the torrent in question. This alert\n"
"is generated as severity level `alert.severity_levels.warning`.";
char const* torrent_checked_alert_doc =
"";
char const* url_seed_alert_doc =
"This alert is generated when a HTTP seed name lookup fails. This\n"
"alert is generated as severity level `alert.severity_levels.warning`.";
char const* file_error_alert_doc =
"If the storage fails to read or write files that it needs access\n"
"to, this alert is generated and the torrent is paused. It is\n"
"generated as severity level `alert.severity_levels.fatal`.";
char const* metadata_failed_alert_doc =
"This alert is generated when the metadata has been completely\n"
"received and the info-hash failed to match it. i.e. the\n"
@ -273,9 +295,25 @@ char const* metadata_received_alert_doc =
"needs to download it from peers (when utilizing the libtorrent\n"
"extension). It is generated at severity level `alert.severity_levels.info`.";
char const* listen_failed_alert_doc =
"This alert is generated when none of the ports, given in the\n"
"port range, to `session` can be opened for listening. This alert\n"
"is generated as severity level `alert.severity_levels.fatal`.";
char const* listen_succeeded_alert_doc =
"";
char const* portmap_error_alert_doc =
"";
char const* portmap_alert_doc =
"";
char const* fastresume_rejected_alert_doc =
"This alert is generated when a fastresume file has been passed\n"
"to `session.add_torrent` but the files on disk did not match the\n"
"fastresume file. The string explains the reason why the resume\n"
"file was rejected. It is generated at severity level `alert.severity_levels.warning`.";
char const* peer_blocked_alert_doc =
"";

View File

@ -109,6 +109,15 @@ namespace
} // namespace unnamed
boost::shared_ptr<torrent_plugin> create_metadata_plugin_wrapper(torrent* t) {
return create_metadata_plugin(t, NULL);
}
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
return create_ut_pex_plugin(t, NULL);
}
void bind_extensions()
{
class_<
@ -142,7 +151,9 @@ void bind_extensions()
// TODO move to it's own file
class_<peer_connection, boost::noncopyable>("peer_connection", no_init);
def("create_ut_pex_plugin", create_ut_pex_plugin);
def("create_metadata_plugin", create_metadata_plugin);
class_<torrent_plugin, boost::shared_ptr<torrent_plugin> >("torrent_plugin", no_init);
def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
def("create_metadata_plugin", create_metadata_plugin_wrapper);
}

View File

@ -44,9 +44,16 @@ 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_stop_upnp_doc;
extern char const* session_start_natpmp_doc;
extern char const* session_stop_natpmp_doc;
namespace
{
@ -63,7 +70,7 @@ namespace
: cb(callback)
{}
boost::shared_ptr<torrent_plugin> operator()(torrent* t)
boost::shared_ptr<torrent_plugin> operator()(torrent* t, void*)
{
lock_gil lock;
return extract<boost::shared_ptr<torrent_plugin> >(cb(ptr(t)))();
@ -80,10 +87,10 @@ namespace
torrent_handle add_torrent(session& s, torrent_info const& ti
, boost::filesystem::path const& save, entry const& resume
, bool compact, bool paused)
, storage_mode_t storage_mode, bool paused)
{
allow_threading_guard guard;
return s.add_torrent(ti, save, resume, compact, paused, default_storage_constructor);
return s.add_torrent(ti, save, resume, storage_mode, paused, default_storage_constructor);
}
} // namespace unnamed
@ -147,6 +154,17 @@ void bind_session()
#endif
;
enum_<storage_mode_t>("storage_mode_t")
.value("storage_mode_allocate", storage_mode_allocate)
.value("storage_mode_compact", storage_mode_compact)
.value("storage_mode_sparse", storage_mode_sparse)
;
enum_<session::options_t>("options_t")
.value("none", session::none)
.value("delete_files", session::delete_files)
;
class_<session, boost::noncopyable>("session", session_doc, no_init)
.def(
init<fingerprint>(arg("fingerprint")=fingerprint("LT",0,1,0,0), session_init_doc)
@ -167,8 +185,8 @@ void bind_session()
.def(
"add_torrent", &add_torrent
, (
arg("torrent_info"), "save_path", arg("resume_data") = entry()
, arg("compact_mode") = true, arg("paused") = false
arg("resume_data") = entry(), arg("compact_mode") = true
, arg("paused") = false
)
, session_add_torrent_doc
)
@ -203,7 +221,13 @@ void bind_session()
"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_pe_settings", allow_threads(&session::set_pe_settings), session_set_pe_settings_doc)
.def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>())
.def(
"set_severity_level", allow_threads(&session::set_severity_level)
, session_set_severity_level_doc
@ -216,10 +240,13 @@ void bind_session()
#ifndef TORRENT_DISABLE_DHT
.def("set_dht_proxy", allow_threads(&session::set_dht_proxy))
#endif
.def("start_upnp", allow_threads(&session::start_upnp), session_start_upnp_doc)
.def("stop_upnp", allow_threads(&session::stop_upnp), session_stop_upnp_doc)
.def("start_natpmp", allow_threads(&session::start_natpmp), session_start_natpmp_doc)
.def("stop_natpmp", allow_threads(&session::stop_natpmp), session_stop_natpmp_doc)
;
def("supports_sparse_files", &supports_sparse_files);
register_ptr_to_python<std::auto_ptr<alert> >();
}

View File

@ -47,7 +47,7 @@ void bind_session_settings()
.value("http", proxy_settings::http)
.value("http_pw", proxy_settings::http_pw)
;
scope ps = class_<proxy_settings>("proxy_settings")
class_<proxy_settings>("proxy_settings")
.def_readwrite("hostname", &proxy_settings::hostname)
.def_readwrite("port", &proxy_settings::port)
.def_readwrite("password", &proxy_settings::password)
@ -64,9 +64,10 @@ void bind_session_settings()
enum_<pe_settings::enc_level>("enc_level")
.value("rc4", pe_settings::rc4)
.value("plaintext", pe_settings::plaintext)
.value("both", pe_settings::both)
;
scope pes = class_<pe_settings>("pe_settings")
class_<pe_settings>("pe_settings")
.def_readwrite("out_enc_policy", &pe_settings::out_enc_policy)
.def_readwrite("in_enc_policy", &pe_settings::in_enc_policy)
.def_readwrite("allowed_enc_level", &pe_settings::allowed_enc_level)
@ -75,3 +76,4 @@ void bind_session_settings()
}

View File

@ -123,3 +123,4 @@ void bind_torrent_info()
;
}