diff options
author | Andrew Bartlett <abartlet@samba.org> | 2016-11-01 15:23:58 +1300 |
---|---|---|
committer | Garming Sam <garming@samba.org> | 2016-11-04 04:41:19 +0100 |
commit | c8505c53da3e21f31454f121efd5961d95349a38 (patch) | |
tree | 686acac488a701d7e839390244f85f69a0dec65e /python | |
parent | f72da5ba51ae8bf9f3f54bed36b4572cd1b57adb (diff) | |
download | samba-c8505c53da3e21f31454f121efd5961d95349a38.tar.gz |
python: create NTSTATUSError, HRESULTError and WERRORError
The advantage of these over the previous use of just RuntimeError is that we can
catch just the errors we want, without having to catch all possible RuntimeError
cases and assume they decode to a tuple
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12398
Diffstat (limited to 'python')
-rw-r--r-- | python/pyglue.c | 20 | ||||
-rw-r--r-- | python/samba/__init__.py | 4 |
2 files changed, 24 insertions, 0 deletions
diff --git a/python/pyglue.c b/python/pyglue.c index 81244a24973..938a9f0ecf4 100644 --- a/python/pyglue.c +++ b/python/pyglue.c @@ -24,6 +24,9 @@ #include "lib/socket/netif.h" void init_glue(void); +static PyObject *PyExc_NTSTATUSError; +static PyObject *PyExc_WERRORError; +static PyObject *PyExc_HRESULTError; static PyObject *py_generate_random_str(PyObject *self, PyObject *args) { @@ -294,5 +297,22 @@ void init_glue(void) PyModule_AddObject(m, "version", PyString_FromString(SAMBA_VERSION_STRING)); + PyExc_NTSTATUSError = PyErr_NewException(discard_const_p(char, "samba.NTSTATUSError"), PyExc_RuntimeError, NULL); + if (PyExc_NTSTATUSError != NULL) { + Py_INCREF(PyExc_NTSTATUSError); + PyModule_AddObject(m, "NTSTATUSError", PyExc_NTSTATUSError); + } + + PyExc_WERRORError = PyErr_NewException(discard_const_p(char, "samba.WERRORError"), PyExc_RuntimeError, NULL); + if (PyExc_WERRORError != NULL) { + Py_INCREF(PyExc_WERRORError); + PyModule_AddObject(m, "WERRORError", PyExc_WERRORError); + } + + PyExc_HRESULTError = PyErr_NewException(discard_const_p(char, "samba.HRESULTError"), PyExc_RuntimeError, NULL); + if (PyExc_HRESULTError != NULL) { + Py_INCREF(PyExc_HRESULTError); + PyModule_AddObject(m, "HRESULTError", PyExc_HRESULTError); + } } diff --git a/python/samba/__init__.py b/python/samba/__init__.py index 7cfbc4c1088..8c75a48874b 100644 --- a/python/samba/__init__.py +++ b/python/samba/__init__.py @@ -399,3 +399,7 @@ generate_random_password = _glue.generate_random_password strcasecmp_m = _glue.strcasecmp_m strstr_m = _glue.strstr_m is_ntvfs_fileserver_built = _glue.is_ntvfs_fileserver_built + +NTSTATUSError = _glue.NTSTATUSError +HRESULTError = _glue.HRESULTError +WERRORError = _glue.WERRORError |