+16 October 2023: George
+ - Expose the script filename in the Python module environment 'mod_env'
+ instead of the config_file structure which includes the linked list
+ of scripts in a multi Python module setup; fixes #79.
+
13 October 2023: George
- Better fix for infinite loop when reading multiple lines of input on
a broken remote control socket, by treating a zero byte line the
def init(id, cfg):
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, cfg.python_script))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, mod_env['script']))
return True
def init_standard(id, env):
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, env.cfg.port, env.cfg.python_script))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, env.cfg.port, mod_env['script']))
return True
def deinit(id):
::
def init(id, cfg):
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, cfg.python_script))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, mod_env['script']))
return True
::
def init_standard(id, env):
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, env.cfg.port, env.cfg.python_script))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, env.cfg.port, mod_env['script']))
return True
.. attribute:: python_script
- Python script file.
+ Linked list of Python script files.
+ Deprecated; `mod_env['script']` should be used instead.
.. envvar:: mod_env
- Module environment, contains data pointer for module-specific data.
- See :class:`pythonmod_env`.
+ Module environment, it is the 'data' pointer for module-specific data
+ in :class:`pythonmod_env`.
+ It is initialized as a dictionary with the 'script' key pointing to the
+ module's python script.
+ It can be further populated during runtime for module-specific data.
Predefined constants
..note:: The previously accessible configuration options can now be found in
env.cfg.
"""
- log_info("python: inited script {}".format(env.cfg.python_script))
+ log_info("python: inited script {}".format(mod_env['script']))
# Register EDNS option 65001 as a known EDNS option.
if not register_edns_option(env, 65001, bypass_cache_stage=True,
env.cfg.
"""
- log_info("python: inited script {}".format(env.cfg.python_script))
+ log_info("python: inited script {}".format(mod_env['script']))
# Register the inplace_reply_callback function as an inplace callback
# function when answering a resolved query.
print "-"*100
def init(id, cfg):
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, cfg.python_script))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, mod_env['script']))
return True
def deinit(id):
/* ************************************************************************************ *
Structure config_file
* ************************************************************************************ */
+%ignore config_file::python_script;
struct config_file {
int verbosity;
int stat_interval;
struct config_strlist* python_script;
};
+%extend config_file {
+ %pythoncode %{
+ def _deprecated_python_script(self): return "cfg.python_script is deprecated, you can use `mod_env['script']` instead."
+ python_script = property(_deprecated_python_script)
+ %}
+}
+
/* ************************************************************************************ *
ASN: Adding structures related to forwards_lookup and dns_cache_find_delegation
* ************************************************************************************ */
/* Initialize module */
FILE* script_py = NULL;
- PyObject* py_init_arg = NULL, *res = NULL;
+ PyObject* py_init_arg = NULL, *res = NULL, *fname = NULL;
PyGILState_STATE gil;
int init_standard = 1, i = 0;
#if PY_MAJOR_VERSION < 3
pe->dict = PyModule_GetDict(pe->module);
Py_XINCREF(pe->dict);
pe->data = PyDict_New();
+ /* add the script filename to the global "mod_env" for trivial access */
+ fname = PyString_FromString(pe->fname);
+ if(PyDict_SetItemString(pe->data, "script", fname) < 0) {
+ log_err("pythonmod: could not add item to dictionary");
+ Py_XDECREF(fname);
+ goto python_init_fail;
+ }
+ Py_XDECREF(fname);
Py_XINCREF(pe->data); /* reference will be stolen below */
if(PyModule_AddObject(pe->module, "mod_env", pe->data) < 0) {
log_err("pythonmod: could not add mod_env object");
import os
def init(id, cfg):
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, cfg.python_script))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, mod_env['script']))
return True
def deinit(id):
POSSIBILITY OF SUCH DAMAGE.
'''
def init(id, cfg):
- scripts=[]
- s = cfg.python_script
- while s != None:
- scripts.append(s.str)
- s = s.next
- log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, scripts))
+ log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, mod_env['script']))
return True
def deinit(id):