]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/smbconf: add a python function for raising smbconf exceptions
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 23 Apr 2022 18:19:59 +0000 (14:19 -0400)
committerJeremy Allison <jra@samba.org>
Fri, 6 May 2022 17:16:30 +0000 (17:16 +0000)
The previous implementation in C was private to the module. Add
a small python wrapper function so that a different python module
may reuse the implementation.

The python level function is prefixed with "_" to mark it as
"private". Only future cooperating modules in the samba sources
should make use of it.

The function is shared at the python level as per the recommendation:
    https://stackoverflow.com/a/2136670

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/smbconf/pysmbconf.c

index 5250a03684fb5859643e79e80f98bd6ca296b152..efb11d0432c6f9ff8919f2bc3cdffea6c4ef837a 100644 (file)
@@ -365,9 +365,24 @@ static PyObject *py_init_txt(PyObject * module, PyObject * args)
        return (PyObject *) obj;
 }
 
+static PyObject *py_smbconf_error(PyObject * module, PyObject * args)
+{
+       sbcErr errcode;
+
+       if (!PyArg_ParseTuple(args, "i", &errcode)) {
+               return NULL;
+       }
+
+       /* this always raises an exception. it doesn't return the exception. */
+       py_raise_SMBConfError(errcode);
+       return NULL;
+}
+
 static PyMethodDef pysmbconf_methods[] = {
        { "init_txt", (PyCFunction) py_init_txt, METH_VARARGS,
         "Return an SMBConf object for the given text config file." },
+       { "_smbconf_error", (PyCFunction) py_smbconf_error, METH_VARARGS,
+        "Raise an SMBConfError based on the given error code." },
        { 0 },
 };