Update libtorrent python bindings to lt rev 2120.

This commit is contained in:
Andrew Resch 2008-03-29 04:36:30 +00:00
parent 81d07734e5
commit c35553d4a8
8 changed files with 290 additions and 200 deletions

View File

@ -181,6 +181,7 @@ char const* session_stop_natpmp_doc =
""; "";
char const* session_set_ip_filter_doc = char const* session_set_ip_filter_doc =
""; "";
// -- alert ----------------------------------------------------------------- // -- alert -----------------------------------------------------------------
char const* alert_doc = char const* alert_doc =

View File

@ -25,3 +25,4 @@ void bind_ip_filter()
.def_readonly("export_filter", allow_threads(&ip_filter::export_filter)) .def_readonly("export_filter", allow_threads(&ip_filter::export_filter))
; ;
} }

View File

@ -4,15 +4,51 @@
#include <libtorrent/peer_info.hpp> #include <libtorrent/peer_info.hpp>
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/python/iterator.hpp>
using namespace boost::python; using namespace boost::python;
using namespace libtorrent; using namespace libtorrent;
int get_last_active(peer_info const& pi)
{
return total_seconds(pi.last_active);
}
int get_last_request(peer_info const& pi)
{
return total_seconds(pi.last_request);
}
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
str get_country(peer_info const& pi)
{
return str(pi.country, 2);
}
#endif
tuple get_ip(peer_info const& pi)
{
return make_tuple(boost::lexical_cast<std::string>(pi.ip.address()), pi.ip.port());
}
list get_pieces(peer_info const& pi)
{
list ret;
for (std::vector<bool>::const_iterator i = pi.pieces.begin()
, end(pi.pieces.end()); i != end; ++i)
{
ret.append(*i);
}
return ret;
}
void bind_peer_info() void bind_peer_info()
{ {
scope pi = class_<peer_info>("peer_info") scope pi = class_<peer_info>("peer_info")
.def_readonly("flags", &peer_info::flags) .def_readonly("flags", &peer_info::flags)
.def_readonly("ip", &peer_info::ip) .def_readonly("source", &peer_info::source)
.add_property("ip", get_ip)
.def_readonly("up_speed", &peer_info::up_speed) .def_readonly("up_speed", &peer_info::up_speed)
.def_readonly("down_speed", &peer_info::down_speed) .def_readonly("down_speed", &peer_info::down_speed)
.def_readonly("payload_up_speed", &peer_info::payload_up_speed) .def_readonly("payload_up_speed", &peer_info::payload_up_speed)
@ -20,21 +56,32 @@ void bind_peer_info()
.def_readonly("total_download", &peer_info::total_download) .def_readonly("total_download", &peer_info::total_download)
.def_readonly("total_upload", &peer_info::total_upload) .def_readonly("total_upload", &peer_info::total_upload)
.def_readonly("pid", &peer_info::pid) .def_readonly("pid", &peer_info::pid)
.def_readonly("pieces", &peer_info::pieces) .add_property("pieces", get_pieces)
.def_readonly("upload_limit", &peer_info::upload_limit) .def_readonly("upload_limit", &peer_info::upload_limit)
.def_readonly("download_limit", &peer_info::download_limit) .def_readonly("download_limit", &peer_info::download_limit)
.add_property("last_request", get_last_request)
.add_property("last_active", get_last_active)
.def_readonly("send_buffer_size", &peer_info::send_buffer_size)
.def_readonly("used_send_buffer", &peer_info::used_send_buffer)
.def_readonly("num_hashfails", &peer_info::num_hashfails)
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
.add_property("country", get_country)
#endif
.def_readonly("load_balancing", &peer_info::load_balancing) .def_readonly("load_balancing", &peer_info::load_balancing)
.def_readonly("download_queue_length", &peer_info::download_queue_length) .def_readonly("download_queue_length", &peer_info::download_queue_length)
.def_readonly("upload_queue_length", &peer_info::upload_queue_length) .def_readonly("upload_queue_length", &peer_info::upload_queue_length)
.def_readonly("failcount", &peer_info::failcount)
.def_readonly("downloading_piece_index", &peer_info::downloading_piece_index) .def_readonly("downloading_piece_index", &peer_info::downloading_piece_index)
.def_readonly("downloading_block_index", &peer_info::downloading_block_index) .def_readonly("downloading_block_index", &peer_info::downloading_block_index)
.def_readonly("downloading_progress", &peer_info::downloading_progress) .def_readonly("downloading_progress", &peer_info::downloading_progress)
.def_readonly("downloading_total", &peer_info::downloading_total) .def_readonly("downloading_total", &peer_info::downloading_total)
.def_readonly("client", &peer_info::client) .def_readonly("client", &peer_info::client)
.def_readonly("connection_type", &peer_info::connection_type) .def_readonly("connection_type", &peer_info::connection_type)
.def_readonly("source", &peer_info::source) .def_readonly("remote_dl_rate", &peer_info::remote_dl_rate)
.def_readonly("pending_disk_bytes", &peer_info::pending_disk_bytes)
; ;
// flags
pi.attr("interesting") = (int)peer_info::interesting; pi.attr("interesting") = (int)peer_info::interesting;
pi.attr("choked") = (int)peer_info::choked; pi.attr("choked") = (int)peer_info::choked;
pi.attr("remote_interested") = (int)peer_info::remote_interested; pi.attr("remote_interested") = (int)peer_info::remote_interested;
@ -51,13 +98,15 @@ void bind_peer_info()
pi.attr("plaintext_encrypted") = (int)peer_info::plaintext_encrypted; pi.attr("plaintext_encrypted") = (int)peer_info::plaintext_encrypted;
#endif #endif
pi.attr("standard_bittorrent") = 0; // connection_type
pi.attr("web_seed") = 1; pi.attr("standard_bittorrent") = (int)peer_info::standard_bittorrent;
pi.attr("web_seed") = (int)peer_info::web_seed;
pi.attr("tracker") = 0x1; // source
pi.attr("dht") = 0x2; pi.attr("tracker") = (int)peer_info::tracker;
pi.attr("pex") = 0x4; pi.attr("dht") = (int)peer_info::dht;
pi.attr("lsd") = 0x8; pi.attr("pex") = (int)peer_info::pex;
pi.attr("resume_data") = 0x10; pi.attr("lsd") = (int)peer_info::lsd;
pi.attr("resume_data") = (int)peer_info::resume_data;
} }

View File

@ -69,11 +69,13 @@ namespace
return s.listen_on(std::make_pair(min_, max_), interface); return s.listen_on(std::make_pair(min_, max_), interface);
} }
#ifndef TORRENT_DISABLE_DHT
void add_dht_router(session& s, std::string router_, int port_) void add_dht_router(session& s, std::string router_, int port_)
{ {
allow_threading_guard guard; allow_threading_guard guard;
return s.add_dht_router(std::make_pair(router_, port_)); return s.add_dht_router(std::make_pair(router_, port_));
} }
#endif
struct invoke_extension_factory struct invoke_extension_factory
{ {
@ -185,18 +187,19 @@ void bind_session()
, (arg("min"), "max", arg("interface") = (char const*)0) , (arg("min"), "max", arg("interface") = (char const*)0)
, session_listen_on_doc , session_listen_on_doc
) )
.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)
#ifndef TORRENT_DISABLE_DHT
.def( .def(
"add_dht_router", &add_dht_router "add_dht_router", &add_dht_router
, (arg("router"), "port") , (arg("router"), "port")
, session_add_dht_router_doc , session_add_dht_router_doc
) )
.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)
#ifndef TORRENT_DISABLE_DHT
.def("start_dht", allow_threads(&session::start_dht), session_start_dht_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("stop_dht", allow_threads(&session::stop_dht), session_stop_dht_doc)
.def("dht_state", allow_threads(&session::dht_state), session_dht_state_doc) .def("dht_state", allow_threads(&session::dht_state), session_dht_state_doc)
.def("set_dht_proxy", allow_threads(&session::set_dht_proxy))
#endif #endif
.def( .def(
"add_torrent", &add_torrent "add_torrent", &add_torrent
@ -206,7 +209,8 @@ void bind_session()
) )
, session_add_torrent_doc , session_add_torrent_doc
) )
.def("remove_torrent", allow_threads(&session::remove_torrent), session_remove_torrent_doc) .def("remove_torrent", allow_threads(&session::remove_torrent), arg("option") = session::none
, session_remove_torrent_doc)
.def( .def(
"set_download_rate_limit", allow_threads(&session::set_download_rate_limit) "set_download_rate_limit", allow_threads(&session::set_download_rate_limit)
, session_set_download_rate_limit_doc , session_set_download_rate_limit_doc
@ -242,8 +246,10 @@ void bind_session()
, session_num_connections_doc , session_num_connections_doc
) )
.def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc) .def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc)
#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), session_set_pe_settings_doc)
.def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>()) .def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>())
#endif
.def( .def(
"set_severity_level", allow_threads(&session::set_severity_level) "set_severity_level", allow_threads(&session::set_severity_level)
, session_set_severity_level_doc , session_set_severity_level_doc
@ -253,9 +259,6 @@ void bind_session()
.def("set_peer_proxy", allow_threads(&session::set_peer_proxy)) .def("set_peer_proxy", allow_threads(&session::set_peer_proxy))
.def("set_tracker_proxy", allow_threads(&session::set_tracker_proxy)) .def("set_tracker_proxy", allow_threads(&session::set_tracker_proxy))
.def("set_web_seed_proxy", allow_threads(&session::set_web_seed_proxy)) .def("set_web_seed_proxy", allow_threads(&session::set_web_seed_proxy))
#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("start_upnp", allow_threads(&session::start_upnp), session_start_upnp_doc)
.def("stop_upnp", allow_threads(&session::stop_upnp), session_stop_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("start_lsd", allow_threads(&session::start_lsd), session_start_lsd_doc)

View File

@ -55,6 +55,7 @@ void bind_session_settings()
.def_readwrite("type", &proxy_settings::type) .def_readwrite("type", &proxy_settings::type)
; ;
#ifndef TORRENT_DISABLE_ENCRYPTION
enum_<pe_settings::enc_policy>("enc_policy") enum_<pe_settings::enc_policy>("enc_policy")
.value("forced", pe_settings::forced) .value("forced", pe_settings::forced)
.value("enabled", pe_settings::enabled) .value("enabled", pe_settings::enabled)
@ -73,6 +74,7 @@ void bind_session_settings()
.def_readwrite("allowed_enc_level", &pe_settings::allowed_enc_level) .def_readwrite("allowed_enc_level", &pe_settings::allowed_enc_level)
.def_readwrite("prefer_rc4", &pe_settings::prefer_rc4) .def_readwrite("prefer_rc4", &pe_settings::prefer_rc4)
; ;
#endif
} }

View File

@ -4,6 +4,7 @@
#include <libtorrent/torrent_handle.hpp> #include <libtorrent/torrent_handle.hpp>
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/lexical_cast.hpp>
#include "gil.hpp" #include "gil.hpp"
using namespace boost::python; using namespace boost::python;
@ -12,13 +13,57 @@ using namespace libtorrent;
namespace namespace
{ {
list url_seeds(torrent_handle& handle)
{
list ret;
std::set<std::string> urls;
{
allow_threading_guard guard;
urls = handle.url_seeds();
}
for (std::set<std::string>::iterator i(urls.begin())
, end(urls.end()); i != end; ++i)
ret.append(*i);
return ret;
}
list piece_availability(torrent_handle& handle)
{
list ret;
std::vector<int> avail;
{
allow_threading_guard guard;
handle.piece_availability(avail);
}
for (std::vector<int>::iterator i(avail.begin())
, end(avail.end()); i != end; ++i)
ret.append(*i);
return ret;
}
list piece_priorities(torrent_handle& handle)
{
list ret;
std::vector<int> prio;
{
allow_threading_guard guard;
prio = handle.piece_priorities();
}
for (std::vector<int>::iterator i(prio.begin())
, end(prio.end()); i != end; ++i)
ret.append(*i);
return ret;
}
std::vector<announce_entry>::const_iterator begin_trackers(torrent_handle& i) std::vector<announce_entry>::const_iterator begin_trackers(torrent_handle& i)
{ {
allow_threading_guard guard; allow_threading_guard guard;
return i.trackers().begin(); return i.trackers().begin();
} }
std::vector<announce_entry>::const_iterator end_trackers(torrent_handle& i) std::vector<announce_entry>::const_iterator end_trackers(torrent_handle& i)
{ {
allow_threading_guard guard; allow_threading_guard guard;
@ -57,87 +102,49 @@ list get_peer_info(torrent_handle const& handle)
list result; list result;
for (std::vector<peer_info>::iterator i = pi.begin(); i != pi.end(); ++i) for (std::vector<peer_info>::iterator i = pi.begin(); i != pi.end(); ++i)
{ result.append(*i);
dict peer;
peer["flags"] = i->flags;
peer["ip"] = i->ip.address().to_string();
peer["up_speed"] = i->up_speed;
peer["down_speed"] = i->down_speed;
peer["payload_up_speed"] = i->payload_up_speed;
peer["payload_down_speed"] = i->payload_down_speed;
peer["total_download"] = i->total_download;
peer["total_upload"] = i->total_upload;
peer["pid"] = i->pid;
list pieces;
for (std::vector<bool>::const_iterator p = i->pieces.begin(); p != i->pieces.end(); ++p)
pieces.append(*p);
peer["pieces"] = pieces;
peer["upload_limit"] = i->upload_limit;
peer["download_limit"] = i->download_limit;
peer["load_balancing"] = i->load_balancing;
peer["download_queue_length"] = i->download_queue_length;
peer["upload_queue_length"] = i->upload_queue_length;
peer["downloading_piece_index"] = i->downloading_piece_index;
peer["downloading_block_index"] = i->downloading_block_index;
peer["downloading_progess"] = i->downloading_progress;
peer["downloading_total"] = i->downloading_total;
peer["client"] = i->client;
peer["connection_type"] = i->connection_type;
peer["source"] = i->source;
peer["country"] = i->country;
peer["interesting"] = (int)i->interesting;
peer["choked"] = (int)i->choked;
peer["remote_interested"] = (int)i->remote_interested;
peer["remote_choked"] = (int)i->remote_choked;
peer["supports_extensions"] = (int)i->supports_extensions;
peer["local_connection"] = (int)i->local_connection;
peer["handshake"] = (int)i->handshake;
peer["connecting"] = (int)i->connecting;
peer["queued"] = (int)i->queued;
peer["on_parole"] = (int)i->on_parole;
peer["seed"] = (int)i->seed;
#ifndef TORRENT_DISABLE_ENCRYPTION
peer["rc4_encrypted"] = (int)i->rc4_encrypted;
peer["plaintext_encrypted"] = (int)i->plaintext_encrypted;
#endif
peer["standard_bittorrent"] = 0;
peer["web_seed"] = 1;
peer["tracker"] = 0x1;
peer["dht"] = 0x2;
peer["pex"] = 0x4;
peer["lsd"] = 0x8;
peer["resume_data"] = 0x10;
result.append(peer);
}
return result; return result;
} }
void prioritize_pieces(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_pieces(result);
return;
}
}
void prioritize_files(torrent_handle& info, object o) void prioritize_files(torrent_handle& info, object o)
{ {
std::vector<int> result;
std::vector<int> result; try
try {
{ object iter_obj = object( handle<>( PyObject_GetIter( o.ptr() ) ));
object iter_obj = object( handle<>( PyObject_GetIter( o.ptr() ) )); while( 1 )
while( 1 ) {
{ object obj = extract<object>( iter_obj.attr( "next" )() );
object obj = extract<object>( iter_obj.attr( "next" )() ); result.push_back(extract<int const>( obj ));
result.push_back(extract<int const>( obj )); }
} }
} catch( error_already_set )
catch( error_already_set ) {
{ PyErr_Clear();
PyErr_Clear(); info.prioritize_files(result);
info.prioritize_files(result); return;
return; }
}
} }
@ -163,87 +170,137 @@ void replace_trackers(torrent_handle& info, object trackers)
list get_download_queue(torrent_handle& handle) list get_download_queue(torrent_handle& handle)
{ {
list ret; list ret;
std::vector<partial_piece_info> downloading; std::vector<partial_piece_info> downloading;
{ {
allow_threading_guard guard; allow_threading_guard guard;
handle.get_download_queue(downloading); handle.get_download_queue(downloading);
} }
for (std::vector<partial_piece_info>::iterator i = downloading.begin() for (std::vector<partial_piece_info>::iterator i = downloading.begin()
, end(downloading.end()); i != end; ++i) , end(downloading.end()); i != end; ++i)
{ {
dict partial_piece; dict partial_piece;
partial_piece["piece_index"] = i->piece_index; partial_piece["piece_index"] = i->piece_index;
partial_piece["blocks_in_piece"] = i->blocks_in_piece; partial_piece["blocks_in_piece"] = i->blocks_in_piece;
list block_list; list block_list;
for (int k = 0; k < i->blocks_in_piece; ++k) for (int k = 0; k < i->blocks_in_piece; ++k)
{ {
dict block_info; dict block_info;
block_info["state"] = i->blocks[k].state; block_info["state"] = i->blocks[k].state;
block_info["num_peers"] = i->blocks[k].num_peers; block_info["num_peers"] = i->blocks[k].num_peers;
block_info["bytes_progress"] = i->blocks[k].bytes_progress; block_info["bytes_progress"] = i->blocks[k].bytes_progress;
block_info["block_size"] = i->blocks[k].block_size; block_info["block_size"] = i->blocks[k].block_size;
// block_info["peer"] = i->info[k].peer; block_info["peer"] = std::make_pair(
block_list.append(block_info); boost::lexical_cast<std::string>(i->blocks[k].peer.address()), i->blocks[k].peer.port());
} block_list.append(block_info);
partial_piece["blocks"] = block_list; }
partial_piece["blocks"] = block_list;
ret.append(partial_piece); ret.append(partial_piece);
} }
return ret; return ret;
}
namespace
{
tcp::endpoint tuple_to_endpoint(tuple const& t)
{
return tcp::endpoint(address::from_string(extract<std::string>(t[0])), extract<int>(t[1]));
}
}
void force_reannounce(torrent_handle& th, int s)
{
th.force_reannounce(boost::posix_time::seconds(s));
}
void connect_peer(torrent_handle& th, tuple ip, int source)
{
th.connect_peer(tuple_to_endpoint(ip), source);
}
void set_peer_upload_limit(torrent_handle& th, tuple const& ip, int limit)
{
th.set_peer_upload_limit(tuple_to_endpoint(ip), limit);
}
void set_peer_download_limit(torrent_handle& th, tuple const& ip, int limit)
{
th.set_peer_download_limit(tuple_to_endpoint(ip), limit);
} }
void bind_torrent_handle() void bind_torrent_handle()
{ {
void (torrent_handle::*force_reannounce0)() const = &torrent_handle::force_reannounce; void (torrent_handle::*force_reannounce0)() const = &torrent_handle::force_reannounce;
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; int (torrent_handle::*piece_priority0)(int) const = &torrent_handle::piece_priority;
void (torrent_handle::*piece_priority1)(int, int) const = &torrent_handle::piece_priority; void (torrent_handle::*piece_priority1)(int, int) const = &torrent_handle::piece_priority;
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
bool (torrent_handle::*resolve_countries0)() const = &torrent_handle::resolve_countries;
void (torrent_handle::*resolve_countries1)(bool) = &torrent_handle::resolve_countries;
#endif
return_value_policy<copy_const_reference> copy; return_value_policy<copy_const_reference> copy;
#define _ allow_threads #define _ allow_threads
class_<torrent_handle>("torrent_handle") class_<torrent_handle>("torrent_handle")
.def("get_peer_info", get_peer_info)
.def("status", _(&torrent_handle::status)) .def("status", _(&torrent_handle::status))
.def("torrent_info", _(&torrent_handle::get_torrent_info), return_internal_reference<>()) .def("get_download_queue", get_download_queue)
.def("is_valid", _(&torrent_handle::is_valid))
.def("write_resume_data", _(&torrent_handle::write_resume_data))
.def("force_reannounce", _(force_reannounce0))
.def("force_reannounce", _(force_reannounce1))
.def("set_tracker_login", _(&torrent_handle::set_tracker_login))
.def("add_url_seed", _(&torrent_handle::add_url_seed))
.def("set_ratio", _(&torrent_handle::set_ratio))
.def("set_max_uploads", _(&torrent_handle::set_max_uploads))
.def("set_max_connections", _(&torrent_handle::set_max_connections))
.def("set_upload_limit", _(&torrent_handle::set_upload_limit))
.def("set_download_limit", _(&torrent_handle::set_download_limit))
.def("set_sequenced_download_threshold", _(&torrent_handle::set_sequenced_download_threshold))
.def("pause", _(&torrent_handle::pause))
.def("resume", _(&torrent_handle::resume))
.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))
.def("move_storage", _(&torrent_handle::move_storage))
.def("info_hash", _(&torrent_handle::info_hash), copy)
.def("file_progress", file_progress) .def("file_progress", file_progress)
.def("trackers", range(begin_trackers, end_trackers)) .def("trackers", range(begin_trackers, end_trackers))
.def("replace_trackers", replace_trackers) .def("replace_trackers", replace_trackers)
.def("add_url_seed", _(&torrent_handle::add_url_seed))
.def("remove_url_seed", _(&torrent_handle::remove_url_seed))
.def("url_seeds", url_seeds)
.def("has_metadata", _(&torrent_handle::has_metadata))
.def("get_torrent_info", _(&torrent_handle::get_torrent_info), return_internal_reference<>())
.def("is_valid", _(&torrent_handle::is_valid))
.def("is_seed", _(&torrent_handle::is_seed))
.def("is_paused", _(&torrent_handle::is_paused))
.def("pause", _(&torrent_handle::pause))
.def("resume", _(&torrent_handle::resume))
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
.def("resolve_countries", _(resolve_countries0))
.def("resolve_countries", _(resolve_countries1))
#endif
// deprecated
.def("filter_piece", _(&torrent_handle::filter_piece))
.def("is_piece_filtered", _(&torrent_handle::is_piece_filtered))
.def("piece_availability", piece_availability)
.def("piece_priority", _(piece_priority0))
.def("piece_priority", _(piece_priority1))
.def("prioritize_pieces", prioritize_pieces)
.def("piece_prioritize", piece_priorities)
.def("prioritize_files", prioritize_files) .def("prioritize_files", prioritize_files)
.def("get_peer_info", get_peer_info) .def("use_interface", &torrent_handle::use_interface)
.def("get_download_queue", get_download_queue) .def("write_resume_data", _(&torrent_handle::write_resume_data))
.def("scrape_tracker", (&torrent_handle::scrape_tracker)) .def("force_reannounce", _(force_reannounce0))
.def("force_reannounce", force_reannounce)
.def("scrape_tracker", _(&torrent_handle::scrape_tracker))
.def("name", _(&torrent_handle::name))
.def("set_upload_limit", _(&torrent_handle::set_upload_limit))
.def("upload_limit", _(&torrent_handle::upload_limit))
.def("set_download_limit", _(&torrent_handle::set_download_limit))
.def("download_limit", _(&torrent_handle::download_limit))
.def("set_sequenced_download_threshold", _(&torrent_handle::set_sequenced_download_threshold))
.def("set_peer_upload_limit", set_peer_upload_limit)
.def("set_peer_download_limit", set_peer_download_limit)
.def("connect_peer", connect_peer)
.def("set_ratio", _(&torrent_handle::set_ratio))
.def("save_path", _(&torrent_handle::save_path))
.def("set_max_uploads", _(&torrent_handle::set_max_uploads))
.def("set_max_connections", _(&torrent_handle::set_max_connections))
.def("set_tracker_login", _(&torrent_handle::set_tracker_login))
.def("move_storage", _(&torrent_handle::move_storage))
.def("info_hash", _(&torrent_handle::info_hash), copy)
; ;
} }

View File

@ -44,12 +44,12 @@ namespace
{ {
return i.begin_files(storage); return i.begin_files(storage);
} }
std::vector<file_entry>::const_iterator end_files(torrent_info& i, bool storage) std::vector<file_entry>::const_iterator end_files(torrent_info& i, bool storage)
{ {
return i.end_files(storage); return i.end_files(storage);
} }
//list files(torrent_info const& ti, bool storage) { //list files(torrent_info const& ti, bool storage) {
list files(torrent_info const& ti, bool storage) { list files(torrent_info const& ti, bool storage) {
list result; list result;
@ -61,7 +61,7 @@ namespace
return result; return result;
} }
} // namespace unnamed } // namespace unnamed
@ -92,8 +92,8 @@ void bind_torrent_info()
.def("hash_for_piece", &torrent_info::hash_for_piece, copy) .def("hash_for_piece", &torrent_info::hash_for_piece, copy)
.def("piece_size", &torrent_info::piece_size) .def("piece_size", &torrent_info::piece_size)
.def("num_files", &torrent_info::num_files, (arg("storage")=false)) .def("num_files", &torrent_info::num_files, (arg("storage")=false))
.def("file_at", &torrent_info::file_at, return_internal_reference<>()) .def("file_at", &torrent_info::file_at, return_internal_reference<>())
.def("files", &files, (arg("storage")=false)) .def("files", &files, (arg("storage")=false))
@ -106,6 +106,7 @@ void bind_torrent_info()
.def("add_node", &add_node) .def("add_node", &add_node)
.def("nodes", &nodes) .def("nodes", &nodes)
; ;
class_<file_entry>("file_entry") class_<file_entry>("file_entry")
.add_property( .add_property(
"path" "path"

View File

@ -18,79 +18,55 @@ object pieces(torrent_status const& s)
return result; return result;
} }
extern char const* torrent_status_doc;
extern char const* torrent_status_state_doc;
extern char const* torrent_status_paused_doc;
extern char const* torrent_status_progress_doc;
extern char const* torrent_status_next_announce_doc;
extern char const* torrent_status_announce_interval_doc;
extern char const* torrent_status_current_tracker_doc;
extern char const* torrent_status_total_download_doc;
extern char const* torrent_status_total_upload_doc;
extern char const* torrent_status_total_payload_download_doc;
extern char const* torrent_status_total_payload_upload_doc;
extern char const* torrent_status_total_failed_bytes_doc;
void bind_torrent_status() void bind_torrent_status()
{ {
scope status = class_<torrent_status>("torrent_status", torrent_status_doc) scope status = class_<torrent_status>("torrent_status")
.def_readonly("state", &torrent_status::state, torrent_status_state_doc) .def_readonly("state", &torrent_status::state)
.def_readonly("paused", &torrent_status::paused, torrent_status_paused_doc) .def_readonly("paused", &torrent_status::paused)
.def_readonly("progress", &torrent_status::progress, torrent_status_progress_doc) .def_readonly("progress", &torrent_status::progress)
.add_property( .add_property(
"next_announce" "next_announce"
, make_getter( , make_getter(
&torrent_status::next_announce, return_value_policy<return_by_value>() &torrent_status::next_announce, return_value_policy<return_by_value>()
) )
, torrent_status_next_announce_doc
) )
.add_property( .add_property(
"announce_interval" "announce_interval"
, make_getter( , make_getter(
&torrent_status::announce_interval, return_value_policy<return_by_value>() &torrent_status::announce_interval, return_value_policy<return_by_value>()
) )
, torrent_status_announce_interval_doc
)
.def_readonly(
"current_tracker", &torrent_status::current_tracker
, torrent_status_current_tracker_doc
)
.def_readonly(
"total_download", &torrent_status::total_download
, torrent_status_total_download_doc
)
.def_readonly(
"total_upload", &torrent_status::total_upload
, torrent_status_total_upload_doc
)
.def_readonly(
"total_payload_download", &torrent_status::total_payload_download
, torrent_status_total_payload_download_doc
)
.def_readonly(
"total_payload_upload", &torrent_status::total_payload_upload
, torrent_status_total_payload_upload_doc
)
.def_readonly(
"total_failed_bytes", &torrent_status::total_failed_bytes
, torrent_status_total_failed_bytes_doc
) )
.def_readonly("current_tracker", &torrent_status::current_tracker)
.def_readonly("total_download", &torrent_status::total_download)
.def_readonly("total_upload", &torrent_status::total_upload)
.def_readonly("total_payload_download", &torrent_status::total_payload_download)
.def_readonly("total_payload_upload", &torrent_status::total_payload_upload)
.def_readonly("total_failed_bytes", &torrent_status::total_failed_bytes)
.def_readonly("total_redundant_bytes", &torrent_status::total_redundant_bytes) .def_readonly("total_redundant_bytes", &torrent_status::total_redundant_bytes)
.def_readonly("download_rate", &torrent_status::download_rate) .def_readonly("download_rate", &torrent_status::download_rate)
.def_readonly("upload_rate", &torrent_status::upload_rate) .def_readonly("upload_rate", &torrent_status::upload_rate)
.def_readonly("download_payload_rate", &torrent_status::download_payload_rate) .def_readonly("download_payload_rate", &torrent_status::download_payload_rate)
.def_readonly("upload_payload_rate", &torrent_status::upload_payload_rate) .def_readonly("upload_payload_rate", &torrent_status::upload_payload_rate)
.def_readonly("num_seeds", &torrent_status::num_seeds)
.def_readonly("num_peers", &torrent_status::num_peers) .def_readonly("num_peers", &torrent_status::num_peers)
.def_readonly("num_complete", &torrent_status::num_complete) .def_readonly("num_complete", &torrent_status::num_complete)
.def_readonly("num_incomplete", &torrent_status::num_incomplete) .def_readonly("num_incomplete", &torrent_status::num_incomplete)
.def_readonly("list_seeds", &torrent_status::list_seeds)
.def_readonly("list_peers", &torrent_status::list_peers)
.add_property("pieces", pieces) .add_property("pieces", pieces)
.def_readonly("num_pieces", &torrent_status::num_pieces) .def_readonly("num_pieces", &torrent_status::num_pieces)
.def_readonly("total_done", &torrent_status::total_done) .def_readonly("total_done", &torrent_status::total_done)
.def_readonly("total_wanted_done", &torrent_status::total_wanted_done) .def_readonly("total_wanted_done", &torrent_status::total_wanted_done)
.def_readonly("total_wanted", &torrent_status::total_wanted) .def_readonly("total_wanted", &torrent_status::total_wanted)
.def_readonly("num_seeds", &torrent_status::num_seeds)
.def_readonly("distributed_copies", &torrent_status::distributed_copies) .def_readonly("distributed_copies", &torrent_status::distributed_copies)
.def_readonly("block_size", &torrent_status::block_size) .def_readonly("block_size", &torrent_status::block_size)
.def_readonly("num_uploads", &torrent_status::num_uploads)
.def_readonly("num_connections", &torrent_status::num_connections)
.def_readonly("uploads_limit", &torrent_status::uploads_limit)
.def_readonly("connections_limit", &torrent_status::connections_limit)
.def_readonly("storage_mode", &torrent_status::storage_mode)
.def_readonly("up_bandwidth_queue", &torrent_status::up_bandwidth_queue)
.def_readonly("down_bandwidth_queue", &torrent_status::down_bandwidth_queue)
; ;
enum_<torrent_status::state_t>("states") enum_<torrent_status::state_t>("states")