Commit ff6ca570 authored by Philipp Hörist's avatar Philipp Hörist

Fix no-else-return pylint errors

parent d6f02426
......@@ -1081,7 +1081,7 @@ class ChatControl(ChatControlBase):
if self.contact.jid == app.get_jid_from_account(self.account):
return
elif chatstate_setting == 'composing_only' and state != 'active' and\
if chatstate_setting == 'composing_only' and state != 'active' and\
state != 'composing':
return
......
......@@ -610,11 +610,11 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.parent_win.move_to_next_unread_tab(False)
return True
# SHIFT + PAGE_[UP|DOWN]: send to conv_textview
elif event.keyval == Gdk.KEY_Page_Down or \
if event.keyval == Gdk.KEY_Page_Down or \
event.keyval == Gdk.KEY_Page_Up:
self.conv_textview.tv.event(event)
return True
elif event.get_state() & Gdk.ModifierType.CONTROL_MASK:
if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
if event.keyval == Gdk.KEY_Tab: # CTRL + TAB
self.parent_win.move_to_next_unread_tab(True)
return True
......
......@@ -43,7 +43,7 @@ class StandardCommonCommands(CommandContainer):
@command(overlap=True)
@doc(_("Show help on a given command or a list of available commands if -a is given"))
def help(self, cmd=None, all=False):
def help(self, cmd=None, all_=False):
if cmd:
cmd = self.get_command(cmd)
......@@ -58,7 +58,8 @@ class StandardCommonCommands(CommandContainer):
text.append(usage)
return '\n\n'.join(text)
elif all:
if all_:
for cmd_ in self.list_commands():
names = ', '.join(cmd_.names)
description = cmd_.extract_description()
......
......@@ -356,8 +356,7 @@ def get_resource_from_jid(jid):
jids = jid.split('/', 1)
if len(jids) > 1:
return jids[1] # abc@doremi.org/res/res-continued
else:
return ''
return ''
def get_number_of_accounts():
"""
......@@ -481,14 +480,13 @@ def get_transport_name_from_jid(jid, use_config_setting = True):
if host in ('irc', 'icq', 'sms', 'weather', 'mrim', 'facebook'):
return host
elif host == 'gg':
if host == 'gg':
return 'gadu-gadu'
elif host == 'jit':
if host == 'jit':
return 'icq'
elif host == 'facebook':
if host == 'facebook':
return 'facebook'
else:
return None
return None
def jid_is_transport(jid):
# if not '@' or '@' starts the jid then it is transport
......
......@@ -71,12 +71,11 @@ def client_supports(client_caps, requested_feature):
supported_features = cache_item.features
if requested_feature in supported_features:
return True
elif not supported_features and cache_item.status in (NEW, QUERIED, FAKED):
if not supported_features and cache_item.status in (NEW, QUERIED, FAKED):
# assume feature is supported, if we don't know yet, what the client
# is capable of
return requested_feature not in FEATURE_BLACKLIST
else:
return False
return False
def create_suitable_client_caps(node, caps_hash, hash_method, fjid=None):
"""
......@@ -478,7 +477,7 @@ class MucCapsCache:
try:
if nbxmpp.NS_MAM_2 in self.cache[jid].features:
return nbxmpp.NS_MAM_2
elif nbxmpp.NS_MAM_1 in self.cache[jid].features:
if nbxmpp.NS_MAM_1 in self.cache[jid].features:
return nbxmpp.NS_MAM_1
except (KeyError, AttributeError):
return
......
......@@ -537,15 +537,13 @@ class Config:
return None
if type_[0] == 'boolean':
return self.is_valid_bool(val)
elif type_[0] == 'integer':
if type_[0] == 'integer':
return self.is_valid_int(val)
elif type_[0] == 'string':
if type_[0] == 'string':
return self.is_valid_string(val)
else:
if re.match(type_[1], val):
return val
else:
return None
if re.match(type_[1], val):
return val
return None
def set(self, optname, value):
if optname not in self.__options[1]:
......
......@@ -165,7 +165,7 @@ class CommonConnection:
self.gpg.password = None
if signed == 'KEYEXPIRED':
return 'expired'
elif signed == 'BAD_PASSPHRASE':
if signed == 'BAD_PASSPHRASE':
return 'bad_pass'
return 'ok'
......@@ -600,11 +600,11 @@ class Connection(CommonConnection, ConnectionHandlers):
if self.registered_name:
# This returns the full jid we received on the bind event
return self.registered_name
else:
if warn:
log.warning('only bare JID available')
# This returns the bare jid
return nbxmpp.JID(app.get_jid_from_account(self.name))
if warn:
log.warning('only bare JID available')
# This returns the bare jid
return nbxmpp.JID(app.get_jid_from_account(self.name))
def reconnect(self):
# Do not try to reco while we are already trying
......@@ -804,14 +804,14 @@ class Connection(CommonConnection, ConnectionHandlers):
if len(hosts_lowest_prio) == 1:
return hosts_lowest_prio[0]
else:
rndint = random.randint(0, sum(h['weight'] for h in hosts_lowest_prio))
weightsum = 0
for host in sorted(hosts_lowest_prio, key=operator.itemgetter(
'weight')):
weightsum += host['weight']
if weightsum >= rndint:
return host
rndint = random.randint(0, sum(h['weight'] for h in hosts_lowest_prio))
weightsum = 0
for host in sorted(hosts_lowest_prio,
key=operator.itemgetter('weight')):
weightsum += host['weight']
if weightsum >= rndint:
return host
def connect(self, data=None):
"""
......
......@@ -281,15 +281,13 @@ class ConnectionHandlersBase:
if pm:
return self.make_new_session(fjid, thread_id, type_='pm')
else:
return self.make_new_session(fjid, thread_id)
return self.make_new_session(fjid, thread_id)
def find_session(self, jid, thread_id):
try:
if not thread_id:
return self.find_null_session(jid)
else:
return self.sessions[jid][thread_id]
return self.sessions[jid][thread_id]
except KeyError:
return None
......@@ -324,10 +322,9 @@ class ConnectionHandlersBase:
if chat_sessions:
# return the session that we last sent a message in
return sorted(chat_sessions, key=operator.attrgetter('last_send'))[
-1]
else:
return None
return sorted(chat_sessions,
key=operator.attrgetter('last_send'))[-1]
return None
def get_latest_session(self, jid):
"""
......
......@@ -88,8 +88,7 @@ class CommonContact(XMPPEntity):
# show, so we can be sure it's existant. Otherwise, we still
# return caps for a contact that has no resources left.
return False
else:
return caps_cache.client_supports(self.client_caps, requested_feature)
return caps_cache.client_supports(self.client_caps, requested_feature)
class Contact(CommonContact):
......@@ -136,14 +135,13 @@ class Contact(CommonContact):
def get_shown_groups(self):
if self.is_observer():
return [_('Observers')]
elif self.is_groupchat():
if self.is_groupchat():
return [_('Groupchats')]
elif self.is_transport():
if self.is_transport():
return [_('Transports')]
elif not self.groups:
if not self.groups:
return [_('General')]
else:
return self.groups
return self.groups
def is_hidden_from_roster(self):
"""
......@@ -415,8 +413,7 @@ class LegacyContactsAPI:
# Only called if self has no attr_name
if hasattr(self._metacontact_manager, attr_name):
return getattr(self._metacontact_manager, attr_name)
else:
raise AttributeError(attr_name)
raise AttributeError(attr_name)
def create_gc_contact(self, room_jid, account, name='', show='', status='',
role='', affiliation='', jid='', resource='', avatar_sha=None):
......
......@@ -53,8 +53,7 @@ if app.is_installed('GPG'):
if key['trust'] not in ('f', 'u'):
if key['keyid'][-8:] not in self.always_trust:
return '', 'NOT_TRUSTED ' + key['keyid'][-8:]
else:
trust = True
trust = True
result = super(GnuPG, self).encrypt(str_.encode('utf8'), recipients,
always_trust=trust, passphrase=self.passphrase)
......
......@@ -180,9 +180,8 @@ def parse_resource(resource):
try:
if HAS_PRECIS_I18N:
return resource.encode('Nickname').decode('utf-8')
else:
from nbxmpp.stringprepare import resourceprep
return resourceprep.prepare(resource)
from nbxmpp.stringprepare import resourceprep
return resourceprep.prepare(resource)
except UnicodeError:
raise InvalidFormat('Invalid character in resource.')
......@@ -254,13 +253,11 @@ def prep(user, server, resource):
if user:
if resource:
return '%s@%s/%s' % (user, server, resource)
else:
return '%s@%s' % (user, server)
else:
if resource:
return '%s/%s' % (server, resource)
else:
return server
return '%s@%s' % (user, server)
if resource:
return '%s/%s' % (server, resource)
return server
def windowsify(s):
if os.name == 'nt':
......@@ -333,11 +330,11 @@ def get_uf_show(show, use_mnemonic = False):
def get_css_show_color(show):
if show in ('online', 'chat', 'invisible'):
return 'status-online'
elif show in ('offline', 'not in roster', 'requested'):
if show in ('offline', 'not in roster', 'requested'):
return None
elif show in ('xa', 'dnd'):
if show in ('xa', 'dnd'):
return 'status-dnd'
elif show == 'away':
if show == 'away':
return 'status-away'
def get_uf_sub(sub):
......@@ -434,14 +431,14 @@ def get_uf_chatstate(chatstate):
"""
if chatstate == 'active':
return _('is paying attention to the conversation')
elif chatstate == 'inactive':
if chatstate == 'inactive':
return _('is doing something else')
elif chatstate == 'composing':
if chatstate == 'composing':
return _('is composing a message…')
elif chatstate == 'paused':
if chatstate == 'paused':
#paused means he or she was composing but has stopped for a while
return _('paused composing a message')
elif chatstate == 'gone':
if chatstate == 'gone':
return _('has closed the chat window or tab')
return ''
......@@ -456,8 +453,7 @@ def is_in_path(command, return_abs_path=False):
if command in os.listdir(directory):
if return_abs_path:
return os.path.join(directory, command)
else:
return True
return True
except OSError:
# If the user has non directories in his path
pass
......@@ -724,7 +720,7 @@ def check_soundfile_path(file_, dirs=None):
if not file_:
return None
elif os.path.exists(file_):
if os.path.exists(file_):
return file_
for d in dirs:
......@@ -766,7 +762,7 @@ def play_sound_file(path_to_soundfile):
path_to_soundfile = check_soundfile_path(path_to_soundfile)
if path_to_soundfile is None:
return
elif sys.platform == 'win32' and HAS_SOUND:
if sys.platform == 'win32' and HAS_SOUND:
try:
winsound.PlaySound(path_to_soundfile,
winsound.SND_FILENAME|winsound.SND_ASYNC)
......@@ -831,14 +827,14 @@ def statuses_unified():
return False
return True
def get_icon_name_to_show(contact, account = None):
def get_icon_name_to_show(contact, account=None):
"""
Get the icon name to show in online, away, requested, etc
"""
if account and app.events.get_nb_roster_events(account, contact.jid):
return 'event'
if account and app.events.get_nb_roster_events(account,
contact.get_full_jid()):
if account and app.events.get_nb_roster_events(
account, contact.get_full_jid()):
return 'event'
if account and account in app.interface.minimized_controls and \
contact.jid in app.interface.minimized_controls[account] and app.interface.\
......@@ -847,8 +843,7 @@ def get_icon_name_to_show(contact, account = None):
if account and contact.jid in app.gc_connected[account]:
if app.gc_connected[account][contact.jid]:
return 'muc_active'
else:
return 'muc_inactive'
return 'muc_inactive'
if contact.jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent
return contact.show
if contact.sub in ('both', 'to'):
......@@ -956,7 +951,7 @@ def get_chat_control(account, contact):
if contact.resource:
full_jid_with_resource += '/' + contact.resource
highest_contact = app.contacts.get_contact_with_highest_priority(
account, contact.jid)
account, contact.jid)
# Look for a chat control that has the given resource, or default to
# one without resource
......@@ -965,12 +960,14 @@ def get_chat_control(account, contact):
if ctrl:
return ctrl
elif highest_contact and highest_contact.resource and \
contact.resource != highest_contact.resource:
if (highest_contact and
highest_contact.resource and
contact.resource != highest_contact.resource):
return None
else:
# unknown contact or offline message
return app.interface.msg_win_mgr.get_control(contact.jid, account)
# unknown contact or offline message
return app.interface.msg_win_mgr.get_control(contact.jid, account)
def get_notification_icon_tooltip_dict():
"""
......@@ -1122,20 +1119,20 @@ def get_current_show(account):
def get_iconset_path(iconset):
if os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', iconset)):
return os.path.join(configpaths.get('DATA'), 'iconsets', iconset)
elif os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), iconset)):
if os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), iconset)):
return os.path.join(configpaths.get('MY_ICONSETS'), iconset)
def get_mood_iconset_path(iconset):
if os.path.isdir(os.path.join(configpaths.get('DATA'), 'moods', iconset)):
return os.path.join(configpaths.get('DATA'), 'moods', iconset)
elif os.path.isdir(
if os.path.isdir(
os.path.join(configpaths.get('MY_MOOD_ICONSETS'), iconset)):
return os.path.join(configpaths.get('MY_MOOD_ICONSETS'), iconset)
def get_activity_iconset_path(iconset):
if os.path.isdir(os.path.join(configpaths.get('DATA'), 'activities', iconset)):
return os.path.join(configpaths.get('DATA'), 'activities', iconset)
elif os.path.isdir(os.path.join(configpaths.get('MY_ACTIVITY_ICONSETS'),
if os.path.isdir(os.path.join(configpaths.get('MY_ACTIVITY_ICONSETS'),
iconset)):
return os.path.join(configpaths.get('MY_ACTIVITY_ICONSETS'), iconset)
......@@ -1143,7 +1140,7 @@ def get_transport_path(transport):
if os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', 'transports',
transport)):
return os.path.join(configpaths.get('DATA'), 'iconsets', 'transports', transport)
elif os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), 'transports',
if os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), 'transports',
transport)):
return os.path.join(configpaths.get('MY_ICONSETS'), 'transports', transport)
# No transport folder found, use default jabber one
......
......@@ -181,15 +181,15 @@ class ConnectionJingle:
if contact.supports(nbxmpp.NS_HASHES_2):
if contact.supports(nbxmpp.NS_HASHES_BLAKE2B_512):
return 'blake2b-512'
elif contact.supports(nbxmpp.NS_HASHES_BLAKE2B_256):
if contact.supports(nbxmpp.NS_HASHES_BLAKE2B_256):
return 'blake2b-256'
elif contact.supports(nbxmpp.NS_HASHES_SHA3_512):
if contact.supports(nbxmpp.NS_HASHES_SHA3_512):
return 'sha3-512'
elif contact.supports(nbxmpp.NS_HASHES_SHA3_256):
if contact.supports(nbxmpp.NS_HASHES_SHA3_256):
return 'sha3-256'
elif contact.supports(nbxmpp.NS_HASHES_SHA512):
if contact.supports(nbxmpp.NS_HASHES_SHA512):
return 'sha-512'
elif contact.supports(nbxmpp.NS_HASHES_SHA256):
if contact.supports(nbxmpp.NS_HASHES_SHA256):
return 'sha-256'
return None
......@@ -202,11 +202,8 @@ class ConnectionJingle:
if media:
if media not in ('audio', 'video', 'file'):
return tuple()
else:
return (session for session in sessions if \
session.get_content(media))
else:
return sessions
return (session for session in sessions if session.get_content(media))
return sessions
def set_file_info(self, file_):
# Saves information about the files we have transferred in case they need
......@@ -228,9 +225,8 @@ class ConnectionJingle:
if sid:
if sid in self._sessions:
return self._sessions[sid]
else:
return None
elif media:
return None
if media:
if media not in ('audio', 'video', 'file'):
return None
for session in self._sessions.values():
......
......@@ -470,7 +470,7 @@ class JingleVideo(JingleRTPContent):
def get_content(desc):
if desc['media'] == 'audio':
return JingleAudio
elif desc['media'] == 'video':
if desc['media'] == 'video':
return JingleVideo
contents[nbxmpp.NS_JINGLE_RTP] = get_content
......@@ -362,9 +362,8 @@ class Logger:
if jid.find('/') > -1:
possible_room_jid = jid.split('/', 1)[0]
return self.jid_is_room_jid(possible_room_jid)
else:
# it's not a full jid, so it's not a pm one
return False
# it's not a full jid, so it's not a pm one
return False
def jid_is_room_jid(self, jid):
"""
......@@ -465,21 +464,21 @@ class Logger:
if show == 'online':
return ShowConstant.ONLINE
elif show == 'chat':
if show == 'chat':
return ShowConstant.CHAT
elif show == 'away':
if show == 'away':
return ShowConstant.AWAY
elif show == 'xa':
if show == 'xa':
return ShowConstant.XA
elif show == 'dnd':
if show == 'dnd':
return ShowConstant.DND
elif show == 'offline':
if show == 'offline':
return ShowConstant.OFFLINE
elif show is None:
if show is None:
return ShowConstant.ONLINE
else: # invisible in GC when someone goes invisible
# it's a RFC violation .... but we should not crash
return None
# invisible in GC when someone goes invisible
# it's a RFC violation .... but we should not crash
return None
def convert_human_transport_type_to_db_api_values(self, type_):
"""
......
......@@ -24,11 +24,10 @@ def parseLogLevel(arg):
"""
if arg.isdigit():
return int(arg)
elif arg.isupper() and hasattr(logging, arg):
if arg.isupper() and hasattr(logging, arg):
return getattr(logging, arg)
else:
print(_('%s is not a valid loglevel') % repr(arg))
return 0
print(_('%s is not a valid loglevel') % repr(arg))
return 0
def parseLogTarget(arg):
"""
......@@ -39,12 +38,11 @@ def parseLogTarget(arg):
arg = arg.lower()
if not arg:
return 'gajim'
elif arg.startswith('.'):
if arg.startswith('.'):
return arg[1:]
elif arg.startswith('gajim'):
if arg.startswith('gajim'):
return arg
else:
return 'gajim.' + arg
return 'gajim.' + arg
def parseAndSetLogLevels(arg):
"""
......
......@@ -36,8 +36,7 @@ class AbstractPEP:
if items:
log.debug('Received PEP "user %s" from %s', cls.type_, jid)
return cls(jid, account, items)
else:
return None
return None
def __init__(self, jid, account, items):
self.data, self._retracted = self._extract_info(items)
......
......@@ -554,8 +554,8 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
}
proxyhost_dicts.append(host_dict)
return proxyhost_dicts
else:
return []
return []
def _result_socks5_sid(self, sid, hash_id):
"""
......
......@@ -288,7 +288,7 @@ class HostTester(Socks5, IdleObject):
if self.state == 0:
self.do_connect()
return
elif self.state == 1: # send initially: version and auth types
if self.state == 1: # send initially: version and auth types
data = self._get_auth_buff()
self.send_raw(data)
else:
......@@ -408,7 +408,7 @@ class ReceiverTester(Socks5, IdleObject):
if self.state == 0:
self.do_connect()
return
elif self.state == 1: # send initially: version and auth types
if self.state == 1: # send initially: version and auth types
data = self._get_auth_buff()
self.send_raw(data)
else:
......
......@@ -213,7 +213,7 @@ class SocksQueue:
if 'idx' in host:
if host['state'] >= 0:
return
elif host['state'] == -2:
if host['state'] == -2:
unused_hosts = True
if unused_hosts:
for host in file_props.streamhosts:
......@@ -541,12 +541,12 @@ class Socks5:
self.connected = False
return None
# win32 needs this
elif errnum not in (10056, EISCONN) or self.state != 0:
if errnum not in (10056, EISCONN) or self.state != 0:
return None
else: # socket is already connected
self._sock.setblocking(False)
self._send=self._sock.send
self._recv=self._sock.recv
# socket is already connected
self._sock.setblocking(False)
self._send=self._sock.send
self._recv=self._sock.recv
self.buff = ''
self.connected = True
self.file_props.connected = True
......@@ -1312,7 +1312,7 @@ class Socks5Client(Socks5):
if self.state == 0:
self.do_connect()
return
elif self.state == 1: # send initially: version and auth types
if self.state == 1: # send initially: version and auth types
self.send_raw(self._get_auth_buff())
elif self.state == 3: # send 'connect' request
self.send_raw(self._get_request_buff(self._get_sha1_auth()))
......
......@@ -474,14 +474,16 @@ class P2PConnection(IdleObject, PlugIn):
errors += (errno.WSAEINVAL,)
if errnum in errors:
return
# win32 needs this
elif errnum not in (0, 10056, errno.EISCONN) or self.state != 0:
if errnum not in (0, 10056, errno.EISCONN) or self.state != 0:
log.error('Could not connect to %s: %s [%s]', str(self.host),
errnum, errstr)
self.connect_to_next_ip()
return
else: # socket is already connected
self._sock.setblocking(False)
# socket is already connected
self._sock.setblocking(False)
self.state = 1 # connected
# we are connected
self.on_connect(self)
......
......@@ -259,7 +259,7 @@ class Zeroconf:
def replace_show(self, show):
if show in ['chat', 'online', '']:
return 'avail'
elif show == 'xa':
if show == 'xa':
return 'away'
return show
......@@ -336,8 +336,7 @@ class Zeroconf:
self.announced = False
return True
else:
return False
return False
except dbus.DBusException:
log.debug("Can't remove service. That should not happen")
......@@ -485,8 +484,7 @@ class Zeroconf:
txt, reply_handler=self.service_updated_callback,
error_handler=self.error_callback)
return True
else:
return False
return False
# END Zeroconf
......@@ -257,7 +257,7 @@ class Zeroconf:
def replace_show(self, show):
if show in ['chat', 'online', '']:
return 'avail'
elif show == 'xa':
if show == 'xa':
return 'away'
return show
......@@ -327,9 +327,9 @@ class Zeroconf:
# start browsing
if self.browse_domain():
return True
else:
self.disconnect()
return False
self.disconnect()
return False
def disconnect(self):
if self.connected:
......@@ -362,8 +362,7 @@ class Zeroconf:
if error.errorCode == pybonjour.kDNSServiceErr_ServiceNotRunning:
log.info('Service not running')
return False