From: Douglas Bagnall Date: Fri, 26 Oct 2018 07:25:59 +0000 (+1300) Subject: python: do not use "is" for string equality X-Git-Tag: tdb-1.3.17~1133 X-Git-Url: http://git.samba.org/samba.git/?p=sfrench%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=b37f8f88eaf26a4d12fe9728e09aed68ddaaf1c0 python: do not use "is" for string equality This is not always going to work, and is not guaranteed to be consistent even between minor versions. Here is a simple counterexample: >>> a = 'hello' >>> a is 'hello' True >>> a is 'hello'.lower() False >>> a == a.lower() True Possibly it always works for the empty string, but we cannot rely on that. Signed-off-by: Douglas Bagnall Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Mon Oct 29 23:13:36 CET 2018 on sn-devel-144 --- diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index a85c16a179b..159b5711d1e 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -2334,7 +2334,7 @@ class cmd_domain_trust_create(DomainTrustCommand): def get_password(name): password = None while True: - if password is not None and password is not '': + if password is not None and password != '': return password password = getpass("New %s Password: " % name) passwordverify = getpass("Retype %s Password: " % name) @@ -2625,7 +2625,7 @@ class cmd_domain_trust_create(DomainTrustCommand): self.outf.write("Deleting local TDO.\n") local_lsa.DeleteObject(local_tdo_handle) local_tdo_handle = None - if current_request['location'] is "remote": + if current_request['location'] == "remote": raise self.RemoteRuntimeError(self, error, "%s" % ( current_request['name'])) raise self.LocalRuntimeError(self, error, "%s" % ( diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py index 87726d4636e..2b1410bd3ba 100644 --- a/python/samba/netcmd/user.py +++ b/python/samba/netcmd/user.py @@ -325,7 +325,7 @@ Example5 shows how to create an RFC2307/NIS domain enabled user account. If smartcard_required=False): if smartcard_required: - if password is not None and password is not '': + if password is not None and password != '': raise CommandError('It is not allowed to specify ' '--newpassword ' 'together with --smartcard-required.') @@ -340,7 +340,7 @@ Example5 shows how to create an RFC2307/NIS domain enabled user account. If while True: if smartcard_required: break - if password is not None and password is not '': + if password is not None and password != '': break password = getpass("New Password: ") passwordverify = getpass("Retype Password: ") @@ -714,7 +714,7 @@ class cmd_user_password(Command): password = newpassword while True: - if password is not None and password is not '': + if password is not None and password != '': break password = getpass("New Password: ") passwordverify = getpass("Retype Password: ") @@ -798,7 +798,7 @@ Example3 shows how an administrator would reset TestUser3 user's password to pas password = newpassword if smartcard_required: - if password is not None and password is not '': + if password is not None and password != '': raise CommandError('It is not allowed to specify ' '--newpassword ' 'together with --smartcard-required.') @@ -817,7 +817,7 @@ Example3 shows how an administrator would reset TestUser3 user's password to pas while True: if smartcard_required: break - if password is not None and password is not '': + if password is not None and password != '': break password = getpass("New Password: ") passwordverify = getpass("Retype Password: ") diff --git a/python/samba/provision/backend.py b/python/samba/provision/backend.py index 2e3b1dc0c0b..502afdf53ff 100644 --- a/python/samba/provision/backend.py +++ b/python/samba/provision/backend.py @@ -569,7 +569,7 @@ class OpenLDAPBackend(LDAPBackend): self.slapd_provision_command.extend([self.ldap_uri, "-d0"]) uris = self.ldap_uri - if server_port_string is not "": + if server_port_string != "": uris = uris + " " + server_port_string self.slapd_command.append(uris) diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 1abd94b1938..415142b2245 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -380,7 +380,7 @@ member: %s displayname += ' %s' % surname cn = username - if useusernameascn is None and displayname is not "": + if useusernameascn is None and displayname != "": cn = displayname user_dn = "CN=%s,%s,%s" % (cn, (userou or "CN=Users"), self.domain_dn()) @@ -405,7 +405,7 @@ member: %s if givenname is not None: ldbmessage["givenName"] = givenname - if displayname is not "": + if displayname != "": ldbmessage["displayName"] = displayname ldbmessage["name"] = displayname diff --git a/source4/dsdb/tests/python/password_lockout.py b/source4/dsdb/tests/python/password_lockout.py index aceebd66072..14cf00adb90 100755 --- a/source4/dsdb/tests/python/password_lockout.py +++ b/source4/dsdb/tests/python/password_lockout.py @@ -151,11 +151,11 @@ userAccountControl: %d """ % uac) def _reset_by_method(self, res, method): - if method is "ldap_userAccountControl": + if method == "ldap_userAccountControl": self._reset_ldap_userAccountControl(res) - elif method is "ldap_lockoutTime": + elif method == "ldap_lockoutTime": self._reset_ldap_lockoutTime(res) - elif method is "samr": + elif method == "samr": self._reset_samr(res) else: self.assertTrue(False, msg="Invalid reset method[%s]" % method)