From 72858134491ef370d5e8258860490533d44876a7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 25 Jan 2017 23:42:26 -0500 Subject: [PATCH] fix merge issue in python endpoint converter (#1625) fix merge issue in python endpoint converter --- bindings/python/client.py | 11 ++--- bindings/python/src/converters.cpp | 1 - bindings/python/test.py | 77 +++++++++++++++--------------- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/bindings/python/client.py b/bindings/python/client.py index 3e07b9ec1..fef925fbe 100755 --- a/bindings/python/client.py +++ b/bindings/python/client.py @@ -221,8 +221,7 @@ def main(): ses = lt.session({'user_agent': 'python_client/' + lt.__version__, 'listen_interfaces':'0.0.0.0:' + str(options.port), 'download_rate_limit': int(options.max_download_rate), - 'upload_rate_limit': int(options.max_upload_rate), - 'alert_mask' : 0xfffffff + 'upload_rate_limit': int(options.max_upload_rate) }) if options.proxy_host != '': @@ -240,9 +239,8 @@ def main(): atp = {} atp["save_path"] = options.save_path atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse - atp["paused"] = False - atp["auto_managed"] = True - atp["duplicate_is_error"] = True + atp["flags"] = lt.add_torrent_params_flags_t.flag_duplicate_is_error \ + | lt.add_torrent_params_flags_t.flag_auto_managed if f.startswith('magnet:') or f.startswith( 'http://') or f.startswith('https://'): atp["url"] = f @@ -331,7 +329,8 @@ def main(): write_line(console, '(q)uit), (p)ause), (u)npause), (r)eannounce\n') write_line(console, 76 * '-' + '\n') - alerts = ses.pop_alerts() + # only print the last 20 alerts + alerts = ses.pop_alerts()[-20:] for a in alerts: if type(a) == str: diff --git a/bindings/python/src/converters.cpp b/bindings/python/src/converters.cpp index 83ad32735..cd67f4b7a 100644 --- a/bindings/python/src/converters.cpp +++ b/bindings/python/src/converters.cpp @@ -234,7 +234,6 @@ void bind_converters() // C++ -> python conversions to_python_converter, pair_to_tuple>(); to_python_converter, pair_to_tuple>(); - to_python_converter, pair_to_tuple>(); to_python_converter>(); to_python_converter>(); to_python_converter(); diff --git a/bindings/python/test.py b/bindings/python/test.py index 04458f7f9..f7f3871db 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -341,6 +341,45 @@ class test_session(unittest.TestCase): self.assertEqual(s.get_settings()['num_want'], 66) self.assertEqual(s.get_settings()['user_agent'], 'test123') + + def test_post_session_stats(self): + s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, + 'enable_dht': False}) + s.post_session_stats() + a = s.wait_for_alert(1000) + self.assertTrue(isinstance(a, lt.session_stats_alert)) + self.assertTrue(isinstance(a.values, dict)) + self.assertTrue(len(a.values) > 0) + + def test_add_torrent(self): + s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, + 'enable_dht': False}) + s.add_torrent({ + 'ti': lt.torrent_info('base.torrent'), + 'save_path': '.', + 'dht_nodes': [('1.2.3.4', 6881), ('4.3.2.1', 6881)], + 'http_seeds': ['http://test.com/seed'], + 'peers': [('5.6.7.8', 6881)], + 'banned_peers': [('8.7.6.5', 6881)], + 'file_priorities': [1, 1, 1, 2, 0]}) + + def test_unknown_settings(self): + try: + lt.session({'unexpected-key-name': 42}) + self.assertFalse('should have thrown an exception') + except KeyError as e: + print(e) + + def test_apply_settings(self): + s = lt.session({'enable_dht': False}) + s.apply_settings({'num_want': 66, 'user_agent': 'test123'}) + self.assertEqual(s.get_settings()['num_want'], 66) + self.assertEqual(s.get_settings()['user_agent'], 'test123') + + def test_fingerprint(self): + self.assertEqual(lt.generate_fingerprint('LT', 0, 1, 2, 3), '-LT0123-') + self.assertEqual(lt.generate_fingerprint('..', 10, 1, 2, 3), '-..A123-') + class test_example_client(unittest.TestCase): def test_execute_client(self): @@ -412,44 +451,6 @@ class test_example_client(unittest.TestCase): + "some configuration does not output errors like missing module members," + "try to call it manually to get the error message\n") - def test_post_session_stats(self): - s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, - 'enable_dht': False}) - s.post_session_stats() - a = s.wait_for_alert(1000) - self.assertTrue(isinstance(a, lt.session_stats_alert)) - self.assertTrue(isinstance(a.values, dict)) - self.assertTrue(len(a.values) > 0) - - def test_add_torrent(self): - s = lt.session({'alert_mask': lt.alert.category_t.stats_notification, - 'enable_dht': False}) - s.add_torrent({ - 'ti': lt.torrent_info('base.torrent'), - 'save_path': '.', - 'dht_nodes': [('1.2.3.4', 6881), ('4.3.2.1', 6881)], - 'http_seeds': ['http://test.com/seed'], - 'peers': [('5.6.7.8', 6881)], - 'banned_peers': [('8.7.6.5', 6881)], - 'file_priorities': [1, 1, 1, 2, 0]}) - - def test_unknown_settings(self): - try: - lt.session({'unexpected-key-name': 42}) - self.assertFalse('should have thrown an exception') - except KeyError as e: - print(e) - - def test_apply_settings(self): - s = lt.session({'enable_dht': False}) - s.apply_settings({'num_want': 66, 'user_agent': 'test123'}) - self.assertEqual(s.get_settings()['num_want'], 66) - self.assertEqual(s.get_settings()['user_agent'], 'test123') - - def test_fingerprint(self): - self.assertEqual(lt.generate_fingerprint('LT', 0, 1, 2, 3), '-LT0123-') - self.assertEqual(lt.generate_fingerprint('..', 10, 1, 2, 3), '-..A123-') - if __name__ == '__main__': print(lt.__version__) shutil.copy(os.path.join('..', '..', 'test', 'test_torrents',