Commit a3c687da authored by Philipp Hörist's avatar Philipp Hörist Committed by Philipp Hörist
Browse files

Fix len-as-condition pylint errors

parent e953820f
......@@ -236,7 +236,7 @@ def stage2(self):
# close old stage
self.stage_finish()
assert len(self.commandlist)>0
assert self.commandlist
self.stages_notebook.set_current_page(
self.stages_notebook.page_num(self.command_list_stage_vbox))
......
......@@ -48,7 +48,7 @@ def __init__(self):
"""
Create new window... only if we have anything to show
"""
assert len(self.__class__.entries)
assert self.__class__.entries
self.entry = None # the entry actually displayed
......@@ -72,7 +72,7 @@ def displayNextEntry(self):
"""
Get next entry from the queue and display it in the window
"""
assert len(self.__class__.entries)>0
assert self.__class__.entries
newentry = self.__class__.entries.pop(0)
......
......@@ -1377,7 +1377,7 @@ def restore_conversation(self):
local_old_kind = None
else:
local_old_kind = kind
if len(rows):
if rows:
self.conv_textview.print_empty_line()
def read_queue(self):
......
......@@ -1222,7 +1222,7 @@ def _on_edge_reached(self, scrolledwindow, pos):
else: # Not a GC
types_list = ['printed_' + type_, type_]
if not len(app.events.get_events(self.account, jid, types_list)):
if not app.events.get_events(self.account, jid, types_list):
return
if not self.parent_win:
return
......
......@@ -481,7 +481,7 @@ def get_transport_name_from_jid(jid, use_config_setting = True):
# host is now f.e. icq.foo.org or just icq (sometimes on hacky transports)
host_splitted = host.split('.')
if len(host_splitted) != 0:
if host_splitted:
# now we support both 'icq.' and 'icq' but not icqsucks.org
host = host_splitted[0]
......
......@@ -1275,7 +1275,7 @@ def ssl_certificate_accepted(self):
for mech in auth_mechs:
if mech not in nbxmpp.auth_nb.SASL_AUTHENTICATION_MECHANISMS | set(['XEP-0078']):
log.warning("Unknown authentication mechanisms %s" % mech)
if len(auth_mechs) == 0:
if not auth_mechs:
auth_mechs = None
else:
auth_mechs = set(auth_mechs)
......@@ -1453,7 +1453,7 @@ def _discover_server_at_connection(self, con):
self._on_stun_resolved)
def _on_stun_resolved(self, host, result_array):
if len(result_array) != 0:
if result_array:
self._stun_servers = self._hosts = [i for i in result_array]
@helpers.call_counter
......
......@@ -156,7 +156,7 @@ def is_hidden_from_roster(self):
return False
if self.sub in ('none', 'from') and self.ask == 'subscribe':
return False
if self.sub in ('none', 'from') and (self.name or len(self.groups)):
if self.sub in ('none', 'from') and (self.name or self.groups):
return False
if _('Not in Roster') in self.groups:
return False
......@@ -486,7 +486,7 @@ def remove_contact(self, contact):
return
if contact in self._contacts[contact.jid]:
self._contacts[contact.jid].remove(contact)
if len(self._contacts[contact.jid]) == 0:
if not self._contacts[contact.jid]:
del self._contacts[contact.jid]
def remove_jid(self, jid):
......@@ -626,7 +626,7 @@ def remove_gc_contact(self, gc_contact):
return
del self._rooms[gc_contact.room_jid][gc_contact.name]
# It was the last nick in room ?
if not len(self._rooms[gc_contact.room_jid]):
if not self._rooms[gc_contact.room_jid]:
del self._rooms[gc_contact.room_jid]
def remove_room(self, room_jid):
......
......@@ -214,7 +214,7 @@ def prep(user, server, resource):
if server is not None:
if server.endswith('.'): # RFC7622, 3.2
server = server[:-1]
if len(server) < 1 or len(server.encode('utf-8')) > 1023:
if not server or len(server.encode('utf-8')) > 1023:
raise InvalidFormat(_('Server must be between 1 and 1023 bytes'))
try:
from nbxmpp.stringprepare import nameprep
......@@ -225,7 +225,7 @@ def prep(user, server, resource):
raise InvalidFormat(_('Server address required.'))
if user is not None:
if len(user) < 1 or len(user.encode('utf-8')) > 1023:
if not user or len(user.encode('utf-8')) > 1023:
raise InvalidFormat(_('Username must be between 1 and 1023 bytes'))
try:
if HAS_PRECIS_I18N:
......@@ -239,7 +239,7 @@ def prep(user, server, resource):
user = None
if resource is not None:
if len(resource) < 1 or len(resource.encode('utf-8')) > 1023:
if not resource or len(resource.encode('utf-8')) > 1023:
raise InvalidFormat(_('Resource must be between 1 and 1023 bytes'))
try:
if HAS_PRECIS_I18N:
......@@ -1054,7 +1054,7 @@ def get_notification_icon_tooltip_text():
accounts = get_notification_icon_tooltip_dict()
if len(accounts) == 0:
if not accounts:
# No configured account
return _('Gajim')
......
......@@ -126,11 +126,11 @@ def write(self):
def update_config(self, old_version, new_version):
old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y)
old = []
while len(old_version_list):
while old_version_list:
old.append(int(old_version_list.pop(0)))
new_version_list = new_version.split('.')
new = []
while len(new_version_list):
while new_version_list:
new.append(int(new_version_list.pop(0)))
if old < [0, 14, 0, 1] and new >= [0, 14, 0, 1]:
......
......@@ -426,7 +426,7 @@ def remove_sender(self, idx, do_disconnect=True, remove_all=False):
self.remove_sender_by_key(key, do_disconnect=do_disconnect)
if not remove_all:
break
if len(self.senders) == 0 and self.listener is not None:
if not self.senders and self.listener is not None:
self.listener.disconnect()
self.listener = None
self.connected -= 1
......@@ -646,7 +646,7 @@ def receive(self):
except Exception:
add = b''
received += add
if len(add) == 0:
if not add:
self.disconnect()
return add
......@@ -676,7 +676,7 @@ def write_next(self):
self.file_props.error = -7 # unable to read from file
return -1
buff = self.file.read(MAX_BUFF_LEN)
if len(buff) > 0:
if buff:
lenn = 0
try:
lenn = self._send(buff)
......@@ -765,7 +765,7 @@ def get_file_contents(self, timeout):
self.file_props.last_time
self.file_props.last_time = current_time
self.file_props.received_len += len(buff)
if len(buff) == 0:
if not buff:
# Transfer stopped somehow:
# reset, paused or network error
self.rem_fd(fd)
......
......@@ -373,14 +373,16 @@ def get_next_addrinfo(self):
except socket.gaierror as e:
log.info('Lookup failure for %s: %s[%s]', self.host, e[1],
repr(e[0]), exc_info=True)
if len(self.addresses_) > 0: return self.get_next_addrinfo()
if self.addresses_:
return self.get_next_addrinfo()
else:
self.connect_to_next_ip()
def connect_to_next_ip(self):
if len(self.ais) == 0:
if not self.ais:
log.error('Connection failure to %s', str(self.host), exc_info=True)
if len(self.addresses_) > 0: return self.get_next_addrinfo()
if self.addresses_:
return self.get_next_addrinfo()
self.disconnect()
return
ai = self.ais.pop(0)
......@@ -449,7 +451,7 @@ def send(self, packet, is_message=False, now=False):
def read_timeout(self):
ids = self.client.conn_holder.ids_of_awaiting_messages
if self.fd in ids and len(ids[self.fd]) > 0:
if self.fd in ids and ids[self.fd]:
for (id_, thread_id) in ids[self.fd]:
if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event('', DATA_ERROR, (
......
......@@ -265,7 +265,7 @@ def refresh_multiple_buttons(self):
self.up_button.set_sensitive(False)
self.down_button.set_sensitive(False)
if len(model) == 0:
if not model:
self.clear_button.set_sensitive(False)
else:
self.clear_button.set_sensitive(True)
......
......@@ -532,7 +532,7 @@ def _format_time(self, _time):
return _('%(hours)02.d:%(minutes)02.d:%(seconds)02.d') % times
def _get_eta_and_speed(self, full_size, transfered_size, file_props):
if len(file_props.transfered_size) == 0:
if not file_props.transfered_size:
return 0., 0.
elif len(file_props.transfered_size) == 1:
speed = round(float(transfered_size) / file_props.elapsed_time)
......@@ -739,7 +739,7 @@ def set_cleanup_sensitivity(self):
Check if there are transfer rows and set cleanup_button sensitive, or
insensitive if model is empty
"""
if len(self.model) == 0:
if not self.model:
self.cleanup_button.set_sensitive(False)
else:
self.cleanup_button.set_sensitive(True)
......
......@@ -369,7 +369,7 @@ def help_on_command(self, command):
str_ = _('Usage: %(basename)s %(command)s %(arguments)s \n\t %(help)s')\
% {'basename': BASENAME, 'command': command,
'arguments': arguments_str, 'help': command_props[0]}
if len(command_props[1]) > 0:
if command_props[1]:
str_ += '\n\n' + _('Arguments:') + '\n'
for argument in command_props[1]:
str_ += ' ' + argument[0] + ' - ' + argument[1] + '\n'
......
......@@ -1702,8 +1702,7 @@ def draw_contact(self, nick, selected=False, focus=False):
gc_contact = app.contacts.get_gc_contact(self.account, self.room_jid,
nick)
theme = Gtk.IconTheme.get_default()
if len(app.events.get_events(self.account, self.room_jid + '/' + \
nick)):
if app.events.get_events(self.account, self.room_jid + '/' + nick):
icon_name = gtkgui_helpers.get_iconset_name_for('event')
surface = theme.load_surface(icon_name, 16, self.scale_factor, None, 0)
else:
......@@ -1914,8 +1913,8 @@ def _nec_gc_presence_received(self, obj):
self.autorejoin = False
self.print_conversation(obj.reason, 'info', graphics=False)
if len(app.events.get_events(self.account, jid=obj.fjid,
types=['pm'])) == 0:
if not app.events.get_events(
self.account, jid=obj.fjid, types=['pm']):
self.remove_contact(obj.nick)
self.draw_all_roles()
else:
......@@ -2471,7 +2470,7 @@ def _on_message_textview_key_press_event(self, widget, event):
# nick completion
# check if tab is pressed with empty message
if len(splitted_text): # if there are any words
if splitted_text: # if there are any words
begin = splitted_text[-1] # last word we typed
else:
begin = ''
......@@ -2485,7 +2484,7 @@ def _on_message_textview_key_press_event(self, widget, event):
gc_refer_to_nick_char + ' '):
with_refer_to_nick_char = True
after_nick_len = len(gc_refer_to_nick_char + ' ')
if len(self.nick_hits) and self.last_key_tabs and \
if self.nick_hits and self.last_key_tabs and \
text[:-after_nick_len].endswith(self.nick_hits[0]):
# we should cycle
# Previous nick in list may had a space inside, so we check text
......@@ -2512,7 +2511,7 @@ def _on_message_textview_key_press_event(self, widget, event):
helpers.jid_is_blocked(self.account, fjid):
# the word is the beginning of a nick
self.nick_hits.append(nick)
if len(self.nick_hits):
if self.nick_hits:
if len(splitted_text) < 2 or with_refer_to_nick_char:
# This is the 1st word of the line or no word or we are cycling
# at the beginning, possibly with a space in one nick
......
......@@ -727,7 +727,7 @@ def setup_dialog(self):
app.config.get('gc_proposed_nick_char'))
def check_next(self):
if len(self.room_queue) == 0:
if not self.room_queue:
self.cancel_handler = None
self.dialog.destroy()
if 'change_nick_dialog' in app.interface.instances:
......
......@@ -475,7 +475,7 @@ def get_per_account_option(self, opt):
Return the value of the option opt if it's the same in all accounts else
returns "mixed"
"""
if len(app.connections) == 0:
if not app.connections:
# a non existent key return default value
return app.config.get_per('accounts', '__default__', opt)
val = None
......
......@@ -153,7 +153,7 @@ def privacy_list_received(self, rules):
self.max_order = int(rule['order'])
self.global_rules[text_item] = rule
model.append([text_item])
if len(rules) == 0:
if not rules:
self.title_hbox.set_sensitive(False)
self.list_of_rules_combobox.set_sensitive(False)
self.delete_rule_button.set_sensitive(False)
......@@ -474,7 +474,7 @@ def draw_privacy_lists_in_combobox(self, privacy_lists):
self.draw_widgets()
def draw_widgets(self):
if len(self.privacy_lists_save) == 0:
if not self.privacy_lists_save:
self.list_of_privacy_lists_combobox.set_sensitive(False)
self.open_privacy_list_button.set_sensitive(False)
self.delete_privacy_list_button.set_sensitive(False)
......
......@@ -1974,7 +1974,7 @@ def new_private_chat(self, gc_contact, account, session=None):
if s.control:
session = s
break
if not session and not len(sessions) == 0:
if not session and sessions:
# there are no sessions with chat controls, just take the first
# one
session = sessions[0]
......@@ -2018,7 +2018,7 @@ def new_chat(self, contact, account, resource=None, session=None):
mw.new_tab(chat_control)
if len(app.events.get_events(account, fjid)):
if app.events.get_events(account, fjid):
# We call this here to avoid race conditions with widget validation
chat_control.read_queue()
......@@ -2038,7 +2038,7 @@ def new_chat_from_jid(self, account, fjid, message=None):
if not ctrl:
ctrl = self.new_chat(contact, account,
resource=resource)
if len(app.events.get_events(account, fjid)):
if app.events.get_events(account, fjid):
ctrl.read_queue()
if message:
......@@ -2644,7 +2644,7 @@ def __init__(self):
# except Exception:
# pass
# add default status messages if there is not in the config file
if len(app.config.get_per('statusmsg')) == 0:
if not app.config.get_per('statusmsg'):
default = app.config.statusmsg_default
for msg in default:
app.config.add_per('statusmsg', msg)
......@@ -2662,7 +2662,7 @@ def __init__(self):
default[msg][5])
# Add Tor proxy if there is not in the config
if len(app.config.get_per('proxies')) == 0:
if not app.config.get_per('proxies'):
default = app.config.proxies_default
for proxy in default:
app.config.add_per('proxies', proxy)
......@@ -2807,7 +2807,7 @@ def interrupt(self, account=None):
self.callbacks.remove((acct, cb))
else:
self.callbacks = []
if not len(self.callbacks):
if not self.callbacks:
self.dialog.window.destroy()
def run_callback(self, account, callback):
......
......@@ -111,7 +111,7 @@ def build_invite_submenu(invite_menuitem, list_, ignore_rooms=None,
for (c, a) in list_:
if c.supports(NS_MUC):
list2.append((c, a))
if len(list2) > 0:
if list2:
invite_to_new_room_menuitem.connect('activate',
roster.on_invite_to_new_room, list2, None)
else:
......@@ -144,7 +144,7 @@ def build_invite_submenu(invite_menuitem, list_, ignore_rooms=None,
app.gc_connected[acct][room_jid] and \
contacts_transport in ['jabber', None]:
rooms.append((room_jid, acct))
if len(rooms):
if rooms:
item = Gtk.SeparatorMenuItem.new() # separator
invite_to_submenu.append(item)
for (room_jid, account) in rooms:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment