PyObject * PyMapNode_Wrap(const MapNode &node) { if(node.Type() == MapNode::EMPTY_TYPE && node.GetNumEntries() == 0) { Py_INCREF(Py_None); return Py_None; } // must be a variant, use variant helper if(node.Type() != MapNode::EMPTY_TYPE) { return PyVariant_Wrap(node); } // we have a dict with map nodes as entries PyObject *dict = PyDict_New(); stringVector entry_names; node.GetEntryNames(entry_names); for(size_t i=0;i<entry_names.size();i++) { const MapNode *child_node = node.GetEntry(entry_names[i]); if(child_node == NULL) continue; PyObject *child = PyMapNode_Wrap(*child_node); #if (PY_MAJOR_VERSION < 2) || ((PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION < 5)) char *str = new char[entry_names[i].length()+1]; strcpy(str, entry_names[i].c_str()); PyDict_SetItemString(dict, str, child); delete [] str; #else PyDict_SetItemString(dict, entry_names[i].c_str(), child); #endif } return dict; }
static PyObject *args_QueryRPC(ViewerRPC *rpc) { PyObject *tuple = PyTuple_New(1); PyTuple_SET_ITEM(tuple, 0, PyMapNode_Wrap(rpc->GetQueryParams())); return tuple; }