add support for entry::preformatted to python binding (#952)
This commit is contained in:
parent
48ca20968e
commit
69f82c5274
|
@ -45,6 +45,15 @@ struct entry_to_python
|
||||||
return convert(e.list());
|
return convert(e.list());
|
||||||
case entry::dictionary_t:
|
case entry::dictionary_t:
|
||||||
return convert(e.dict());
|
return convert(e.dict());
|
||||||
|
case entry::preformatted_t:
|
||||||
|
{
|
||||||
|
std::vector<char> const& pre = e.preformatted();
|
||||||
|
list l;
|
||||||
|
for (std::vector<char>::const_iterator i = pre.begin()
|
||||||
|
, end(pre.end()); i != end; ++i)
|
||||||
|
l.append(*i);
|
||||||
|
return tuple(l);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return object();
|
return object();
|
||||||
}
|
}
|
||||||
|
@ -136,6 +145,19 @@ struct entry_from_python
|
||||||
{
|
{
|
||||||
return entry(extract<entry::integer_type>(e)());
|
return entry(extract<entry::integer_type>(e)());
|
||||||
}
|
}
|
||||||
|
else if (extract<tuple>(e).check())
|
||||||
|
{
|
||||||
|
tuple t = extract<tuple>(e);
|
||||||
|
|
||||||
|
std::size_t const length = extract<std::size_t>(t.attr("__len__")());
|
||||||
|
std::vector<char> preformatted(length);
|
||||||
|
for (std::size_t i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
preformatted[i] = extract<char>(t[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry(preformatted);
|
||||||
|
}
|
||||||
|
|
||||||
return entry();
|
return entry();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,20 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
|
|
||||||
|
class test_create_torrent(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_from_torrent_info(self):
|
||||||
|
ti = lt.torrent_info('unordered.torrent')
|
||||||
|
ct = lt.create_torrent(ti)
|
||||||
|
entry = ct.generate()
|
||||||
|
content = lt.bencode(entry).strip()
|
||||||
|
with open('unordered.torrent', 'r') as f:
|
||||||
|
file_content = f.read().strip()
|
||||||
|
print file_content
|
||||||
|
print content
|
||||||
|
self.assertEqual(content, file_content)
|
||||||
|
|
||||||
class test_torrent_handle(unittest.TestCase):
|
class test_torrent_handle(unittest.TestCase):
|
||||||
|
|
||||||
def test_torrent_handle(self):
|
def test_torrent_handle(self):
|
||||||
|
@ -165,5 +179,6 @@ if __name__ == '__main__':
|
||||||
print(lt.__version__)
|
print(lt.__version__)
|
||||||
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'url_seed_multi.torrent'), '.')
|
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'url_seed_multi.torrent'), '.')
|
||||||
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'base.torrent'), '.')
|
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'base.torrent'), '.')
|
||||||
|
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'unordered.torrent'), '.')
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ EXTRA_DIST = Jamfile \
|
||||||
test_torrents/string.torrent \
|
test_torrents/string.torrent \
|
||||||
test_torrents/symlink1.torrent \
|
test_torrents/symlink1.torrent \
|
||||||
test_torrents/unaligned_pieces.torrent \
|
test_torrents/unaligned_pieces.torrent \
|
||||||
|
test_torrents/unordered.torrent \
|
||||||
test_torrents/url_list.torrent \
|
test_torrents/url_list.torrent \
|
||||||
test_torrents/url_list2.torrent \
|
test_torrents/url_list2.torrent \
|
||||||
test_torrents/url_list3.torrent \
|
test_torrents/url_list3.torrent \
|
||||||
|
|
|
@ -131,6 +131,7 @@ static test_torrent_t test_torrents[] =
|
||||||
{ "invalid_name2.torrent" },
|
{ "invalid_name2.torrent" },
|
||||||
{ "invalid_name3.torrent" },
|
{ "invalid_name3.torrent" },
|
||||||
{ "symlink1.torrent" },
|
{ "symlink1.torrent" },
|
||||||
|
{ "unordered.torrent" },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct test_failing_torrent_t
|
struct test_failing_torrent_t
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
d10:created by10:libtorrent13:creation datei1359599503e4:infod4:name4:temp6:lengthi425e12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee
|
Loading…
Reference in New Issue