Merge branch 'singlecompression' into single
[kai/samba-autobuild/.git] / lib / tdb / tdb.py
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.35
3 #
4 # Don't modify this file, modify the SWIG interface instead.
5
6 """
7 TDB is a simple key-value database similar to GDBM that supports multiple writers.
8 """
9
10 import _tdb
11 import new
12 new_instancemethod = new.instancemethod
13 try:
14     _swig_property = property
15 except NameError:
16     pass # Python < 2.2 doesn't have 'property'.
17 def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
18     if (name == "thisown"): return self.this.own(value)
19     if (name == "this"):
20         if type(value).__name__ == 'PySwigObject':
21             self.__dict__[name] = value
22             return
23     method = class_type.__swig_setmethods__.get(name,None)
24     if method: return method(self,value)
25     if (not static) or hasattr(self,name):
26         self.__dict__[name] = value
27     else:
28         raise AttributeError("You cannot add attributes to %s" % self)
29
30 def _swig_setattr(self,class_type,name,value):
31     return _swig_setattr_nondynamic(self,class_type,name,value,0)
32
33 def _swig_getattr(self,class_type,name):
34     if (name == "thisown"): return self.this.own()
35     method = class_type.__swig_getmethods__.get(name,None)
36     if method: return method(self)
37     raise AttributeError,name
38
39 def _swig_repr(self):
40     try: strthis = "proxy of " + self.this.__repr__()
41     except: strthis = ""
42     return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
43
44 import types
45 try:
46     _object = types.ObjectType
47     _newclass = 1
48 except AttributeError:
49     class _object : pass
50     _newclass = 0
51 del types
52
53
54 def _swig_setattr_nondynamic_method(set):
55     def set_attr(self,name,value):
56         if (name == "thisown"): return self.this.own(value)
57         if hasattr(self,name) or (name == "this"):
58             set(self,name,value)
59         else:
60             raise AttributeError("You cannot add attributes to %s" % self)
61     return set_attr
62
63
64 REPLACE = _tdb.REPLACE
65 INSERT = _tdb.INSERT
66 MODIFY = _tdb.MODIFY
67 DEFAULT = _tdb.DEFAULT
68 CLEAR_IF_FIRST = _tdb.CLEAR_IF_FIRST
69 INTERNAL = _tdb.INTERNAL
70 NOLOCK = _tdb.NOLOCK
71 NOMMAP = _tdb.NOMMAP
72 CONVERT = _tdb.CONVERT
73 BIGENDIAN = _tdb.BIGENDIAN
74 TDB_SUCCESS = _tdb.TDB_SUCCESS
75 TDB_ERR_CORRUPT = _tdb.TDB_ERR_CORRUPT
76 TDB_ERR_IO = _tdb.TDB_ERR_IO
77 TDB_ERR_LOCK = _tdb.TDB_ERR_LOCK
78 TDB_ERR_OOM = _tdb.TDB_ERR_OOM
79 TDB_ERR_EXISTS = _tdb.TDB_ERR_EXISTS
80 TDB_ERR_NOLOCK = _tdb.TDB_ERR_NOLOCK
81 TDB_ERR_LOCK_TIMEOUT = _tdb.TDB_ERR_LOCK_TIMEOUT
82 TDB_ERR_NOEXIST = _tdb.TDB_ERR_NOEXIST
83 TDB_ERR_EINVAL = _tdb.TDB_ERR_EINVAL
84 TDB_ERR_RDONLY = _tdb.TDB_ERR_RDONLY
85 class Tdb(object):
86     """A TDB file."""
87     thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
88     __repr__ = _swig_repr
89     def __init__(self, *args, **kwargs): 
90         """
91         S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600)
92         Open a TDB file.
93         """
94         _tdb.Tdb_swiginit(self,_tdb.new_Tdb(*args, **kwargs))
95     def error(*args, **kwargs):
96         """
97         S.error() -> int
98         Find last error number returned by operation on this TDB.
99         """
100         return _tdb.Tdb_error(*args, **kwargs)
101
102     __swig_destroy__ = _tdb.delete_Tdb
103     def close(*args, **kwargs):
104         """
105         S.close() -> None
106         Close the TDB file.
107         """
108         return _tdb.Tdb_close(*args, **kwargs)
109
110     def errorstr(*args, **kwargs):
111         """
112         S.errorstr() -> errorstring
113         Obtain last error message.
114         """
115         return _tdb.Tdb_errorstr(*args, **kwargs)
116
117     def get(*args, **kwargs):
118         """
119         S.fetch(key) -> value
120         Fetch a value.
121         """
122         return _tdb.Tdb_get(*args, **kwargs)
123
124     def delete(*args, **kwargs):
125         """
126         S.delete(key) -> None
127         Delete an entry.
128         """
129         return _tdb.Tdb_delete(*args, **kwargs)
130
131     def store(*args, **kwargs):
132         """
133         S.store(key, value, flag=TDB_REPLACE) -> None
134         Store an entry.
135         """
136         return _tdb.Tdb_store(*args, **kwargs)
137
138     def exists(*args, **kwargs):
139         """
140         S.exists(key) -> bool
141         Check whether key exists in this database.
142         """
143         return _tdb.Tdb_exists(*args, **kwargs)
144
145     def firstkey(*args, **kwargs):
146         """
147         S.firstkey() -> data
148         Return the first key in this database.
149         """
150         return _tdb.Tdb_firstkey(*args, **kwargs)
151
152     def nextkey(*args, **kwargs):
153         """
154         S.nextkey(prev) -> data
155         Return the next key in this database.
156         """
157         return _tdb.Tdb_nextkey(*args, **kwargs)
158
159     def lock_all(*args, **kwargs):
160         """S.lockall() -> bool"""
161         return _tdb.Tdb_lock_all(*args, **kwargs)
162
163     def unlock_all(*args, **kwargs):
164         """S.unlockall() -> bool"""
165         return _tdb.Tdb_unlock_all(*args, **kwargs)
166
167     def reopen(*args, **kwargs):
168         """
169         S.reopen() -> bool
170         Reopen this file.
171         """
172         return _tdb.Tdb_reopen(*args, **kwargs)
173
174     def transaction_start(*args, **kwargs):
175         """
176         S.transaction_start() -> None
177         Start a new transaction.
178         """
179         return _tdb.Tdb_transaction_start(*args, **kwargs)
180
181     def transaction_commit(*args, **kwargs):
182         """
183         S.transaction_commit() -> None
184         Commit the currently active transaction.
185         """
186         return _tdb.Tdb_transaction_commit(*args, **kwargs)
187
188     def transaction_cancel(*args, **kwargs):
189         """
190         S.transaction_cancel() -> None
191         Cancel the currently active transaction.
192         """
193         return _tdb.Tdb_transaction_cancel(*args, **kwargs)
194
195     def hash_size(*args, **kwargs):
196         """S.hash_size() -> int"""
197         return _tdb.Tdb_hash_size(*args, **kwargs)
198
199     def map_size(*args, **kwargs):
200         """S.map_size() -> int"""
201         return _tdb.Tdb_map_size(*args, **kwargs)
202
203     def get_flags(*args, **kwargs):
204         """S.get_flags() -> int"""
205         return _tdb.Tdb_get_flags(*args, **kwargs)
206
207     def set_max_dead(*args, **kwargs):
208         """S.set_max_dead(int) -> None"""
209         return _tdb.Tdb_set_max_dead(*args, **kwargs)
210
211     def name(*args, **kwargs):
212         """
213         S.name() -> path
214         Return filename of this TDB file.
215         """
216         return _tdb.Tdb_name(*args, **kwargs)
217
218     def __repr__(self):
219         return "Tdb('%s')" % self.name()
220
221
222     def __getitem__(self, key):
223         result = self.get(key)
224         if result is None:
225             raise KeyError, '%s: %s' % (key, self.errorstr())
226         return result
227
228     def __setitem__(self, key, item):
229         if self.store(key, item) == -1:
230             raise IOError, self.errorstr()
231
232     def __delitem__(self, key):
233         if not self.exists(key):
234             raise KeyError, '%s: %s' % (key, self.errorstr())
235         self.delete(key)
236
237     def __contains__(self, key):
238         return self.exists(key) != 0
239
240     def has_key(self, key):
241         return self.exists(key) != 0
242
243     def fetch_uint32(self, key):
244         data = self.get(key)
245         if data is None:
246             return None
247         import struct
248         return struct.unpack("<L", data)[0]
249
250     def fetch_int32(self, key):
251         data = self.get(key)
252         if data is None:
253             return None
254         import struct
255         return struct.unpack("<l", data)[0]
256
257
258     class TdbIterator:
259         def __init__(self, tdb):
260             self.tdb = tdb
261             self.key = None
262
263         def __iter__(self):
264             return self
265             
266         def next(self):
267             if self.key is None:
268                 self.key = self.tdb.firstkey()
269                 if self.key is None:
270                     raise StopIteration
271                 return self.key
272             else:
273                 self.key = self.tdb.nextkey(self.key)
274                 if self.key is None:
275                     raise StopIteration
276                 return self.key
277
278     def __iter__(self):
279         return self.TdbIterator(self)
280
281
282
283     def keys(self):
284         return [k for k in iter(self)]
285
286     def values(self):
287         return [self[k] for k in iter(self)]
288
289     def items(self):
290         return [(k, self[k]) for k in iter(self)]
291
292     def __len__(self):
293         return len(self.keys())
294
295     def clear(self):
296         for k in iter(self):
297             del(self[k])
298
299     def iterkeys(self):
300         for k in iter(self):
301             yield k
302        
303     def itervalues(self):
304         for k in iter(self):
305             yield self[k]
306
307     def iteritems(self):
308         for k in iter(self):
309             yield (k, self[k])
310
311
312
313 Tdb.error = new_instancemethod(_tdb.Tdb_error,None,Tdb)
314 Tdb.close = new_instancemethod(_tdb.Tdb_close,None,Tdb)
315 Tdb.append = new_instancemethod(_tdb.Tdb_append,None,Tdb)
316 Tdb.errorstr = new_instancemethod(_tdb.Tdb_errorstr,None,Tdb)
317 Tdb.get = new_instancemethod(_tdb.Tdb_get,None,Tdb)
318 Tdb.delete = new_instancemethod(_tdb.Tdb_delete,None,Tdb)
319 Tdb.store = new_instancemethod(_tdb.Tdb_store,None,Tdb)
320 Tdb.exists = new_instancemethod(_tdb.Tdb_exists,None,Tdb)
321 Tdb.firstkey = new_instancemethod(_tdb.Tdb_firstkey,None,Tdb)
322 Tdb.nextkey = new_instancemethod(_tdb.Tdb_nextkey,None,Tdb)
323 Tdb.lock_all = new_instancemethod(_tdb.Tdb_lock_all,None,Tdb)
324 Tdb.unlock_all = new_instancemethod(_tdb.Tdb_unlock_all,None,Tdb)
325 Tdb.read_lock_all = new_instancemethod(_tdb.Tdb_read_lock_all,None,Tdb)
326 Tdb.read_unlock_all = new_instancemethod(_tdb.Tdb_read_unlock_all,None,Tdb)
327 Tdb.reopen = new_instancemethod(_tdb.Tdb_reopen,None,Tdb)
328 Tdb.transaction_start = new_instancemethod(_tdb.Tdb_transaction_start,None,Tdb)
329 Tdb.transaction_commit = new_instancemethod(_tdb.Tdb_transaction_commit,None,Tdb)
330 Tdb.transaction_cancel = new_instancemethod(_tdb.Tdb_transaction_cancel,None,Tdb)
331 Tdb.transaction_recover = new_instancemethod(_tdb.Tdb_transaction_recover,None,Tdb)
332 Tdb.hash_size = new_instancemethod(_tdb.Tdb_hash_size,None,Tdb)
333 Tdb.map_size = new_instancemethod(_tdb.Tdb_map_size,None,Tdb)
334 Tdb.get_flags = new_instancemethod(_tdb.Tdb_get_flags,None,Tdb)
335 Tdb.set_max_dead = new_instancemethod(_tdb.Tdb_set_max_dead,None,Tdb)
336 Tdb.name = new_instancemethod(_tdb.Tdb_name,None,Tdb)
337 Tdb_swigregister = _tdb.Tdb_swigregister
338 Tdb_swigregister(Tdb)
339
340
341