From 968b2acc4fe2642ee0c7af3060251baf40f7616c Mon Sep 17 00:00:00 2001
From: Jean-Marie Traissard <jim@lapin.org>
Date: Fri, 18 Apr 2008 00:26:07 +0000
Subject: [PATCH] http://python.org/dev/peps/pep-0008/ " Comparisons to
 singletons like None should always be done with 'is' or 'is not', never the
 equality operators." Comparisons to None part; second one... roster_win.py is
 NOT checked here (waiting for modelfilter)

---
 src/chat_control.py               |  5 ++--
 src/common/GnuPGInterface.py      | 17 ++++++++-----
 src/common/connection_handlers.py |  8 +++----
 src/common/helpers.py             |  2 +-
 src/common/pep.py                 | 40 +++++++++++++++----------------
 src/common/socks5.py              |  4 ++--
 src/common/xmpp/client.py         |  2 +-
 src/common/xmpp/client_nb.py      |  2 +-
 src/common/xmpp/commands.py       |  4 ++--
 src/common/xmpp/dispatcher.py     |  2 +-
 src/common/xmpp/protocol.py       |  2 +-
 src/conversation_textview.py      |  2 +-
 src/gajim.py                      |  2 +-
 src/gtkgui_helpers.py             |  2 +-
 src/lastfm.py                     |  2 +-
 src/message_window.py             |  5 ++--
 src/notify.py                     |  4 ++--
 17 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/src/chat_control.py b/src/chat_control.py
index 1985db73c6..6cfd56226e 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -1700,7 +1700,7 @@ class ChatControl(ChatControlBase):
 		gajim.jid_is_transport(jid):
 			toggle_gpg_menuitem.set_sensitive(False)
 		else:
-			e2e_is_active = int(self.session != None and self.session.enable_encryption)
+			e2e_is_active = int(self.session is not None and self.session.enable_encryption)
 			toggle_gpg_menuitem.set_sensitive(not e2e_is_active)
 			toggle_gpg_menuitem.set_active(self.gpg_is_active)
 
@@ -1708,7 +1708,8 @@ class ChatControl(ChatControlBase):
 		if not gajim.HAVE_PYCRYPTO:
 			toggle_e2e_menuitem.set_sensitive(False)
 		else:
-			isactive = int(self.session != None and self.session.enable_encryption)
+			isactive = int(self.session is not None and \
+				self.session.enable_encryption)
 			toggle_e2e_menuitem.set_active(isactive)
 			toggle_e2e_menuitem.set_sensitive(not self.gpg_is_active)
 
diff --git a/src/common/GnuPGInterface.py b/src/common/GnuPGInterface.py
index 90830e5549..9b50af8945 100644
--- a/src/common/GnuPGInterface.py
+++ b/src/common/GnuPGInterface.py
@@ -350,7 +350,7 @@ class GnuPG:
         
         handle_passphrase = 0
         
-        if self.passphrase != None \
+        if self.passphrase is not None \
            and not attach_fhs.has_key('passphrase') \
            and 'passphrase' not in create_fhs:
             handle_passphrase = 1
@@ -567,11 +567,16 @@ class Options:
     def get_standard_args( self ):
         """Generate a list of standard, non-meta or extra arguments"""
         args = []
-        if self.homedir != None: args.extend( [ '--homedir', self.homedir ] )
-        if self.options != None: args.extend( [ '--options', self.options ] )
-        if self.comment != None: args.extend( [ '--comment', self.comment ] )
-        if self.compress_algo != None: args.extend( [ '--compress-algo', self.compress_algo ] )
-        if self.default_key != None: args.extend( [ '--default-key', self.default_key ] )
+        if self.homedir is not None:
+            args.extend( [ '--homedir', self.homedir ] )
+        if self.options is not None:
+            args.extend( [ '--options', self.options ] )
+        if self.comment is not None:
+            args.extend( [ '--comment', self.comment ] )
+        if self.compress_algo is not None:
+            args.extend( [ '--compress-algo', self.compress_algo ] )
+        if self.default_key is not None:
+            args.extend( [ '--default-key', self.default_key ] )
         
         if self.no_options: args.append( '--no-options' )
         if self.armor: args.append( '--armor' )
diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index ee35525eaf..e6f72c2df4 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -489,7 +489,7 @@ class ConnectionBytestream:
 				if proxyhost['jid'] == jid:
 					proxy = proxyhost
 
-		if proxy != None:
+		if proxy is not None:
 			file_props['streamhost-used'] = True
 			if not file_props.has_key('streamhosts'):
 				file_props['streamhosts'] = []
@@ -1104,7 +1104,7 @@ class ConnectionVcard:
 						order = int(order)
 					except:
 						order = 0
-					if order != None:
+					if order is not None:
 						data['order'] = order
 					if meta_list.has_key(tag):
 						meta_list[tag].append(data)
@@ -1602,7 +1602,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 			invite = msg.getTag('x', namespace = common.xmpp.NS_MUC_USER)
 			if invite and not invite.getTag('invite'):
 				invite = None
-		delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None
+		delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) is not None
 		msg_id = None
 		composing_xep = None
 		# FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) do NOT RECOMMENDED
@@ -1675,7 +1675,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 			has_timestamp = False
 			if msg.timestamp:
 				has_timestamp = True
-			if subject != None:
+			if subject is not None:
 				self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp))
 			else:
 				statusCode = msg.getStatusCode()
diff --git a/src/common/helpers.py b/src/common/helpers.py
index c38e9228eb..2f597645e5 100644
--- a/src/common/helpers.py
+++ b/src/common/helpers.py
@@ -908,7 +908,7 @@ advanced_notif_num = None, is_first_message = True):
 
 def allow_popup_window(account, advanced_notif_num = None):
 	'''is it allowed to popup windows?'''
-	if advanced_notif_num != None:
+	if advanced_notif_num is not None:
 		popup = gajim.config.get_per('notifications', str(advanced_notif_num),
 			'auto_open')
 		if popup == 'yes':
diff --git a/src/common/pep.py b/src/common/pep.py
index c9f2f59c2a..f5609dc4c7 100644
--- a/src/common/pep.py
+++ b/src/common/pep.py
@@ -20,9 +20,9 @@ def user_mood(items, name, jid):
 				del acc.mood['mood']
 			if acc.mood.has_key('text'):
 				del acc.mood['text']
-			if mood != None:
+			if mood is not None:
 				acc.mood['mood'] = mood
-			if text != None:
+			if text is not None:
 				acc.mood['text'] = text
 
 	(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
@@ -34,9 +34,9 @@ def user_mood(items, name, jid):
 			del contact.mood['mood']
 		if contact.mood.has_key('text'):
 			del contact.mood['text']
-		if mood != None:
+		if mood is not None:
 			contact.mood['mood'] = mood
-		if text != None:
+		if text is not None:
 			contact.mood['text'] = text
 
 def user_tune(items, name, jid):
@@ -76,15 +76,15 @@ def user_tune(items, name, jid):
 				del acc.tune['track']
 			if acc.tune.has_key('length'):
 				del acc.tune['length']
-			if artist != None:
+			if artist is not None:
 				acc.tune['artist'] = artist
-			if title != None:
+			if title is not None:
 				acc.tune['title'] = title
-			if source != None:
+			if source is not None:
 				acc.tune['source'] = source
-			if track != None:
+			if track is not None:
 				acc.tune['track'] = track
-			if length != None:
+			if length is not None:
 				acc.tune['length'] = length
 
 	(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
@@ -102,15 +102,15 @@ def user_tune(items, name, jid):
 			del contact.tune['track']
 		if contact.tune.has_key('length'):
 			del contact.tune['length']
-		if artist != None:
+		if artist is not None:
 			contact.tune['artist'] = artist
-		if title != None:
+		if title is not None:
 			contact.tune['title'] = title
-		if source != None:
+		if source is not None:
 			contact.tune['source'] = source
-		if track != None:
+		if track is not None:
 			contact.tune['track'] = track
-		if length != None:
+		if length is not None:
 			contact.tune['length'] = length
 
 def user_geoloc(items, name, jid):
@@ -143,11 +143,11 @@ def user_activity(items, name, jid):
 				del acc.activity['subactivity']
 			if acc.activity.has_key('text'):
 				del acc.activity['text']
-			if activity != None:
+			if activity is not None:
 				acc.activity['activity'] = activity
-			if subactivity != None:
+			if subactivity is not None:
 				acc.activity['subactivity'] = subactivity
-			if text != None:
+			if text is not None:
 				acc.activity['text'] = text
 
 	(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
@@ -161,11 +161,11 @@ def user_activity(items, name, jid):
 			del contact.activity['subactivity']
 		if contact.activity.has_key('text'):
 			del contact.activity['text']
-		if activity != None:
+		if activity is not None:
 			contact.activity['activity'] = activity
-		if subactivity != None:
+		if subactivity is not None:
 			contact.activity['subactivity'] = subactivity
-		if text != None:
+		if text is not None:
 			contact.activity['text'] = text
 
 def user_send_mood(account, mood, message = ''):
diff --git a/src/common/socks5.py b/src/common/socks5.py
index 3e7feeeb5c..4e02125cab 100644
--- a/src/common/socks5.py
+++ b/src/common/socks5.py
@@ -201,7 +201,7 @@ class SocksQueue:
 		self.idx += 1
 		result = sock5_receiver.connect()
 		self.connected += 1
-		if result != None:
+		if result is not None:
 			result = sock5_receiver.main()
 			self.process_result(result, sock5_receiver)
 			return 1
@@ -547,7 +547,7 @@ class Socks5:
 				self.file_props['completed'] = True
 				return 0
 			# return number of read bytes. It can be used in progressbar
-		if fd != None:
+		if fd is not None:
 			self.file_props['stalled'] = False
 		if fd is None and self.file_props['stalled'] is False:
 			return None
diff --git a/src/common/xmpp/client.py b/src/common/xmpp/client.py
index cc8f773138..bc2335effe 100644
--- a/src/common/xmpp/client.py
+++ b/src/common/xmpp/client.py
@@ -283,7 +283,7 @@ class Component(CommonClient):
             self.Namespace=auth.NS_COMPONENT_1
             self.Server=server[0]
         CommonClient.connect(self,server=server,proxy=proxy)
-        if self.connected and (self.typ=='jabberd2' or not self.typ and self.Dispatcher.Stream.features != None):
+        if self.connected and (self.typ=='jabberd2' or not self.typ and self.Dispatcher.Stream.features is not None):
                 self.defaultNamespace=auth.NS_CLIENT
                 self.Dispatcher.RegisterNamespace(self.defaultNamespace)
                 self.Dispatcher.RegisterProtocol('iq',dispatcher.Iq)
diff --git a/src/common/xmpp/client_nb.py b/src/common/xmpp/client_nb.py
index 6d3a852db4..142a04d853 100644
--- a/src/common/xmpp/client_nb.py
+++ b/src/common/xmpp/client_nb.py
@@ -354,7 +354,7 @@ class Component(NBCommonClient):
 			on_connect = self._on_connect, on_connect_failure = self.on_connect_failure)
 		
 	def _on_connect(self):
-		if self.typ=='jabberd2' or not self.typ and self.Dispatcher.Stream.features != None:
+		if self.typ=='jabberd2' or not self.typ and self.Dispatcher.Stream.features is not None:
 				self.defaultNamespace=auth.NS_CLIENT
 				self.Dispatcher.RegisterNamespace(self.defaultNamespace)
 				self.Dispatcher.RegisterProtocol('iq',dispatcher.Iq)
diff --git a/src/common/xmpp/commands.py b/src/common/xmpp/commands.py
index 673cf894d3..433faee86c 100644
--- a/src/common/xmpp/commands.py
+++ b/src/common/xmpp/commands.py
@@ -115,7 +115,7 @@ class Commands(PlugIn):
             if items != []:
                 for each in items:
                     i = self._handlers[each[0]][each[1]]['disco'](conn,request,'list')
-                    if i != None:
+                    if i is not None:
                         list.append(Node(tag='item',attrs={'jid':i[0],'node':i[1],'name':i[2]}))
                 iq = request.buildReply('result')
                 if request.getQuerynode(): iq.setQuerynode(request.getQuerynode())
@@ -243,7 +243,7 @@ class Command_Handler_Prototype(PlugIn):
                 # Jid and session don't match. Go away imposter
                 self._owner.send(Error(request,ERR_BAD_REQUEST))
                 raise NodeProcessed
-        elif session != None:
+        elif session is not None:
             # Not on this sessionid you won't.
             self._owner.send(Error(request,ERR_BAD_REQUEST))
             raise NodeProcessed
diff --git a/src/common/xmpp/dispatcher.py b/src/common/xmpp/dispatcher.py
index 556690964f..95e0f00b05 100644
--- a/src/common/xmpp/dispatcher.py
+++ b/src/common/xmpp/dispatcher.py
@@ -246,7 +246,7 @@ class Dispatcher(PlugIn):
 
         if not direct and self._owner._component:
             if name == 'route':
-                if stanza.getAttr('error') == None:
+                if stanza.getAttr('error') is None:
                     if len(stanza.getChildren()) == 1:
                         stanza = stanza.getChildren()[0]
                         name=stanza.getName()
diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py
index c09b9921f0..ad68c9bdda 100644
--- a/src/common/xmpp/protocol.py
+++ b/src/common/xmpp/protocol.py
@@ -405,7 +405,7 @@ class Message(Protocol):
         Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
         if body: self.setBody(body)
         if xhtml: self.setXHTML(xhtml)
-        if subject != None: self.setSubject(subject)
+        if subject is not None: self.setSubject(subject)
     def getBody(self):
         """ Returns text of the message. """
         return self.getTagData('body')
diff --git a/src/conversation_textview.py b/src/conversation_textview.py
index cfa8553c49..38d742246c 100644
--- a/src/conversation_textview.py
+++ b/src/conversation_textview.py
@@ -973,7 +973,7 @@ class ConversationTextview:
 			imagepath = self.latex_to_image(special_text)
 			end_iter = buffer.get_end_iter()
 			anchor = buffer.create_child_anchor(end_iter)
-			if imagepath != None:
+			if imagepath is not None:
 				img = gtk.Image()
 				img.set_from_file(imagepath)
 				img.show()
diff --git a/src/gajim.py b/src/gajim.py
index b513034ef2..2c2a11f7db 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -1457,7 +1457,7 @@ class Interface:
 				title = _('Wrong Passphrase')
 				second = _('Please retype your GPG passphrase or press Cancel.')
 		self.gpg_dialog = None
-		if passphrase != None:
+		if passphrase is not None:
 			self.gpg_passphrase[keyid] = passphrase
 			gobject.timeout_add(30000, self.forget_gpg_passphrase, keyid)
 		gajim.connections[account].gpg_passphrase(passphrase)
diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py
index 73e2469a46..6b388a0f4d 100644
--- a/src/gtkgui_helpers.py
+++ b/src/gtkgui_helpers.py
@@ -660,7 +660,7 @@ def possibly_set_gajim_as_xmpp_handler():
 		path_to_kde_file = None
 
 	def set_gajim_as_xmpp_handler(is_checked=None):
-		if is_checked != None:
+		if is_checked is not None:
 			# come from confirmation dialog
 			gajim.config.set('check_if_gajim_is_default', is_checked)
 		path_to_gajim_script, typ = get_abspath_for_script('gajim-remote', True)
diff --git a/src/lastfm.py b/src/lastfm.py
index c658a49123..3e4822b2cb 100644
--- a/src/lastfm.py
+++ b/src/lastfm.py
@@ -192,7 +192,7 @@ class LastFM:
 		if songTuple is None:
 			songTuple = self.getLastRecentSong()
 
-		if songTuple != None:
+		if songTuple is not None:
 			dict = {
 				'a': songTuple[0],
 				'n': songTuple[1],
diff --git a/src/message_window.py b/src/message_window.py
index 31e070147d..72f87435d5 100644
--- a/src/message_window.py
+++ b/src/message_window.py
@@ -784,11 +784,12 @@ class MessageWindowMgr(gobject.GObject):
 		return None
 
 	def has_window(self, jid, acct):
-		return self.get_window(jid, acct) != None
+		return self.get_window(jid, acct) is not None
 
 	def one_window_opened(self, contact=None, acct=None, type=None):
 		try:
-			return self._windows[self._mode_to_key(contact, acct, type)] != None
+			return \
+				self._windows[self._mode_to_key(contact, acct, type)] is not None
 		except KeyError:
 			return False
 
diff --git a/src/notify.py b/src/notify.py
index 6d6a3f599c..cc4f60d011 100644
--- a/src/notify.py
+++ b/src/notify.py
@@ -59,7 +59,7 @@ def get_show_in_roster(event, account, contact):
 	if event == 'gc_message_received':
 		return True
 	num = get_advanced_notification(event, account, contact)
-	if num != None:
+	if num is not None:
 		if gajim.config.get_per('notifications', str(num), 'roster') == 'yes':
 			return True
 		if gajim.config.get_per('notifications', str(num), 'roster') == 'no':
@@ -73,7 +73,7 @@ def get_show_in_roster(event, account, contact):
 def get_show_in_systray(event, account, contact, type_=None):
 	'''Return True if this event must be shown in systray, else False'''
 	num = get_advanced_notification(event, account, contact)
-	if num != None:
+	if num is not None:
 		if gajim.config.get_per('notifications', str(num), 'systray') == 'yes':
 			return True
 		if gajim.config.get_per('notifications', str(num), 'systray') == 'no':
-- 
GitLab