from unittest import TestCase
import os
+
+class OpenTdbTests(TestCase):
+ def test_nonexistant_read(self):
+ self.assertRaises(IOError, tdb.Tdb, "/some/nonexistant/file", 0, tdb.DEFAULT, os.O_RDWR)
+
+
class SimpleTdbTests(TestCase):
def setUp(self):
super(SimpleTdbTests, self).setUp()
TDB_ERR_RDONLY
};
-%rename(Tdb) tdb;
%rename(lock_all) tdb_context::lockall;
%rename(unlock_all) tdb_context::unlockall;
$1 = TDB_REPLACE;
}
+%rename(Tdb) tdb;
+%typemap(out,noblock=1) tdb * {
+ /* Throw an IOError exception from errno if tdb_open() returns NULL */
+ if ($1 == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ SWIG_fail;
+ }
+ $result = SWIG_NewPointerObj($1, $1_descriptor, 0);
+}
+
typedef struct tdb_context {
%extend {
- tdb(const char *name, int hash_size,
- int tdb_flags,
- int open_flags, mode_t mode)
- {
- tdb *ret = tdb_open(name, hash_size, tdb_flags, open_flags, mode);
-
- /* Throw an IOError exception from errno if tdb_open() returns
- NULL */
- if (ret == NULL) {
- PyErr_SetFromErrno(PyExc_IOError);
- SWIG_fail;
- }
-
-fail:
- return ret;
+ tdb(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode) {
+ return tdb_open(name, hash_size, tdb_flags, open_flags, mode);
}
enum TDB_ERROR error();
~tdb() { tdb_close($self); }
}
SWIGINTERN tdb *new_tdb(char const *name,int hash_size,int tdb_flags,int open_flags,mode_t mode){
- tdb *ret = tdb_open(name, hash_size, tdb_flags, open_flags, mode);
-
- /* Throw an IOError exception from errno if tdb_open() returns
- NULL */
- if (ret == NULL) {
- PyErr_SetFromErrno(PyExc_IOError);
- SWIG_fail;
- }
-
-fail:
- return ret;
+ return tdb_open(name, hash_size, tdb_flags, open_flags, mode);
}
SWIGINTERN void delete_tdb(tdb *self){ tdb_close(self); }
arg5 = (mode_t)(val5);
}
result = (tdb *)new_tdb((char const *)arg1,arg2,arg3,arg4,arg5);
- resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_tdb_context, SWIG_POINTER_OWN | 0 );
+ /* Throw an IOError exception from errno if tdb_open() returns NULL */
+ if (result == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ SWIG_fail;
+ }
+ resultobj = SWIG_NewPointerObj(result, SWIGTYPE_p_tdb_context, 0);
if (alloc1 == SWIG_NEWOBJ) free((char*)buf1);
return resultobj;
fail:
pidl "";
pidl "status = dcerpc_$fn->{NAME}(\$self->pipe, mem_ctx, &r);";
pidl "if (NT_STATUS_IS_ERR(status)) {";
- pidl "\treturn status;";
+ indent; pidl "return status;"; deindent;
pidl "}";
pidl "";
pidl "/* Set out arguments */";