fix backwards compatibility of python binding for set_settings

This commit is contained in:
arvidn 2016-04-04 00:52:21 -04:00
parent cf5c39a050
commit f409a5abf3
2 changed files with 41 additions and 8 deletions

View File

@ -135,7 +135,26 @@ namespace
return boost::make_shared<lt::session>(p, flags); 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; settings_pack p;
make_settings_pack(p, sett_dict); make_settings_pack(p, sett_dict);
@ -782,14 +801,11 @@ void bind_session()
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
.def("add_feed", &add_feed) .def("add_feed", &add_feed)
.def("status", allow_threads(&lt::session::status)) .def("status", allow_threads(&lt::session::status))
.def("set_settings", &lt::session::set_settings)
.def("settings", &lt::session::settings)
.def("get_settings", &session_get_settings)
#else
.def("settings", &session_get_settings) .def("settings", &session_get_settings)
.def("get_settings", &session_get_settings) .def("set_settings", &session_set_settings)
#endif #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_NO_DEPRECATE
#ifndef TORRENT_DISABLE_ENCRYPTION #ifndef TORRENT_DISABLE_ENCRYPTION
.def("set_pe_settings", allow_threads(&lt::session::set_pe_settings)) .def("set_pe_settings", allow_threads(&lt::session::set_pe_settings))
@ -803,7 +819,7 @@ void bind_session()
#ifdef TORRENT_NO_DEPRECATE #ifdef TORRENT_NO_DEPRECATE
, return_internal_reference<>() , return_internal_reference<>()
#endif #endif
) )
.def("add_extension", &add_extension) .def("add_extension", &add_extension)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
.def("pop_alert", &pop_alert) .def("pop_alert", &pop_alert)

View File

@ -104,6 +104,23 @@ class test_session(unittest.TestCase):
self.assertTrue(isinstance(a.values, dict)) self.assertTrue(isinstance(a.values, dict))
self.assertTrue(len(a.values) > 0) 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__': if __name__ == '__main__':
print(lt.__version__) print(lt.__version__)