diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 8357a9b54..d8e1b80f6 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -25,17 +25,6 @@ bytes get_buffer(read_piece_alert const& rpa) : bytes(); } -std::string dht_announce_alert_ip(dht_announce_alert const& pa) -{ - error_code ec; - return pa.ip.to_string(ec); -} - -std::string external_ip_alert_ip(external_ip_alert const& eia) -{ - return eia.external_address.to_string(); -} - list stats_alert_transferred(stats_alert const& alert) { list result; @@ -242,7 +231,7 @@ namespace boost POLY(save_resume_data_failed_alert) POLY(performance_alert) POLY(stats_alert) - POLY(cache_flushed_alert) + POLY(cache_flushed_alert) POLY(anonymous_mode_alert) POLY(incoming_connection_alert) POLY(torrent_need_cert_alert) @@ -275,6 +264,8 @@ void bind_alert() { using boost::noncopyable; + typedef return_value_policy by_value; + { scope alert_scope = class_("alert", no_init) .def("message", &alert::message) @@ -349,6 +340,9 @@ void bind_alert() class_, noncopyable>( "read_piece_alert", nullptr, no_init) .def_readonly("error", &read_piece_alert::error) +#ifndef TORRENT_NO_DEPRECATE + .def_readonly("ec", &read_piece_alert::ec) +#endif .add_property("buffer", get_buffer) .def_readonly("piece", &read_piece_alert::piece) .def_readonly("size", &read_piece_alert::size) @@ -357,11 +351,9 @@ void bind_alert() class_, noncopyable>( "peer_alert", no_init) #ifndef TORRENT_NO_DEPRECATE - .add_property("ip", make_getter(&peer_alert::ip - , return_value_policy())) + .add_property("ip", make_getter(&peer_alert::ip, by_value())) #endif - .add_property("endpoint", make_getter(&peer_alert::endpoint - , return_value_policy())) + .add_property("endpoint", make_getter(&peer_alert::endpoint, by_value())) .def_readonly("pid", &peer_alert::pid) ; class_, noncopyable>( @@ -452,6 +444,8 @@ void bind_alert() class_, noncopyable>( "storage_moved_failed_alert", no_init) .def_readonly("error", &storage_moved_failed_alert::error) + .def("file_path", &storage_moved_failed_alert::file_path) + .def_readonly("operation", &storage_moved_failed_alert::operation) ; class_, noncopyable>( @@ -471,7 +465,9 @@ void bind_alert() .def_readonly("url", &url_seed_alert::url) .def_readonly("msg", &url_seed_alert::msg) #endif + .def_readonly("error", &url_seed_alert::error) .def("server_url", &url_seed_alert::server_url) + .def("error_message", &url_seed_alert::error_message) ; class_, noncopyable>( @@ -485,7 +481,9 @@ void bind_alert() ; class_, noncopyable>( - "metadata_failed_alert", no_init); + "metadata_failed_alert", no_init) + .def_readonly("error", &metadata_failed_alert::error) + ; class_, noncopyable>( "metadata_received_alert", no_init); @@ -493,9 +491,9 @@ void bind_alert() class_, noncopyable>( "listen_failed_alert", no_init) #ifndef TORRENT_NO_DEPRECATE - .def_readonly("endpoint", &listen_failed_alert::endpoint) + .add_property("endpoint", make_getter(&listen_failed_alert::endpoint, by_value())) #endif - .def_readonly("address", &listen_failed_alert::address) + .add_property("address", make_getter(&listen_failed_alert::address, by_value())) .def_readonly("port", &listen_failed_alert::port) .def("listen_interface", &listen_failed_alert::listen_interface) .def_readonly("error", &listen_failed_alert::error) @@ -509,9 +507,9 @@ void bind_alert() class_, noncopyable>( "listen_succeeded_alert", no_init) #ifndef TORRENT_NO_DEPRECATE - .def_readonly("endpoint", &listen_succeeded_alert::endpoint) + .add_property("endpoint", make_getter(&listen_succeeded_alert::endpoint, by_value())) #endif - .def_readonly("address", &listen_succeeded_alert::address) + .add_property("address", make_getter(&listen_succeeded_alert::address, by_value())) .def_readonly("port", &listen_succeeded_alert::port) #ifndef TORRENT_NO_DEPRECATE .def_readonly("sock_type", &listen_succeeded_alert::sock_type) @@ -519,6 +517,15 @@ void bind_alert() .def_readonly("socket_type", &listen_succeeded_alert::socket_type) ; + enum_("socket_type_t") + .value("tcp", socket_type_t::tcp) + .value("tcp_ssl", socket_type_t::tcp_ssl) + .value("udp", socket_type_t::udp) + .value("i2p", socket_type_t::i2p) + .value("socks5", socket_type_t::socks5) + .value("utp_ssl", socket_type_t::utp_ssl) + ; + class_, noncopyable>( "portmap_error_alert", no_init) .def_readonly("mapping", &portmap_error_alert::mapping) @@ -559,10 +566,15 @@ void bind_alert() #ifndef TORRENT_NO_DEPRECATE .def_readonly("msg", &fastresume_rejected_alert::msg) #endif + .def("file_path", &fastresume_rejected_alert::file_path) + .def_readonly("operation", &fastresume_rejected_alert::operation) ; class_, noncopyable>( "peer_blocked_alert", no_init) +#ifndef TORRENT_NO_DEPRECATE + .add_property("ip", make_getter(&peer_blocked_alert::ip, by_value())) +#endif .add_property("reason", &peer_blocked_alert::reason) ; @@ -588,19 +600,18 @@ void bind_alert() .def_readonly("msg", &scrape_failed_alert::msg) #endif .def("error_message", &scrape_failed_alert::error_message) + .def_readonly("error", &scrape_failed_alert::error) ; class_, noncopyable>( "udp_error_alert", no_init) - .def_readonly("endpoint", &udp_error_alert::endpoint) + .add_property("endpoint", make_getter(&udp_error_alert::endpoint, by_value())) .def_readonly("error", &udp_error_alert::error) ; class_, noncopyable>( "external_ip_alert", no_init) - .add_property("external_address" - , make_getter(&external_ip_alert::external_address - , return_value_policy())) + .add_property("external_address", make_getter(&external_ip_alert::external_address, by_value())) ; class_, noncopyable>( @@ -655,7 +666,7 @@ void bind_alert() class_, noncopyable>( "dht_announce_alert", no_init) - .add_property("ip", &dht_announce_alert_ip) + .add_property("ip", make_getter(&dht_announce_alert::ip, by_value())) .def_readonly("port", &dht_announce_alert::port) .def_readonly("info_hash", &dht_announce_alert::info_hash) ; @@ -710,6 +721,7 @@ void bind_alert() .def_readonly("msg", &torrent_delete_failed_alert::msg) #endif .def_readonly("error", &torrent_delete_failed_alert::error) + .def_readonly("info_hash", &torrent_delete_failed_alert::info_hash) ; class_, noncopyable>( @@ -778,11 +790,9 @@ void bind_alert() "incoming_connection_alert", no_init) .def_readonly("socket_type", &incoming_connection_alert::socket_type) #ifndef TORRENT_NO_DEPRECATE - .add_property("ip", make_getter(&incoming_connection_alert::ip - , return_value_policy())) + .add_property("ip", make_getter(&incoming_connection_alert::ip, by_value())) #endif - .add_property("endpoint", make_getter(&incoming_connection_alert::endpoint - , return_value_policy())) + .add_property("endpoint", make_getter(&incoming_connection_alert::endpoint, by_value())) ; class_, noncopyable>( "torrent_need_cert_alert", no_init) @@ -808,11 +818,9 @@ void bind_alert() .def_readonly("info_hash", &dht_outgoing_get_peers_alert::info_hash) .def_readonly("obfuscated_info_hash", &dht_outgoing_get_peers_alert::obfuscated_info_hash) #ifndef TORRENT_NO_DEPRECATE - .add_property("ip", make_getter(&dht_outgoing_get_peers_alert::ip - , return_value_policy())) + .add_property("ip", make_getter(&dht_outgoing_get_peers_alert::ip, by_value())) #endif - .add_property("endpoint", make_getter(&dht_outgoing_get_peers_alert::endpoint - , return_value_policy())) + .add_property("endpoint", make_getter(&dht_outgoing_get_peers_alert::endpoint, by_value())) ; class_, noncopyable>( @@ -858,18 +866,30 @@ void bind_alert() class_, noncopyable>( "dht_immutable_item_alert", no_init) + .def_readonly("target", &dht_immutable_item_alert::target) .add_property("item", &dht_immutable_item) ; class_, noncopyable>( "dht_mutable_item_alert", no_init) + .def_readonly("key", &dht_mutable_item_alert::key) + .def_readonly("signature", &dht_mutable_item_alert::signature) + .def_readonly("seq", &dht_mutable_item_alert::seq) + .def_readonly("salt", &dht_mutable_item_alert::salt) .add_property("item", &dht_mutable_item) + .def_readonly("authoritative", &dht_mutable_item_alert::authoritative) ; class_, noncopyable>( "dht_put_alert", no_init) - .add_property("item", &dht_put_item) + .def_readonly("target", &dht_put_alert::target) + .def_readonly("public_key", &dht_put_alert::public_key) + .def_readonly("signature", &dht_put_alert::signature) + .def_readonly("salt", &dht_put_alert::salt) + .def_readonly("seq", &dht_put_alert::seq) + .def_readonly("num_success", &dht_put_alert::num_success) ; + class_, noncopyable>( "session_stats_alert", no_init) .add_property("values", &session_stats_values) diff --git a/bindings/python/src/converters.cpp b/bindings/python/src/converters.cpp index e04ae4720..051547be0 100644 --- a/bindings/python/src/converters.cpp +++ b/bindings/python/src/converters.cpp @@ -67,6 +67,15 @@ struct pair_to_tuple } }; +struct address_to_tuple +{ + static PyObject* convert(libtorrent::address const& addr) + { + libtorrent::error_code ec; + return incref(bp::object(addr.to_string(ec)).ptr()); + } +}; + template struct tuple_to_pair { @@ -151,6 +160,8 @@ void bind_converters() to_python_converter, pair_to_tuple>(); to_python_converter>(); to_python_converter>(); + to_python_converter(); + to_python_converter, vector_to_list>(); to_python_converter, vector_to_list>(); to_python_converter, vector_to_list>(); diff --git a/bindings/python/test.py b/bindings/python/test.py index 4939fbebd..94edc3c29 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -8,7 +8,6 @@ import os import shutil import binascii - class test_create_torrent(unittest.TestCase): def test_from_torrent_info(self): @@ -127,6 +126,13 @@ class test_alerts(unittest.TestCase): alerts = ses.pop_alerts() for a in alerts: print(a.message()) + for field_name in dir(a): + if field_name.startswith('__'): continue + field = getattr(a, field_name) + if callable(field): + print(' ', field_name, ' = ', field()) + else: + print(' ', field_name, ' = ', field) print(st.next_announce) self.assertEqual(st.name, 'temp')