[meld/Python3: 1/54] Initial pass at Python 3 porting basics



commit b0ff88acf0048d2507079e100111cdb4f6d659a5
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Dec 7 09:33:09 2013 +1000

    Initial pass at Python 3 porting basics

 meld/dirdiff.py    |    5 +++--
 meld/meldbuffer.py |    2 --
 meld/recent.py     |   16 +++++++---------
 meld/tree.py       |    5 +----
 4 files changed, 11 insertions(+), 17 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 02ab2a7..47fdd2e 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -39,6 +39,7 @@ from . import misc
 from . import recent
 from .ui import gnomeglade
 from .ui import emblemcellrenderer
+from meld.util.compat import text_type
 
 from collections import namedtuple
 from decimal import Decimal
@@ -623,7 +624,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
         # the time we get this far. This is a fallback, and may be wrong!
         locations = list(locations)
         for i, l in enumerate(locations):
-            if not isinstance(l, unicode):
+            if not isinstance(l, text_type):
                 locations[i] = l.decode(sys.getfilesystemencoding())
         locations = [os.path.abspath(l) if l else '' for l in locations]
         self.current_path = None
@@ -718,7 +719,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
 
                 for e in entries:
                     try:
-                        if not isinstance(e, unicode):
+                        if not isinstance(e, text_type):
                             e = e.decode('utf8')
                     except UnicodeDecodeError:
                         approximate_name = e.decode('utf8', 'replace')
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 9e75887..37c9b9a 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -14,8 +14,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from __future__ import unicode_literals
-
 import sys
 
 from gi.repository import Gio
diff --git a/meld/recent.py b/meld/recent.py
index abbd7f9..f8065dd 100644
--- a/meld/recent.py
+++ b/meld/recent.py
@@ -60,7 +60,6 @@ class RecentFiles(object):
 
     mime_type = "application/x-meld-comparison"
     recent_path = os.path.join(GLib.get_user_data_dir(), "meld")
-    recent_path = recent_path.decode('utf8')
     recent_suffix = ".meldcmp"
 
     # Recent data
@@ -120,8 +119,8 @@ class RecentFiles(object):
         recent_metadata.mime_type = self.mime_type
         recent_metadata.app_name = self.app_name
         recent_metadata.app_exec = "%s --comparison-file %%u" % self.app_exec
-        recent_metadata.display_name = display_name.encode('utf8')
-        recent_metadata.description = description.encode('utf8')
+        recent_metadata.display_name = display_name
+        recent_metadata.description = description
         recent_metadata.is_private = True
         self.recent_manager.add_full(gio_file.get_uri(), recent_metadata)
 
@@ -158,10 +157,9 @@ class RecentFiles(object):
         paths = [p.encode(sys.getfilesystemencoding()) for p in paths]
         # TODO: Use GKeyFile instead, and return a Gio.File. This is why we're
         # using ';' to join comparison paths.
-        with tempfile.NamedTemporaryFile(prefix='recent-',
-                                         suffix=self.recent_suffix,
-                                         dir=self.recent_path,
-                                         delete=False) as f:
+        with tempfile.NamedTemporaryFile(
+                mode='w+t', prefix='recent-', suffix=self.recent_suffix,
+                dir=self.recent_path, delete=False) as f:
             config = configparser.RawConfigParser()
             config.add_section("Comparison")
             config.set("Comparison", "type", comp_type)
@@ -215,7 +213,7 @@ class RecentFiles(object):
                    Gtk.RecentFilterFlags.GROUP: "groups",
                    Gtk.RecentFilterFlags.AGE: "age"}
         needed = recent_filter.get_needed()
-        attrs = [v for k, v in getters.iteritems() if needed & k]
+        attrs = [v for k, v in getters.items() if needed & k]
 
         filtered_items = []
         for i in items:
@@ -224,7 +222,7 @@ class RecentFiles(object):
                 filter_data[attr] = getattr(i, "get_" + attr)()
             filter_info = Gtk.RecentFilterInfo()
             filter_info.contains = recent_filter.get_needed()
-            for f, v in filter_data.iteritems():
+            for f, v in filter_data.items():
                 # https://bugzilla.gnome.org/show_bug.cgi?id=695970
                 if isinstance(v, list):
                     continue
diff --git a/meld/tree.py b/meld/tree.py
index 519dbb7..6994e9c 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -102,10 +102,7 @@ class DiffTreeStore(Gtk.TreeStore):
         return [self.value_path(it, i) for i in range(self.ntree)]
 
     def value_path(self, it, pane):
-        path = self.get_value(it, self.column_index(COL_PATH, pane))
-        if path is not None:
-            path = path.decode('utf8')
-        return path
+        return self.get_value(it, self.column_index(COL_PATH, pane))
 
     def is_folder(self, it, pane, path):
         # A folder may no longer exist, and is only tracked by VC.


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