1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

Python: Don't complain if hooks.py does not exist.

Nor if -no-home prevents it from being found.

This patch is from bug 880, comment 5, attachment 305.
http://bugzilla.elinks.cz/show_bug.cgi?id=880#c5
This commit is contained in:
M. Levinson 2006-12-08 23:29:00 +01:00 committed by Kalle Olavi Niemitalo
parent 37c9bf3f75
commit f7be8f7dfc

View File

@ -121,6 +121,41 @@ end:
return result;
}
/* Determine whether or not a user-supplied hooks module exists. */
static int
hooks_module_exists(void)
{
PyObject *imp_module = NULL, *result = NULL;
int found_hooks = 0;
/*
* Use the find_module() function in Python's imp module to look for
* the hooks module in Python's search path. An ImportError exception
* indicates that no such module was found; any other exception will
* be reported as an error.
*/
imp_module = PyImport_ImportModule("imp");
if (!imp_module) goto python_error;
result = PyObject_CallMethod(imp_module, "find_module", "s", "hooks");
if (result) {
found_hooks = 1;
goto end;
} else if (PyErr_ExceptionMatches(PyExc_ImportError)) {
PyErr_Clear();
goto end;
}
python_error:
alert_python_error();
end:
Py_XDECREF(imp_module);
Py_XDECREF(result);
return found_hooks;
}
/* Module-level documentation for the Python interpreter's elinks module. */
static char module_doc[] =
@ -169,6 +204,8 @@ init_python(struct module *module)
Py_Initialize();
if (!hooks_module_exists()) return;
elinks_module = Py_InitModule3("elinks", NULL, module_doc);
if (!elinks_module) goto python_error;