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
roster_win.py is NOT checked here (waiting for modelfilter)
This commit is contained in:
Jean-Marie Traissard 2008-04-18 00:02:56 +00:00
parent b35b2f9ad0
commit 2ce13dc40e
16 changed files with 29 additions and 29 deletions

View file

@ -150,7 +150,7 @@ if gajim.HAVE_GPG:
return 'BAD_PASSPHRASE' return 'BAD_PASSPHRASE'
def verify(self, str, sign): def verify(self, str, sign):
if str == None: if str is None:
return '' return ''
f = tmpfile() f = tmpfile()
fd = f.fileno() fd = f.fileno()

View file

@ -339,9 +339,9 @@ class GnuPG:
and can be written to. and can be written to.
""" """
if args == None: args = [] if args is None: args = []
if create_fhs == None: create_fhs = [] if create_fhs is None: create_fhs = []
if attach_fhs == None: attach_fhs = {} if attach_fhs is None: attach_fhs = {}
for std in _stds: for std in _stds:
if not attach_fhs.has_key(std) \ if not attach_fhs.has_key(std) \

View file

@ -191,7 +191,7 @@ class ConnectionBytestream:
ft_add_hosts.append(ft_host) ft_add_hosts.append(ft_host)
listener = gajim.socks5queue.start_listener(port, listener = gajim.socks5queue.start_listener(port,
sha_str, self._result_socks5_sid, file_props['sid']) sha_str, self._result_socks5_sid, file_props['sid'])
if listener == None: if listener is None:
file_props['error'] = -5 file_props['error'] = -5
self.dispatch('FILE_REQUEST_ERROR', (unicode(receiver), file_props, self.dispatch('FILE_REQUEST_ERROR', (unicode(receiver), file_props,
'')) ''))

View file

@ -644,7 +644,7 @@ def statuses_unified():
if not gajim.config.get_per('accounts', account, if not gajim.config.get_per('accounts', account,
'sync_with_global_status'): 'sync_with_global_status'):
continue continue
if reference == None: if reference is None:
reference = gajim.connections[account].connected reference = gajim.connections[account].connected
elif reference != gajim.connections[account].connected: elif reference != gajim.connections[account].connected:
return False return False

View file

@ -83,7 +83,7 @@ class OptionsParser:
return True return True
def write_line(self, fd, opt, parents, value): def write_line(self, fd, opt, parents, value):
if value == None: if value is None:
return return
value = value[1] value = value[1]
# convert to utf8 before writing to file if needed # convert to utf8 before writing to file if needed

View file

@ -81,7 +81,7 @@ class SocksQueue:
and do a socks5 authentication using sid for generated sha and do a socks5 authentication using sid for generated sha
''' '''
self.sha_handlers[sha_str] = (sha_handler, sid) self.sha_handlers[sha_str] = (sha_handler, sid)
if self.listener == None: if self.listener is None:
self.listener = Socks5Listener(self.idlequeue, port) self.listener = Socks5Listener(self.idlequeue, port)
self.listener.queue = self self.listener.queue = self
self.listener.bind() self.listener.bind()
@ -372,7 +372,7 @@ class Socks5:
self.file = None self.file = None
def open_file_for_reading(self): def open_file_for_reading(self):
if self.file == None: if self.file is None:
try: try:
self.file = open(self.file_props['file-name'],'rb') self.file = open(self.file_props['file-name'],'rb')
if self.file_props.has_key('offset') and self.file_props['offset']: if self.file_props.has_key('offset') and self.file_props['offset']:
@ -549,7 +549,7 @@ class Socks5:
# return number of read bytes. It can be used in progressbar # return number of read bytes. It can be used in progressbar
if fd != None: if fd != None:
self.file_props['stalled'] = False self.file_props['stalled'] = False
if fd == None and self.file_props['stalled'] is False: if fd is None and self.file_props['stalled'] is False:
return None return None
if self.file_props.has_key('received-len'): if self.file_props.has_key('received-len'):
if self.file_props['received-len'] != 0: if self.file_props['received-len'] != 0:
@ -1019,7 +1019,7 @@ class Socks5Receiver(Socks5, IdleObject):
if version != 0x05 or method == 0xff: if version != 0x05 or method == 0xff:
self.disconnect() self.disconnect()
elif self.state == 4: # get approve of our request elif self.state == 4: # get approve of our request
if buff == None: if buff is None:
return None return None
sub_buff = buff[:4] sub_buff = buff[:4]
if len(sub_buff) < 4: if len(sub_buff) < 4:

View file

@ -226,11 +226,11 @@ class EncryptedStanzaSession(StanzaSession):
self.hmac(k, 'Responder SIGMA Key') ) self.hmac(k, 'Responder SIGMA Key') )
def compress(self, plaintext): def compress(self, plaintext):
if self.compression == None: if self.compression is None:
return plaintext return plaintext
def decompress(self, compressed): def decompress(self, compressed):
if self.compression == None: if self.compression is None:
return compressed return compressed
def encrypt(self, encryptable): def encrypt(self, encryptable):
@ -865,7 +865,7 @@ class EncryptedStanzaSession(StanzaSession):
def fail_bad_negotiation(self, reason, fields = None): def fail_bad_negotiation(self, reason, fields = None):
'''sends an error and cancels everything. '''sends an error and cancels everything.
if fields == None, the remote party has given us a bad cryptographic value of some kind if fields is None, the remote party has given us a bad cryptographic value of some kind
otherwise, list the fields we haven't implemented''' otherwise, list the fields we haven't implemented'''

View file

@ -227,7 +227,7 @@ class Command_Handler_Prototype(PlugIn):
action = request.getTagAttr('command','action') action = request.getTagAttr('command','action')
except: except:
action = None action = None
if action == None: action = 'execute' if action is None: action = 'execute'
# Check session is in session list # Check session is in session list
if self.sessions.has_key(session): if self.sessions.has_key(session):
if self.sessions[session]['jid']==request.getFrom(): if self.sessions[session]['jid']==request.getFrom():
@ -279,7 +279,7 @@ class TestCommand(Command_Handler_Prototype):
session = request.getTagAttr('command','sessionid') session = request.getTagAttr('command','sessionid')
except: except:
session = None session = None
if session == None: if session is None:
session = self.getSessionID() session = self.getSessionID()
sessions[session]={'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage},'data':{'type':None}} sessions[session]={'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage},'data':{'type':None}}
# As this is the first stage we only send a form # As this is the first stage we only send a form

View file

@ -355,7 +355,7 @@ class Debug:
lst2 = self._as_one_list( l ) lst2 = self._as_one_list( l )
for l2 in lst2: for l2 in lst2:
self._append_unique_str(r, l2 ) self._append_unique_str(r, l2 )
elif l == None: elif l is None:
continue continue
else: else:
self._append_unique_str(r, l ) self._append_unique_str(r, l )

View file

@ -287,7 +287,7 @@ class Dispatcher(PlugIn):
if not direct and self._owner._component: if not direct and self._owner._component:
if name == 'route': if name == 'route':
if stanza.getAttr('error') == None: if stanza.getAttr('error') is None:
if len(stanza.getChildren()) == 1: if len(stanza.getChildren()) == 1:
stanza = stanza.getChildren()[0] stanza = stanza.getChildren()[0]
name=stanza.getName() name=stanza.getName()

View file

@ -65,7 +65,7 @@ class Roster(PlugIn):
""" Subscription tracker. Used internally for setting items state in """ Subscription tracker. Used internally for setting items state in
internal roster representation. """ internal roster representation. """
sender = stanza.getAttr('from') sender = stanza.getAttr('from')
if not sender == None and not sender.bareMatch( if not sender is None and not sender.bareMatch(
self._owner.User + '@' + self._owner.Server): self._owner.User + '@' + self._owner.Server):
return return
for item in stanza.getTag('query').getTags('item'): for item in stanza.getTag('query').getTags('item'):

View file

@ -653,7 +653,7 @@ class AddNewContactWindow:
def __init__(self, account = None, jid = None, user_nick = None, def __init__(self, account = None, jid = None, user_nick = None,
group = None): group = None):
self.account = account self.account = account
if account == None: if account is None:
# fill accounts with active accounts # fill accounts with active accounts
accounts = [] accounts = []
for account in gajim.connections.keys(): for account in gajim.connections.keys():

View file

@ -2166,7 +2166,7 @@ class Interface:
def handle_event_ping_sent(self, account, contact): def handle_event_ping_sent(self, account, contact):
ctrl = self.msg_win_mgr.get_control(contact.get_full_jid(), account) ctrl = self.msg_win_mgr.get_control(contact.get_full_jid(), account)
if ctrl == None: if ctrl is None:
ctrl = self.msg_win_mgr.get_control(contact.jid, account) ctrl = self.msg_win_mgr.get_control(contact.jid, account)
ctrl.print_conversation(_('Ping?'), 'status') ctrl.print_conversation(_('Ping?'), 'status')
@ -2174,14 +2174,14 @@ class Interface:
contact = data[0] contact = data[0]
seconds = data[1] seconds = data[1]
ctrl = self.msg_win_mgr.get_control(contact.get_full_jid(), account) ctrl = self.msg_win_mgr.get_control(contact.get_full_jid(), account)
if ctrl == None: if ctrl is None:
ctrl = self.msg_win_mgr.get_control(contact.jid, account) ctrl = self.msg_win_mgr.get_control(contact.jid, account)
if ctrl: if ctrl:
ctrl.print_conversation(_('Pong! (%s s.)') % seconds, 'status') ctrl.print_conversation(_('Pong! (%s s.)') % seconds, 'status')
def handle_event_ping_error(self, account, contact): def handle_event_ping_error(self, account, contact):
ctrl = self.msg_win_mgr.get_control(contact.get_full_jid(), account) ctrl = self.msg_win_mgr.get_control(contact.get_full_jid(), account)
if ctrl == None: if ctrl is None:
ctrl = self.msg_win_mgr.get_control(contact.jid, account) ctrl = self.msg_win_mgr.get_control(contact.jid, account)
if ctrl: if ctrl:
ctrl.print_conversation(_('Error.'), 'status') ctrl.print_conversation(_('Error.'), 'status')
@ -2393,7 +2393,7 @@ class Interface:
shows[show].append(a) shows[show].append(a)
for show in shows: for show in shows:
message = self.roster.get_status_message(show) message = self.roster.get_status_message(show)
if message == None: if message is None:
continue continue
for a in shows[show]: for a in shows[show]:
self.roster.send_status(a, show, message) self.roster.send_status(a, show, message)

View file

@ -147,7 +147,7 @@ class LastFM:
lst, the Unix time at which a song has been scrobbled, defaults to that lst, the Unix time at which a song has been scrobbled, defaults to that
of the last song of the last song
""" """
if lst == None: if lst is None:
lst = self.getLastScrobbledTime() lst = self.getLastScrobbledTime()
return int(time()) - lst return int(time()) - lst
@ -158,7 +158,7 @@ class LastFM:
delay, the delay to use, defaults to self.MAX_DELAY delay, the delay to use, defaults to self.MAX_DELAY
""" """
if delay == None: if delay is None:
delay = self.MAX_DELAY delay = self.MAX_DELAY
return self.timeSinceLastScrobbled() < delay return self.timeSinceLastScrobbled() < delay
@ -189,7 +189,7 @@ class LastFM:
songTuple, the tuple representing the song, defaults to the last song songTuple, the tuple representing the song, defaults to the last song
""" """
str = '' str = ''
if songTuple == None: if songTuple is None:
songTuple = self.getLastRecentSong() songTuple = self.getLastRecentSong()
if songTuple != None: if songTuple != None:

View file

@ -547,7 +547,7 @@ class MessageWindow(object):
else: else:
page_num = key page_num = key
notebook = self.notebook notebook = self.notebook
if page_num == None: if page_num is None:
page_num = notebook.get_current_page() page_num = notebook.get_current_page()
nth_child = notebook.get_nth_page(page_num) nth_child = notebook.get_nth_page(page_num)
return self._widget_to_control(nth_child) return self._widget_to_control(nth_child)

View file

@ -610,7 +610,7 @@ class SignalObject(dbus.service.Object):
return None return None
prim_contact = None # primary contact prim_contact = None # primary contact
for contact in contacts: for contact in contacts:
if prim_contact == None or contact.priority > prim_contact.priority: if prim_contact is None or contact.priority > prim_contact.priority:
prim_contact = contact prim_contact = contact
contact_dict = DBUS_DICT_SV() contact_dict = DBUS_DICT_SV()
contact_dict['name'] = DBUS_STRING(prim_contact.name) contact_dict['name'] = DBUS_STRING(prim_contact.name)