merged python 3 support from RC_0_16
This commit is contained in:
parent
0657690b1c
commit
bcfba9e485
|
@ -5,6 +5,7 @@
|
|||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import sys
|
||||
import atexit
|
||||
import libtorrent as lt
|
||||
import time
|
||||
import os.path
|
||||
|
@ -36,7 +37,7 @@ class UnixConsole:
|
|||
new[6][termios.VMIN] = 1
|
||||
termios.tcsetattr(self.fd.fileno(), termios.TCSADRAIN, new)
|
||||
|
||||
sys.exitfunc = self._onexit
|
||||
atexit.register(self._onexit)
|
||||
|
||||
def _onexit(self):
|
||||
termios.tcsetattr(self.fd.fileno(), termios.TCSADRAIN, self.old)
|
||||
|
@ -239,7 +240,7 @@ def main():
|
|||
for f in args:
|
||||
e = lt.bdecode(open(f, 'rb').read())
|
||||
info = lt.torrent_info(e)
|
||||
print 'Adding \'%s\'...' % info.name()
|
||||
print('Adding \'%s\'...' % info.name())
|
||||
|
||||
atp = {}
|
||||
try:
|
||||
|
|
|
@ -7,8 +7,8 @@ import platform
|
|||
import sys
|
||||
|
||||
if '@BOOST_PYTHON_LIB@' == '':
|
||||
print 'You need to pass --enable-python-binding to configure in order ',
|
||||
print 'to properly use this setup. There is no boost.python library configured now'
|
||||
print('You need to pass --enable-python-binding to configure in order '),
|
||||
print('to properly use this setup. There is no boost.python library configured now')
|
||||
sys.exit(1)
|
||||
|
||||
def parse_cmd(cmdline, prefix, keep_prefix = False):
|
||||
|
@ -33,7 +33,7 @@ if platform.system() == 'Windows':
|
|||
# msvc 9.0 (2008) is the official windows compiler for python 2.6
|
||||
# http://docs.python.org/whatsnew/2.6.html#build-and-c-api-changes
|
||||
if os.system('bjam boost=source link=static geoip=static boost-link=static release msvc-9.0 optimization=space') != 0:
|
||||
print 'build failed'
|
||||
print('build failed')
|
||||
sys.exit(1)
|
||||
try: os.mkdir(r'build')
|
||||
except: pass
|
||||
|
|
|
@ -13,19 +13,19 @@ ses.listen_on(6881, 6891)
|
|||
|
||||
info = lt.torrent_info(sys.argv[1])
|
||||
h = ses.add_torrent({'ti': info, 'save_path': './'})
|
||||
print 'starting', h.name()
|
||||
print('starting', h.name())
|
||||
|
||||
while (not h.is_seed()):
|
||||
s = h.status()
|
||||
|
||||
state_str = ['queued', 'checking', 'downloading metadata', \
|
||||
'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']
|
||||
print '\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
|
||||
print('\r%.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]),
|
||||
s.num_peers, state_str[s.state]), end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
print h.name(), 'complete'
|
||||
print(h.name(), 'complete')
|
||||
|
||||
|
|
|
@ -267,7 +267,20 @@ namespace
|
|||
object get_buffer()
|
||||
{
|
||||
static char const data[] = "foobar";
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
Py_buffer view;
|
||||
memset(&view, 0, sizeof(Py_buffer));
|
||||
view.buf = (void*)data;
|
||||
view.len = 6;
|
||||
view.ndim = 1;
|
||||
view.readonly = true;
|
||||
view.itemsize = sizeof(char);
|
||||
Py_ssize_t shape[] = { 6 };
|
||||
view.shape = shape;
|
||||
return object(handle<>(PyMemoryView_FromBuffer(&view)));
|
||||
#else
|
||||
return object(handle<>(PyBuffer_FromMemory((void*)data, 6)));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace unnamed
|
||||
|
|
Loading…
Reference in New Issue