python: do not use "is" for string equality
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 26 Oct 2018 07:25:59 +0000 (20:25 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 29 Oct 2018 22:13:36 +0000 (23:13 +0100)
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 <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Mon Oct 29 23:13:36 CET 2018 on sn-devel-144

python/samba/netcmd/domain.py
python/samba/netcmd/user.py
python/samba/provision/backend.py
python/samba/samdb.py
source4/dsdb/tests/python/password_lockout.py

index a85c16a179b25b93cc73bf3ad3e599fd2eb14d49..159b5711d1ee33bb662eb0f4fb0fbd72f4592381 100644 (file)
@@ -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" % (
index 87726d4636ef0258780474192eaad1b73ea86f9c..2b1410bd3ba775ea39d0eef7b3abcbe1662715c4 100644 (file)
@@ -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: ")
index 2e3b1dc0c0b544831bb4944f29ec5e2c0c043e74..502afdf53fffb434dd93a2d871b4563f1f953f42 100644 (file)
@@ -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)
index 1abd94b193843988f87f4e48f1b98f618336ea79..415142b2245f00161228d2c9b5b30a001e2e08f5 100644 (file)
@@ -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
 
index aceebd660723bfc722b4b469a0e6e52b61cffcb2..14cf00adb90f20bf49482946df7b69d7c0088cbb 100755 (executable)
@@ -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)