forked from premiere/premiere-libtorrent
fix backwards compatibility of python binding for set_settings
This commit is contained in:
parent
cf5c39a050
commit
f409a5abf3
|
@ -135,7 +135,26 @@ namespace
|
|||
return boost::make_shared<lt::session>(p, flags);
|
||||
}
|
||||
|
||||
void session_set_settings(lt::session& ses, dict const& sett_dict)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
void session_set_settings(lt::session& ses, object const& sett)
|
||||
{
|
||||
extract<session_settings> old_settings(sett);
|
||||
if (old_settings.check())
|
||||
{
|
||||
allow_threading_guard guard;
|
||||
ses.set_settings(old_settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings_pack p;
|
||||
make_settings_pack(p, extract<dict>(sett));
|
||||
allow_threading_guard guard;
|
||||
ses.apply_settings(p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void session_apply_settings(lt::session& ses, dict const& sett_dict)
|
||||
{
|
||||
settings_pack p;
|
||||
make_settings_pack(p, sett_dict);
|
||||
|
@ -782,14 +801,11 @@ void bind_session()
|
|||
#ifndef TORRENT_NO_DEPRECATE
|
||||
.def("add_feed", &add_feed)
|
||||
.def("status", allow_threads(<::session::status))
|
||||
.def("set_settings", <::session::set_settings)
|
||||
.def("settings", <::session::settings)
|
||||
.def("get_settings", &session_get_settings)
|
||||
#else
|
||||
.def("settings", &session_get_settings)
|
||||
.def("get_settings", &session_get_settings)
|
||||
.def("set_settings", &session_set_settings)
|
||||
#endif
|
||||
.def("apply_settings", &session_set_settings)
|
||||
.def("get_settings", &session_get_settings)
|
||||
.def("apply_settings", &session_apply_settings)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
.def("set_pe_settings", allow_threads(<::session::set_pe_settings))
|
||||
|
|
|
@ -104,6 +104,23 @@ class test_session(unittest.TestCase):
|
|||
self.assertTrue(isinstance(a.values, dict))
|
||||
self.assertTrue(len(a.values) > 0)
|
||||
|
||||
def test_deprecated_settings(self):
|
||||
|
||||
# this detects whether libtorrent was built with deprecated APIs
|
||||
if hasattr(lt, 'version'):
|
||||
s = lt.session({})
|
||||
sett = lt.session_settings()
|
||||
sett.num_want = 10;
|
||||
s.set_settings(sett)
|
||||
s.set_settings({'num_want': 33})
|
||||
self.assertEqual(s.get_settings()['num_want'], 33)
|
||||
|
||||
def test_apply_settings(self):
|
||||
|
||||
s = lt.session({})
|
||||
s.apply_settings({'num_want': 66})
|
||||
self.assertEqual(s.get_settings()['num_want'], 66)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(lt.__version__)
|
||||
|
|
Loading…
Reference in New Issue