fix metadata() and hash_for_piece() in python3 binding
This commit is contained in:
parent
7f232dd195
commit
f1c3ecd067
|
@ -9,7 +9,14 @@
|
|||
|
||||
struct bytes
|
||||
{
|
||||
bytes(char const* s, int len): arr(s, len) {}
|
||||
bytes(std::string const& s): arr(s) {}
|
||||
#if __cplusplus >= 201103L
|
||||
bytes(std::string&& s): arr(std::move(s)) {}
|
||||
bytes(bytes const&) = default;
|
||||
bytes(bytes&&) = default;
|
||||
bytes& operator=(bytes&&) = default;
|
||||
#endif
|
||||
bytes() {}
|
||||
std::string arr;
|
||||
};
|
||||
|
|
|
@ -90,15 +90,14 @@ namespace
|
|||
ti.set_merkle_tree(h);
|
||||
}
|
||||
|
||||
std::string hash_for_piece(torrent_info const& ti, int i)
|
||||
bytes hash_for_piece(torrent_info const& ti, int i)
|
||||
{
|
||||
return ti.hash_for_piece(i).to_string();
|
||||
return bytes(ti.hash_for_piece(i).to_string());
|
||||
}
|
||||
|
||||
std::string metadata(torrent_info const& ti)
|
||||
bytes metadata(torrent_info const& ti)
|
||||
{
|
||||
std::string result(ti.metadata().get(), ti.metadata_size());
|
||||
return result;
|
||||
return bytes(ti.metadata().get(), ti.metadata_size());
|
||||
}
|
||||
|
||||
list map_block(torrent_info& ti, int piece, boost::int64_t offset, int size)
|
||||
|
|
|
@ -36,6 +36,13 @@ class test_torrent_info(unittest.TestCase):
|
|||
self.assertEqual(f.file_size(0), 1234)
|
||||
self.assertEqual(info.total_size(), 1234)
|
||||
|
||||
def test_metadata(self):
|
||||
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'base.torrent'), '.')
|
||||
ti = lt.torrent_info('base.torrent');
|
||||
|
||||
self.assertTrue(len(ti.metadata()) != 0)
|
||||
self.assertTrue(len(ti.hash_for_piece(0)) != 0)
|
||||
|
||||
class test_alerts(unittest.TestCase):
|
||||
|
||||
def test_alert(self):
|
||||
|
|
Loading…
Reference in New Issue