From 7f232dd19594d199d0913c3538e956f6fe83a3ce Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 30 Mar 2016 23:35:47 -0400 Subject: [PATCH] fix python3 issue in binding --- bindings/python/src/torrent_handle.cpp | 8 ++++++++ bindings/python/test.py | 16 +++++++++++++++- src/torrent.cpp | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 7854c1327..6b608dda5 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -130,7 +130,11 @@ void prioritize_pieces(torrent_handle& info, object o) object iter_obj = object( handle<>( PyObject_GetIter( o.ptr() ) )); while( 1 ) { +#if PY_MAJOR_VERSION >= 3 + object obj = extract( iter_obj.attr( "__next__" )() ); +#else object obj = extract( iter_obj.attr( "next" )() ); +#endif extract val1(obj); if (val1.check()) { @@ -164,7 +168,11 @@ void prioritize_files(torrent_handle& info, object o) object iter_obj = object( handle<>( PyObject_GetIter( o.ptr() ) )); while( 1 ) { +#if PY_MAJOR_VERSION >= 3 + object obj = extract( iter_obj.attr( "__next__" )() ); +#else object obj = extract( iter_obj.attr( "next" )() ); +#endif result.push_back(extract( obj )); } } diff --git a/bindings/python/test.py b/bindings/python/test.py index 324b8cb46..c7d59640a 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -8,7 +8,19 @@ import os import shutil import binascii -# test torrent_info +class test_torrent_handle(unittest.TestCase): + + def test_torrent_handle(self): + ses = lt.session({'alert_mask': lt.alert.category_t.all_categories}) + shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'url_seed_multi.torrent'), '.') + ti = lt.torrent_info('url_seed_multi.torrent'); + h = ses.add_torrent({'ti': ti, 'save_path': os.getcwd()}) + + h.prioritize_files([0,1]) + self.assertEqual(h.file_priorities(), [0,1]) + + h.prioritize_pieces([0]) + self.assertEqual(h.piece_priorities(), [0]) class test_torrent_info(unittest.TestCase): @@ -75,6 +87,7 @@ class test_sha1hash(unittest.TestCase): class test_session(unittest.TestCase): + def test_post_session_stats(self): s = lt.session({'alert_mask': lt.alert.category_t.stats_notification}) s.post_session_stats() @@ -83,6 +96,7 @@ class test_session(unittest.TestCase): self.assertTrue(isinstance(a.values, dict)) self.assertTrue(len(a.values) > 0) + if __name__ == '__main__': print(lt.__version__) unittest.main() diff --git a/src/torrent.cpp b/src/torrent.cpp index 04226a615..610d62629 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5493,6 +5493,8 @@ namespace libtorrent TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered()); } update_gauge(); + update_want_tick(); + if (filter_updated) { // we need to save this new state