r26523: Refactor provisioning code.
[ira/wip.git] / source / scripting / python / samba / __init__.py
index 8e0eff301108478c92d940e1a6d35d1795ac8a6a..398146468174699cbfbee1f4ab1a0be14d75d895 100644 (file)
@@ -75,20 +75,21 @@ class Ldb(ldb.Ldb):
         if lp is not None:
             self.set_loadparm(self, lp)
 
-        if url:
-            self.connect(url)
-
         def msg(l,text):
             print text
         #self.set_debug(msg)
 
+        if url is not None:
+            self.connect(url)
+
+
     set_credentials = misc.ldb_set_credentials
     set_session_info = misc.ldb_set_session_info
     set_loadparm = misc.ldb_set_loadparm
 
-    def searchone(self, basedn, expression, attribute):
+    def searchone(self, basedn, attribute, expression=None, scope=ldb.SCOPE_BASE):
         """Search for one attribute as a string."""
-        res = self.search(basedn, SCOPE_SUBTREE, expression, [attribute])
+        res = self.search(basedn, scope, expression, [attribute])
         if len(res) != 1 or res[0][attribute] is None:
             return None
         return res[0][attribute]
@@ -124,6 +125,8 @@ def substitute_var(text, values):
     """
 
     for (name, value) in values.items():
+        assert isinstance(name, str), "%r is not a string" % name
+        assert isinstance(value, str), "Value %r for %s is not a string" % (value, name)
         text = text.replace("${%s}" % name, value)
 
     assert "${" not in text, text