aboutsummaryrefslogtreecommitdiff
path: root/python/exception.hh
diff options
context:
space:
mode:
Diffstat (limited to 'python/exception.hh')
-rw-r--r--python/exception.hh13
1 files changed, 12 insertions, 1 deletions
diff --git a/python/exception.hh b/python/exception.hh
index 767ab9a..b817551 100644
--- a/python/exception.hh
+++ b/python/exception.hh
@@ -68,7 +68,12 @@ namespace paludis
_e(PyErr_NewException(const_cast<char*>(_longname.c_str()), base, NULL))
{
PyModule_AddObject(boost::python::detail::current_scope, const_cast<char*>(_name.c_str()), _e);
- PyObject * doc_string = PyString_FromString(doc.c_str());
+ PyObject * doc_string =
+#if PY_MAJOR_VERSION < 3
+ PyString_FromString(doc.c_str());
+# else
+ PyUnicode_FromString(doc.c_str());
+# endif
PyObject_SetAttrString(_e, "__doc__", doc_string);
boost::python::register_exception_translator<Ex_>(
std::bind(std::mem_fn(&RegisteredException<Ex_>::translator), this, std::placeholders::_1));
@@ -78,9 +83,15 @@ namespace paludis
void
RegisteredException<Ex_>::translator(const Ex_ & x) const
{
+#if PY_MAJOR_VERSION < 3
PyObject * backtrace = PyString_FromString(x.backtrace("\n").c_str());
PyObject * message = PyString_FromString(x.message().c_str());
PyObject * what = PyString_FromString(x.what());
+#else
+ PyObject * backtrace = PyUnicode_FromString(x.backtrace("\n").c_str());
+ PyObject * message = PyUnicode_FromString(x.message().c_str());
+ PyObject * what = PyUnicode_FromString(x.what());
+#endif
PyObject_SetAttrString(_e, "backtrace", backtrace);
PyObject_SetAttrString(_e, "message", message);
PyObject_SetAttrString(_e, "what", what);