From df46401c9cbee46986b170fc14468b4362137b1c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 20 Feb 2007 04:32:13 +0000 Subject: [PATCH] added docs for python binding. Fixed warning in python binding. --- bindings/README.txt | 3 + bindings/python/simple_client.py | 24 ++++++++ bindings/python/src/entry.cpp | 4 +- docs/index.html | 2 +- docs/index.rst | 2 +- docs/python_binding.html | 94 ++++++++++++++++++++++++++++++++ docs/python_binding.rst | 86 +++++++++++++++++++++++++++++ examples/simple_client.cpp | 2 +- test/test_web_seed.cpp | 6 +- 9 files changed, 215 insertions(+), 8 deletions(-) create mode 100644 bindings/README.txt create mode 100755 bindings/python/simple_client.py create mode 100644 docs/python_binding.html create mode 100644 docs/python_binding.rst diff --git a/bindings/README.txt b/bindings/README.txt new file mode 100644 index 000000000..977ca8c1c --- /dev/null +++ b/bindings/README.txt @@ -0,0 +1,3 @@ +Documentation covering building and using the python binding for libtorrent +is located in the main doc directory. See docs/python_binding.html + diff --git a/bindings/python/simple_client.py b/bindings/python/simple_client.py new file mode 100755 index 000000000..b06aba6bc --- /dev/null +++ b/bindings/python/simple_client.py @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import libtorrent as lt +import time + +ses = lt.session() +ses.listen_on(6881, 6891) + +e = lt.bdecode(open("test.torrent", 'rb').read()) +info = lt.torrent_info(e) + +h = ses.add_torrent(info, "./", compact_mode = True) + +while (not h.is_seed()): + s = h.status() + + state_str = ['queued', 'checking', 'connecting', 'downloading metadata', \ + 'downloading', 'finished', 'seeding', 'allocating'] + print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ + (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \ + s.num_peers, state_str[s.state]) + + time.sleep(1) + diff --git a/bindings/python/src/entry.cpp b/bindings/python/src/entry.cpp index bccba78ce..b24f6a2cf 100755 --- a/bindings/python/src/entry.cpp +++ b/bindings/python/src/entry.cpp @@ -44,9 +44,9 @@ struct entry_to_python return convert(e.list()); case entry::dictionary_t: return convert(e.dict()); + default: + return object(); } - - return object(); } static PyObject* convert(entry const& e) diff --git a/docs/index.html b/docs/index.html index 511dc89c4..53d5ad1d3 100755 --- a/docs/index.html +++ b/docs/index.html @@ -37,7 +37,7 @@

Bindings