From: Julien Cristau Date: Fri, 11 Oct 2019 13:33:31 +0000 (+0200) Subject: Use "foo is None" instead of "foo == None". X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=commitdiff_plain;h=fe67fab54bca15f4820e4f0a911023ed10a743b7 Use "foo is None" instead of "foo == None". --- diff --git a/debian/changelog b/debian/changelog index d4f9404..01cfbb2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,7 @@ userdir-ldap (0.3.97) UNRELEASED; urgency=medium * Use "not in" operator in various places ("foo not in bar" instead of "not foo in bar"). * ud-mailgate: use subprocess.Popen instead of os.popen. + * Use "foo is None" instead of "foo == None". -- Peter Palfrader Sat, 06 Apr 2019 22:04:34 +0200 diff --git a/ud-arbimport b/ud-arbimport index 90a1746..bfc65e6 100755 --- a/ud-arbimport +++ b/ud-arbimport @@ -49,7 +49,7 @@ while(1): if Line != "": # Glob similar lines Split = re.split("[:\n]",Line); - if User == None: + if User is None: User = Split[0]; if Split[0] == User: Set.append(Split[1].strip()); diff --git a/ud-echelon b/ud-echelon index 38e0718..884ba3b 100755 --- a/ud-echelon +++ b/ud-echelon @@ -46,14 +46,14 @@ def TryGPG(mail): # Try to guess the name from the email address def TryMatcher(mail): Sender = mail["From"]; - if Sender == None: + if Sender is None: return None; # Split up the address and invoke the matcher routine UID = GetUID(l,SplitEmail(Sender)); - if UID[0] == None: - if UID[1] == None or len(UID[1]) == 0: + if UID[0] is None: + if UID[1] is None or len(UID[1]) == 0: return None; # Print out an error message @@ -72,7 +72,7 @@ for (switch, val) in options: Debug = ""; # Open the log files -if Debug == None: +if Debug is None: MainLog = open(Ech_MainLog,"a+",0); ErrLog = open(Ech_ErrorLog,"a+",0); else: @@ -96,7 +96,7 @@ try: ErrMsg = "An error occured while performing the LDAP lookup"; global l; l = connectLDAP() - if Debug == None: + if Debug is None: F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r"); AccessPass = F.readline().strip().split(" ") l.simple_bind_s("uid="+AccessPass[0]+","+BaseDn,AccessPass[1]); @@ -108,7 +108,7 @@ try: ErrType = EX_TEMPFAIL; ErrMsg = "An error occured while trying GPG decoding"; User = TryGPG(mail); - if User == None: + if User is None: ErrMsg = "An error occured while trying Matcher decoding"; User = TryMatcher(mail); @@ -122,7 +122,7 @@ try: MainLog.write("%s %s %s\n"%(User[0],User[1],Msg)); Dn = "uid=" + User[0] + "," + BaseDn; Rec = [(ldap.MOD_REPLACE,"activity-%s"%(User[1]),Msg)]; - if Debug == None: + if Debug is None: l.modify_s(Dn,Rec); else: print Rec; diff --git a/ud-emailmatcher b/ud-emailmatcher index 4d42d77..aa717d5 100755 --- a/ud-emailmatcher +++ b/ud-emailmatcher @@ -84,7 +84,7 @@ while(1): if FingerPrint != None and UID != None: for x in Emails: Match = AddressSplit.match(x); - if Match == None: + if Match is None: continue; Groups = Match.groups(); Email = Groups[1]+'@'+Groups[2]; diff --git a/ud-forwardlist b/ud-forwardlist index 727cfd9..68c8c1d 100755 --- a/ud-forwardlist +++ b/ud-forwardlist @@ -21,7 +21,7 @@ while (1): if File == "": break; - # Attempt to determine the UID + # Attempt to determine the UID try: User = pwd.getpwuid(os.stat(File)[stat.ST_UID])[0]; except KeyError: @@ -37,13 +37,13 @@ while (1): break; if Line2[0] == '#' or Line2[0] == '\n': continue; - if Line == None: + if Line is None: Line = Line2; else: break; # If we got more than one line or no lines at all it is invalid - if Line == None or Line == "" or Line2 != "": + if Line is None or Line == "" or Line2 != "": print "Invalid1", File; continue; @@ -55,7 +55,7 @@ while (1): # Split off the address part Address = AddressSplit.match(Line); - if Address == None: + if Address is None: # Or parse a qmail adddress.. Address = Line; if Address[0] == '&': diff --git a/ud-generate b/ud-generate index a8ee854..4b589c5 100755 --- a/ud-generate +++ b/ud-generate @@ -309,7 +309,7 @@ def GenShadowSudo(accounts, File, untrusted, current_host): if 'sudoPassword' in a: for entry in a['sudoPassword']: Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*-]+) ([^ ]+)$').match(entry) - if Match == None: + if Match is None: continue uuid = Match.group(1) status = Match.group(2) @@ -918,7 +918,7 @@ def ExtractDNSInfo(x): Algorithm = 2 if key_prefix == 'ssh-ed25519': Algorithm = 4 - if Algorithm == None: + if Algorithm is None: continue # and more from the registry sshfp_digest_codepoints = [ (1, 'sha1'), (2, 'sha256') ] @@ -1142,7 +1142,7 @@ def get_hosts(ldap_conn): "mXRecord", "ipHostNumber", "dnsTTL", "machine", "architecture", "sshfpHostname"]) - if HostAttrs == None: + if HostAttrs is None: raise UDEmptyList, "No Hosts" HostAttrs.sort(lambda x, y: cmp((GetAttr(x, "hostname")).lower(), (GetAttr(y, "hostname")).lower())) diff --git a/ud-gpgimport b/ud-gpgimport index ee158cb..72f09a4 100755 --- a/ud-gpgimport +++ b/ud-gpgimport @@ -177,7 +177,7 @@ for fpr in pgpkeys: continue; UID = GetUID(l,SplitEmail(pgp_uid),UnknownMap); - if UID[0] == None: + if UID[0] is None: print "Unassigned key in keyrings: %s, belonging to %s"%(fpr, pgp_uid) if UID[1] != None: for x in UID[1]: print x; diff --git a/ud-sshlist b/ud-sshlist index 61f5f15..7df0242 100755 --- a/ud-sshlist +++ b/ud-sshlist @@ -37,7 +37,7 @@ while (1): break; if Line[0] == '#' or Line[0] == '\n': continue; - if SSHAuthSplit.match(Line) == None: + if SSHAuthSplit.match(Line) is None: print "Bad line", File; else: Lines.append(Line); diff --git a/ud-useradd b/ud-useradd index 8872507..6dd82d9 100755 --- a/ud-useradd +++ b/ud-useradd @@ -180,7 +180,7 @@ while 1: cn = GetAttr(Attrs[0],"cn"); sn = GetAttr(Attrs[0],"sn"); mn = GetAttr(Attrs[0],"mn"); - if privsub == None or privsub == "": + if privsub is None or privsub == "": privsub = " "; break; else: @@ -267,7 +267,7 @@ if Update == 0 or ForceMail == 1: CryptedPass = GPGEncrypt("Your new password is '" + Password + "'\n",\ "0x"+Keys[0][1],UsePGP2); Password = None; - if CryptedPass == None: + if CryptedPass is None: raise "Error","Password Encryption failed" else: Pass = HashPass(Password); diff --git a/unmaintained/gpgwrapper b/unmaintained/gpgwrapper index cf25226..793a524 100755 --- a/unmaintained/gpgwrapper +++ b/unmaintained/gpgwrapper @@ -148,7 +148,7 @@ try: if Res[0] != None: raise Error, Res[0]; - if Res[3] == None: + if Res[3] is None: raise Error, "Null signature text"; # Extract the plain message text in the event of mime encoding @@ -179,9 +179,9 @@ try: ErrType = EX_PERMFAIL; ErrMsg = "A problem occured while trying to formulate the reply"; Sender = Email.getheader("Reply-To"); - if Sender == None: + if Sender is None: Sender = Email.getheader("From"); - if Sender == None: + if Sender is None: raise Error, "Unable to determine the sender's address"; # Setup the environment diff --git a/userdir_gpg.py b/userdir_gpg.py index da8abfc..fb5b938 100644 --- a/userdir_gpg.py +++ b/userdir_gpg.py @@ -343,7 +343,7 @@ def GPGCheckSig(Message): # Good signature response if Split[1] == "GOODSIG": # Just in case GPG returned a bad signal before this (bug?) - if Why == None: + if Why is None: GoodSig = 1; KeyID = Split[2]; Owner = ' '.join(Split[3:]) @@ -416,11 +416,11 @@ def GPGCheckSig(Message): Text = Res[2].read(); # A gpg failure is an automatic bad signature - if Exit[1] != 0 and Why == None: + if Exit[1] != 0 and Why is None: GoodSig = 0; Why = "GPG execution returned non-zero exit status: " + str(Exit[1]); - if GoodSig == 0 and (Why == None or len(Why) == 0): + if GoodSig == 0 and (Why is None or len(Why) == 0): Why = "Checking Failed"; # Try to decide if this message was sent using PGP2 @@ -585,7 +585,7 @@ class ReplayCache: # Check a signature. 'sig' is a 3 tuple that has the sigId, date and # key ID def Check(self,Sig): - if Sig[0] == None or Sig[1] == None or Sig[2] == None: + if Sig[0] is None or Sig[1] is None or Sig[2] is None: return "Invalid signature"; if int(Sig[1]) > time.time() + self.FutureCutOff: return "Signature has a time too far in the future"; @@ -598,7 +598,7 @@ class ReplayCache: # Add a signature, the sig is the same as is given to Check def Add(self,Sig): - if Sig[0] == None or Sig[1] == None: + if Sig[0] is None or Sig[1] is None: raise RuntimeError,"Invalid signature"; if Sig[1] < time.time() - self.CleanCutOff: return;