39 size_t slash_pos = message_type.find(
'/');
40 if (slash_pos == std::string::npos)
42 throw std::runtime_error(
"Passed message type string does not include a slash character.");
44 std::string module_name = message_type.substr(0, slash_pos);
45 std::string class_name = message_type.substr(slash_pos + 1, std::string::npos);
50 PyObject* module = PyImport_ImportModule((module_name +
"." + submodule).c_str());
54 throw std::runtime_error(
"Unable to import message module " + module_name +
".");
56 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");
70 throw std::runtime_error(
"Class for message " + message_type +
" did not contain" +
71 "expected _md5sum attribute.");
73 Py_XDECREF(msg_class);
75 #if PY_VERSION_HEX > 0x03000000 84 msginfo.
full_text.assign(PyString_AsString(full_text));
86 msginfo.
md5sum.assign(PyString_AsString(md5sum));
92 if (full_text && msginfo.
full_text.empty())
97 Py_XDECREF(full_text);
const MsgInfo lookupMessage(const std::string &message_type, const std::string submodule="msg")