[gedit-plugins/wip/python3: 4/4] Port plugins to python 3



commit e35c76e8160242109edfe24639e9b205b0a25397
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Fri Oct 26 12:53:15 2012 +0200

    Port plugins to python 3

 plugins/charmap/charmap/__init__.py              |    2 +-
 plugins/commander/commander/commands/__init__.py |   22 +++++++++++-----------
 plugins/commander/commander/commands/method.py   |    4 ++--
 plugins/commander/commander/commands/module.py   |    6 +++---
 plugins/commander/commander/entry.py             |   12 ++++++------
 plugins/commander/commander/history.py           |    5 +++--
 plugins/commander/commander/info.py              |    4 ++--
 plugins/commander/modules/align.py               |    2 +-
 plugins/commander/modules/edit.py                |    4 ++--
 plugins/commander/modules/format.py              |    4 ++--
 plugins/commander/modules/grep.py                |    2 +-
 plugins/commander/modules/move.py                |    4 ++--
 plugins/commander/modules/shell.py               |    2 +-
 plugins/dashboard/dashboard/__init__.py          |    2 +-
 plugins/dashboard/dashboard/dashboard.py         |    6 +++---
 plugins/multiedit/multiedit/__init__.py          |    4 ++--
 plugins/multiedit/multiedit/documenthelper.py    |   10 +++++-----
 plugins/synctex/synctex/__init__.py              |    2 +-
 plugins/synctex/synctex/evince_dbus.py           |    4 ++--
 plugins/synctex/synctex/synctex.py               |    2 +-
 plugins/textsize/textsize/__init__.py            |    2 +-
 plugins/textsize/textsize/documenthelper.py      |    2 +-
 22 files changed, 54 insertions(+), 53 deletions(-)
---
diff --git a/plugins/charmap/charmap/__init__.py b/plugins/charmap/charmap/__init__.py
index 61fbbbf..25b8c15 100644
--- a/plugins/charmap/charmap/__init__.py
+++ b/plugins/charmap/charmap/__init__.py
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
 from gi.repository import GObject, Gio, Pango, Gtk, Gedit, Gucharmap
-from panel import CharmapPanel
+from .panel import CharmapPanel
 import sys
 import gettext
 from gpdefs import *
diff --git a/plugins/commander/commander/commands/__init__.py b/plugins/commander/commander/commands/__init__.py
index c1a57ee..9b9c561 100644
--- a/plugins/commander/commander/commands/__init__.py
+++ b/plugins/commander/commander/commands/__init__.py
@@ -28,14 +28,14 @@ import shlex
 import re
 import os
 
-import module
-import method
-import result
-import exceptions
-import metamodule
+import commands.module as module
+import commands.method as method
+import commands.result as result
+import commands.exceptions as exceptions
+import commands.metamodule as metamodule
 
-from accel_group import AccelGroup
-from accel_group import Accelerator
+from commands.accel_group import AccelGroup
+from commands.accel_group import Accelerator
 
 __all__ = ['is_commander_module', 'Commands', 'Accelerator']
 
@@ -198,7 +198,7 @@ class Commands(Singleton):
 
         try:
             monitor = gfile.monitor_directory(Gio.FileMonitorFlags.NONE, None)
-        except Gio.Error, e:
+        except Gio.Error as e:
             # Could not create monitor, this happens on systems where file monitoring is
             # not supported, but we don't really care
             pass
@@ -275,7 +275,7 @@ class Commands(Singleton):
 
             if state:
                 return self.run(state)
-        except Exception, e:
+        except Exception as e:
             # Something error like, we throw on the parent generator
             state.pop()
 
@@ -405,9 +405,9 @@ class Commands(Singleton):
         # Now, try to reload the module
         try:
             mod.reload()
-        except Exception, e:
+        except Exception as e:
             # Reload failed, we remove the module
-            print 'Failed to reload module (%s):' % (mod.name,), e
+            print('Failed to reload module (%s):' % (mod.name,), e)
 
             self._modules.remove(mod)
             return
diff --git a/plugins/commander/commander/commands/method.py b/plugins/commander/commander/commands/method.py
index aa124e0..42acf52 100644
--- a/plugins/commander/commander/commands/method.py
+++ b/plugins/commander/commander/commands/method.py
@@ -19,11 +19,11 @@
 #  Foundation, Inc., 51 Franklin Street, Fifth Floor,
 #  Boston, MA 02110-1301, USA.
 
-import exceptions
+import commands.exceptions as exceptions
 import types
 import inspect
 import sys
-import commander.utils as utils
+import utils
 
 class Method:
     def __init__(self, method, name, parent):
diff --git a/plugins/commander/commander/commands/module.py b/plugins/commander/commander/commands/module.py
index 112e579..0bd0346 100644
--- a/plugins/commander/commander/commands/module.py
+++ b/plugins/commander/commander/commands/module.py
@@ -25,9 +25,9 @@ import types
 import bisect
 
 import utils
-import exceptions
-import method
-import rollbackimporter
+import commands.exceptions as exceptions
+import commands.method as method
+import commands.rollbackimporter as rollbackimporter
 
 class Module(method.Method):
     def __init__(self, base, mod, parent=None):
diff --git a/plugins/commander/commander/entry.py b/plugins/commander/commander/entry.py
index 67f7f99..f29c07e 100644
--- a/plugins/commander/commander/entry.py
+++ b/plugins/commander/commander/entry.py
@@ -60,7 +60,7 @@ class Entry(Gtk.EventBox):
         self._entry.show()
 
         css = Gtk.CssProvider()
-        css.load_from_data("""
+        css.load_from_data(bytes("""
 @binding-set terminal-like-bindings {
     unbind "<Control>A";
 
@@ -82,7 +82,7 @@ GtkEntry#gedit-commander-entry {
     border-width: 0;
     box-shadow: 0 0 transparent;
 }
-""")
+""", 'utf-8'))
 
         # FIXME: remove hardcopy of 600 (GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
         # https://bugzilla.gnome.org/show_bug.cgi?id=646860
@@ -389,7 +389,7 @@ GtkEntry#gedit-commander-entry {
 
         try:
             ret = cb()
-        except Exception, e:
+        except Exception as e:
             self.command_history_done()
             self._command_state.clear()
 
@@ -494,7 +494,7 @@ GtkEntry#gedit-commander-entry {
         #  * "hello world|"
         posidx = None
 
-        for idx in xrange(0, len(words)):
+        for idx in range(0, len(words)):
             spec = self._complete_word_match(words[idx])
 
             if words[idx].start(0) > pos:
@@ -582,10 +582,10 @@ GtkEntry#gedit-commander-entry {
                             del kwargs[k]
 
                 ret = func(**kwargs)
-            except Exception, e:
+            except Exception as e:
                 # Can be number of arguments, or return values or simply buggy
                 # modules
-                print e
+                print(e)
                 traceback.print_exc()
                 return True
 
diff --git a/plugins/commander/commander/history.py b/plugins/commander/commander/history.py
index 8544be6..f6ce8f4 100644
--- a/plugins/commander/commander/history.py
+++ b/plugins/commander/commander/history.py
@@ -72,7 +72,8 @@ class History:
 
     def load(self):
         try:
-            self._history = map(lambda x: x.strip("\n"), file(self._filename, 'r').readlines())
+            #FIXME: we should rewrite this
+            self._history = list(map(lambda x: x.strip("\n"), open(self._filename, 'r').readlines()))
             self._history.append('')
             self._ptr = len(self._history) - 1
         except IOError:
@@ -85,7 +86,7 @@ class History:
             pass
 
         try:
-            f = file(self._filename, 'w')
+            f = open(self._filename, 'w')
 
             if self._history[-1] == '':
                 hist = self._history[:-1]
diff --git a/plugins/commander/commander/info.py b/plugins/commander/commander/info.py
index ea32123..b51b83d 100644
--- a/plugins/commander/commander/info.py
+++ b/plugins/commander/commander/info.py
@@ -176,8 +176,8 @@ class Info(TransparentWindow):
 
         try:
             ret = Pango.parse_markup(line, -1, u'\x00')
-        except Exception, e:
-            print 'Could not parse markup:', e
+        except Exception as e:
+            print('Could not parse markup:', e)
             buf.insert(buf.get_end_iter(), line)
             return
 
diff --git a/plugins/commander/modules/align.py b/plugins/commander/modules/align.py
index ac792be..4beb68a 100644
--- a/plugins/commander/modules/align.py
+++ b/plugins/commander/modules/align.py
@@ -166,7 +166,7 @@ def _regex(view, reg, group, additional_ws, add_ws_group, flags=0):
     # Compile the regular expression
     try:
         reg = re.compile(reg, flags)
-    except Exception, e:
+    except Exception as e:
         raise commander.commands.exceptions.Execute('Failed to compile regular expression: %s' % (e,))
 
     # Query the user to provide a regex group number to align on
diff --git a/plugins/commander/modules/edit.py b/plugins/commander/modules/edit.py
index 271485c..756569e 100644
--- a/plugins/commander/modules/edit.py
+++ b/plugins/commander/modules/edit.py
@@ -106,7 +106,7 @@ def rename(view, newfile):
             # Create parent directories
             try:
                 os.makedirs(dest.get_parent().get_path())
-            except OSError, e:
+            except OSError as e:
                 raise commander.commands.exceptions.Execute('Could not create directory')
         else:
             yield commander.commands.result.HIDE
@@ -122,7 +122,7 @@ def rename(view, newfile):
 
         doc.set_location(dest)
         yield commander.commands.result.HIDE
-    except Exception, e:
+    except Exception as e:
         raise commander.commands.exceptions.Execute('Could not move file: %s' % (e,))
 
 def _mod_has_func(mod, func):
diff --git a/plugins/commander/modules/format.py b/plugins/commander/modules/format.py
index 0f90aa6..649822c 100644
--- a/plugins/commander/modules/format.py
+++ b/plugins/commander/modules/format.py
@@ -73,8 +73,8 @@ the open documents."""
                 start = end.copy()
                 start.forward_line()
 
-        except Exception, e:
-            print e
+        except Exception as e:
+            print(e)
 
         buf.delete_mark(until)
         buf.end_user_action()
diff --git a/plugins/commander/modules/grep.py b/plugins/commander/modules/grep.py
index 2fde969..4055c72 100644
--- a/plugins/commander/modules/grep.py
+++ b/plugins/commander/modules/grep.py
@@ -126,7 +126,7 @@ def _grep(view, regex, match_action, non_match_action):
 
     try:
         reg = re.compile(regex)
-    except Exception, e:
+    except Exception as e:
         raise commands.exceptions.Execute('Invalid regular expression: ' + str(e))
 
     while True:
diff --git a/plugins/commander/modules/move.py b/plugins/commander/modules/move.py
index 0c7625d..87addcf 100644
--- a/plugins/commander/modules/move.py
+++ b/plugins/commander/modules/move.py
@@ -64,12 +64,12 @@ def regex(view, modifier, regex, num=1):
 Move the cursor per regex (use negative num to move backwards)"""
     try:
         r = re.compile(regex, re.DOTALL | re.MULTILINE | re.UNICODE)
-    except Exception, e:
+    except Exception as e:
         raise commands.exceptions.Execute('Invalid regular expression: ' + str(e))
 
     try:
         num = int(num)
-    except Exception, e:
+    except Exception as e:
         raise commands.exceptions.Execute('Invalid number: ' + str(e))
 
     buf = view.get_buffer()
diff --git a/plugins/commander/modules/shell.py b/plugins/commander/modules/shell.py
index 8905fa4..bc3d89b 100644
--- a/plugins/commander/modules/shell.py
+++ b/plugins/commander/modules/shell.py
@@ -148,7 +148,7 @@ def _run_command(entry, replace, background, argstr):
         p = subprocess.Popen(argstr, shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         stdout = p.stdout
 
-    except Exception, e:
+    except Exception as e:
         raise commander.commands.exceptions.Execute('Failed to execute: ' + e)
 
     suspend = None
diff --git a/plugins/dashboard/dashboard/__init__.py b/plugins/dashboard/dashboard/__init__.py
index b02625f..f46771a 100644
--- a/plugins/dashboard/dashboard/__init__.py
+++ b/plugins/dashboard/dashboard/__init__.py
@@ -20,7 +20,7 @@
 #
 
 from gi.repository import GObject, Gedit
-from dashboard import Dashboard
+from .dashboard import Dashboard
 
 class DashboardWindowActivatable(GObject.Object, Gedit.WindowActivatable):
 
diff --git a/plugins/dashboard/dashboard/dashboard.py b/plugins/dashboard/dashboard/dashboard.py
index d39532e..2f56c2c 100644
--- a/plugins/dashboard/dashboard/dashboard.py
+++ b/plugins/dashboard/dashboard/dashboard.py
@@ -22,7 +22,7 @@
 from gi.repository import GObject, Gedit, Gtk, Gio, GLib, GdkPixbuf, GtkSource
 from zeitgeist.client import ZeitgeistClient
 from zeitgeist.datamodel import Event, TimeRange
-from utils import *
+from .utils import *
 
 import time
 import os
@@ -39,7 +39,7 @@ CLIENT = ZeitgeistClient()
 version = [int(x) for x in CLIENT.get_version()]
 MIN_VERSION = [0, 8, 0, 0]
 if version < MIN_VERSION:
-    print "PLEASE USE ZEITGEIST 0.8.0 or above"
+    print("PLEASE USE ZEITGEIST 0.8.0 or above")
 
 class Item(Gtk.Button):
 
@@ -423,7 +423,7 @@ class Dashboard (Gtk.Box):
     def _on_search(self, widget, query):
         self.search_result_box.show()
         self.dash_box.hide()
-        print "Dashboard search for:", query
+        print("Dashboard search for:", query)
         ZG_FTS.search(query, self.tree_view.insert_results)
         self.last_used_button.set_active(False)
 
diff --git a/plugins/multiedit/multiedit/__init__.py b/plugins/multiedit/multiedit/__init__.py
index 2dbfc87..73abc6c 100644
--- a/plugins/multiedit/multiedit/__init__.py
+++ b/plugins/multiedit/multiedit/__init__.py
@@ -20,8 +20,8 @@
 #  Boston, MA 02110-1301, USA.
 
 from gi.repository import GObject, Gtk, Gedit
-from signals import Signals
-from documenthelper import DocumentHelper
+from .signals import Signals
+from .documenthelper import DocumentHelper
 import gettext
 from gpdefs import *
 
diff --git a/plugins/multiedit/multiedit/documenthelper.py b/plugins/multiedit/multiedit/documenthelper.py
index 131d6e1..f7caf4a 100644
--- a/plugins/multiedit/multiedit/documenthelper.py
+++ b/plugins/multiedit/multiedit/documenthelper.py
@@ -22,8 +22,8 @@
 import re
 import time
 import xml.sax.saxutils
-from gi.repository import GObject, Pango, PangoCairo, Gdk, Gtk, Gedit
-from signals import Signals
+from gi.repository import GLib, GObject, Pango, PangoCairo, Gdk, Gtk, Gedit
+from .signals import Signals
 import gettext
 from gpdefs import *
 
@@ -161,7 +161,7 @@ class DocumentHelper(Signals):
         ]
 
         for handler in self._event_handlers:
-            handler[0] = map(lambda x: Gdk.keyval_from_name(x), handler[0])
+            handler[0] = list(map(lambda x: Gdk.keyval_from_name(x), handler[0]))
 
     def disable_multi_edit(self):
         if self._column_mode:
@@ -354,9 +354,9 @@ class DocumentHelper(Signals):
         self._invalidate_status()
 
         if self._status_timeout != 0:
-            GObject.source_remove(self._status_timeout)
+            GLib.source_remove(self._status_timeout)
 
-        self._status_timeout = GObject.timeout_add(3000, self._remove_status)
+        self._status_timeout = GLib.timeout_add(3000, self._remove_status)
 
     def _apply_column_mode(self):
         mode = self._column_mode
diff --git a/plugins/synctex/synctex/__init__.py b/plugins/synctex/synctex/__init__.py
index 5aa4425..e8217b3 100644
--- a/plugins/synctex/synctex/__init__.py
+++ b/plugins/synctex/synctex/__init__.py
@@ -1 +1 @@
-from synctex import SynctexWindowActivatable
+from .synctex import SynctexWindowActivatable
diff --git a/plugins/synctex/synctex/evince_dbus.py b/plugins/synctex/synctex/evince_dbus.py
index 3c1957b..ba6aaea 100755
--- a/plugins/synctex/synctex/evince_dbus.py
+++ b/plugins/synctex/synctex/evince_dbus.py
@@ -145,9 +145,9 @@ if __name__ == '__main__':
     from gi.repository import GObject
 
     def print_usage():
-        print '''
+        print('''
 The usage is evince_dbus output_file line_number input_file from the directory of output_file.
-'''
+''')
         sys.exit(1)
 
     if len(sys.argv)!=4:
diff --git a/plugins/synctex/synctex/synctex.py b/plugins/synctex/synctex/synctex.py
index ec130ef..d5ac9dc 100644
--- a/plugins/synctex/synctex/synctex.py
+++ b/plugins/synctex/synctex/synctex.py
@@ -20,7 +20,7 @@
 #  Boston, MA 02110-1301, USA.
 
 from gi.repository import GObject, Pango, Gtk, Gedit, Peas, PeasGtk, Gio, Gdk
-from evince_dbus import EvinceWindowProxy
+from .evince_dbus import EvinceWindowProxy
 import dbus.mainloop.glib
 import logging
 import gettext
diff --git a/plugins/textsize/textsize/__init__.py b/plugins/textsize/textsize/__init__.py
index 320b3a0..2d853c8 100644
--- a/plugins/textsize/textsize/__init__.py
+++ b/plugins/textsize/textsize/__init__.py
@@ -23,7 +23,7 @@
 #  Boston, MA 02110-1301, USA.
 
 from gi.repository import GObject, Gtk, Gdk, Gedit
-from documenthelper import DocumentHelper
+from .documenthelper import DocumentHelper
 import gettext
 from gpdefs import *
 
diff --git a/plugins/textsize/textsize/documenthelper.py b/plugins/textsize/textsize/documenthelper.py
index bf4435c..ba9ca61 100644
--- a/plugins/textsize/textsize/documenthelper.py
+++ b/plugins/textsize/textsize/documenthelper.py
@@ -19,7 +19,7 @@
 #  Foundation, Inc., 51 Franklin Street, Fifth Floor,
 #  Boston, MA 02110-1301, USA.
 
-from signals import Signals
+from .signals import Signals
 from gi.repository import Gtk, Gdk, Pango
 
 class DocumentHelper(Signals):



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