r26088: Import some native-python python modules and move original python swig tortur...
[ambi/samba-autobuild/.git] / source4 / libcli / util / errors.i
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4    Copyright (C) Tim Potter 2004
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef SWIGPYTHON
21 %typemap(out) WERROR {
22     if (!W_ERROR_IS_OK($1)) {
23         PyObject *obj = Py_BuildValue("(i,s)", $1.v, win_errstr($1));
24         PyErr_SetObject(PyExc_RuntimeError, obj);
25     } else if ($result == NULL) {
26         $result = Py_None;
27     }
28 };
29
30 %typemap(out) NTSTATUS {
31     if (NT_STATUS_IS_ERR($1)) {
32         PyObject *obj = Py_BuildValue("(i,s)", $1.v, nt_errstr($1));
33         PyErr_SetObject(PyExc_RuntimeError, obj);
34     } else if ($result == NULL) {
35         $result = Py_None;
36     }
37 };
38
39 %typemap(in) NTSTATUS {
40         if (PyLong_Check($input))
41                 $1 = NT_STATUS(PyLong_AsUnsignedLong($input));
42         else if (PyInt_Check($input))
43                 $1 = NT_STATUS(PyInt_AsLong($input));
44         else {
45                 PyErr_SetString(PyExc_TypeError, "Expected a long or an int");
46                 return NULL;
47         }
48 }
49
50 #endif