fix python3 issue in binding

This commit is contained in:
arvidn 2016-03-30 23:35:47 -04:00
parent c8450ef6bc
commit 7f232dd195
3 changed files with 25 additions and 1 deletions

View File

@ -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<object>( iter_obj.attr( "__next__" )() );
#else
object obj = extract<object>( iter_obj.attr( "next" )() );
#endif
extract<int const> 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<object>( iter_obj.attr( "__next__" )() );
#else
object obj = extract<object>( iter_obj.attr( "next" )() );
#endif
result.push_back(extract<int const>( obj ));
}
}

View File

@ -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()

View File

@ -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