merged (python) fixes from RC_0_16

This commit is contained in:
Arvid Norberg
2012-11-23 20:43:42 +00:00
parent 08454e518a
commit 5077c06c4a
6 changed files with 93 additions and 2 deletions

View File

@@ -53,6 +53,7 @@ python-extension libtorrent
src/session.cpp
src/entry.cpp
src/torrent_info.cpp
src/string.cpp
src/torrent_handle.cpp
src/torrent_status.cpp
src/session_settings.cpp

View File

@@ -22,6 +22,7 @@ EXTRA_DIST = \
src/peer_info.cpp \
src/session.cpp \
src/session_settings.cpp \
src/string.cpp \
src/torrent.cpp \
src/torrent_handle.cpp \
src/torrent_info.cpp \

View File

@@ -14,6 +14,7 @@ void bind_big_number();
void bind_session();
void bind_entry();
void bind_torrent_info();
void bind_unicode_string_conversion();
void bind_torrent_handle();
void bind_torrent_status();
void bind_session_settings();
@@ -40,6 +41,7 @@ BOOST_PYTHON_MODULE(libtorrent)
bind_entry();
bind_session();
bind_torrent_info();
bind_unicode_string_conversion();
bind_torrent_handle();
bind_torrent_status();
bind_session_settings();

View File

@@ -666,7 +666,9 @@ void bind_session()
;
enum_<session::listen_on_flags_t>("listen_on_flags_t")
#ifndef TORRENT_NO_DEPRECATE
.value("listen_reuse_address", session::listen_reuse_address)
#endif
.value("listen_no_system_port", session::listen_no_system_port)
;

View File

@@ -0,0 +1,71 @@
// Copyright Daniel Wallin 2006. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python.hpp>
#include "libtorrent/utf8.hpp"
#include <string>
using namespace boost::python;
struct unicode_from_python
{
unicode_from_python()
{
converter::registry::push_back(
&convertible, &construct, type_id<std::string>()
);
}
static void* convertible(PyObject* x)
{
#if PY_VERSION_HEX >= 0x03020000
return PyBytes_Check(x) ? x : PyUnicode_Check(x) ? x : 0;
#else
return PyString_Check(x) ? x : PyUnicode_Check(x) ? x : 0;
#endif
}
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
{
using libtorrent::wchar_utf8;
void* storage = ((converter::rvalue_from_python_storage<
std::string>*)data)->storage.bytes;
if (PyUnicode_Check(x))
{
std::wstring str;
str.resize(PyUnicode_GetSize(x) + 1, 0);
#if PY_VERSION_HEX >= 0x03020000
int len = PyUnicode_AsWideChar(x, &str[0], str.size());
#else
int len = PyUnicode_AsWideChar((PyUnicodeObject*)x, &str[0], str.size());
#endif
if (len > -1)
{
assert(len < str.size());
str[len] = 0;
}
else str[str.size()-1] = 0;
std::string utf8;
int ret = wchar_utf8(str, utf8);
new (storage) std::string(utf8);
}
else
{
#if PY_VERSION_HEX >= 0x03000000
new (storage) std::string(PyBytes_AsString(x));
#else
new (storage) std::string(PyString_AsString(x));
#endif
}
data->convertible = storage;
}
};
void bind_unicode_string_conversion()
{
unicode_from_python();
}