From 2ce418f344ead3b562e478f28780ba3d8f3a603b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 26 Dec 2010 01:58:35 +0000 Subject: [PATCH] properly expose endpoints and addresses from alerts to python --- bindings/python/src/alert.cpp | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index f2741d51c..126f6c55e 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -15,24 +15,30 @@ std::string get_buffer(read_piece_alert const& rpa) : std::string(); } -struct endpoint_to_python +tuple endpoint_to_tuple(tcp::endpoint const& ep) { - static PyObject* convert(tcp::endpoint const& ep) - { - return incref(make_tuple(ep.address().to_string(), ep.port()).ptr()); - } + return make_tuple(ep.address().to_string(), ep.port()); +} - static PyObject* convert(udp::endpoint const& ep) - { - return incref(make_tuple(ep.address().to_string(), ep.port()).ptr()); - } -}; +tuple peer_alert_ip(peer_alert const& pa) +{ + return endpoint_to_tuple(pa.ip); +} + +std::string peer_blocked_alert_ip(peer_blocked_alert const& pa) +{ + error_code ec; + return pa.ip.to_string(ec); +} + +std::string dht_announce_alert_ip(dht_announce_alert const& pa) +{ + error_code ec; + return pa.ip.to_string(ec); +} void bind_alert() { - to_python_converter(); - to_python_converter(); - using boost::noncopyable; { @@ -93,7 +99,7 @@ void bind_alert() class_, noncopyable>( "peer_alert", no_init) - .def_readonly("ip", &peer_alert::ip) + .add_property("ip", &peer_alert_ip) .def_readonly("pid", &peer_alert::pid) ; class_, noncopyable>( @@ -250,7 +256,7 @@ void bind_alert() class_, noncopyable>( "peer_blocked_alert", no_init) - .def_readonly("ip", &peer_blocked_alert::ip) + .add_property("ip", &peer_blocked_alert_ip) ; class_, noncopyable>( @@ -312,7 +318,7 @@ void bind_alert() class_, noncopyable>( "dht_announce_alert", no_init) - .def_readonly("ip", &dht_announce_alert::ip) + .add_property("ip", &dht_announce_alert_ip) .def_readonly("port", &dht_announce_alert::port) .def_readonly("info_hash", &dht_announce_alert::info_hash) ;