Fix len-as-condition pylint errors

This commit is contained in:
Philipp Hörist 2018-09-16 01:10:04 +02:00 committed by Philipp Hörist
parent e953820ff8
commit a3c687dae1
26 changed files with 80 additions and 80 deletions

View File

@ -236,7 +236,7 @@ class CommandWindow:
# 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))

View File

@ -48,7 +48,7 @@ class AtomWindow:
"""
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 @@ class AtomWindow:
"""
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)

View File

@ -1377,7 +1377,7 @@ class ChatControl(ChatControlBase):
local_old_kind = None
else:
local_old_kind = kind
if len(rows):
if rows:
self.conv_textview.print_empty_line()
def read_queue(self):

View File

@ -1222,7 +1222,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
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

View File

@ -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]

View File

@ -1275,7 +1275,7 @@ class Connection(CommonConnection, ConnectionHandlers):
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 @@ class Connection(CommonConnection, ConnectionHandlers):
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

View File

@ -156,7 +156,7 @@ class Contact(CommonContact):
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 @@ class Contacts():
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 @@ class GC_Contacts():
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):

View File

@ -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')

View File

@ -126,11 +126,11 @@ class OptionsParser:
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]:

View File

@ -426,7 +426,7 @@ class SocksQueue:
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 @@ class Socks5(object):
except Exception:
add = b''
received += add
if len(add) == 0:
if not add:
self.disconnect()
return add
@ -676,7 +676,7 @@ class Socks5(object):
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 @@ class Socks5(object):
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)

View File

@ -373,14 +373,16 @@ class P2PConnection(IdleObject, PlugIn):
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 @@ class P2PConnection(IdleObject, PlugIn):
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, (

View File

@ -265,7 +265,7 @@ class DataFormWidget(Gtk.Alignment, object):
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)

View File

@ -532,7 +532,7 @@ class FileTransfersWindow:
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 @@ class FileTransfersWindow:
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)

View File

@ -369,7 +369,7 @@ class GajimRemote:
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'

View File

@ -1702,8 +1702,7 @@ class GroupchatControl(ChatControlBase):
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 @@ class GroupchatControl(ChatControlBase):
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 @@ class GroupchatControl(ChatControlBase):
# 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 @@ class GroupchatControl(ChatControlBase):
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 @@ class GroupchatControl(ChatControlBase):
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

View File

@ -727,7 +727,7 @@ class ChangeNickDialog(InputDialogCheck):
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:

View File

@ -475,7 +475,7 @@ class Preferences(Gtk.ApplicationWindow):
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

View File

@ -153,7 +153,7 @@ class PrivacyListWindow:
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 @@ class PrivacyListsWindow:
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)

View File

@ -1974,7 +1974,7 @@ class Interface:
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 @@ class Interface:
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 @@ class Interface:
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 @@ class Interface:
# 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 @@ class Interface:
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 @@ class PassphraseRequest:
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):

View File

@ -111,7 +111,7 @@ show_bookmarked=False, force_resource=False):
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 @@ show_bookmarked=False, force_resource=False):
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:

View File

@ -570,7 +570,7 @@ class MessageWindow(object):
del self._controls[ctrl.account][fjid]
if len(self._controls[ctrl.account]) == 0:
if not self._controls[ctrl.account]:
del self._controls[ctrl.account]
self.check_tabs()

View File

@ -155,7 +155,7 @@ class MusicTrackListener(GObject.GObject):
info.title = meta.get('xesam:title')
info.album = meta.get('xesam:album')
artist = meta.get('xesam:artist')
if artist is not None and len(artist):
if artist:
info.artist = artist[0]
else:
info.artist = None

View File

@ -388,7 +388,7 @@ class RosterWindow:
parent_iters = self._get_contact_iter(
big_brother_contact.jid, big_brother_account,
big_brother_contact, self.model)
assert len(parent_iters) > 0, 'Big brother is not yet in roster!'
assert parent_iters, 'Big brother is not yet in roster!'
# Do not confuse get_contact_iter: Sync groups of family members
contact.groups = big_brother_contact.groups[:]
@ -445,8 +445,7 @@ class RosterWindow:
if group not in app.groups[account]:
app.groups[account][group] = {'expand': is_expanded}
assert len(added_iters), '%s has not been added to roster!' % \
contact.jid
assert added_iters, '%s has not been added to roster!' % contact.jid
return added_iters
def _remove_entity(self, contact, account, groups=None):
@ -530,8 +529,8 @@ class RosterWindow:
big_brother_contact = app.contacts.get_first_contact_from_jid(
big_brother_account, big_brother_jid)
assert len(self._get_contact_iter(big_brother_jid,
big_brother_account, big_brother_contact, self.model)) == 0, \
assert not self._get_contact_iter(big_brother_jid,
big_brother_account, big_brother_contact, self.model), \
'Big brother %s already in roster\n Family: %s' \
% (big_brother_jid, family)
self._add_entity(big_brother_contact, big_brother_account)
@ -549,8 +548,8 @@ class RosterWindow:
# or brother already added
continue
assert len(self._get_contact_iter(_jid, _account,
_contact, self.model)) == 0, \
assert not self._get_contact_iter(_jid, _account,
_contact, self.model), \
"%s already in roster.\n Family: %s" % (_jid, nearby_family)
self._add_entity(_contact, _account,
big_brother_contact = big_brother_contact,
@ -600,8 +599,8 @@ class RosterWindow:
ok = self._remove_entity(_contact, _account)
assert ok, '%s was not removed' % _jid
assert len(self._get_contact_iter(_jid, _account, _contact,
self.model)) == 0, '%s is removed but still in roster' % _jid
assert not self._get_contact_iter(_jid, _account, _contact,
self.model), '%s is removed but still in roster' % _jid
if not family_in_roster:
return False
@ -610,15 +609,15 @@ class RosterWindow:
(nearby_family, family)
iters = self._get_contact_iter(old_big_jid, old_big_account,
old_big_contact, self.model)
assert len(iters) > 0, 'Old Big Brother %s is not in roster anymore' % \
assert iters, 'Old Big Brother %s is not in roster anymore' % \
old_big_jid
assert not self.model.iter_children(iters[0]), \
'Old Big Brother %s still has children' % old_big_jid
ok = self._remove_entity(old_big_contact, old_big_account)
assert ok, "Old Big Brother %s not removed" % old_big_jid
assert len(self._get_contact_iter(old_big_jid, old_big_account,
old_big_contact, self.model)) == 0, \
assert not self._get_contact_iter(old_big_jid, old_big_account,
old_big_contact, self.model), \
'Old Big Brother %s is removed but still in roster' % old_big_jid
return True
@ -683,8 +682,8 @@ class RosterWindow:
jid = app.get_jid_from_account(account)
contact = app.contacts.get_first_contact_from_jid(account, jid)
assert len(self._get_contact_iter(jid, account, contact,
self.model)) == 0, 'Self contact %s already in roster' % jid
assert not self._get_contact_iter(jid, account, contact,
self.model), 'Self contact %s already in roster' % jid
child_iterA = self._get_account_iter(account, self.model)
self._iters[account]['contacts'][jid] = [self.model.append(child_iterA,
@ -716,7 +715,7 @@ class RosterWindow:
account -- the corresponding account.
"""
contact = app.contacts.get_contact_with_highest_priority(account, jid)
if len(self._get_contact_iter(jid, account, contact, self.model)):
if self._get_contact_iter(jid, account, contact, self.model):
# If contact already in roster, do nothing
return
@ -1152,8 +1151,8 @@ class RosterWindow:
to_hide = []
while(iterG):
parent = self.modelfilter.iter_parent(iterG)
if (not self.modelfilter.iter_has_child(iterG)) or (len(to_hide) > \
0 and self.modelfilter.iter_n_children(iterG) == 1):
if (not self.modelfilter.iter_has_child(iterG)) or (to_hide \
and self.modelfilter.iter_n_children(iterG) == 1):
to_hide.append(iterG)
if not parent or self.modelfilter[parent][Column.TYPE] != \
'group':
@ -1300,7 +1299,7 @@ class RosterWindow:
# a child has awaiting messages?
jidC = self.model[iterC][Column.JID]
accountC = self.model[iterC][Column.ACCOUNT]
if len(app.events.get_events(accountC, jidC)):
if app.events.get_events(accountC, jidC):
icon_name = 'event'
break
iterC = self.model.iter_next(iterC)
@ -2583,7 +2582,7 @@ class RosterWindow:
GLib.idle_add(ctrl.parent_win.set_active_tab, ctrl)
else:
ctrl = app.interface.new_chat(obj.contact, account)
if len(app.events.get_events(account, obj.jid)):
if app.events.get_events(account, obj.jid):
ctrl.read_queue()
def _nec_gc_presence_received(self, obj):
@ -2718,7 +2717,7 @@ class RosterWindow:
contact = app.contacts.get_contact(obj.conn.name, obj.jid)
obj.session.control = app.interface.new_chat(contact,
obj.conn.name, session=obj.session)
if len(app.events.get_events(obj.conn.name, obj.fjid)):
if app.events.get_events(obj.conn.name, obj.fjid):
obj.session.control.read_queue()
if obj.show_in_roster:
@ -3196,7 +3195,7 @@ class RosterWindow:
elif event.keyval == Gdk.KEY_Delete:
treeselection = self.tree.get_selection()
model, list_of_paths = treeselection.get_selected_rows()
if not len(list_of_paths):
if not list_of_paths:
return
type_ = model[list_of_paths[0]][Column.TYPE]
account = model[list_of_paths[0]][Column.ACCOUNT]
@ -3535,7 +3534,7 @@ class RosterWindow:
self.previous_status_combobox_active = active
return
accounts = list(app.connections.keys())
if len(accounts) == 0:
if not accounts:
ErrorDialog(_('No account available'),
_('You must create an account before you can chat with other '
'contacts.'))
@ -3697,7 +3696,7 @@ class RosterWindow:
# if a contact row is selected, update colors (eg. for status msg)
# because gtk engines may differ in bg when window is selected
# or not
if len(self._last_selected_contact):
if self._last_selected_contact:
for (jid, account) in self._last_selected_contact:
self.draw_contact(jid, account, selected=True, focus=True)
@ -3705,7 +3704,7 @@ class RosterWindow:
# if a contact row is selected, update colors (eg. for status msg)
# because gtk engines may differ in bg when window is selected
# or not
if len(self._last_selected_contact):
if self._last_selected_contact:
for (jid, account) in self._last_selected_contact:
self.draw_contact(jid, account, selected=True, focus=False)
@ -3720,7 +3719,7 @@ class RosterWindow:
# let message window close the tab
return
list_of_paths = self.tree.get_selection().get_selected_rows()[1]
if not len(list_of_paths) and not app.config.get(
if not list_of_paths and not app.config.get(
'quit_on_roster_x_button') and ((app.interface.systray_enabled and\
app.config.get('trayicon') == 'always') or app.config.get(
'allow_hide_roster')):
@ -4385,7 +4384,7 @@ class RosterWindow:
path = helpers.get_file_path_from_dnd_dropped_uri(a_uri)
if not os.path.isfile(path):
bad_uris.append(a_uri)
if len(bad_uris):
if bad_uris:
ErrorDialog(_('Invalid file URI:'), '\n'.join(bad_uris))
return
def _on_send_files(account, jid, uris):
@ -5523,7 +5522,7 @@ class RosterWindow:
except TypeError:
self.tree.get_selection().unselect_all()
return
if not len(list_of_paths):
if not list_of_paths:
# no row is selected
return
if len(list_of_paths) > 1:

View File

@ -209,7 +209,7 @@ class SearchWindow:
return
self.dataform = dataforms.extend_form(node=obj.data)
if len(self.dataform.items) == 0:
if not self.dataform.items:
# No result
self.label.set_text(_('No result'))
self.label.show()

View File

@ -404,7 +404,7 @@ class ChatControlSession(object):
self.control = app.interface.new_chat(contact,
self.conn.name, session=self)
if len(app.events.get_events(self.conn.name, fjid)):
if app.events.get_events(self.conn.name, fjid):
self.control.read_queue()
else:
if no_queue: # We didn't have a queue: we change icons

View File

@ -371,7 +371,7 @@ class StatusIcon:
def on_left_click(self):
win = app.interface.roster.window
if len(app.events.get_systray_events()) == 0:
if not app.events.get_systray_events():
# No pending events, so toggle visible/hidden for roster window
if win.get_property('visible') and (win.get_property(
'has-toplevel-focus') or os.name == 'nt'):