merged torrent_info constructor fix (python bindings) from RC_1_0
This commit is contained in:
parent
742548b69c
commit
1a4c017ec5
|
@ -47,4 +47,5 @@ script:
|
||||||
- bjam -j 3 variant=$variant warnings=off $CC
|
- bjam -j 3 variant=$variant warnings=off $CC
|
||||||
- cd ../bindings/python
|
- cd ../bindings/python
|
||||||
- bjam -j 3 variant=$variant warnings=off $CC
|
- bjam -j 3 variant=$variant warnings=off $CC
|
||||||
|
- python test.py
|
||||||
- ccache --show-stats
|
- ccache --show-stats
|
||||||
|
|
|
@ -154,6 +154,7 @@ void bind_create_torrent()
|
||||||
file_entry (file_storage::*at)(int) const = &file_storage::at;
|
file_entry (file_storage::*at)(int) const = &file_storage::at;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO: 3 move this to its own file
|
||||||
class_<file_storage>("file_storage")
|
class_<file_storage>("file_storage")
|
||||||
.def("is_valid", &file_storage::is_valid)
|
.def("is_valid", &file_storage::is_valid)
|
||||||
.def("add_file", add_file0, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
|
.def("add_file", add_file0, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
|
||||||
|
|
|
@ -143,26 +143,62 @@ namespace
|
||||||
|
|
||||||
} // namespace unnamed
|
} // namespace unnamed
|
||||||
|
|
||||||
boost::shared_ptr<torrent_info> buffer_constructor(char const* buf, int len, int flags)
|
boost::shared_ptr<torrent_info> buffer_constructor0(char const* buf, int len, int flags)
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
boost::shared_ptr<torrent_info> ret(new torrent_info(buf, len, ec, flags));
|
boost::shared_ptr<torrent_info> ret(boost::make_shared<torrent_info>(buf, len, ec, flags));
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
if (ec) throw libtorrent_exception(ec);
|
if (ec) throw libtorrent_exception(ec);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<torrent_info> file_constructor(std::string const& filename, int flags)
|
boost::shared_ptr<torrent_info> buffer_constructor1(char const* buf, int len)
|
||||||
|
{
|
||||||
|
return buffer_constructor0(buf, len, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<torrent_info> file_constructor0(std::string const& filename, int flags)
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
boost::shared_ptr<torrent_info> ret(new torrent_info(filename, ec, flags));
|
boost::shared_ptr<torrent_info> ret(boost::make_shared<torrent_info>(filename, ec, flags));
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
if (ec) throw libtorrent_exception(ec);
|
if (ec) throw libtorrent_exception(ec);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<torrent_info> file_constructor1(std::string const& filename)
|
||||||
|
{
|
||||||
|
return file_constructor0(filename, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<torrent_info> bencoded_constructor0(entry const& ent, int flags)
|
||||||
|
{
|
||||||
|
std::vector<char> buf;
|
||||||
|
bencode(std::back_inserter(buf), ent);
|
||||||
|
|
||||||
|
bdecode_node e;
|
||||||
|
error_code ec;
|
||||||
|
if (buf.size() == 0 || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
throw invalid_torrent_file(ec);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<torrent_info> ret(boost::make_shared<torrent_info>(e, ec, flags));
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if (ec) throw libtorrent_exception(ec);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<torrent_info> bencoded_constructor1(entry const& ent)
|
||||||
|
{
|
||||||
|
return bencoded_constructor0(ent, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void bind_torrent_info()
|
void bind_torrent_info()
|
||||||
{
|
{
|
||||||
return_value_policy<copy_const_reference> copy;
|
return_value_policy<copy_const_reference> copy;
|
||||||
|
@ -179,15 +215,13 @@ void bind_torrent_info()
|
||||||
;
|
;
|
||||||
|
|
||||||
class_<torrent_info, boost::shared_ptr<torrent_info> >("torrent_info", no_init)
|
class_<torrent_info, boost::shared_ptr<torrent_info> >("torrent_info", no_init)
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
|
||||||
.def(init<entry const&>(arg("e")))
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
.def(init<sha1_hash const&, int>((arg("info_hash"), arg("flags") = 0)))
|
.def(init<sha1_hash const&, int>((arg("info_hash"), arg("flags") = 0)))
|
||||||
.def("__init__", make_constructor(&buffer_constructor))
|
.def("__init__", make_constructor(&buffer_constructor0))
|
||||||
.def("__init__", make_constructor(&file_constructor))
|
.def("__init__", make_constructor(&buffer_constructor1))
|
||||||
|
.def("__init__", make_constructor(&file_constructor0))
|
||||||
|
.def("__init__", make_constructor(&file_constructor1))
|
||||||
|
.def("__init__", make_constructor(&bencoded_constructor0))
|
||||||
|
.def("__init__", make_constructor(&bencoded_constructor1))
|
||||||
.def(init<torrent_info const&>((arg("ti"))))
|
.def(init<torrent_info const&>((arg("ti"))))
|
||||||
|
|
||||||
#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE
|
#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import libtorrent as lt
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
# test torrent_info
|
||||||
|
|
||||||
|
class test_torrent_info(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_bencoded_constructor(self):
|
||||||
|
info = lt.torrent_info({ 'info': {'name': 'test_torrent', 'length': 1234,
|
||||||
|
'piece length': 16 * 1024,
|
||||||
|
'pieces': 'aaaaaaaaaaaaaaaaaaaa'}})
|
||||||
|
|
||||||
|
self.assertEqual(info.num_files(), 1)
|
||||||
|
|
||||||
|
f = info.files()
|
||||||
|
self.assertEqual(f.file_path(0), 'test_torrent')
|
||||||
|
self.assertEqual(f.file_size(0), 1234)
|
||||||
|
self.assertEqual(info.total_size(), 1234)
|
||||||
|
|
||||||
|
class test_bencoder(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_bencode(self):
|
||||||
|
|
||||||
|
encoded = lt.bencode({'a': 1, 'b': [1,2,3], 'c': 'foo'})
|
||||||
|
self.assertEqual(encoded, 'd1:ai1e1:bli1ei2ei3ee1:c3:fooe')
|
||||||
|
|
||||||
|
def test_bdecode(self):
|
||||||
|
|
||||||
|
encoded = 'd1:ai1e1:bli1ei2ei3ee1:c3:fooe'
|
||||||
|
decoded = lt.bdecode(encoded)
|
||||||
|
self.assertEqual(decoded, {'a': 1, 'b': [1,2,3], 'c': 'foo'})
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
|
@ -156,7 +156,8 @@ params = { save_path: '.', \
|
||||||
ti: info }
|
ti: info }
|
||||||
h = ses.add_torrent(params)
|
h = ses.add_torrent(params)
|
||||||
|
|
||||||
while (not h.is_seed()):
|
s = h.status()
|
||||||
|
while (not s.is_seeding):
|
||||||
s = h.status()
|
s = h.status()
|
||||||
|
|
||||||
state_str = ['queued', 'checking', 'downloading metadata', \
|
state_str = ['queued', 'checking', 'downloading metadata', \
|
||||||
|
|
|
@ -127,7 +127,8 @@ A very simple example usage of the module would be something like this::
|
||||||
ti: info }
|
ti: info }
|
||||||
h = ses.add_torrent(params)
|
h = ses.add_torrent(params)
|
||||||
|
|
||||||
while (not h.is_seed()):
|
s = h.status()
|
||||||
|
while (not s.is_seeding):
|
||||||
s = h.status()
|
s = h.status()
|
||||||
|
|
||||||
state_str = ['queued', 'checking', 'downloading metadata', \
|
state_str = ['queued', 'checking', 'downloading metadata', \
|
||||||
|
|
|
@ -303,14 +303,6 @@ namespace libtorrent
|
||||||
torrent_info(bdecode_node const& torrent_file, int flags = 0);
|
torrent_info(bdecode_node const& torrent_file, int flags = 0);
|
||||||
torrent_info(char const* buffer, int size, int flags = 0);
|
torrent_info(char const* buffer, int size, int flags = 0);
|
||||||
torrent_info(std::string const& filename, int flags = 0);
|
torrent_info(std::string const& filename, int flags = 0);
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
#if TORRENT_USE_WSTRING
|
|
||||||
// all wstring APIs are deprecated since 0.16.11 instead, use the wchar
|
|
||||||
// -> utf8 conversion functions and pass in utf8 strings
|
|
||||||
TORRENT_DEPRECATED
|
|
||||||
torrent_info(std::wstring const& filename, int flags = 0);
|
|
||||||
#endif // TORRENT_USE_WSTRING
|
|
||||||
#endif // TORRENT_NO_DEPRECATE
|
|
||||||
#endif // BOOST_NO_EXCEPTIONS
|
#endif // BOOST_NO_EXCEPTIONS
|
||||||
torrent_info(torrent_info const& t);
|
torrent_info(torrent_info const& t);
|
||||||
torrent_info(sha1_hash const& info_hash, int flags = 0);
|
torrent_info(sha1_hash const& info_hash, int flags = 0);
|
||||||
|
@ -329,6 +321,8 @@ namespace libtorrent
|
||||||
TORRENT_DEPRECATED
|
TORRENT_DEPRECATED
|
||||||
torrent_info(std::wstring const& filename, error_code& ec
|
torrent_info(std::wstring const& filename, error_code& ec
|
||||||
, int flags = 0);
|
, int flags = 0);
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
torrent_info(std::wstring const& filename, int flags = 0);
|
||||||
#endif // TORRENT_USE_WSTRING
|
#endif // TORRENT_USE_WSTRING
|
||||||
#endif // TORRENT_NO_DEPRECATE
|
#endif // TORRENT_NO_DEPRECATE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue