samba3: work around bytes formatting for Python 3.4
authorJoe Guo <joeg@catalyst.net.nz>
Wed, 28 Mar 2018 02:08:40 +0000 (15:08 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 5 Apr 2018 06:59:09 +0000 (08:59 +0200)
  b'%s\x00' % key

The above % formatting for bytes is only available since Python 3.5,
however we need to support Python 3.4 so far.

Work around this with `+`.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/samba3/__init__.py

index a0bb76f68c1c942b6a8b6df825f9a107ad525093..f7927836c989b8b28bf53577453f5128dc8fad81 100644 (file)
@@ -87,7 +87,7 @@ class Registry(DbDatabase):
         :param key: Key path.
         :return: list with key names
         """
-        data = self.db.get(b"%s\x00" % key)
+        data = self.db.get(key + b"\x00")
         if data is None:
             return []
         (num, ) = struct.unpack("<L", data[0:4])
@@ -103,7 +103,7 @@ class Registry(DbDatabase):
         :param key: Key to retrieve values for.
         :return: Dictionary with value names as key, tuple with type and
             data as value."""
-        data = self.db.get(b"%s/%s\x00" % (REGISTRY_VALUE_PREFIX, key))
+        data = self.db.get(REGISTRY_VALUE_PREFIX + b'/' + key + b'\x00')
         if data is None:
             return {}
         ret = {}
@@ -177,13 +177,13 @@ class IdmapDatabase(DbDatabase):
         :param uid: UID to retrieve SID for.
         :return: A SID or None if no mapping was found.
         """
-        data = self.db.get(b"%s%d\0" % (IDMAP_USER_PREFIX, uid))
+        data = self.db.get(IDMAP_USER_PREFIX + str(uid).encode() + b'\0')
         if data is None:
             return data
         return data.rstrip(b"\0")
 
     def get_group_sid(self, gid):
-        data = self.db.get(b"%s%d\0" % (IDMAP_GROUP_PREFIX, gid))
+        data = self.db.get(IDMAP_GROUP_PREFIX + str(gid).encode() + b'\0')
         if data is None:
             return data
         return data.rstrip(b"\0")