2012-02-01 15:32:36 +00:00
|
|
|
/*-
|
2012-02-02 20:18:52 +00:00
|
|
|
* Copyright (c) 2008-2012 WiredTiger, Inc.
|
2012-03-12 12:09:20 -04:00
|
|
|
* All rights reserved.
|
2012-02-02 20:18:52 +00:00
|
|
|
*
|
|
|
|
|
* See the file LICENSE for redistribution information.
|
|
|
|
|
*
|
2011-04-28 17:05:35 -04:00
|
|
|
* wiredtiger.i
|
2012-05-14 10:22:33 +10:00
|
|
|
* The SWIG interface file defining the wiredtiger python API.
|
2011-04-28 17:05:35 -04:00
|
|
|
*/
|
|
|
|
|
|
2011-11-02 10:34:30 +11:00
|
|
|
%define DOCSTRING
|
|
|
|
|
"@defgroup wt_python WiredTiger Python API
|
|
|
|
|
Python wrappers aroung the WiredTiger C API.
|
|
|
|
|
@{
|
|
|
|
|
@cond IGNORE"
|
|
|
|
|
%enddef
|
|
|
|
|
|
|
|
|
|
%module(docstring=DOCSTRING) wiredtiger
|
|
|
|
|
|
|
|
|
|
%feature("autodoc", "0");
|
2011-03-10 22:17:48 +11:00
|
|
|
|
2011-04-26 15:48:06 +10:00
|
|
|
%pythoncode %{
|
|
|
|
|
from packing import pack, unpack
|
2011-11-02 10:34:30 +11:00
|
|
|
## @endcond
|
2011-04-26 15:48:06 +10:00
|
|
|
%}
|
|
|
|
|
|
2011-03-10 22:17:48 +11:00
|
|
|
/* Set the input argument to point to a temporary variable */
|
2011-03-31 07:44:57 -04:00
|
|
|
%typemap(in, numinputs=0) WT_CONNECTION ** (WT_CONNECTION *temp = NULL) {
|
2012-05-14 10:22:33 +10:00
|
|
|
$1 = &temp;
|
2011-03-10 22:17:48 +11:00
|
|
|
}
|
2011-03-31 07:44:57 -04:00
|
|
|
%typemap(in, numinputs=0) WT_SESSION ** (WT_SESSION *temp = NULL) {
|
2012-05-14 10:22:33 +10:00
|
|
|
$1 = &temp;
|
2011-03-31 07:44:57 -04:00
|
|
|
}
|
|
|
|
|
%typemap(in, numinputs=0) WT_CURSOR ** (WT_CURSOR *temp = NULL) {
|
2012-05-14 10:22:33 +10:00
|
|
|
$1 = &temp;
|
2011-03-31 07:44:57 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-16 00:08:47 +10:00
|
|
|
/* Event handlers are not supported in Python. */
|
|
|
|
|
%typemap(in, numinputs=0) WT_EVENT_HANDLER * { $1 = NULL; }
|
|
|
|
|
|
2011-03-31 07:44:57 -04:00
|
|
|
/* Set the return value to the returned connection, session, or cursor */
|
2011-03-10 22:17:48 +11:00
|
|
|
%typemap(argout) WT_CONNECTION ** {
|
2012-05-14 10:22:33 +10:00
|
|
|
$result = SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
|
|
|
|
|
SWIGTYPE_p___wt_connection, 0);
|
2011-03-10 22:17:48 +11:00
|
|
|
}
|
2011-03-31 07:44:57 -04:00
|
|
|
%typemap(argout) WT_SESSION ** {
|
2012-05-14 10:22:33 +10:00
|
|
|
$result = SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
|
|
|
|
|
SWIGTYPE_p___wt_session, 0);
|
2011-03-31 07:44:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%typemap(argout) WT_CURSOR ** {
|
2012-05-14 10:22:33 +10:00
|
|
|
$result = SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
|
|
|
|
|
SWIGTYPE_p___wt_cursor, 0);
|
|
|
|
|
if (*$1 != NULL) {
|
|
|
|
|
(*$1)->flags |= WT_CURSTD_RAW;
|
|
|
|
|
PyObject_SetAttrString($result, "is_column",
|
|
|
|
|
PyBool_FromLong(strcmp((*$1)->key_format, "r") == 0));
|
2012-10-24 14:33:39 +11:00
|
|
|
PyObject_SetAttrString($result, "key_format",
|
|
|
|
|
PyString_InternFromString((*$1)->key_format));
|
|
|
|
|
PyObject_SetAttrString($result, "value_format",
|
|
|
|
|
PyString_InternFromString((*$1)->value_format));
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
2011-03-31 07:44:57 -04:00
|
|
|
}
|
|
|
|
|
|
2011-09-14 16:30:25 -04:00
|
|
|
/* 64 bit typemaps. */
|
|
|
|
|
%typemap(in) uint64_t {
|
2012-05-14 10:22:33 +10:00
|
|
|
$1 = PyLong_AsUnsignedLongLong($input);
|
2011-09-14 16:30:25 -04:00
|
|
|
}
|
|
|
|
|
%typemap(out) uint64_t {
|
2012-05-14 10:22:33 +10:00
|
|
|
$result = PyLong_FromUnsignedLongLong($1);
|
2011-09-14 16:30:25 -04:00
|
|
|
}
|
|
|
|
|
|
2011-07-16 00:12:42 +10:00
|
|
|
/* Throw away references after close. */
|
|
|
|
|
%define DESTRUCTOR(class, method)
|
|
|
|
|
%feature("shadow") class::method %{
|
2012-05-14 10:22:33 +10:00
|
|
|
def method(self, *args):
|
|
|
|
|
'''close(self, config) -> int
|
|
|
|
|
|
|
|
|
|
@copydoc class::method'''
|
|
|
|
|
try:
|
|
|
|
|
return $action(self, *args)
|
|
|
|
|
finally:
|
|
|
|
|
self.this = None
|
2011-07-16 00:12:42 +10:00
|
|
|
%}
|
|
|
|
|
%enddef
|
2012-01-18 11:55:01 +11:00
|
|
|
DESTRUCTOR(__wt_connection, close)
|
|
|
|
|
DESTRUCTOR(__wt_cursor, close)
|
|
|
|
|
DESTRUCTOR(__wt_session, close)
|
2011-07-16 00:12:42 +10:00
|
|
|
|
2011-07-16 00:08:47 +10:00
|
|
|
/* Don't require empty config strings. */
|
|
|
|
|
%typemap(default) const char *config { $1 = NULL; }
|
|
|
|
|
|
2011-04-28 17:05:35 -04:00
|
|
|
/*
|
|
|
|
|
* Error returns other than WT_NOTFOUND generate an exception.
|
|
|
|
|
* Use our own exception type, in future tailored to the kind
|
|
|
|
|
* of error.
|
2011-03-31 07:44:57 -04:00
|
|
|
*/
|
2011-04-28 17:05:35 -04:00
|
|
|
%header %{
|
|
|
|
|
static PyObject *wtError;
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%init %{
|
2012-05-14 10:22:33 +10:00
|
|
|
/*
|
|
|
|
|
* Create an exception type and put it into the _wiredtiger module.
|
|
|
|
|
* First increment the reference count because PyModule_AddObject
|
|
|
|
|
* decrements it. Then note that "m" is the local variable for the
|
|
|
|
|
* module in the SWIG generated code. If there is a SWIG variable for
|
|
|
|
|
* this, I haven't found it.
|
|
|
|
|
*/
|
|
|
|
|
wtError = PyErr_NewException("_wiredtiger.WiredTigerError", NULL, NULL);
|
|
|
|
|
Py_INCREF(wtError);
|
|
|
|
|
PyModule_AddObject(m, "WiredTigerError", wtError);
|
2011-04-28 17:05:35 -04:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%pythoncode %{
|
|
|
|
|
WiredTigerError = _wiredtiger.WiredTigerError
|
2011-09-06 06:44:21 -04:00
|
|
|
|
2011-11-02 10:34:30 +11:00
|
|
|
## @cond DISABLE
|
2011-09-06 06:44:21 -04:00
|
|
|
# Implements the iterable contract
|
|
|
|
|
class IterableCursor:
|
2012-05-14 10:22:33 +10:00
|
|
|
def __init__(self, cursor):
|
|
|
|
|
self.cursor = cursor
|
2011-09-06 06:44:21 -04:00
|
|
|
|
2012-05-14 10:22:33 +10:00
|
|
|
def __iter__(self):
|
|
|
|
|
return self
|
2011-09-06 06:44:21 -04:00
|
|
|
|
2012-05-14 10:22:33 +10:00
|
|
|
def next(self):
|
|
|
|
|
if self.cursor.next() == WT_NOTFOUND:
|
|
|
|
|
raise StopIteration
|
|
|
|
|
return self.cursor.get_keys() + self.cursor.get_values()
|
2011-11-02 10:34:30 +11:00
|
|
|
## @endcond
|
2011-04-28 17:05:35 -04:00
|
|
|
%}
|
|
|
|
|
|
2011-03-31 07:44:57 -04:00
|
|
|
/*
|
|
|
|
|
* Extra 'self' elimination.
|
|
|
|
|
* The methods we're wrapping look like this:
|
2012-01-18 11:55:01 +11:00
|
|
|
* struct __wt_xxx {
|
2012-05-14 10:22:33 +10:00
|
|
|
* int method(WT_XXX *, ...otherargs...);
|
2011-03-31 07:44:57 -04:00
|
|
|
* };
|
2011-04-04 14:59:29 -04:00
|
|
|
* To SWIG, that is equivalent to:
|
2012-05-14 10:22:33 +10:00
|
|
|
* int method(struct __wt_xxx *self, WT_XXX *, ...otherargs...);
|
2011-04-28 17:05:35 -04:00
|
|
|
* and we use consecutive argument matching of typemaps to convert two args to
|
|
|
|
|
* one.
|
2011-03-31 07:44:57 -04:00
|
|
|
*/
|
2012-07-30 16:05:15 +10:00
|
|
|
%define SELFHELPER(type, name)
|
|
|
|
|
%typemap(in) (type *self, type *name) (void *argp = 0, int res = 0) %{
|
2012-05-14 10:22:33 +10:00
|
|
|
res = SWIG_ConvertPtr($input, &argp, $descriptor, $disown | 0);
|
|
|
|
|
if (!SWIG_IsOK(res)) {
|
|
|
|
|
SWIG_exception_fail(SWIG_ArgError(res), "in method '$symname', "
|
|
|
|
|
"argument $argnum of type '$type'");
|
|
|
|
|
}
|
|
|
|
|
$2 = $1 = ($ltype)(argp);
|
2011-04-04 14:59:29 -04:00
|
|
|
%}
|
2011-04-14 13:52:27 -04:00
|
|
|
%enddef
|
2011-03-31 07:44:57 -04:00
|
|
|
|
2012-07-30 16:05:15 +10:00
|
|
|
SELFHELPER(struct __wt_connection, connection)
|
|
|
|
|
SELFHELPER(struct __wt_session, session)
|
|
|
|
|
SELFHELPER(struct __wt_cursor, cursor)
|
2012-05-14 10:22:33 +10:00
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
/* Error handling. Default case: a non-zero return is an error. */
|
|
|
|
|
%exception {
|
|
|
|
|
$action
|
|
|
|
|
if (result != 0) {
|
|
|
|
|
/* We could use PyErr_SetObject for more complex reporting. */
|
|
|
|
|
SWIG_SetErrorMsg(wtError, wiredtiger_strerror(result));
|
|
|
|
|
SWIG_fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Cursor positioning methods can also return WT_NOTFOUND. */
|
|
|
|
|
%define NOTFOUND_OK(m)
|
|
|
|
|
%exception m {
|
|
|
|
|
$action
|
|
|
|
|
if (result != 0 && result != WT_NOTFOUND) {
|
|
|
|
|
/* We could use PyErr_SetObject for more complex reporting. */
|
|
|
|
|
SWIG_SetErrorMsg(wtError, wiredtiger_strerror(result));
|
|
|
|
|
SWIG_fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
%enddef
|
|
|
|
|
|
|
|
|
|
/* Cursor compare can return any of -1, 0, 1 or WT_NOTFOUND. */
|
|
|
|
|
%define COMPARE_OK(m)
|
|
|
|
|
%exception m {
|
|
|
|
|
$action
|
|
|
|
|
if ((result < -1 || result > 1) && result != WT_NOTFOUND) {
|
|
|
|
|
/* We could use PyErr_SetObject for more complex reporting. */
|
|
|
|
|
SWIG_SetErrorMsg(wtError, wiredtiger_strerror(result));
|
|
|
|
|
SWIG_fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
%enddef
|
|
|
|
|
|
|
|
|
|
NOTFOUND_OK(__wt_cursor::next)
|
|
|
|
|
NOTFOUND_OK(__wt_cursor::prev)
|
|
|
|
|
NOTFOUND_OK(__wt_cursor::remove)
|
|
|
|
|
NOTFOUND_OK(__wt_cursor::search)
|
|
|
|
|
NOTFOUND_OK(__wt_cursor::update)
|
|
|
|
|
|
|
|
|
|
COMPARE_OK(__wt_cursor::compare)
|
|
|
|
|
COMPARE_OK(__wt_cursor::search_near)
|
|
|
|
|
|
|
|
|
|
/* Lastly, some methods need no (additional) error checking. */
|
|
|
|
|
%exception __wt_connection::search_near;
|
|
|
|
|
%exception __wt_connection::get_home;
|
|
|
|
|
%exception __wt_connection::is_new;
|
|
|
|
|
%exception __wt_cursor::_set_key;
|
|
|
|
|
%exception __wt_cursor::_set_value;
|
|
|
|
|
%exception wiredtiger_strerror;
|
|
|
|
|
%exception wiredtiger_version;
|
|
|
|
|
|
2011-04-26 15:48:06 +10:00
|
|
|
/* WT_CURSOR customization. */
|
|
|
|
|
/* First, replace the varargs get / set methods with Python equivalents. */
|
2012-01-18 11:55:01 +11:00
|
|
|
%ignore __wt_cursor::get_key;
|
|
|
|
|
%ignore __wt_cursor::get_value;
|
2012-07-30 16:05:15 +10:00
|
|
|
%ignore __wt_cursor::set_key;
|
2012-01-18 11:55:01 +11:00
|
|
|
%ignore __wt_cursor::set_value;
|
2011-04-26 15:48:06 +10:00
|
|
|
|
2012-07-30 16:05:15 +10:00
|
|
|
/* Next, override methods that return integers via arguments. */
|
2012-09-07 17:41:26 +00:00
|
|
|
%ignore __wt_cursor::compare(WT_CURSOR *, WT_CURSOR *, int *);
|
2012-07-30 16:05:15 +10:00
|
|
|
%ignore __wt_cursor::search_near(WT_CURSOR *, int *);
|
|
|
|
|
|
2011-04-26 15:48:06 +10:00
|
|
|
/* SWIG magic to turn Python byte strings into data / size. */
|
|
|
|
|
%apply (char *STRING, int LENGTH) { (char *data, int size) };
|
|
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
/* Handle binary data returns from get_key/value -- avoid cstring.i: it creates a list of returns. */
|
|
|
|
|
%typemap(in,numinputs=0) (char **datap, int *sizep) (char *data, int size) { $1 = &data; $2 = &size; }
|
|
|
|
|
%typemap(frearg) (char **datap, int *sizep) "";
|
|
|
|
|
%typemap(argout) (char **datap, int *sizep) {
|
|
|
|
|
if (*$1)
|
|
|
|
|
$result = SWIG_FromCharPtrAndSize(*$1, *$2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handle record number returns from get_recno */
|
|
|
|
|
%typemap(in,numinputs=0) (uint64_t *recnop) (uint64_t recno) { $1 = &recno; }
|
|
|
|
|
%typemap(frearg) (uint64_t *recnop) "";
|
|
|
|
|
%typemap(argout) (uint64_t *recnop) { $result = PyLong_FromUnsignedLongLong(*$1); }
|
|
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
typedef int int_void;
|
|
|
|
|
%}
|
|
|
|
|
typedef int int_void;
|
|
|
|
|
%typemap(out) int_void { $result = VOID_Object; }
|
|
|
|
|
|
2012-01-18 11:55:01 +11:00
|
|
|
%extend __wt_cursor {
|
2012-05-14 10:22:33 +10:00
|
|
|
/* Get / set keys and values */
|
|
|
|
|
void _set_key(char *data, int size) {
|
|
|
|
|
WT_ITEM k;
|
|
|
|
|
k.data = data;
|
|
|
|
|
k.size = (uint32_t)size;
|
|
|
|
|
$self->set_key($self, &k);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
int_void _set_recno(uint64_t recno) {
|
2012-05-14 10:22:33 +10:00
|
|
|
WT_ITEM k;
|
|
|
|
|
uint8_t recno_buf[20];
|
|
|
|
|
size_t size;
|
2012-10-24 14:33:39 +11:00
|
|
|
int ret;
|
|
|
|
|
if ((ret = wiredtiger_struct_size($self->session,
|
|
|
|
|
&size, "r", recno)) != 0 ||
|
|
|
|
|
(ret = wiredtiger_struct_pack($self->session,
|
|
|
|
|
recno_buf, sizeof (recno_buf), "r", recno)) != 0)
|
|
|
|
|
return (ret);
|
|
|
|
|
|
2012-05-14 10:22:33 +10:00
|
|
|
k.data = recno_buf;
|
|
|
|
|
k.size = (uint32_t)size;
|
|
|
|
|
$self->set_key($self, &k);
|
2012-10-24 14:33:39 +11:00
|
|
|
return (ret);
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _set_value(char *data, int size) {
|
|
|
|
|
WT_ITEM v;
|
|
|
|
|
v.data = data;
|
|
|
|
|
v.size = (uint32_t)size;
|
|
|
|
|
$self->set_value($self, &v);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
/* Don't return values, just throw exceptions on failure. */
|
|
|
|
|
int_void _get_key(char **datap, int *sizep) {
|
2012-05-14 10:22:33 +10:00
|
|
|
WT_ITEM k;
|
|
|
|
|
int ret = $self->get_key($self, &k);
|
2012-10-24 14:33:39 +11:00
|
|
|
if (ret == 0) {
|
|
|
|
|
*datap = (char *)k.data;
|
|
|
|
|
*sizep = (int)k.size;
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
2012-10-24 14:33:39 +11:00
|
|
|
return (ret);
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
|
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
int_void _get_recno(uint64_t *recnop) {
|
2012-05-14 10:22:33 +10:00
|
|
|
WT_ITEM k;
|
|
|
|
|
int ret = $self->get_key($self, &k);
|
|
|
|
|
if (ret == 0)
|
|
|
|
|
ret = wiredtiger_struct_unpack($self->session,
|
2012-10-24 14:33:39 +11:00
|
|
|
k.data, k.size, "q", recnop);
|
|
|
|
|
return (ret);
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
|
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
int_void _get_value(char **datap, int *sizep) {
|
2012-05-14 10:22:33 +10:00
|
|
|
WT_ITEM v;
|
|
|
|
|
int ret = $self->get_value($self, &v);
|
2012-10-24 14:33:39 +11:00
|
|
|
if (ret == 0) {
|
|
|
|
|
*datap = (char *)v.data;
|
|
|
|
|
*sizep = (int)v.size;
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
2012-10-24 14:33:39 +11:00
|
|
|
return (ret);
|
2012-05-14 10:22:33 +10:00
|
|
|
}
|
2011-04-26 15:48:06 +10:00
|
|
|
|
2012-09-07 17:41:26 +00:00
|
|
|
/* compare and search_near need special handling. */
|
2012-10-24 14:33:39 +11:00
|
|
|
int compare(WT_CURSOR *other) {
|
2012-09-07 17:41:26 +00:00
|
|
|
int cmp = 0;
|
|
|
|
|
int ret = $self->compare($self, other, &cmp);
|
2012-10-24 14:33:39 +11:00
|
|
|
/*
|
|
|
|
|
* Map less-than-zero to -1 and greater-than-zero to 1 to avoid
|
|
|
|
|
* colliding with other errors.
|
|
|
|
|
*/
|
|
|
|
|
return ((ret != 0) ? ret :
|
|
|
|
|
(cmp < 0) ? -1 : (cmp == 0) ? 0 : 1);
|
2012-07-30 17:08:51 +10:00
|
|
|
}
|
2012-07-30 16:05:15 +10:00
|
|
|
|
2012-10-24 14:33:39 +11:00
|
|
|
int search_near() {
|
2012-07-30 17:08:51 +10:00
|
|
|
int cmp = 0;
|
|
|
|
|
int ret = $self->search_near($self, &cmp);
|
|
|
|
|
/*
|
|
|
|
|
* Map less-than-zero to -1 and greater-than-zero to 1 to avoid
|
|
|
|
|
* colliding with WT_NOTFOUND.
|
|
|
|
|
*/
|
2012-10-24 14:33:39 +11:00
|
|
|
return ((ret != 0) ? ret :
|
|
|
|
|
(cmp < 0) ? -1 : (cmp == 0) ? 0 : 1);
|
2012-07-30 17:08:51 +10:00
|
|
|
}
|
2012-07-30 16:05:15 +10:00
|
|
|
|
2011-04-26 15:48:06 +10:00
|
|
|
%pythoncode %{
|
2012-05-14 10:22:33 +10:00
|
|
|
def get_key(self):
|
|
|
|
|
'''get_key(self) -> object
|
|
|
|
|
|
|
|
|
|
@copydoc WT_CURSOR::get_key
|
|
|
|
|
Returns only the first column.'''
|
|
|
|
|
return self.get_keys()[0]
|
|
|
|
|
|
|
|
|
|
def get_keys(self):
|
|
|
|
|
'''get_keys(self) -> (object, ...)
|
|
|
|
|
|
|
|
|
|
@copydoc WT_CURSOR::get_key'''
|
|
|
|
|
if self.is_column:
|
|
|
|
|
return [self._get_recno(),]
|
|
|
|
|
else:
|
|
|
|
|
return unpack(self.key_format, self._get_key())
|
|
|
|
|
|
|
|
|
|
def get_value(self):
|
|
|
|
|
'''get_value(self) -> object
|
|
|
|
|
|
|
|
|
|
@copydoc WT_CURSOR::get_value
|
|
|
|
|
Returns only the first column.'''
|
|
|
|
|
return self.get_values()[0]
|
|
|
|
|
|
|
|
|
|
def get_values(self):
|
|
|
|
|
'''get_values(self) -> (object, ...)
|
|
|
|
|
|
|
|
|
|
@copydoc WT_CURSOR::get_value'''
|
|
|
|
|
return unpack(self.value_format, self._get_value())
|
|
|
|
|
|
|
|
|
|
def set_key(self, *args):
|
|
|
|
|
'''set_key(self) -> None
|
|
|
|
|
|
|
|
|
|
@copydoc WT_CURSOR::set_key'''
|
|
|
|
|
if self.is_column:
|
2012-05-23 21:45:14 +10:00
|
|
|
self._set_recno(long(args[0]))
|
2012-05-14 10:22:33 +10:00
|
|
|
else:
|
|
|
|
|
# Keep the Python string pinned
|
|
|
|
|
self._key = pack(self.key_format, *args)
|
|
|
|
|
self._set_key(self._key)
|
|
|
|
|
|
|
|
|
|
def set_value(self, *args):
|
|
|
|
|
'''set_value(self) -> None
|
|
|
|
|
|
|
|
|
|
@copydoc WT_CURSOR::set_value'''
|
|
|
|
|
# Keep the Python string pinned
|
|
|
|
|
self._value = pack(self.value_format, *args)
|
|
|
|
|
self._set_value(self._value)
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
'''Cursor objects support iteration, equivalent to calling
|
|
|
|
|
WT_CURSOR::next until it returns ::WT_NOTFOUND.'''
|
|
|
|
|
if not hasattr(self, '_iterable'):
|
|
|
|
|
self._iterable = IterableCursor(self)
|
|
|
|
|
return self._iterable
|
2011-04-26 15:48:06 +10:00
|
|
|
%}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Remove / rename parts of the C API that we don't want in Python. */
|
2012-01-18 11:55:01 +11:00
|
|
|
%immutable __wt_cursor::session;
|
2012-01-31 00:50:04 +11:00
|
|
|
%immutable __wt_cursor::uri;
|
2012-10-24 14:33:39 +11:00
|
|
|
%ignore __wt_cursor::key_format;
|
|
|
|
|
%ignore __wt_cursor::value_format;
|
2012-01-18 11:55:01 +11:00
|
|
|
%immutable __wt_session::connection;
|
|
|
|
|
|
|
|
|
|
%ignore __wt_buf;
|
|
|
|
|
%ignore __wt_collator;
|
|
|
|
|
%ignore __wt_connection::add_collator;
|
|
|
|
|
%ignore __wt_compressor;
|
|
|
|
|
%ignore __wt_connection::add_compressor;
|
2012-03-11 10:46:07 +11:00
|
|
|
%ignore __wt_data_source;
|
|
|
|
|
%ignore __wt_connection::add_data_source;
|
2012-01-18 11:55:01 +11:00
|
|
|
%ignore __wt_event_handler;
|
|
|
|
|
%ignore __wt_extractor;
|
|
|
|
|
%ignore __wt_connection::add_extractor;
|
|
|
|
|
%ignore __wt_item;
|
2011-04-26 15:48:06 +10:00
|
|
|
|
|
|
|
|
%ignore wiredtiger_struct_pack;
|
|
|
|
|
%ignore wiredtiger_struct_packv;
|
|
|
|
|
%ignore wiredtiger_struct_size;
|
|
|
|
|
%ignore wiredtiger_struct_sizev;
|
|
|
|
|
%ignore wiredtiger_struct_unpack;
|
|
|
|
|
%ignore wiredtiger_struct_unpackv;
|
|
|
|
|
|
|
|
|
|
%ignore wiredtiger_extension_init;
|
|
|
|
|
|
2012-07-30 16:05:15 +10:00
|
|
|
/* Convert 'int *' to output args for wiredtiger_version */
|
|
|
|
|
%apply int *OUTPUT { int * };
|
|
|
|
|
|
2012-01-18 11:55:01 +11:00
|
|
|
%rename(Cursor) __wt_cursor;
|
|
|
|
|
%rename(Session) __wt_session;
|
|
|
|
|
%rename(Connection) __wt_connection;
|
2011-03-10 22:17:48 +11:00
|
|
|
|
|
|
|
|
%include "wiredtiger.h"
|
2011-11-02 10:34:30 +11:00
|
|
|
|
|
|
|
|
%pythoncode %{
|
|
|
|
|
## @}
|
2012-01-24 11:39:54 +11:00
|
|
|
|
|
|
|
|
class stat:
|
|
|
|
|
""" a set of static defines used by statistics cursor """
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
class filestat:
|
|
|
|
|
""" a set of static defines used by statistics cursor """
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
# All names starting with 'WT_STAT_file_' are renamed to
|
|
|
|
|
# the wiredtiger.filestat class, those starting with 'WT_STAT_' are
|
|
|
|
|
# renamed to wiredtiger.stat .
|
|
|
|
|
def _rename_with_prefix(prefix, toclass):
|
|
|
|
|
curmodule = sys.modules[__name__]
|
|
|
|
|
for name in dir(curmodule):
|
|
|
|
|
if name.startswith(prefix):
|
|
|
|
|
shortname = name[len(prefix):]
|
|
|
|
|
setattr(toclass, shortname, getattr(curmodule, name))
|
|
|
|
|
delattr(curmodule, name)
|
|
|
|
|
|
|
|
|
|
_rename_with_prefix('WT_STAT_file_', filestat)
|
|
|
|
|
_rename_with_prefix('WT_STAT_', stat)
|
|
|
|
|
del _rename_with_prefix
|
2011-11-02 10:34:30 +11:00
|
|
|
%}
|
|
|
|
|
|