44 size_t slash_pos = message_type.find(
'/');
45 if (slash_pos == std::string::npos)
47 throw std::runtime_error(
"Passed message type string does not include a slash character.");
49 std::string module_name = message_type.substr(0, slash_pos);
50 std::string class_name = message_type.substr(slash_pos + 1, std::string::npos);
52 PyObject* module = PyImport_ImportModule((module_name +
"." + submodule).c_str());
55 throw std::runtime_error(
"Unable to import message module " + module_name +
".");
57 PyObject* msg_class = PyObject_GetAttrString(module, class_name.c_str());
60 throw std::runtime_error(
"Unable to find message class " + class_name +
61 " in module " + module_name +
".");
65 PyObject* full_text = PyObject_GetAttrString(msg_class,
"_full_text");
66 PyObject*
md5sum = PyObject_GetAttrString(msg_class,
"_md5sum");
69 throw std::runtime_error(
"Class for message " + message_type +
" did not contain" +
70 "expected _md5sum attribute.");
72 Py_XDECREF(msg_class);
74 #if PY_VERSION_HEX > 0x03000000
83 msginfo.
full_text.assign(PyString_AsString(full_text));
91 if (full_text && msginfo.
full_text.empty())
96 Py_XDECREF(full_text);