summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/tdb.py
blob: f5c21e43914f2cab06cca4a3c63c892ac25aa433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.33
#
# Don't modify this file, modify the SWIG interface instead.

import _tdb
import new
new_instancemethod = new.instancemethod
try:
    _swig_property = property
except NameError:
    pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
    if (name == "thisown"): return self.this.own(value)
    if (name == "this"):
        if type(value).__name__ == 'PySwigObject':
            self.__dict__[name] = value
            return
    method = class_type.__swig_setmethods__.get(name,None)
    if method: return method(self,value)
    if (not static) or hasattr(self,name):
        self.__dict__[name] = value
    else:
        raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):
    return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
    if (name == "thisown"): return self.this.own()
    method = class_type.__swig_getmethods__.get(name,None)
    if method: return method(self)
    raise AttributeError,name

def _swig_repr(self):
    try: strthis = "proxy of " + self.this.__repr__()
    except: strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

import types
try:
    _object = types.ObjectType
    _newclass = 1
except AttributeError:
    class _object : pass
    _newclass = 0
del types


def _swig_setattr_nondynamic_method(set):
    def set_attr(self,name,value):
        if (name == "thisown"): return self.this.own(value)
        if hasattr(self,name) or (name == "this"):
            set(self,name,value)
        else:
            raise AttributeError("You cannot add attributes to %s" % self)
    return set_attr


REPLACE = _tdb.REPLACE
INSERT = _tdb.INSERT
MODIFY = _tdb.MODIFY
DEFAULT = _tdb.DEFAULT
CLEAR_IF_FIRST = _tdb.CLEAR_IF_FIRST
INTERNAL = _tdb.INTERNAL
NOLOCK = _tdb.NOLOCK
NOMMAP = _tdb.NOMMAP
CONVERT = _tdb.CONVERT
BIGENDIAN = _tdb.BIGENDIAN
TDB_SUCCESS = _tdb.TDB_SUCCESS
TDB_ERR_CORRUPT = _tdb.TDB_ERR_CORRUPT
TDB_ERR_IO = _tdb.TDB_ERR_IO
TDB_ERR_LOCK = _tdb.TDB_ERR_LOCK
TDB_ERR_OOM = _tdb.TDB_ERR_OOM
TDB_ERR_EXISTS = _tdb.TDB_ERR_EXISTS
TDB_ERR_NOLOCK = _tdb.TDB_ERR_NOLOCK
TDB_ERR_LOCK_TIMEOUT = _tdb.TDB_ERR_LOCK_TIMEOUT
TDB_ERR_NOEXIST = _tdb.TDB_ERR_NOEXIST
TDB_ERR_EINVAL = _tdb.TDB_ERR_EINVAL
TDB_ERR_RDONLY = _tdb.TDB_ERR_RDONLY
class tdb(object):
    thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
    def __init__(self): raise AttributeError, "No constructor defined"
    __repr__ = _swig_repr
    __swig_destroy__ = _tdb.delete_tdb
    def __str__(self):
        return self.name()


    def __getitem__(self, key):
        result = self.get(key)
        if result is None:
            raise KeyError, '%s: %s' % (key, self.errorstr())
        return result

    def __setitem__(self, key, item):
        if self.store(key, item) == -1:
            raise IOError, self.errorstr()

    def __delitem__(self, key):
        if not self.exists(key):
            raise KeyError, '%s: %s' % (key, self.errorstr())
        self.delete(key)

    def __contains__(self, key):
        return self.exists(key) != 0

    def has_key(self, key):
        return self.exists(key) != 0

    def fetch_uint32(self, key):
        data = self.get(key)
        if data is None:
            return None
        import struct
        return struct.unpack("<L", data)[0]

    def fetch_int32(self, key):
        data = self.get(key)
        if data is None:
            return None
        import struct
        return struct.unpack("<l", data)[0]


    class TdbIterator:
        def __init__(self, tdb):
            self.tdb = tdb
            self.key = None

        def __iter__(self):
            return self
            
        def next(self):
            if self.key is None:
                self.key = self.tdb.firstkey()
                if self.key is None:
                    raise StopIteration
                return self.key
            else:
                self.key = self.tdb.nextkey(self.key)
                if self.key is None:
                    raise StopIteration
                return self.key

    def __iter__(self):
        return self.TdbIterator(self)



    def keys(self):
        return [k for k in iter(self)]

    def values(self):
        return [self[k] for k in iter(self)]

    def items(self):
        return [(k, self[k]) for k in iter(self)]

    def __len__(self):
        return len(self.keys())

    def clear(self):
        for k in iter(self):
            del(self[k])





tdb.error = new_instancemethod(_tdb.tdb_error,None,tdb)
tdb.close = new_instancemethod(_tdb.tdb_close,None,tdb)
tdb.append = new_instancemethod(_tdb.tdb_append,None,tdb)
tdb.errorstr = new_instancemethod(_tdb.tdb_errorstr,None,tdb)
tdb.get = new_instancemethod(_tdb.tdb_get,None,tdb)
tdb.delete = new_instancemethod(_tdb.tdb_delete,None,tdb)
tdb.store = new_instancemethod(_tdb.tdb_store,None,tdb)
tdb.exists = new_instancemethod(_tdb.tdb_exists,None,tdb)
tdb.firstkey = new_instancemethod(_tdb.tdb_firstkey,None,tdb)
tdb.nextkey = new_instancemethod(_tdb.tdb_nextkey,None,tdb)
tdb.lock_all = new_instancemethod(_tdb.tdb_lock_all,None,tdb)
tdb.unlock_all = new_instancemethod(_tdb.tdb_unlock_all,None,tdb)
tdb.read_lock_all = new_instancemethod(_tdb.tdb_read_lock_all,None,tdb)
tdb.read_unlock_all = new_instancemethod(_tdb.tdb_read_unlock_all,None,tdb)
tdb.reopen = new_instancemethod(_tdb.tdb_reopen,None,tdb)
tdb.transaction_start = new_instancemethod(_tdb.tdb_transaction_start,None,tdb)
tdb.transaction_commit = new_instancemethod(_tdb.tdb_transaction_commit,None,tdb)
tdb.transaction_cancel = new_instancemethod(_tdb.tdb_transaction_cancel,None,tdb)
tdb.transaction_recover = new_instancemethod(_tdb.tdb_transaction_recover,None,tdb)
tdb.hash_size = new_instancemethod(_tdb.tdb_hash_size,None,tdb)
tdb.map_size = new_instancemethod(_tdb.tdb_map_size,None,tdb)
tdb.get_flags = new_instancemethod(_tdb.tdb_get_flags,None,tdb)
tdb.set_max_dead = new_instancemethod(_tdb.tdb_set_max_dead,None,tdb)
tdb.name = new_instancemethod(_tdb.tdb_name,None,tdb)
tdb_swigregister = _tdb.tdb_swigregister
tdb_swigregister(tdb)

def Tdb(*args, **kwargs):
    val = _tdb.new_Tdb(*args, **kwargs)
    return val