restore announce_entry's timestamp fields to posix time in python binding
This commit is contained in:
parent
412325ba46
commit
852fada772
|
@ -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
|
||||
|
|
|
@ -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<system_clock::duration>(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;
|
||||
|
|
|
@ -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]))
|
||||
|
||||
|
|
Loading…
Reference in New Issue