fix merge issue in python endpoint converter (#1625)

fix merge issue in python endpoint converter
This commit is contained in:
Arvid Norberg 2017-01-25 23:42:26 -05:00 committed by GitHub
parent c979802ce9
commit 7285813449
3 changed files with 44 additions and 45 deletions

View File

@ -221,8 +221,7 @@ def main():
ses = lt.session({'user_agent': 'python_client/' + lt.__version__, ses = lt.session({'user_agent': 'python_client/' + lt.__version__,
'listen_interfaces':'0.0.0.0:' + str(options.port), 'listen_interfaces':'0.0.0.0:' + str(options.port),
'download_rate_limit': int(options.max_download_rate), 'download_rate_limit': int(options.max_download_rate),
'upload_rate_limit': int(options.max_upload_rate), 'upload_rate_limit': int(options.max_upload_rate)
'alert_mask' : 0xfffffff
}) })
if options.proxy_host != '': if options.proxy_host != '':
@ -240,9 +239,8 @@ def main():
atp = {} atp = {}
atp["save_path"] = options.save_path atp["save_path"] = options.save_path
atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse
atp["paused"] = False atp["flags"] = lt.add_torrent_params_flags_t.flag_duplicate_is_error \
atp["auto_managed"] = True | lt.add_torrent_params_flags_t.flag_auto_managed
atp["duplicate_is_error"] = True
if f.startswith('magnet:') or f.startswith( if f.startswith('magnet:') or f.startswith(
'http://') or f.startswith('https://'): 'http://') or f.startswith('https://'):
atp["url"] = f atp["url"] = f
@ -331,7 +329,8 @@ def main():
write_line(console, '(q)uit), (p)ause), (u)npause), (r)eannounce\n') write_line(console, '(q)uit), (p)ause), (u)npause), (r)eannounce\n')
write_line(console, 76 * '-' + '\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: for a in alerts:
if type(a) == str: if type(a) == str:

View File

@ -234,7 +234,6 @@ void bind_converters()
// C++ -> python conversions // C++ -> python conversions
to_python_converter<std::pair<int, int>, pair_to_tuple<int, int>>(); to_python_converter<std::pair<int, int>, pair_to_tuple<int, int>>();
to_python_converter<std::pair<lt::piece_index_t, int>, pair_to_tuple<lt::piece_index_t, int>>(); to_python_converter<std::pair<lt::piece_index_t, int>, pair_to_tuple<lt::piece_index_t, int>>();
to_python_converter<std::pair<std::string, int>, pair_to_tuple<std::string, int>>();
to_python_converter<lt::tcp::endpoint, endpoint_to_tuple<lt::tcp::endpoint>>(); to_python_converter<lt::tcp::endpoint, endpoint_to_tuple<lt::tcp::endpoint>>();
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint>>(); to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint>>();
to_python_converter<lt::address, address_to_tuple>(); to_python_converter<lt::address, address_to_tuple>();

View File

@ -341,6 +341,45 @@ class test_session(unittest.TestCase):
self.assertEqual(s.get_settings()['num_want'], 66) self.assertEqual(s.get_settings()['num_want'], 66)
self.assertEqual(s.get_settings()['user_agent'], 'test123') 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): class test_example_client(unittest.TestCase):
def test_execute_client(self): 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," + "some configuration does not output errors like missing module members,"
+ "try to call it manually to get the error message\n") + "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__': if __name__ == '__main__':
print(lt.__version__) print(lt.__version__)
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', shutil.copy(os.path.join('..', '..', 'test', 'test_torrents',