📄 ambulantinterface.cpp
字号:
/* ================== Callbacks Module pyambulant =================== */#include "ambulantinterface.h"#include "ambulantutilities.h"#include "ambulantmodule.h"extern PyObject *audio_format_choicesObj_New(const ambulant::net::audio_format_choices *itself);extern int audio_format_choicesObj_Convert(PyObject *v, ambulant::net::audio_format_choices *p_itself);/* ----------------------- Class node_context ----------------------- */node_context::node_context(PyObject *itself){ PyGILState_STATE _GILState = PyGILState_Ensure(); if (itself) { if (!PyObject_HasAttrString(itself, "set_prefix_mapping")) PyErr_Warn(PyExc_Warning, "node_context: missing attribute: set_prefix_mapping"); if (!PyObject_HasAttrString(itself, "get_namespace_prefix")) PyErr_Warn(PyExc_Warning, "node_context: missing attribute: get_namespace_prefix"); if (!PyObject_HasAttrString(itself, "resolve_url")) PyErr_Warn(PyExc_Warning, "node_context: missing attribute: resolve_url"); if (!PyObject_HasAttrString(itself, "get_root")) PyErr_Warn(PyExc_Warning, "node_context: missing attribute: get_root"); if (!PyObject_HasAttrString(itself, "get_node")) PyErr_Warn(PyExc_Warning, "node_context: missing attribute: get_node"); } if (itself == NULL) itself = Py_None; py_node_context = itself; Py_XINCREF(itself); PyGILState_Release(_GILState);}node_context::~node_context(){ PyGILState_STATE _GILState = PyGILState_Ensure(); Py_XDECREF(py_node_context); py_node_context = NULL; PyGILState_Release(_GILState);}void node_context::set_prefix_mapping(const std::string& prefix, const std::string& uri){ PyGILState_STATE _GILState = PyGILState_Ensure(); PyObject *py_prefix = Py_BuildValue("s", prefix.c_str()); PyObject *py_uri = Py_BuildValue("s", uri.c_str()); PyObject *py_rv = PyObject_CallMethod(py_node_context, "set_prefix_mapping", "(OO)", py_prefix, py_uri); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node_context::set_prefix_mapping() callback:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_prefix); Py_XDECREF(py_uri); PyGILState_Release(_GILState);}const char * node_context::get_namespace_prefix(const ambulant::lib::xml_string& uri) const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const char * _rv; PyObject *py_uri = Py_BuildValue("s", uri.c_str()); PyObject *py_rv = PyObject_CallMethod(py_node_context, "get_namespace_prefix", "(O)", py_uri); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node_context::get_namespace_prefix() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "z", &_rv)) { PySys_WriteStderr("Python exception during node_context::get_namespace_prefix() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_uri); PyGILState_Release(_GILState); return _rv;}ambulant::net::url node_context::resolve_url(const ambulant::net::url& rurl) const{ PyGILState_STATE _GILState = PyGILState_Ensure(); ambulant::net::url _rv; PyObject *py_rurl = Py_BuildValue("O", ambulant_url_New(rurl)); PyObject *py_rv = PyObject_CallMethod(py_node_context, "resolve_url", "(O)", py_rurl); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node_context::resolve_url() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", ambulant_url_Convert, &_rv)) { PySys_WriteStderr("Python exception during node_context::resolve_url() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_rurl); PyGILState_Release(_GILState); return _rv;}const ambulant::lib::node* node_context::get_root() const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node_context, "get_root", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node_context::get_root() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node_context::get_root() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}const ambulant::lib::node* node_context::get_node(const std::string& idd) const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_idd = Py_BuildValue("s", idd.c_str()); PyObject *py_rv = PyObject_CallMethod(py_node_context, "get_node", "(O)", py_idd); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node_context::get_node() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node_context::get_node() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_idd); PyGILState_Release(_GILState); return _rv;}/* --------------------------- Class node --------------------------- */node::node(PyObject *itself){ PyGILState_STATE _GILState = PyGILState_Ensure(); if (itself) { if (!PyObject_HasAttrString(itself, "down")) PyErr_Warn(PyExc_Warning, "node: missing attribute: down"); if (!PyObject_HasAttrString(itself, "up")) PyErr_Warn(PyExc_Warning, "node: missing attribute: up"); if (!PyObject_HasAttrString(itself, "next")) PyErr_Warn(PyExc_Warning, "node: missing attribute: next"); if (!PyObject_HasAttrString(itself, "down")) PyErr_Warn(PyExc_Warning, "node: missing attribute: down"); if (!PyObject_HasAttrString(itself, "up")) PyErr_Warn(PyExc_Warning, "node: missing attribute: up"); if (!PyObject_HasAttrString(itself, "next")) PyErr_Warn(PyExc_Warning, "node: missing attribute: next"); if (!PyObject_HasAttrString(itself, "down")) PyErr_Warn(PyExc_Warning, "node: missing attribute: down"); if (!PyObject_HasAttrString(itself, "up")) PyErr_Warn(PyExc_Warning, "node: missing attribute: up"); if (!PyObject_HasAttrString(itself, "next")) PyErr_Warn(PyExc_Warning, "node: missing attribute: next"); if (!PyObject_HasAttrString(itself, "previous")) PyErr_Warn(PyExc_Warning, "node: missing attribute: previous"); if (!PyObject_HasAttrString(itself, "get_last_child")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_last_child"); if (!PyObject_HasAttrString(itself, "locate_node")) PyErr_Warn(PyExc_Warning, "node: missing attribute: locate_node"); if (!PyObject_HasAttrString(itself, "get_first_child")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_first_child"); if (!PyObject_HasAttrString(itself, "get_first_child")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_first_child"); if (!PyObject_HasAttrString(itself, "get_root")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_root"); if (!PyObject_HasAttrString(itself, "get_container_attribute")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_container_attribute"); if (!PyObject_HasAttrString(itself, "append_child")) PyErr_Warn(PyExc_Warning, "node: missing attribute: append_child"); if (!PyObject_HasAttrString(itself, "append_child")) PyErr_Warn(PyExc_Warning, "node: missing attribute: append_child"); if (!PyObject_HasAttrString(itself, "detach")) PyErr_Warn(PyExc_Warning, "node: missing attribute: detach"); if (!PyObject_HasAttrString(itself, "clone")) PyErr_Warn(PyExc_Warning, "node: missing attribute: clone"); if (!PyObject_HasAttrString(itself, "append_data")) PyErr_Warn(PyExc_Warning, "node: missing attribute: append_data"); if (!PyObject_HasAttrString(itself, "append_data")) PyErr_Warn(PyExc_Warning, "node: missing attribute: append_data"); if (!PyObject_HasAttrString(itself, "append_data")) PyErr_Warn(PyExc_Warning, "node: missing attribute: append_data"); if (!PyObject_HasAttrString(itself, "set_attribute")) PyErr_Warn(PyExc_Warning, "node: missing attribute: set_attribute"); if (!PyObject_HasAttrString(itself, "set_attribute")) PyErr_Warn(PyExc_Warning, "node: missing attribute: set_attribute"); if (!PyObject_HasAttrString(itself, "set_namespace")) PyErr_Warn(PyExc_Warning, "node: missing attribute: set_namespace"); if (!PyObject_HasAttrString(itself, "get_namespace")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_namespace"); if (!PyObject_HasAttrString(itself, "get_local_name")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_local_name"); if (!PyObject_HasAttrString(itself, "get_qname")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_qname"); if (!PyObject_HasAttrString(itself, "get_numid")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_numid"); if (!PyObject_HasAttrString(itself, "get_data")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_data"); if (!PyObject_HasAttrString(itself, "get_trimmed_data")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_trimmed_data"); if (!PyObject_HasAttrString(itself, "get_attribute")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_attribute"); if (!PyObject_HasAttrString(itself, "get_attribute")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_attribute"); if (!PyObject_HasAttrString(itself, "del_attribute")) PyErr_Warn(PyExc_Warning, "node: missing attribute: del_attribute"); if (!PyObject_HasAttrString(itself, "get_url")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_url"); if (!PyObject_HasAttrString(itself, "size")) PyErr_Warn(PyExc_Warning, "node: missing attribute: size"); if (!PyObject_HasAttrString(itself, "get_path_display_desc")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_path_display_desc"); if (!PyObject_HasAttrString(itself, "get_sig")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_sig"); if (!PyObject_HasAttrString(itself, "xmlrepr")) PyErr_Warn(PyExc_Warning, "node: missing attribute: xmlrepr"); if (!PyObject_HasAttrString(itself, "get_context")) PyErr_Warn(PyExc_Warning, "node: missing attribute: get_context"); if (!PyObject_HasAttrString(itself, "set_context")) PyErr_Warn(PyExc_Warning, "node: missing attribute: set_context"); } if (itself == NULL) itself = Py_None; py_node = itself; Py_XINCREF(itself); PyGILState_Release(_GILState);}node::~node(){ PyGILState_STATE _GILState = PyGILState_Ensure(); Py_XDECREF(py_node); py_node = NULL; PyGILState_Release(_GILState);}const ambulant::lib::node* node::down() const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "down", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::down() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::down() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}const ambulant::lib::node* node::up() const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "up", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::up() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::up() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}const ambulant::lib::node* node::next() const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "next", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::next() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::next() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}ambulant::lib::node* node::down(){ PyGILState_STATE _GILState = PyGILState_Ensure(); ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "down", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::down() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::down() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}ambulant::lib::node* node::up(){ PyGILState_STATE _GILState = PyGILState_Ensure(); ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "up", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::up() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::up() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}ambulant::lib::node* node::next(){ PyGILState_STATE _GILState = PyGILState_Ensure(); ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "next", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::next() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::next() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}void node::down(ambulant::lib::node* n){ PyGILState_STATE _GILState = PyGILState_Ensure(); PyObject *py_n = Py_BuildValue("O&", nodeObj_New, n); PyObject *py_rv = PyObject_CallMethod(py_node, "down", "(O)", py_n); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::down() callback:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_n); PyGILState_Release(_GILState);}void node::up(ambulant::lib::node* n){ PyGILState_STATE _GILState = PyGILState_Ensure(); PyObject *py_n = Py_BuildValue("O&", nodeObj_New, n); PyObject *py_rv = PyObject_CallMethod(py_node, "up", "(O)", py_n); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::up() callback:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_n); PyGILState_Release(_GILState);}void node::next(ambulant::lib::node* n){ PyGILState_STATE _GILState = PyGILState_Ensure(); PyObject *py_n = Py_BuildValue("O&", nodeObj_New, n); PyObject *py_rv = PyObject_CallMethod(py_node, "next", "(O)", py_n); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::next() callback:\n"); PyErr_Print(); } Py_XDECREF(py_rv); Py_XDECREF(py_n); PyGILState_Release(_GILState);}const ambulant::lib::node* node::previous() const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "previous", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::previous() callback:\n"); PyErr_Print(); } if (py_rv && !PyArg_Parse(py_rv, "O&", nodeObj_Convert, &_rv)) { PySys_WriteStderr("Python exception during node::previous() return:\n"); PyErr_Print(); } Py_XDECREF(py_rv); PyGILState_Release(_GILState); return _rv;}const ambulant::lib::node* node::get_last_child() const{ PyGILState_STATE _GILState = PyGILState_Ensure(); const ambulant::lib::node* _rv; PyObject *py_rv = PyObject_CallMethod(py_node, "get_last_child", "()"); if (PyErr_Occurred()) { PySys_WriteStderr("Python exception during node::get_last_child() callback:\n"); PyErr_Print();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -