summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Resch <andrewresch@gmail.com>2008-11-30 00:24:13 +0000
committerAndrew Resch <andrewresch@gmail.com>2008-11-30 00:24:13 +0000
commitaeb6b96987552312fc2f251da9539a68f17475ec (patch)
treeaec2d75c7e4dd99b5d8f048caed9e6976f0f5ba4
parent318b81f62b0ae35e46111d9906e74bb244dfaba9 (diff)
downloaddeluge-aeb6b96987552312fc2f251da9539a68f17475ec.tar.gz
deluge-aeb6b96987552312fc2f251da9539a68f17475ec.tar.bz2
deluge-aeb6b96987552312fc2f251da9539a68f17475ec.zip
lt sync 2996
-rwxr-xr-xlibtorrent/bindings/python/src/filesystem.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/libtorrent/bindings/python/src/filesystem.cpp b/libtorrent/bindings/python/src/filesystem.cpp
index 3c5badb8e..777294bbf 100755
--- a/libtorrent/bindings/python/src/filesystem.cpp
+++ b/libtorrent/bindings/python/src/filesystem.cpp
@@ -4,6 +4,7 @@
#include <boost/python.hpp>
#include <boost/filesystem/path.hpp>
+#include "libtorrent/utf8.hpp"
using namespace boost::python;
@@ -26,15 +27,33 @@ struct path_from_python
static void* convertible(PyObject* x)
{
- return PyString_Check(x) ? x : 0;
+ return PyString_Check(x) ? x : PyUnicode_Check(x) ? x : 0;
}
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
{
+ using libtorrent::wchar_utf8;
void* storage = ((converter::rvalue_from_python_storage<
boost::filesystem::path
>*)data)->storage.bytes;
- new (storage) boost::filesystem::path(PyString_AsString(x));
+ if (PyUnicode_Check(x))
+ {
+ std::wstring str;
+ str.resize(PyUnicode_GetSize(x) + 1, 0);
+ int len = PyUnicode_AsWideChar((PyUnicodeObject*)x, &str[0], str.size());
+ if (len > -1)
+ {
+ assert(len < str.size());
+ str[len] = 0;
+ }
+ else str[str.size()-1] = 0;
+ std::string utf8 = wchar_utf8(str);
+ new (storage) boost::filesystem::path(utf8);
+ }
+ else
+ {
+ new (storage) boost::filesystem::path(PyString_AsString(x));
+ }
data->convertible = storage;
}
};