Commit b0ff88ac authored by Kai Willadsen's avatar Kai Willadsen

Initial pass at Python 3 porting basics

parent 0b9de7f0
......@@ -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')
......
......@@ -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
......
......@@ -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
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment