]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
buildtools: remove Python2 compatibility
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 28 May 2024 07:45:17 +0000 (19:45 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 31 May 2024 00:25:33 +0000 (00:25 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/bin/waf
buildtools/wafsamba/samba_patterns.py
buildtools/wafsamba/samba_utils.py
buildtools/wafsamba/samba_version.py

index 0f70fa21de2347319c808944a1dd10841431ba95..c103979cc00e5b8c7990abe5bac6505390930c40 100755 (executable)
@@ -45,13 +45,9 @@ join = os.path.join
 if sys.hexversion<0x206000f:
        raise ImportError('Python >= 2.6 is required to create the waf file')
 
-WAF='waf'
+WAF='waf3'
 def b(x):
-       return x
-if sys.hexversion>0x300000f:
-       WAF='waf3'
-       def b(x):
-               return x.encode()
+       return x.encode()
 
 def err(m):
        print(('\033[91mError: %s\033[0m' % m))
@@ -107,11 +103,6 @@ def unpack_wafdir(dir, src):
        for x in ('Tools', 'extras'):
                os.chmod(join('waflib',x), 493)
 
-       if sys.hexversion<0x300000f:
-               sys.path = [join(dir, 'waflib')] + sys.path
-               import fixpy2
-               fixpy2.fixdir(dir)
-
        os.remove(tmp)
        os.chdir(cwd)
 
index 41296810e1313b7269aa3e83f50cfe6e8dd51be7..faaade75ae4ccc6af3b25ec6ee1101e00b09c806 100644 (file)
@@ -187,11 +187,7 @@ def write_build_options(task):
     keys_header_sys = []
     keys_header_other = []
     keys_misc = []
-    if sys.hexversion>0x300000f:
-        trans_table = bytes.maketrans(b'.-()', b'____')
-    else:
-        import string
-        trans_table = string.maketrans('.-()', '____')
+    trans_table = bytes.maketrans(b'.-()', b'____')
 
     for key in tbl:
         if key.startswith("HAVE_UT_UT_") or key.find("UTMP") >= 0:
index f287e85d8381704b92e78af1cb75bf022d4113e7..e45f0ae1a35eaefaaf819cad0b7a0c044d046954 100644 (file)
@@ -15,38 +15,16 @@ from waflib.Build import CACHE_SUFFIX
 # TODO: make this a --option
 LIB_PATH="shared"
 
-
-PY3 = sys.version_info[0] == 3
-
-if PY3:
-
-    # helper function to get a string from a variable that maybe 'str' or
-    # 'bytes' if 'bytes' then it is decoded using 'utf8'. If 'str' is passed
-    # it is returned unchanged
-    # Using this function is PY2/PY3 code should ensure in most cases
-    # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
-    # decodes the variable (see PY2 implementation of this function below)
-    def get_string(bytesorstring):
-        tmp = bytesorstring
-        if isinstance(bytesorstring, bytes):
-            tmp = bytesorstring.decode('utf8')
-        elif not isinstance(bytesorstring, str):
-            raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
-        return tmp
-
-else:
-
-    # Helper function to return string.
-    # if 'str' or 'unicode' passed in they are returned unchanged
-    # otherwise an exception is generated
-    # Using this function is PY2/PY3 code should ensure in most cases
-    # the PY2 code runs unchanged in PY2 whereas the code in PY3 possibly
-    # decodes the variable (see PY3 implementation of this function above)
-    def get_string(bytesorstring):
-        tmp = bytesorstring
-        if not(isinstance(bytesorstring, str) or isinstance(bytesorstring, unicode)):
-            raise ValueError('Expected str or unicode for %s:%s' % (type(bytesorstring), bytesorstring))
-        return tmp
+# Py3 transition helper function to get a string from a variable that
+# may be 'str' or 'bytes'. If 'bytes' then it is decoded using 'utf8'.
+# If 'str' is passed it is returned unchanged.
+def get_string(bytesorstring):
+    tmp = bytesorstring
+    if isinstance(bytesorstring, bytes):
+        tmp = bytesorstring.decode('utf8')
+    elif not isinstance(bytesorstring, str):
+        raise ValueError('Expected byte of string for %s:%s' % (type(bytesorstring), bytesorstring))
+    return tmp
 
 # sigh, python octal constants are a mess
 MODE_644 = int('644', 8)
index 31103e0f8c4cd8819e67201ecb44aaa1021f59a9..3d2998c744148dee05d39fd69d6cac617320fce8 100644 (file)
@@ -200,8 +200,6 @@ also accepted as dictionary entries here
             string+="#define SAMBA_VERSION_%s " % name
             value = self.vcs_fields[name]
             string_types = str
-            if sys.version_info[0] < 3:
-                string_types = basestring
             if isinstance(value, string_types):
                 string += "\"%s\"" % value
             elif type(value) is int: