Module: kamailio
Branch: master
Commit: 5aaff5e434e3f424b9ebc3ce88f9c37bc9951bf5
URL:
https://github.com/kamailio/kamailio/commit/5aaff5e434e3f424b9ebc3ce88f9c37…
Author: AnthonyA <ascanio.alba7(a)gmail.com>
Committer: AnthonyA <ascanio.alba7(a)gmail.com>
Date: 2018-03-01T07:51:47+08:00
app_python3: app_python compatible syntax for internal kemi modules
Python 3 does not create a package-like hierarchy of modules.
import Router.Logger # doesn't work!
Do some early imports so that kemi scripts which use
import Router.Logger as Logger
will continue to work. The affected modules are KSR.pv, KSR.x, Router.Core,
Router.Logger, and Router.Ranks.
---
Modified: src/modules/app_python3/app_python_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/5aaff5e434e3f424b9ebc3ce88f9c37…
Patch:
https://github.com/kamailio/kamailio/commit/5aaff5e434e3f424b9ebc3ce88f9c37…
---
diff --git a/src/modules/app_python3/app_python_mod.c
b/src/modules/app_python3/app_python_mod.c
index 1b7f880896..e851b105d7 100644
--- a/src/modules/app_python3/app_python_mod.c
+++ b/src/modules/app_python3/app_python_mod.c
@@ -332,6 +332,7 @@ int apy_load_script(void)
{
PyObject *sys_path, *pDir, *pModule;
PyGILState_STATE gstate;
+ int rc;
if (ap_init_modules() != 0) {
return -1;
@@ -342,6 +343,24 @@ int apy_load_script(void)
myThreadState = PyThreadState_Get();
PY_GIL_ENSURE
+
+ // Py3 does not create a package-like hierarchy of modules
+ // make legacy modules importable using Py2 syntax
+ // import Router.Logger
+
+ rc = PyRun_SimpleString("import sys\n"
+ "import Router\n"
+ "import KSR\n"
+ "sys.modules['Router.Core'] = Router.Core\n"
+ "sys.modules['Router.Logger'] = Router.Logger\n"
+ "sys.modules['Router.Ranks'] = Router.Ranks\n"
+ "sys.modules['KSR.pv'] = KSR.pv\n"
+ "sys.modules['KSR.x'] = KSR.x\n"
+ );
+ if (rc) {
+ LM_ERR("Early imports of modules failed\n");
+ }
+
format_exc_obj = InitTracebackModule();
if (format_exc_obj == NULL || !PyCallable_Check(format_exc_obj))