From eb6f5761ecf49e273cbe3aede13c74169bf98d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 16 Sep 2018 17:11:52 +0200 Subject: [PATCH] Fix redefined-outer-name pylint errors --- gajim/chat_control_base.py | 4 +- gajim/command_system/framework.py | 28 ++++++------ .../command_system/implementation/standard.py | 18 ++++---- gajim/common/dbus_support.py | 4 +- gajim/common/events.py | 5 +-- gajim/common/helpers.py | 1 - gajim/common/zeroconf/zeroconf_avahi.py | 2 +- gajim/disco.py | 8 ++-- gajim/gajim.py | 1 - gajim/gtk/account_wizard.py | 8 ++-- gajim/gtk/util.py | 3 +- gajim/gtkgui_helpers.py | 3 +- gajim/htmltextview.py | 44 +++++++++---------- gajim/music_track_listener.py | 2 +- gajim/plugins/helpers.py | 2 +- gajim/vcard.py | 8 ++-- 16 files changed, 68 insertions(+), 73 deletions(-) diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index 1a82f304e..456fadeea 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -711,12 +711,12 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): """ pass - def _on_drag_leave(self, widget, context, time): + def _on_drag_leave(self, *args): # FIXME: DND on non editable TextView, find a better way self.drag_entered = False self.conv_textview.tv.set_editable(False) - def _on_drag_motion(self, widget, context, x, y, time): + def _on_drag_motion(self, *args): # FIXME: DND on non editable TextView, find a better way if not self.drag_entered: # We drag new data over the TextView, make it editable to catch dnd diff --git a/gajim/command_system/framework.py b/gajim/command_system/framework.py index 8b42235fb..a7ade6344 100644 --- a/gajim/command_system/framework.py +++ b/gajim/command_system/framework.py @@ -96,17 +96,17 @@ class CommandProcessor: return True def execute_command(self, name, arguments): - command = self.get_command(name) + cmd = self.get_command(name) args, opts = parse_arguments(arguments) if arguments else ([], []) - args, kwargs = adapt_arguments(command, arguments, args, opts) + args, kwargs = adapt_arguments(cmd, arguments, args, opts) - if self.command_preprocessor(command, name, arguments, args, kwargs): + if self.command_preprocessor(cmd, name, arguments, args, kwargs): return - value = command(self, *args, **kwargs) - self.command_postprocessor(command, name, arguments, args, kwargs, value) + value = cmd(self, *args, **kwargs) + self.command_postprocessor(cmd, name, arguments, args, kwargs, value) - def command_preprocessor(self, command, name, arguments, args, kwargs): + def command_preprocessor(self, cmd, name, arguments, args, kwargs): """ Redefine this method in the subclass to execute custom code before command gets executed. @@ -116,7 +116,7 @@ class CommandProcessor: """ pass - def command_postprocessor(self, command, name, arguments, args, kwargs, value): + def command_postprocessor(self, cmd, name, arguments, args, kwargs, value): """ Redefine this method in the subclass to execute custom code after command gets executed. @@ -135,10 +135,10 @@ class CommandProcessor: pass def get_command(self, name): - command = get_command(self.COMMAND_HOST, name) - if not command: + cmd = get_command(self.COMMAND_HOST, name) + if not cmd: raise NoCommandError("Command does not exist", name=name) - return command + return cmd def list_commands(self): commands = list_commands(self.COMMAND_HOST) @@ -307,16 +307,16 @@ def command(*names, **properties): Decorator which receives handler as a first argument and then wraps it in the command which then returns back. """ - command = Command(handler, *names, **properties) + cmd = Command(handler, *names, **properties) # Extract and inject a native name if either no other names are # specified or native property is enabled, while making # sure it is going to be the first one in the list. if not names or native: - names.insert(0, command.native_name) - command.names = tuple(names) + names.insert(0, cmd.native_name) + cmd.names = tuple(names) - return command + return cmd # Workaround if we are getting called without parameters. Keep in # mind that in that case - first item in the names will be the diff --git a/gajim/command_system/implementation/standard.py b/gajim/command_system/implementation/standard.py index 985afcd8a..6a0871585 100644 --- a/gajim/command_system/implementation/standard.py +++ b/gajim/command_system/implementation/standard.py @@ -43,25 +43,25 @@ 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, command=None, all=False): - if command: - command = self.get_command(command) + def help(self, cmd=None, all=False): + if cmd: + cmd = self.get_command(cmd) - documentation = _(command.extract_documentation()) - usage = generate_usage(command) + documentation = _(cmd.extract_documentation()) + usage = generate_usage(cmd) text = [] if documentation: text.append(documentation) - if command.usage: + if cmd.usage: text.append(usage) return '\n\n'.join(text) elif all: - for command in self.list_commands(): - names = ', '.join(command.names) - description = command.extract_description() + for cmd in self.list_commands(): + names = ', '.join(cmd.names) + description = cmd.extract_description() self.echo("%s - %s" % (names, description)) else: diff --git a/gajim/common/dbus_support.py b/gajim/common/dbus_support.py index 265295524..6152598b9 100644 --- a/gajim/common/dbus_support.py +++ b/gajim/common/dbus_support.py @@ -42,8 +42,8 @@ except ImportError: else: try: # test if dbus-x11 is installed - bus = dbus.SystemBus() - bus = dbus.SessionBus() + _bus = dbus.SystemBus() + _bus = dbus.SessionBus() supported = True # does user have D-Bus bindings? except dbus.DBusException: supported = False diff --git a/gajim/common/events.py b/gajim/common/events.py index 6d9c7aea4..181ab0c63 100644 --- a/gajim/common/events.py +++ b/gajim/common/events.py @@ -61,16 +61,15 @@ class Event: class ChatEvent(Event): type_ = 'chat' - def __init__ (self, message, subject, kind, time, encrypted, resource, + def __init__ (self, message, subject, kind, time_, encrypted, resource, msg_log_id, correct_id=None, xhtml=None, session=None, form_node=None, - displaymarking=None, sent_forwarded=False, time_=None, show_in_roster=False, + displaymarking=None, sent_forwarded=False, show_in_roster=False, show_in_systray=True, additional_data=None): Event.__init__(self, time_, show_in_roster=show_in_roster, show_in_systray=show_in_systray) self.message = message self.subject = subject self.kind = kind - self.time = time self.encrypted = encrypted self.resource = resource self.msg_log_id = msg_log_id diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py index 7c60fce6d..998738004 100644 --- a/gajim/common/helpers.py +++ b/gajim/common/helpers.py @@ -1279,7 +1279,6 @@ def get_subscription_request_msg(account=None): return s def replace_dataform_media(form, stanza): - import nbxmpp found = False for field in form.getTags('field'): for media in field.getTags('media'): diff --git a/gajim/common/zeroconf/zeroconf_avahi.py b/gajim/common/zeroconf/zeroconf_avahi.py index a6e9aa834..b2166032e 100644 --- a/gajim/common/zeroconf/zeroconf_avahi.py +++ b/gajim/common/zeroconf/zeroconf_avahi.py @@ -354,7 +354,7 @@ class Zeroconf: # connect to dbus def connect_dbus(self): try: - import dbus + import dbus # pylint: disable=redefined-outer-name from dbus.mainloop.glib import DBusGMainLoop main_loop = DBusGMainLoop(set_as_default=True) dbus.set_default_main_loop(main_loop) diff --git a/gajim/disco.py b/gajim/disco.py index 0ce636f41..5dde40633 100644 --- a/gajim/disco.py +++ b/gajim/disco.py @@ -2094,11 +2094,11 @@ class DiscussionGroupsBrowser(AgentBrowser): except Exception: return - groups = set() + groups_ = set() for child in subscriptions.getTags('subscription'): - groups.add(child['node']) + groups_.add(child['node']) - self.subscriptions = groups + self.subscriptions = groups_ # try to setup existing items in model model = self.window.services_treeview.get_model() @@ -2108,7 +2108,7 @@ class DiscussionGroupsBrowser(AgentBrowser): # 4 = subscribed? groupnode = row[1] row[3] = False - row[4] = groupnode in groups + row[4] = groupnode in groups_ # we now know subscriptions, update button states self.update_actions() diff --git a/gajim/gajim.py b/gajim/gajim.py index 94d24c7dc..ee96bac73 100644 --- a/gajim/gajim.py +++ b/gajim/gajim.py @@ -38,7 +38,6 @@ def _check_required_deps(): print('Gajim needs python-nbxmpp to run. Quitting…') sys.exit(1) - from distutils.version import LooseVersion as V if V(nbxmpp.__version__) < V(_MIN_NBXMPP_VER): print('Gajim needs python-nbxmpp >= %s to run. ' 'Quitting...' % _MIN_NBXMPP_VER) diff --git a/gajim/gtk/account_wizard.py b/gajim/gtk/account_wizard.py index 74581d3df..5756e6621 100644 --- a/gajim/gtk/account_wizard.py +++ b/gajim/gtk/account_wizard.py @@ -24,11 +24,12 @@ from gajim.common import configpaths from gajim.common import helpers from gajim.common import connection from gajim.common.modules import dataforms +from gajim.config import ManageProxiesWindow +from gajim.config import FakeDataForm from gajim.gtk.util import get_builder from gajim.gtk import ErrorDialog from gajim import gtkgui_helpers from gajim import dataforms_widget -from gajim import config from gajim import gui_menu_builder @@ -347,7 +348,7 @@ class AccountCreationWizard: app.interface.instances['manage_proxies'].window.present() else: app.interface.instances['manage_proxies'] = \ - config.ManageProxiesWindow() + ManageProxiesWindow() def on_custom_host_port_checkbutton_toggled(self, widget): self.xml.get_object('custom_host_hbox').set_sensitive( @@ -377,8 +378,7 @@ class AccountCreationWizard: self.data_form_widget.set_data_form(dataform) empty_config = False else: - self.data_form_widget = config.FakeDataForm( - obj.config, selectable=True) + self.data_form_widget = FakeDataForm(obj.config, selectable=True) for field in obj.config: if field in ('key', 'instructions', 'x', 'registered'): continue diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index b17c17c3a..471627ae1 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -198,8 +198,7 @@ def at_the_end(widget): """ adj_v = widget.get_vadjustment() max_scroll_pos = adj_v.get_upper() - adj_v.get_page_size() - at_the_end = (adj_v.get_value() == max_scroll_pos) - return at_the_end + return adj_v.get_value() == max_scroll_pos def get_image_button(icon_name, tooltip, toggle=False): diff --git a/gajim/gtkgui_helpers.py b/gajim/gtkgui_helpers.py index ccffe3fde..4b18623bd 100644 --- a/gajim/gtkgui_helpers.py +++ b/gajim/gtkgui_helpers.py @@ -211,8 +211,7 @@ def at_the_end(widget): """ adj_v = widget.get_vadjustment() max_scroll_pos = adj_v.get_upper() - adj_v.get_page_size() - at_the_end = (adj_v.get_value() == max_scroll_pos) - return at_the_end + return adj_v.get_value() == max_scroll_pos def scroll_to_end(widget): """Scrolls to the end of a GtkScrolledWindow. diff --git a/gajim/htmltextview.py b/gajim/htmltextview.py index 05db049ad..bb0038640 100644 --- a/gajim/htmltextview.py +++ b/gajim/htmltextview.py @@ -72,7 +72,7 @@ classes = { } # styles for elements -element_styles = { +_element_styles = { 'u' : ';text-decoration: underline', 'em' : ';font-style: oblique', 'cite' : '; background-color:rgb(170,190,250);' @@ -90,12 +90,12 @@ element_styles = { 'dd' : ';margin-left: 2em; font-style: oblique' } # no difference for the moment -element_styles['dfn'] = element_styles['em'] -element_styles['var'] = element_styles['em'] +_element_styles['dfn'] = _element_styles['em'] +_element_styles['var'] = _element_styles['em'] # deprecated, legacy, presentational -element_styles['tt'] = element_styles['kbd'] -element_styles['i'] = element_styles['em'] -element_styles['b'] = element_styles['strong'] +_element_styles['tt'] = _element_styles['kbd'] +_element_styles['i'] = _element_styles['em'] +_element_styles['b'] = _element_styles['strong'] # ========== # XEP-0071 @@ -182,12 +182,12 @@ INLINE = INLINE_PHRASAL.union(INLINE_PRES).union(INLINE_STRUCT) LIST_ELEMS = set( 'dl, ol, ul'.split(', ')) -for name in BLOCK_HEAD: - num = eval(name[1]) - header_size = (num-1) // 2 - weight = (num - 1) % 2 - element_styles[name] = '; font-size: %s; %s' % ( ('large', 'medium', 'small')[header_size], - ('font-weight: bold', 'font-style: oblique')[weight],) +for _name in BLOCK_HEAD: + _num = eval(_name[1]) + _header_size = (_num - 1) // 2 + _weight = (_num - 1) % 2 + _element_styles[_name] = '; font-size: %s; %s' % ( ('large', 'medium', 'small')[_header_size], + ('font-weight: bold', 'font-style: oblique')[_weight],) def _parse_css_color(color): if color.startswith('rgb(') and color.endswith(')'): @@ -741,8 +741,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler): style += ';margin-left: 2em' elif name == 'img': tag = self._process_img(attrs) - if name in element_styles: - style += element_styles[name] + if name in _element_styles: + style += _element_styles[name] # so that explicit styles override implicit ones, # we add the attribute last style += ";"+attrs.get('style', '') @@ -915,8 +915,8 @@ class HtmlTextView(Gtk.TextView): AddNewContactWindow(self.account, jid) def make_link_menu(self, event, kind, text): - xml = get_builder('chat_context_menu.ui') - menu = xml.get_object('chat_context_menu') + ui = get_builder('chat_context_menu.ui') + menu = ui.get_object('chat_context_menu') childs = menu.get_children() if kind == 'url': childs[0].connect('activate', self.on_copy_link_activate, text) @@ -930,7 +930,7 @@ class HtmlTextView(Gtk.TextView): childs[7].hide() # add to roster else: # It's a mail or a JID # load muc icon - join_group_chat_menuitem = xml.get_object('join_group_chat_menuitem') + join_group_chat_menuitem = ui.get_object('join_group_chat_menuitem') text = text.lower() if text.startswith('xmpp:'): @@ -1270,9 +1270,9 @@ hhx4dbgYKAAA7' alt='Larry'/> frame.set_shadow_type(Gtk.ShadowType.IN) frame.show() frame.add(sw) - w = Gtk.Window() - w.add(frame) - w.set_default_size(400, 300) - w.show_all() - w.connect('destroy', lambda w: Gtk.main_quit()) + win = Gtk.Window() + win.add(frame) + win.set_default_size(400, 300) + win.show_all() + win.connect('destroy', lambda win: Gtk.main_quit()) Gtk.main() diff --git a/gajim/music_track_listener.py b/gajim/music_track_listener.py index d9efa3d70..3815e5251 100644 --- a/gajim/music_track_listener.py +++ b/gajim/music_track_listener.py @@ -199,7 +199,7 @@ class MusicTrackListener(GObject.GObject): # here we test :) if __name__ == '__main__': - def music_track_change_cb(listener, music_track_info): + def music_track_change_cb(_listener, music_track_info): if music_track_info is None or music_track_info.paused: print('Stop!') else: diff --git a/gajim/plugins/helpers.py b/gajim/plugins/helpers.py index 8af201fe4..24bf91f2f 100644 --- a/gajim/plugins/helpers.py +++ b/gajim/plugins/helpers.py @@ -51,7 +51,7 @@ class log_calls: even though `log_calls` decorator is used. ''' - def __init__(self, classname='', log=log): + def __init__(self, classname=''): ''' :Keywords: classname : str diff --git a/gajim/vcard.py b/gajim/vcard.py index 37c7c03ca..df2f57e9d 100644 --- a/gajim/vcard.py +++ b/gajim/vcard.py @@ -278,7 +278,7 @@ class VcardWindow: return i = 0 client = '' - os = '' + os_info = '' while i in self.os_info: if self.os_info[i]['resource'] == obj.jid.getResource(): if obj.client_info: @@ -296,13 +296,13 @@ class VcardWindow: self.os_info[i]['os'] = Q_('?OS:Unknown') if i > 0: client += '\n' - os += '\n' + os_info += '\n' client += self.os_info[i]['client'] - os += self.os_info[i]['os'] + os_info += self.os_info[i]['os'] i += 1 self.xml.get_object('client_name_version_label').set_text(client) - self.xml.get_object('os_label').set_text(os) + self.xml.get_object('os_label').set_text(os_info) self.os_info_arrived = True def set_entity_time(self, obj):