[totem] pythonconsole: pylintify the code



commit ed8bf5168356c01c2c41699f554b1f9553cd025d
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Oct 1 01:21:26 2013 +0100

    pythonconsole: pylintify the code
    
    Shut up, pylint.
    
    Helps: https://bugzilla.gnome.org/show_bug.cgi?id=708275

 src/plugins/pythonconsole/console.py       |  227 +++++++++++++++-------------
 src/plugins/pythonconsole/pythonconsole.py |   10 +-
 2 files changed, 128 insertions(+), 109 deletions(-)
---
diff --git a/src/plugins/pythonconsole/console.py b/src/plugins/pythonconsole/console.py
index b31069c..632e026 100644
--- a/src/plugins/pythonconsole/console.py
+++ b/src/plugins/pythonconsole/console.py
@@ -18,7 +18,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-# Parts from "Interactive Python-GTK Console" (stolen from epiphany's console.py)
+# Parts from "Interactive Python-GTK Console" (stolen from epiphany's
+# console.py)
 #     Copyright (C), 1998 James Henstridge <james daa com au>
 #     Copyright (C), 2005 Adam Hooper <adamh densi com>
 # Bits from gedit Python Console Plugin
@@ -32,31 +33,32 @@
 # Monday 7th February 2005: Christian Schaller: Add exception clause.
 # See license_change file for details.
 
-import string
 import sys
 import re
 import traceback
 from gi.repository import GLib, Pango, Gtk, Gdk # pylint: disable-msg=E0611
 
-class PythonConsole(Gtk.ScrolledWindow):
-    def __init__(self, namespace = {}, destroy_cb = None):
+class PythonConsole(Gtk.ScrolledWindow): # pylint: disable-msg=R0902
+    def __init__(self, namespace = {}, # pylint: disable-msg=W0102
+                 destroy_cb = None):
         Gtk.ScrolledWindow.__init__(self)
 
         self.destroy_cb = destroy_cb
-        self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
-        self.set_shadow_type(Gtk.ShadowType.IN)
+        self.set_policy(Gtk.PolicyType.NEVER, # pylint: disable-msg=E1101
+                        Gtk.PolicyType.AUTOMATIC)
+        self.set_shadow_type(Gtk.ShadowType.IN) # pylint: disable-msg=E1101
         self.view = Gtk.TextView()
         self.view.modify_font(Pango.font_description_from_string('Monospace'))
         self.view.set_editable(True)
         self.view.set_wrap_mode(Gtk.WrapMode.CHAR)
-        self.add(self.view)
+        self.add(self.view) # pylint: disable-msg=E1101
         self.view.show()
 
-        buffer = self.view.get_buffer()
-        self.normal = buffer.create_tag("normal")
-        self.error  = buffer.create_tag("error")
+        buf = self.view.get_buffer()
+        self.normal = buf.create_tag("normal")
+        self.error  = buf.create_tag("error")
         self.error.set_property("foreground", "red")
-        self.command = buffer.create_tag("command")
+        self.command = buf.create_tag("command")
         self.command.set_property("foreground", "blue")
 
         self.__spaces_pattern = re.compile(r'^\s+')
@@ -65,9 +67,9 @@ class PythonConsole(Gtk.ScrolledWindow):
         self.block_command = False
 
         # Init first line
-        buffer.create_mark("input-line", buffer.get_end_iter(), True)
-        buffer.insert(buffer.get_end_iter(), ">>> ")
-        buffer.create_mark("input", buffer.get_end_iter(), True)
+        buf.create_mark("input-line", buf.get_end_iter(), True)
+        buf.insert(buf.get_end_iter(), ">>> ")
+        buf.create_mark("input", buf.get_end_iter(), True)
 
         # Init history
         self.history = ['']
@@ -81,59 +83,62 @@ class PythonConsole(Gtk.ScrolledWindow):
 
         # Signals
         self.view.connect("key-press-event", self.__key_press_event_cb)
-        buffer.connect("mark-set", self.__mark_set_cb)
+        buf.connect("mark-set", self.__mark_set_cb)
 
 
-    def __key_press_event_cb(self, view, event):
+    def __key_press_event_cb(self, view, # pylint: disable-msg=R0912,R0915
+                             event):
         modifier_mask = Gtk.accelerator_get_default_mod_mask()
         event_state = event.state & modifier_mask
 
-        if event.keyval == Gdk.KEY_d and event_state == Gdk.ModifierType.CONTROL_MASK:
+        if event.keyval == Gdk.KEY_d and \
+           event_state == Gdk.ModifierType.CONTROL_MASK:
             self.destroy()
 
-        elif event.keyval == Gdk.KEY_Return and event_state == Gdk.ModifierType.CONTROL_MASK:
+        elif event.keyval == Gdk.KEY_Return and \
+             event_state == Gdk.ModifierType.CONTROL_MASK:
             # Get the command
-            buffer = view.get_buffer()
-            inp_mark = buffer.get_mark("input")
-            inp = buffer.get_iter_at_mark(inp_mark)
-            cur = buffer.get_end_iter()
-            line = buffer.get_text(inp, cur, True)
+            buf = view.get_buffer()
+            inp_mark = buf.get_mark("input")
+            inp = buf.get_iter_at_mark(inp_mark)
+            cur = buf.get_end_iter()
+            line = buf.get_text(inp, cur, True)
             self.current_command = self.current_command + line + "\n"
             self.history_add(line)
 
             # Prepare the new line
-            cur = buffer.get_end_iter()
-            buffer.insert(cur, "\n... ")
-            cur = buffer.get_end_iter()
-            buffer.move_mark(inp_mark, cur)
+            cur = buf.get_end_iter()
+            buf.insert(cur, "\n... ")
+            cur = buf.get_end_iter()
+            buf.move_mark(inp_mark, cur)
 
             # Keep indentation of precendent line
             spaces = re.match(self.__spaces_pattern, line)
             if spaces is not None:
-                buffer.insert(cur, line[spaces.start() : spaces.end()])
-                cur = buffer.get_end_iter()
+                buf.insert(cur, line[spaces.start() : spaces.end()])
+                cur = buf.get_end_iter()
 
-            buffer.place_cursor(cur)
+            buf.place_cursor(cur)
             GLib.idle_add(self.scroll_to_end)
             return True
 
         elif event.keyval == Gdk.KEY_Return:
             # Get the marks
-            buffer = view.get_buffer()
-            lin_mark = buffer.get_mark("input-line")
-            inp_mark = buffer.get_mark("input")
+            buf = view.get_buffer()
+            lin_mark = buf.get_mark("input-line")
+            inp_mark = buf.get_mark("input")
 
             # Get the command line
-            inp = buffer.get_iter_at_mark(inp_mark)
-            cur = buffer.get_end_iter()
-            line = buffer.get_text(inp, cur, True)
+            inp = buf.get_iter_at_mark(inp_mark)
+            cur = buf.get_end_iter()
+            line = buf.get_text(inp, cur, True)
             self.current_command = self.current_command + line + "\n"
             self.history_add(line)
 
             # Make the line blue
-            lin = buffer.get_iter_at_mark(lin_mark)
-            buffer.apply_tag(self.command, lin, cur)
-            buffer.insert(cur, "\n")
+            lin = buf.get_iter_at_mark(lin_mark)
+            buf.apply_tag(self.command, lin, cur)
+            buf.insert(cur, "\n")
 
             cur_strip = self.current_command.rstrip()
 
@@ -152,12 +157,12 @@ class PythonConsole(Gtk.ScrolledWindow):
                 com_mark = ">>> "
 
             # Prepare the new line
-            cur = buffer.get_end_iter()
-            buffer.move_mark(lin_mark, cur)
-            buffer.insert(cur, com_mark)
-            cur = buffer.get_end_iter()
-            buffer.move_mark(inp_mark, cur)
-            buffer.place_cursor(cur)
+            cur = buf.get_end_iter()
+            buf.move_mark(lin_mark, cur)
+            buf.insert(cur, com_mark)
+            cur = buf.get_end_iter()
+            buf.move_mark(inp_mark, cur)
+            buf.place_cursor(cur)
             GLib.idle_add(self.scroll_to_end)
             return True
 
@@ -175,42 +180,44 @@ class PythonConsole(Gtk.ScrolledWindow):
             GLib.idle_add(self.scroll_to_end)
             return True
 
-        elif event.keyval == Gdk.KEY_KP_Left or event.keyval == Gdk.KEY_Left or \
+        elif event.keyval == Gdk.KEY_KP_Left or \
+             event.keyval == Gdk.KEY_Left or \
              event.keyval == Gdk.KEY_BackSpace:
-            buffer = view.get_buffer()
-            inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
-            cur = buffer.get_iter_at_mark(buffer.get_insert())
+            buf = view.get_buffer()
+            inp = buf.get_iter_at_mark(buf.get_mark("input"))
+            cur = buf.get_iter_at_mark(buf.get_insert())
             return inp.compare(cur) == 0
 
         elif event.keyval == Gdk.KEY_Home:
             # Go to the begin of the command instead of the begin of the line
-            buffer = view.get_buffer()
-            inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
+            buf = view.get_buffer()
+            inp = buf.get_iter_at_mark(buf.get_mark("input"))
             if event_state == Gdk.ModifierType.SHIFT_MASK:
-                buffer.move_mark_by_name("insert", inp)
+                buf.move_mark_by_name("insert", inp)
             else:
-                buffer.place_cursor(inp)
+                buf.place_cursor(inp)
             return True
 
-    def __mark_set_cb(self, buffer, iter, name):
-        input = buffer.get_iter_at_mark(buffer.get_mark("input"))
-        pos   = buffer.get_iter_at_mark(buffer.get_insert())
-        self.view.set_editable(pos.compare(input) != -1)
+    def __mark_set_cb(self, buf, _, name):
+        inp = buf.get_iter_at_mark(buf.get_mark("input"))
+        pos   = buf.get_iter_at_mark(buf.get_insert())
+        self.view.set_editable(pos.compare(inp) != -1)
 
     def get_command_line(self):
-        buffer = self.view.get_buffer()
-        inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
-        cur = buffer.get_end_iter()
-        return buffer.get_text(inp, cur, True)
+        buf = self.view.get_buffer()
+        inp = buf.get_iter_at_mark(buf.get_mark("input"))
+        cur = buf.get_end_iter()
+        return buf.get_text(inp, cur, True)
 
     def set_command_line(self, command):
-        buffer = self.view.get_buffer()
-        mark = buffer.get_mark("input")
-        inp = buffer.get_iter_at_mark(mark)
-        cur = buffer.get_end_iter()
-        buffer.delete(inp, cur)
-        buffer.insert(inp, command)
-        buffer.select_range(buffer.get_iter_at_mark(mark), buffer.get_end_iter())
+        buf = self.view.get_buffer()
+        mark = buf.get_mark("input")
+        inp = buf.get_iter_at_mark(mark)
+        cur = buf.get_end_iter()
+        buf.delete(inp, cur)
+        buf.insert(inp, command)
+        buf.select_range(buf.get_iter_at_mark(mark),
+                         buf.get_end_iter())
         self.view.grab_focus()
 
     def history_add(self, line):
@@ -232,8 +239,8 @@ class PythonConsole(Gtk.ScrolledWindow):
             self.set_command_line(self.history[self.history_pos])
 
     def scroll_to_end(self):
-        iter = self.view.get_buffer().get_end_iter()
-        self.view.scroll_to_iter(iter, 0.0, False, 0.5, 0.5)
+        iterator = self.view.get_buffer().get_end_iter()
+        self.view.scroll_to_iter(iterator, 0.0, False, 0.5, 0.5)
         return False
 
     def write(self, text, tag = None):
@@ -246,27 +253,27 @@ class PythonConsole(Gtk.ScrolledWindow):
         GLib.idle_add(self.scroll_to_end)
 
     def eval(self, command, display_command = False):
-        buffer = self.view.get_buffer()
-        lin = buffer.get_mark("input-line")
-        buffer.delete(buffer.get_iter_at_mark(lin),
-                      buffer.get_end_iter())
+        buf = self.view.get_buffer()
+        lin = buf.get_mark("input-line")
+        buf.delete(buf.get_iter_at_mark(lin),
+                   buf.get_end_iter())
 
         if isinstance(command, list) or isinstance(command, tuple):
-            for c in command:
+            for char in command:
                 if display_command:
-                    self.write(">>> " + c + "\n", self.command)
-                self.__run(c)
+                    self.write(">>> " + char + "\n", self.command)
+                self.__run(char)
         else:
             if display_command:
-                self.write(">>> " + c + "\n", self.command)
+                self.write(">>> " + char + "\n", self.command)
             self.__run(command)
 
-        cur = buffer.get_end_iter()
-        buffer.move_mark_by_name("input-line", cur)
-        buffer.insert(cur, ">>> ")
-        cur = buffer.get_end_iter()
-        buffer.move_mark_by_name("input", cur)
-        self.view.scroll_to_iter(buffer.get_end_iter(), 0.0, False, 0.5, 0.5)
+        cur = buf.get_end_iter()
+        buf.move_mark_by_name("input-line", cur)
+        buf.insert(cur, ">>> ")
+        cur = buf.get_end_iter()
+        buf.move_mark_by_name("input", cur)
+        self.view.scroll_to_iter(buf.get_end_iter(), 0.0, False, 0.5, 0.5)
 
     def __run(self, command):
         sys.stdout, self.stdout = self.stdout, sys.stdout
@@ -274,13 +281,14 @@ class PythonConsole(Gtk.ScrolledWindow):
 
         try:
             try:
-                r = eval(command, self.namespace, self.namespace)
-                if r is not None:
-                    print(r)
+                res = eval(command, self.namespace, self.namespace)
+                if res is not None:
+                    print(res)
             except SyntaxError:
-                exec(command, self.namespace)
-        except:
-            if hasattr(sys, 'last_type') and sys.last_type == SystemExit:
+                exec(command, self.namespace) # pylint: disable-msg=W0122
+        except: # pylint: disable-msg=W0702
+            if hasattr(sys, 'last_type') and \
+               sys.last_type == SystemExit: # pylint: disable-msg=E1101
                 self.destroy()
             else:
                 traceback.print_exc()
@@ -292,22 +300,33 @@ class PythonConsole(Gtk.ScrolledWindow):
         pass
         #Gtk.ScrolledWindow.destroy(self)
 
-class OutFile:
+class OutFile(object):
     """A fake output file object. It sends output to a TK test widget,
     and if asked for a file number, returns one set on instance creation"""
-    def __init__(self, console, fn, tag):
-        self.fn = fn
+    def __init__(self, console, file_no, tag):
+        self.file_no = file_no
         self.console = console
         self.tag = tag
-    def close(self):         pass
-    def flush(self):         pass
-    def fileno(self):        return self.fn
-    def isatty(self):        return 0
-    def read(self, a):       return ''
-    def readline(self):      return ''
-    def readlines(self):     return []
-    def write(self, s):      self.console.write(s, self.tag)
-    def writelines(self, l): self.console.write(l, self.tag)
-    def seek(self, a):       raise IOError((29, 'Illegal seek'))
-    def tell(self):          raise IOError((29, 'Illegal seek'))
+    def close(self):
+        pass
+    def flush(self):
+        pass
+    def fileno(self):
+        return self.file_no
+    def isatty(self): # pylint: disable-msg=R0201
+        return 0
+    def read(self, _): # pylint: disable-msg=R0201
+        return ''
+    def readline(self): # pylint: disable-msg=R0201
+        return ''
+    def readlines(self): # pylint: disable-msg=R0201
+        return []
+    def write(self, seg):
+        self.console.write(seg, self.tag)
+    def writelines(self, lines):
+        self.console.write(lines, self.tag)
+    def seek(self, _): # pylint: disable-msg=R0201
+        raise IOError((29, 'Illegal seek'))
+    def tell(self): # pylint: disable-msg=R0201
+        raise IOError((29, 'Illegal seek'))
     truncate = tell
diff --git a/src/plugins/pythonconsole/pythonconsole.py b/src/plugins/pythonconsole/pythonconsole.py
index 443b82e..f500039 100644
--- a/src/plugins/pythonconsole/pythonconsole.py
+++ b/src/plugins/pythonconsole/pythonconsole.py
@@ -35,7 +35,7 @@
 
 from console import PythonConsole
 
-__all__ = ('PythonConsole', 'OutFile')
+__all__ = ('PythonConsole', 'OutFile') # pylint: disable-msg=E0603
 
 from gi.repository import GObject, Peas, Gtk, Totem # pylint: disable-msg=E0611
 from gi.repository import Gio # pylint: disable-msg=E0611
@@ -70,7 +70,7 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
         action.connect ('activate', self._show_console)
         self.totem.add_action (action)
 
-        menu = self.totem.get_menu_section ("python-console-placeholder");
+        menu = self.totem.get_menu_section ("python-console-placeholder")
         menu.append (_('_Python Console'), "app.python-console")
 
         if HAVE_RPDB2:
@@ -79,7 +79,7 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
             self.totem.add_action (action)
             menu.append (_('Python Debugger'), "app.python-debugger")
 
-    def _show_console (self, parameter, _action):
+    def _show_console (self, parameter, _action): # pylint: disable-msg=W0613
         if not self.window:
             console = PythonConsole (namespace = {
                 '__builtins__' : __builtins__,
@@ -101,7 +101,7 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
             self.window.grab_focus ()
 
     @classmethod
-    def _enable_debugging (cls, parameter, _action):
+    def _enable_debugging (cls, param, _action): # pylint: disable-msg=W0613
         msg = _("After you press OK, Totem will wait until you connect to it "\
                  "with winpdb or rpdb2. If you have not set a debugger "\
                  "password in DConf, it will use the default password "\
@@ -119,7 +119,7 @@ class PythonConsolePlugin (GObject.Object, Peas.Activatable):
             GObject.idle_add (start_debugger, password)
         dialog.destroy ()
 
-    def _destroy_console (self, *_args):
+    def _destroy_console (self, *_args): # pylint: disable-msg=W0613
         self.window.destroy ()
         self.window = None
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]