8566397ed382f8aaf63da6658d475294cc28bd3a
[ira/wip.git] / source / lib / tdb / tdb.py
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.33
3 #
4 # Don't modify this file, modify the SWIG interface instead.
5
6 import _tdb
7 import new
8 new_instancemethod = new.instancemethod
9 try:
10     _swig_property = property
11 except NameError:
12     pass # Python < 2.2 doesn't have 'property'.
13 def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
14     if (name == "thisown"): return self.this.own(value)
15     if (name == "this"):
16         if type(value).__name__ == 'PySwigObject':
17             self.__dict__[name] = value
18             return
19     method = class_type.__swig_setmethods__.get(name,None)
20     if method: return method(self,value)
21     if (not static) or hasattr(self,name):
22         self.__dict__[name] = value
23     else:
24         raise AttributeError("You cannot add attributes to %s" % self)
25
26 def _swig_setattr(self,class_type,name,value):
27     return _swig_setattr_nondynamic(self,class_type,name,value,0)
28
29 def _swig_getattr(self,class_type,name):
30     if (name == "thisown"): return self.this.own()
31     method = class_type.__swig_getmethods__.get(name,None)
32     if method: return method(self)
33     raise AttributeError,name
34
35 def _swig_repr(self):
36     try: strthis = "proxy of " + self.this.__repr__()
37     except: strthis = ""
38     return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
39
40 import types
41 try:
42     _object = types.ObjectType
43     _newclass = 1
44 except AttributeError:
45     class _object : pass
46     _newclass = 0
47 del types
48
49
50 def _swig_setattr_nondynamic_method(set):
51     def set_attr(self,name,value):
52         if (name == "thisown"): return self.this.own(value)
53         if hasattr(self,name) or (name == "this"):
54             set(self,name,value)
55         else:
56             raise AttributeError("You cannot add attributes to %s" % self)
57     return set_attr
58
59
60 REPLACE = _tdb.REPLACE
61 INSERT = _tdb.INSERT
62 MODIFY = _tdb.MODIFY
63 DEFAULT = _tdb.DEFAULT
64 CLEAR_IF_FIRST = _tdb.CLEAR_IF_FIRST
65 INTERNAL = _tdb.INTERNAL
66 NOLOCK = _tdb.NOLOCK
67 NOMMAP = _tdb.NOMMAP
68 CONVERT = _tdb.CONVERT
69 BIGENDIAN = _tdb.BIGENDIAN
70 TDB_SUCCESS = _tdb.TDB_SUCCESS
71 TDB_ERR_CORRUPT = _tdb.TDB_ERR_CORRUPT
72 TDB_ERR_IO = _tdb.TDB_ERR_IO
73 TDB_ERR_LOCK = _tdb.TDB_ERR_LOCK
74 TDB_ERR_OOM = _tdb.TDB_ERR_OOM
75 TDB_ERR_EXISTS = _tdb.TDB_ERR_EXISTS
76 TDB_ERR_NOLOCK = _tdb.TDB_ERR_NOLOCK
77 TDB_ERR_LOCK_TIMEOUT = _tdb.TDB_ERR_LOCK_TIMEOUT
78 TDB_ERR_NOEXIST = _tdb.TDB_ERR_NOEXIST
79 TDB_ERR_EINVAL = _tdb.TDB_ERR_EINVAL
80 TDB_ERR_RDONLY = _tdb.TDB_ERR_RDONLY
81 class tdb(object):
82     thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
83     def __init__(self): raise AttributeError, "No constructor defined"
84     __repr__ = _swig_repr
85     __swig_destroy__ = _tdb.delete_tdb
86     def __str__(self):
87         return self.name()
88
89
90     def __getitem__(self, key):
91         result = self.fetch(key)
92         if result is None:
93             raise KeyError, '%s: %s' % (key, self.errorstr())
94         return result
95
96     def __setitem__(self, key, item):
97         if self.store(key, item) == -1:
98             raise IOError, self.errorstr()
99
100     def __delitem__(self, key):
101         if not self.exists(key):
102             raise KeyError, '%s: %s' % (key, self.errorstr())
103         self.delete(key)
104
105     def __contains__(self, key):
106         return self.exists(key) != 0
107
108     def has_key(self, key):
109         return self.exists(key) != 0
110
111     def fetch_uint32(self, key):
112         data = self.fetch(key)
113         if data is None:
114             return None
115         import struct
116         return struct.unpack("<L", data)[0]
117
118     def fetch_int32(self, key):
119         data = self.fetch(key)
120         if data is None:
121             return None
122         import struct
123         return struct.unpack("<l", data)[0]
124
125
126     class TdbIterator:
127         def __init__(self, tdb):
128             self.tdb = tdb
129             self.key = None
130
131         def __iter__(self):
132             return self
133             
134         def next(self):
135             if self.key is None:
136                 self.key = self.tdb.firstkey()
137                 if self.key is None:
138                     raise StopIteration
139                 return self.key
140             else:
141                 self.key = self.tdb.nextkey(self.key)
142                 if self.key is None:
143                     raise StopIteration
144                 return self.key
145
146     def __iter__(self):
147         return self.TdbIterator(self)
148
149
150
151     def keys(self):
152         return [k for k in iter(self)]
153
154     def values(self):
155         return [self[k] for k in iter(self)]
156
157     def items(self):
158         return [(k, self[k]) for k in iter(self)]
159
160     def __len__(self):
161         return len(self.keys())
162
163     def clear(self):
164         for k in iter(self):
165             del(self[k])
166
167
168
169
170
171 tdb.error = new_instancemethod(_tdb.tdb_error,None,tdb)
172 tdb.close = new_instancemethod(_tdb.tdb_close,None,tdb)
173 tdb.append = new_instancemethod(_tdb.tdb_append,None,tdb)
174 tdb.errorstr = new_instancemethod(_tdb.tdb_errorstr,None,tdb)
175 tdb.fetch = new_instancemethod(_tdb.tdb_fetch,None,tdb)
176 tdb.delete = new_instancemethod(_tdb.tdb_delete,None,tdb)
177 tdb.store = new_instancemethod(_tdb.tdb_store,None,tdb)
178 tdb.exists = new_instancemethod(_tdb.tdb_exists,None,tdb)
179 tdb.firstkey = new_instancemethod(_tdb.tdb_firstkey,None,tdb)
180 tdb.nextkey = new_instancemethod(_tdb.tdb_nextkey,None,tdb)
181 tdb.lock_all = new_instancemethod(_tdb.tdb_lock_all,None,tdb)
182 tdb.unlock_all = new_instancemethod(_tdb.tdb_unlock_all,None,tdb)
183 tdb.read_lock_all = new_instancemethod(_tdb.tdb_read_lock_all,None,tdb)
184 tdb.read_unlock_all = new_instancemethod(_tdb.tdb_read_unlock_all,None,tdb)
185 tdb.reopen = new_instancemethod(_tdb.tdb_reopen,None,tdb)
186 tdb.transaction_start = new_instancemethod(_tdb.tdb_transaction_start,None,tdb)
187 tdb.transaction_commit = new_instancemethod(_tdb.tdb_transaction_commit,None,tdb)
188 tdb.transaction_cancel = new_instancemethod(_tdb.tdb_transaction_cancel,None,tdb)
189 tdb.transaction_recover = new_instancemethod(_tdb.tdb_transaction_recover,None,tdb)
190 tdb.hash_size = new_instancemethod(_tdb.tdb_hash_size,None,tdb)
191 tdb.map_size = new_instancemethod(_tdb.tdb_map_size,None,tdb)
192 tdb.get_flags = new_instancemethod(_tdb.tdb_get_flags,None,tdb)
193 tdb.set_max_dead = new_instancemethod(_tdb.tdb_set_max_dead,None,tdb)
194 tdb.name = new_instancemethod(_tdb.tdb_name,None,tdb)
195 tdb_swigregister = _tdb.tdb_swigregister
196 tdb_swigregister(tdb)
197
198 def Tdb(*args, **kwargs):
199     val = _tdb.new_Tdb(*args, **kwargs)
200     return val
201
202
203