applied python binding patch from Josh Davis-Ryan

This commit is contained in:
Arvid Norberg 2007-07-23 03:07:15 +00:00
parent 3050e35adf
commit f7fb6778a6
4 changed files with 51 additions and 2 deletions

View File

@ -130,6 +130,10 @@ char const* session_remove_torrent_doc =
"Close all peer connections associated with the torrent and tell the\n"
"tracker that we've stopped participating in the swarm.";
char const* session_download_rate_limit_doc =
"";
char const* session_upload_rate_limit_doc =
"";
char const* session_set_download_rate_limit_doc =
"";
char const* session_set_upload_rate_limit_doc =

View File

@ -38,7 +38,9 @@ extern char const* session_dht_state_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;
@ -176,10 +178,20 @@ void bind_session()
"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_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_max_uploads", allow_threads(&session::set_max_uploads)
, session_set_max_uploads_doc

View File

@ -64,6 +64,30 @@ list get_peer_info(torrent_handle const& handle)
return result;
}
void prioritize_files(torrent_handle& info, object o)
{
std::vector<int> result;
try
{
object iter_obj = object( handle<>( PyObject_GetIter( o.ptr() ) ));
while( 1 )
{
object obj = extract<object>( iter_obj.attr( "next" )() );
result.push_back(extract<int const>( obj ));
}
}
catch( error_already_set )
{
PyErr_Clear();
info.prioritize_files(result);
return;
}
}
void replace_trackers(torrent_handle& info, object trackers)
{
object iter(trackers.attr("__iter__")());
@ -106,7 +130,9 @@ list get_download_queue(torrent_handle& handle)
{
dict block_info;
block_info["state"] = i->blocks[k].state;
block_info["num_downloads"] = i->blocks[k].num_downloads;
block_info["num_peers"] = i->blocks[k].num_peers;
block_info["bytes_progress"] = i->blocks[k].bytes_progress;
block_info["block_size"] = i->blocks[k].block_size;
// block_info["peer"] = i->info[k].peer;
block_list.append(block_info);
}
@ -124,6 +150,9 @@ void bind_torrent_handle()
void (torrent_handle::*force_reannounce1)(boost::posix_time::time_duration) const
= &torrent_handle::force_reannounce;
int (torrent_handle::*piece_priority0)(int) const = &torrent_handle::piece_priority;
void (torrent_handle::*piece_priority1)(int, int) const = &torrent_handle::piece_priority;
return_value_policy<copy_const_reference> copy;
#define _ allow_threads
@ -148,6 +177,8 @@ void bind_torrent_handle()
.def("is_paused", _(&torrent_handle::is_paused))
.def("is_seed", _(&torrent_handle::is_seed))
.def("filter_piece", _(&torrent_handle::filter_piece))
.def("piece_priority", _(piece_priority0))
.def("piece_priority", _(piece_priority1))
.def("is_piece_filtered", _(&torrent_handle::is_piece_filtered))
.def("has_metadata", _(&torrent_handle::has_metadata))
.def("save_path", _(&torrent_handle::save_path))
@ -156,6 +187,7 @@ void bind_torrent_handle()
.def("file_progress", file_progress)
.def("trackers", range(begin_trackers, end_trackers))
.def("replace_trackers", replace_trackers)
.def("prioritize_files", prioritize_files)
.def("get_peer_info", get_peer_info)
.def("get_download_queue", get_download_queue)
;

View File

@ -71,6 +71,7 @@ void bind_torrent_info()
.def("hash_for_piece", &torrent_info::hash_for_piece, copy)
.def("piece_size", &torrent_info::piece_size)
.def("num_files", &torrent_info::num_files)
.def("file_at", &torrent_info::file_at, return_internal_reference<>())
.def("files", range(&torrent_info::begin_files, &torrent_info::end_files))