From 852fada77266903998ddf7a0ac07b5ba5edbd6e7 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 28 Mar 2017 20:22:27 -0400 Subject: [PATCH] restore announce_entry's timestamp fields to posix time in python binding --- ChangeLog | 1 + bindings/python/src/torrent_handle.cpp | 29 ++++++++++++++++++++++++-- bindings/python/test.py | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84217751a..ca760b7bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * restore announce_entry's timestamp fields to posix time in python binding * deprecate torrent_added_alert (in favor of add_torrent_alert) * fix python binding for parse_magnet_uri * fix minor robustness issue in DHT bootstrap logic diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index ea16d66b8..da69100d3 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -231,6 +231,21 @@ void add_tracker(torrent_handle& h, dict d) h.add_tracker(ae); } +namespace +{ +#if defined BOOST_ASIO_HAS_STD_CHRONO + using std::chrono::system_clock; +#else + using boost::chrono::system_clock; +#endif + + time_t to_ptime(time_point tpt) + { + return system_clock::to_time_t(system_clock::now() + + duration_cast(tpt - clock_type::now())); + } +} + list trackers(torrent_handle& h) { list ret; @@ -245,8 +260,18 @@ list trackers(torrent_handle& h) last_error["value"] = i->last_error.value(); last_error["category"] = i->last_error.category().name(); d["last_error"] = last_error; - d["next_announce"] = i->next_announce; - d["min_announce"] = i->min_announce; + if (i->next_announce > min_time()) { + d["next_announce"] = to_ptime(i->next_announce); + } + else { + d["next_announce"] = object(); + } + if (i->min_announce > min_time()) { + d["min_announce"] = to_ptime(i->min_announce); + } + else { + d["min_announce"] = object(); + } d["scrape_incomplete"] = i->scrape_incomplete; d["scrape_complete"] = i->scrape_complete; d["scrape_downloaded"] = i->scrape_downloaded; diff --git a/bindings/python/test.py b/bindings/python/test.py index 5abc13355..63b494936 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -109,6 +109,11 @@ class test_torrent_handle(unittest.TestCase): """Test to ensure the dict contains only python built-in types""" self.setup() self.h.add_tracker({'url':'udp://tracker1.com'}) + tr = self.h.trackers()[0] + # wait a bit until a valid timestamp appears + while tr['next_announce'] == None: + time.sleep(0.1) + tr = self.h.trackers()[0] import json print(json.dumps(self.h.trackers()[0]))