PEP8: add spaces after operators
[nivanova/samba-autobuild/.git] / python / samba / __init__.py
index 3535704ea0c8fe6945f904e9f8389c8412ff89d4..291ef541189891d55dd3fe9ff86a001ee9f738a6 100644 (file)
@@ -29,6 +29,7 @@ import ldb
 import samba.param
 from samba import _glue
 from samba._ldb import Ldb as _Ldb
+from samba.compat import string_types
 
 
 def source_tree_topdir():
@@ -98,13 +99,13 @@ class Ldb(_Ldb):
         # TODO set debug
         def msg(l, text):
             print(text)
-        #self.set_debug(msg)
+        # self.set_debug(msg)
 
         self.set_utf8_casefold()
 
         # Allow admins to force non-sync ldb for all databases
         if lp is not None:
-            nosync_p = lp.get("nosync", "ldb")
+            nosync_p = lp.get("ldb:nosync")
             if nosync_p is not None and nosync_p:
                 flags |= ldb.FLG_NOSYNC
 
@@ -139,7 +140,7 @@ class Ldb(_Ldb):
 
         try:
             res = self.search(base=dn, scope=ldb.SCOPE_SUBTREE, attrs=[],
-                      expression="(|(objectclass=user)(objectclass=computer))")
+                              expression="(|(objectclass=user)(objectclass=computer))")
         except ldb.LdbError as error:
             (errno, estr) = error.args
             if errno == ldb.ERR_NO_SUCH_OBJECT:
@@ -172,8 +173,8 @@ class Ldb(_Ldb):
         # Delete the 'visible' records, and the invisble 'deleted' records (if
         # this DB supports it)
         for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
-                       "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
-                       [], controls=["show_deleted:0", "show_recycled:0"]):
+                               "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
+                               [], controls=["show_deleted:0", "show_recycled:0"]):
             try:
                 self.delete(msg.dn, ["relax:0"])
             except ldb.LdbError as error:
@@ -183,8 +184,8 @@ class Ldb(_Ldb):
                     raise
 
         res = self.search(basedn, ldb.SCOPE_SUBTREE,
-            "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
-            [], controls=["show_deleted:0", "show_recycled:0"])
+                          "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
+                          [], controls=["show_deleted:0", "show_recycled:0"])
         assert len(res) == 0
 
         # delete the specials
@@ -249,8 +250,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)
+        assert isinstance(name, string_types), "%r is not a string" % name
+        assert isinstance(value, string_types), "Value %r for %s is not a string" % (value, name)
         text = text.replace("${%s}" % name, value)
 
     return text
@@ -263,14 +264,14 @@ def check_all_substituted(text):
 
     :param text: The text to search for substitution variables
     """
-    if not "${" in text:
+    if "${" not in text:
         return
 
     var_start = text.find("${")
     var_end = text.find("}", var_start)
 
     raise Exception("Not all variables substituted: %s" %
-        text[var_start:var_end+1])
+                    text[var_start:var_end + 1])
 
 
 def read_and_sub_file(file_name, subst_vars):
@@ -303,7 +304,10 @@ def setup_file(template, fname, subst_vars=None):
     finally:
         f.close()
 
+
 MAX_NETBIOS_NAME_LEN = 15
+
+
 def is_valid_netbios_char(c):
     return (c.isalnum() or c in " !#$%&'()-.@^_{}~")
 
@@ -335,8 +339,8 @@ def import_bundled_package(modulename, location, source_tree_container,
     """
     if in_source_tree():
         extra_path = os.path.join(source_tree_topdir(), source_tree_container,
-            location)
-        if not extra_path in sys.path:
+                                  location)
+        if extra_path not in sys.path:
             sys.path.insert(0, extra_path)
         sys.modules[modulename] = __import__(modulename)
     else:
@@ -355,17 +359,19 @@ def ensure_third_party_module(modulename, location):
         __import__(modulename)
     except ImportError:
         import_bundled_package(modulename, location,
-            source_tree_container="third_party",
-            namespace="samba.third_party")
+                               source_tree_container="third_party",
+                               namespace="samba.third_party")
 
 
 def dn_from_dns_name(dnsdomain):
     """return a DN from a DNS name domain/forest root"""
     return "DC=" + ",DC=".join(dnsdomain.split("."))
 
+
 def current_unix_time():
     return int(time.time())
 
+
 def string_to_byte_array(string):
     blob = [0] * len(string)
 
@@ -374,24 +380,15 @@ def string_to_byte_array(string):
 
     return blob
 
+
 def arcfour_encrypt(key, data):
-    try:
-        from Crypto.Cipher import ARC4
-        c = ARC4.new(key)
-        return c.encrypt(data)
-    except ImportError as e:
-        pass
-    try:
-        from M2Crypto.RC4 import RC4
-        c = RC4(key)
-        return c.update(data)
-    except ImportError as e:
-        pass
-    raise Exception("arcfour_encrypt() requires " +
-                    "python*-crypto or python*-m2crypto or m2crypto")
+    from samba.crypto import arcfour_crypt_blob
+    return arcfour_crypt_blob(data, key)
+
 
 version = _glue.version
 interface_ips = _glue.interface_ips
+fault_setup = _glue.fault_setup
 set_debug_level = _glue.set_debug_level
 get_debug_level = _glue.get_debug_level
 unix2nttime = _glue.unix2nttime
@@ -400,9 +397,12 @@ nttime2unix = _glue.nttime2unix
 unix2nttime = _glue.unix2nttime
 generate_random_password = _glue.generate_random_password
 generate_random_machine_password = _glue.generate_random_machine_password
+check_password_quality = _glue.check_password_quality
+generate_random_bytes = _glue.generate_random_bytes
 strcasecmp_m = _glue.strcasecmp_m
 strstr_m = _glue.strstr_m
 is_ntvfs_fileserver_built = _glue.is_ntvfs_fileserver_built
+is_heimdal_built = _glue.is_heimdal_built
 
 NTSTATUSError = _glue.NTSTATUSError
 HRESULTError = _glue.HRESULTError