9885765e2dad31e1f6b6535824c848c267240fa9
[ira/wip.git] / source4 / lib / ldb / ldb.py
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.36
3 #
4 # Don't modify this file, modify the SWIG interface instead.
5
6 """
7 An interface to LDB, a LDAP-like API that can either to talk an embedded database (TDB-based) or a standards-compliant LDAP server.
8 """
9
10 import _ldb
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 SCOPE_DEFAULT = _ldb.SCOPE_DEFAULT
65 SCOPE_BASE = _ldb.SCOPE_BASE
66 SCOPE_ONELEVEL = _ldb.SCOPE_ONELEVEL
67 SCOPE_SUBTREE = _ldb.SCOPE_SUBTREE
68 CHANGETYPE_NONE = _ldb.CHANGETYPE_NONE
69 CHANGETYPE_ADD = _ldb.CHANGETYPE_ADD
70 CHANGETYPE_DELETE = _ldb.CHANGETYPE_DELETE
71 CHANGETYPE_MODIFY = _ldb.CHANGETYPE_MODIFY
72 ldb_val_to_py_object = _ldb.ldb_val_to_py_object
73 class Dn(object):
74     """A LDB distinguished name."""
75     thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
76     def __init__(self, *args, **kwargs): 
77         """
78         S.__init__(ldb, string)
79         Create a new DN.
80         """
81         _ldb.Dn_swiginit(self,_ldb.new_Dn(*args, **kwargs))
82     __swig_destroy__ = _ldb.delete_Dn
83     def validate(*args, **kwargs):
84         """
85         S.validate() -> bool
86         Validate DN is correct.
87         """
88         return _ldb.Dn_validate(*args, **kwargs)
89
90     def parent(*args, **kwargs):
91         """
92         S.parent() -> dn
93         Get the parent for this DN.
94         """
95         return _ldb.Dn_parent(*args, **kwargs)
96
97     def is_special(*args, **kwargs):
98         """
99         S.is_special() -> bool
100         Check whether this is a special LDB DN.
101         """
102         return _ldb.Dn_is_special(*args, **kwargs)
103
104     def is_null(*args, **kwargs):
105         """
106         S.is_null() -> bool
107         Check whether this is a null DN.
108         """
109         return _ldb.Dn_is_null(*args, **kwargs)
110
111     def add_child(*args, **kwargs):
112         """
113         S.add_child(dn) -> None
114         Add a child DN to this DN.
115         """
116         return _ldb.Dn_add_child(*args, **kwargs)
117
118     def add_base(*args, **kwargs):
119         """
120         S.add_base(dn) -> None
121         Add a base DN to this DN.
122         """
123         return _ldb.Dn_add_base(*args, **kwargs)
124
125     def canonical_str(*args, **kwargs):
126         """
127         S.canonical_str() -> string
128         Canonical version of this DN (like a posix path).
129         """
130         return _ldb.Dn_canonical_str(*args, **kwargs)
131
132     def canonical_ex_str(*args, **kwargs):
133         """
134         S.canonical_ex_str() -> string
135         Canonical version of this DN (like a posix path, with terminating newline).
136         """
137         return _ldb.Dn_canonical_ex_str(*args, **kwargs)
138
139     def __eq__(self, other):
140         if isinstance(other, self.__class__):
141             return self.__cmp__(other) == 0
142         if isinstance(other, str):
143             return str(self) == other
144         return False
145
146 Dn.validate = new_instancemethod(_ldb.Dn_validate,None,Dn)
147 Dn.get_casefold = new_instancemethod(_ldb.Dn_get_casefold,None,Dn)
148 Dn.__str__ = new_instancemethod(_ldb.Dn___str__,None,Dn)
149 Dn.parent = new_instancemethod(_ldb.Dn_parent,None,Dn)
150 Dn.__cmp__ = new_instancemethod(_ldb.Dn___cmp__,None,Dn)
151 Dn.is_valid = new_instancemethod(_ldb.Dn_is_valid,None,Dn)
152 Dn.is_special = new_instancemethod(_ldb.Dn_is_special,None,Dn)
153 Dn.is_null = new_instancemethod(_ldb.Dn_is_null,None,Dn)
154 Dn.check_special = new_instancemethod(_ldb.Dn_check_special,None,Dn)
155 Dn.__len__ = new_instancemethod(_ldb.Dn___len__,None,Dn)
156 Dn.add_child = new_instancemethod(_ldb.Dn_add_child,None,Dn)
157 Dn.add_base = new_instancemethod(_ldb.Dn_add_base,None,Dn)
158 Dn.canonical_str = new_instancemethod(_ldb.Dn_canonical_str,None,Dn)
159 Dn.canonical_ex_str = new_instancemethod(_ldb.Dn_canonical_ex_str,None,Dn)
160 Dn.__repr__ = new_instancemethod(_ldb.Dn___repr__,None,Dn)
161 Dn.__add__ = new_instancemethod(_ldb.Dn___add__,None,Dn)
162 Dn_swigregister = _ldb.Dn_swigregister
163 Dn_swigregister(Dn)
164
165 class MessageElement(object):
166     """Message element."""
167     thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
168     __repr__ = _swig_repr
169     def __init__(self, *args, **kwargs): 
170         """Message element."""
171         _ldb.MessageElement_swiginit(self,_ldb.new_MessageElement(*args, **kwargs))
172     __swig_destroy__ = _ldb.delete_MessageElement
173     def __getitem__(self, i):
174         ret = self.get(i)
175         if ret is None:
176             raise KeyError("no such value")
177         return ret
178
179     def __repr__(self):
180         return "MessageElement([%s])" % (",".join(repr(x) for x in self.__set__()))
181
182     def __eq__(self, other):
183         if (len(self) == 1 and self.get(0) == other):
184             return True
185         if isinstance(other, self.__class__):
186             return self.__cmp__(other) == 0
187         o = iter(other)
188         for i in range(len(self)):
189             if self.get(i) != o.next():
190                 return False
191         return True
192
193 MessageElement.__cmp__ = new_instancemethod(_ldb.MessageElement___cmp__,None,MessageElement)
194 MessageElement.__iter__ = new_instancemethod(_ldb.MessageElement___iter__,None,MessageElement)
195 MessageElement.__set__ = new_instancemethod(_ldb.MessageElement___set__,None,MessageElement)
196 MessageElement.__len__ = new_instancemethod(_ldb.MessageElement___len__,None,MessageElement)
197 MessageElement.get = new_instancemethod(_ldb.MessageElement_get,None,MessageElement)
198 MessageElement_swigregister = _ldb.MessageElement_swigregister
199 MessageElement_swigregister(MessageElement)
200
201 ldb_msg_list_elements = _ldb.ldb_msg_list_elements
202 class Message(object):
203     """Message."""
204     thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
205     __repr__ = _swig_repr
206     dn = _swig_property(_ldb.Message_dn_get, _ldb.Message_dn_set)
207     def __init__(self, *args, **kwargs): 
208         _ldb.Message_swiginit(self,_ldb.new_Message(*args, **kwargs))
209     __swig_destroy__ = _ldb.delete_Message
210     def get(self, key, default=None):
211         if key == "dn":
212             return self.dn
213         return self.find_element(key)
214
215     def __getitem__(self, key):
216         ret = self.get(key, None)
217         if ret is None:
218             raise KeyError("No such element")
219         return ret
220
221     def iteritems(self):
222         for k in self.keys():
223             yield k, self[k]
224
225     def items(self):
226         return list(self.iteritems())
227
228     def __repr__(self):
229         return "Message(%s)" % repr(dict(self.iteritems()))
230
231 Message.find_element = new_instancemethod(_ldb.Message_find_element,None,Message)
232 Message.__setitem__ = new_instancemethod(_ldb.Message___setitem__,None,Message)
233 Message.__len__ = new_instancemethod(_ldb.Message___len__,None,Message)
234 Message.keys = new_instancemethod(_ldb.Message_keys,None,Message)
235 Message.__iter__ = new_instancemethod(_ldb.Message___iter__,None,Message)
236 Message.__delitem__ = new_instancemethod(_ldb.Message___delitem__,None,Message)
237 Message_swigregister = _ldb.Message_swigregister
238 Message_swigregister(Message)
239
240 ldb_ldif_to_pyobject = _ldb.ldb_ldif_to_pyobject
241 LdbError = _ldb.LdbError
242
243 LDB_ERR_OPERATIONS_ERROR = _ldb.LDB_ERR_OPERATIONS_ERROR
244 LDB_ERR_PROTOCOL_ERROR = _ldb.LDB_ERR_PROTOCOL_ERROR
245 LDB_ERR_TIME_LIMIT_EXCEEDED = _ldb.LDB_ERR_TIME_LIMIT_EXCEEDED
246 LDB_ERR_SIZE_LIMIT_EXCEEDED = _ldb.LDB_ERR_SIZE_LIMIT_EXCEEDED
247 LDB_ERR_COMPARE_FALSE = _ldb.LDB_ERR_COMPARE_FALSE
248 LDB_ERR_COMPARE_TRUE = _ldb.LDB_ERR_COMPARE_TRUE
249 LDB_ERR_AUTH_METHOD_NOT_SUPPORTED = _ldb.LDB_ERR_AUTH_METHOD_NOT_SUPPORTED
250 LDB_ERR_STRONG_AUTH_REQUIRED = _ldb.LDB_ERR_STRONG_AUTH_REQUIRED
251 LDB_ERR_REFERRAL = _ldb.LDB_ERR_REFERRAL
252 LDB_ERR_ADMIN_LIMIT_EXCEEDED = _ldb.LDB_ERR_ADMIN_LIMIT_EXCEEDED
253 LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION = _ldb.LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION
254 LDB_ERR_CONFIDENTIALITY_REQUIRED = _ldb.LDB_ERR_CONFIDENTIALITY_REQUIRED
255 LDB_ERR_SASL_BIND_IN_PROGRESS = _ldb.LDB_ERR_SASL_BIND_IN_PROGRESS
256 LDB_ERR_NO_SUCH_ATTRIBUTE = _ldb.LDB_ERR_NO_SUCH_ATTRIBUTE
257 LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE = _ldb.LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE
258 LDB_ERR_INAPPROPRIATE_MATCHING = _ldb.LDB_ERR_INAPPROPRIATE_MATCHING
259 LDB_ERR_CONSTRAINT_VIOLATION = _ldb.LDB_ERR_CONSTRAINT_VIOLATION
260 LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS = _ldb.LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS
261 LDB_ERR_INVALID_ATTRIBUTE_SYNTAX = _ldb.LDB_ERR_INVALID_ATTRIBUTE_SYNTAX
262 LDB_ERR_NO_SUCH_OBJECT = _ldb.LDB_ERR_NO_SUCH_OBJECT
263 LDB_ERR_ALIAS_PROBLEM = _ldb.LDB_ERR_ALIAS_PROBLEM
264 LDB_ERR_INVALID_DN_SYNTAX = _ldb.LDB_ERR_INVALID_DN_SYNTAX
265 LDB_ERR_ALIAS_DEREFERENCING_PROBLEM = _ldb.LDB_ERR_ALIAS_DEREFERENCING_PROBLEM
266 LDB_ERR_INAPPROPRIATE_AUTHENTICATION = _ldb.LDB_ERR_INAPPROPRIATE_AUTHENTICATION
267 LDB_ERR_INVALID_CREDENTIALS = _ldb.LDB_ERR_INVALID_CREDENTIALS
268 LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS = _ldb.LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS
269 LDB_ERR_BUSY = _ldb.LDB_ERR_BUSY
270 LDB_ERR_UNAVAILABLE = _ldb.LDB_ERR_UNAVAILABLE
271 LDB_ERR_UNWILLING_TO_PERFORM = _ldb.LDB_ERR_UNWILLING_TO_PERFORM
272 LDB_ERR_LOOP_DETECT = _ldb.LDB_ERR_LOOP_DETECT
273 LDB_ERR_NAMING_VIOLATION = _ldb.LDB_ERR_NAMING_VIOLATION
274 LDB_ERR_OBJECT_CLASS_VIOLATION = _ldb.LDB_ERR_OBJECT_CLASS_VIOLATION
275 LDB_ERR_NOT_ALLOWED_ON_NON_LEAF = _ldb.LDB_ERR_NOT_ALLOWED_ON_NON_LEAF
276 LDB_ERR_NOT_ALLOWED_ON_RDN = _ldb.LDB_ERR_NOT_ALLOWED_ON_RDN
277 LDB_ERR_ENTRY_ALREADY_EXISTS = _ldb.LDB_ERR_ENTRY_ALREADY_EXISTS
278 LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED = _ldb.LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED
279 LDB_ERR_AFFECTS_MULTIPLE_DSAS = _ldb.LDB_ERR_AFFECTS_MULTIPLE_DSAS
280 LDB_ERR_OTHER = _ldb.LDB_ERR_OTHER
281 class Ldb(object):
282     """Connection to a LDB database."""
283     thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
284     def __init__(self, *args, **kwargs): 
285         _ldb.Ldb_swiginit(self,_ldb.new_Ldb(*args, **kwargs))
286     def connect(*args, **kwargs):
287         """
288         S.connect(url,flags=0,options=None) -> None
289         Connect to a LDB URL.
290         """
291         return _ldb.Ldb_connect(*args, **kwargs)
292
293     __swig_destroy__ = _ldb.delete_Ldb
294     def delete(*args, **kwargs):
295         """
296         S.delete(dn) -> None
297         Remove an entry.
298         """
299         return _ldb.Ldb_delete(*args, **kwargs)
300
301     def rename(*args, **kwargs):
302         """
303         S.rename(old_dn, new_dn) -> None
304         Rename an entry.
305         """
306         return _ldb.Ldb_rename(*args, **kwargs)
307
308     def add(*args, **kwargs):
309         """
310         S.add(message) -> None
311         Add an entry.
312         """
313         return _ldb.Ldb_add(*args, **kwargs)
314
315     def modify(*args, **kwargs):
316         """
317         S.modify(message) -> None
318         Modify an entry.
319         """
320         return _ldb.Ldb_modify(*args, **kwargs)
321
322     def set_create_perms(*args, **kwargs):
323         """
324         S.set_create_perms(mode) -> None
325         Set mode to use when creating new LDB files.
326         """
327         return _ldb.Ldb_set_create_perms(*args, **kwargs)
328
329     def set_modules_dir(*args, **kwargs):
330         """
331         S.set_modules_dir(path) -> None
332         Set path LDB should search for modules
333         """
334         return _ldb.Ldb_set_modules_dir(*args, **kwargs)
335
336     def set_debug(*args, **kwargs):
337         """
338         S.set_debug(callback) -> None
339         Set callback for LDB debug messages.
340         The callback should accept a debug level and debug text.
341         """
342         return _ldb.Ldb_set_debug(*args, **kwargs)
343
344     def set_opaque(*args, **kwargs):
345         """
346         S.set_opaque(name, value) -> None
347         Set an opaque value on this LDB connection. 
348         :note: Passing incorrect values may cause crashes.
349         """
350         return _ldb.Ldb_set_opaque(*args, **kwargs)
351
352     def get_opaque(*args, **kwargs):
353         """
354         S.get_opaque(name) -> value
355         Get an opaque value set on this LDB connection. 
356         :note: The returned value may not be useful in Python.
357         """
358         return _ldb.Ldb_get_opaque(*args, **kwargs)
359
360     def transaction_start(*args, **kwargs):
361         """
362         S.transaction_start() -> None
363         Start a new transaction.
364         """
365         return _ldb.Ldb_transaction_start(*args, **kwargs)
366
367     def transaction_commit(*args, **kwargs):
368         """
369         S.transaction_commit() -> None
370         Commit currently active transaction.
371         """
372         return _ldb.Ldb_transaction_commit(*args, **kwargs)
373
374     def transaction_cancel(*args, **kwargs):
375         """
376         S.transaction_cancel() -> None
377         Cancel currently active transaction.
378         """
379         return _ldb.Ldb_transaction_cancel(*args, **kwargs)
380
381     def parse_ldif(*args, **kwargs):
382         """
383         S.parse_ldif(ldif) -> iter(messages)
384         Parse a string formatted using LDIF.
385         """
386         return _ldb.Ldb_parse_ldif(*args, **kwargs)
387
388     def __init__(self, url=None, flags=0, options=None):
389         """Create a new LDB object.
390
391         Will also connect to the specified URL if one was given.
392         """
393         _ldb.Ldb_swiginit(self,_ldb.new_Ldb())
394         if url is not None:
395             self.connect(url, flags, options)
396
397     def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, 
398                attrs=None, controls=None):
399         """Search in a database.
400
401         :param base: Optional base DN to search
402         :param scope: Search scope (SCOPE_BASE, SCOPE_ONELEVEL or SCOPE_SUBTREE)
403         :param expression: Optional search expression
404         :param attrs: Attributes to return (defaults to all)
405         :param controls: Optional list of controls
406         :return: Iterator over Message objects
407         """
408         if not (attrs is None or isinstance(attrs, list)):
409             raise TypeError("attributes not a list")
410         parsed_controls = None
411         if controls is not None:
412             parsed_controls = self.parse_control_strings(controls)
413         return self.search_ex(base, scope, expression, attrs, 
414                               parsed_controls)
415
416 Ldb.connect = new_instancemethod(_ldb.Ldb_connect,None,Ldb)
417 Ldb.search_ex = new_instancemethod(_ldb.Ldb_search_ex,None,Ldb)
418 Ldb.delete = new_instancemethod(_ldb.Ldb_delete,None,Ldb)
419 Ldb.rename = new_instancemethod(_ldb.Ldb_rename,None,Ldb)
420 Ldb.parse_control_strings = new_instancemethod(_ldb.Ldb_parse_control_strings,None,Ldb)
421 Ldb.add = new_instancemethod(_ldb.Ldb_add,None,Ldb)
422 Ldb.modify = new_instancemethod(_ldb.Ldb_modify,None,Ldb)
423 Ldb.get_config_basedn = new_instancemethod(_ldb.Ldb_get_config_basedn,None,Ldb)
424 Ldb.get_root_basedn = new_instancemethod(_ldb.Ldb_get_root_basedn,None,Ldb)
425 Ldb.get_schema_basedn = new_instancemethod(_ldb.Ldb_get_schema_basedn,None,Ldb)
426 Ldb.get_default_basedn = new_instancemethod(_ldb.Ldb_get_default_basedn,None,Ldb)
427 Ldb.schema_format_value = new_instancemethod(_ldb.Ldb_schema_format_value,None,Ldb)
428 Ldb.errstring = new_instancemethod(_ldb.Ldb_errstring,None,Ldb)
429 Ldb.set_create_perms = new_instancemethod(_ldb.Ldb_set_create_perms,None,Ldb)
430 Ldb.set_modules_dir = new_instancemethod(_ldb.Ldb_set_modules_dir,None,Ldb)
431 Ldb.set_debug = new_instancemethod(_ldb.Ldb_set_debug,None,Ldb)
432 Ldb.set_opaque = new_instancemethod(_ldb.Ldb_set_opaque,None,Ldb)
433 Ldb.get_opaque = new_instancemethod(_ldb.Ldb_get_opaque,None,Ldb)
434 Ldb.transaction_start = new_instancemethod(_ldb.Ldb_transaction_start,None,Ldb)
435 Ldb.transaction_commit = new_instancemethod(_ldb.Ldb_transaction_commit,None,Ldb)
436 Ldb.transaction_cancel = new_instancemethod(_ldb.Ldb_transaction_cancel,None,Ldb)
437 Ldb.schema_attribute_remove = new_instancemethod(_ldb.Ldb_schema_attribute_remove,None,Ldb)
438 Ldb.schema_attribute_add = new_instancemethod(_ldb.Ldb_schema_attribute_add,None,Ldb)
439 Ldb.setup_wellknown_attributes = new_instancemethod(_ldb.Ldb_setup_wellknown_attributes,None,Ldb)
440 Ldb.__contains__ = new_instancemethod(_ldb.Ldb___contains__,None,Ldb)
441 Ldb.parse_ldif = new_instancemethod(_ldb.Ldb_parse_ldif,None,Ldb)
442 Ldb.__repr__ = new_instancemethod(_ldb.Ldb___repr__,None,Ldb)
443 Ldb_swigregister = _ldb.Ldb_swigregister
444 Ldb_swigregister(Ldb)
445
446
447 def valid_attr_name(*args, **kwargs):
448   """
449     S.valid_attr_name(name) -> bool
450     Check whether the supplied name is a valid attribute name.
451     """
452   return _ldb.valid_attr_name(*args, **kwargs)
453
454 def timestring(*args, **kwargs):
455   """
456     S.timestring(int) -> string
457     Generate a LDAP time string from a UNIX timestamp
458     """
459   return _ldb.timestring(*args, **kwargs)
460
461 def string_to_time(*args, **kwargs):
462   """
463     S.string_to_time(string) -> int
464     Parse a LDAP time string into a UNIX timestamp.
465     """
466   return _ldb.string_to_time(*args, **kwargs)
467
468 def register_module(*args, **kwargs):
469   """
470     S.register_module(module) -> None
471     Register a LDB module.
472     """
473   return _ldb.register_module(*args, **kwargs)
474 __docformat__ = "restructuredText"
475 open = Ldb
476
477
478