From 9fe4433ee53c26aacb93d89824a661748a34dedc Mon Sep 17 00:00:00 2001
From: Martin Pitt <martin.pitt@ubuntu.com>
Date: Fri, 6 Jan 2012 16:25:47 +0100
Subject: [PATCH] Revert "Convert all strings to utf-8 encoding when
 retrieving from TreeModel"

This changes existing behaviour (model values being str instead of unicode) and
also makes tree model behaviour incompatible to the rest of Gtk behaviour
(which always returns UTF-8 encoded str objects, not unicode). The original bug
description was a bug in the test case code, you cannot mix str and unicode
objects in interpolation.

This reverts commit 654711d0f940d7480d0f1cdb25a3dc9996f7a706.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=663610
Bug-Ubuntu: https://launchpad.net/bugs/905602
---
 gi/overrides/Gtk.py     |   15 ---------------
 tests/compathelper.py   |    2 --
 tests/test_overrides.py |   31 +------------------------------
 3 files changed, 1 insertions(+), 47 deletions(-)

diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 3b3055c..d496529 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -797,13 +797,6 @@ class TreeModel(Gtk.TreeModel):
 
             self.set_value(treeiter, i, value)
 
-    def _decode_value(self, treeiter, column, value):
-        type_ = self.get_column_type(column)
-        if type_ == GObject.TYPE_STRING and sys.version_info < (3, 0):
-            value = value.decode('UTF-8')
-
-        return value
-
     def _convert_value(self, treeiter, column, value):
             if value is None:
                 return
@@ -972,10 +965,6 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable):
         value = self._convert_value(treeiter, column, value)
         Gtk.ListStore.set_value(self, treeiter, column, value)
 
-    def get_value(self, treeiter, column):
-        value = Gtk.ListStore.get_value(self, treeiter, column)
-        return self._decode_value(treeiter, column, value)
-
     def set(self, treeiter, *args):
 
         def _set_lists(columns, values):
@@ -1191,10 +1180,6 @@ class TreeStore(Gtk.TreeStore, TreeModel, TreeSortable):
         value = self._convert_value(treeiter, column, value)
         Gtk.TreeStore.set_value(self, treeiter, column, value)
 
-    def get_value(self, treeiter, column):
-        value = Gtk.TreeStore.get_value(self, treeiter, column)
-        return self._decode_value(treeiter, column, value)
-
     def set(self, treeiter, *args):
 
         def _set_lists(columns, values):
diff --git a/tests/compathelper.py b/tests/compathelper.py
index b061335..2465747 100644
--- a/tests/compathelper.py
+++ b/tests/compathelper.py
@@ -62,10 +62,8 @@ if sys.version_info >= (3, 0):
     '''
 
     _unicode = lambda s: str(s)
-    _unichr = chr
 else:
     _long = long
     _basestring = basestring
     _bytes = str
     _unicode = lambda s: unicode(s, 'UTF-8')
-    _unichr = unichr
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index e875d30..8974273 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 # -*- Mode: Python; py-indent-offset: 4 -*-
 # vim: tabstop=4 shiftwidth=4 expandtab
 
@@ -8,7 +7,7 @@ import sys
 import os
 sys.path.insert(0, "../")
 
-from compathelper import _long, _unicode, _bytes, _unichr
+from compathelper import _long, _unicode, _bytes
 
 from gi.repository import GLib
 from gi.repository import GObject
@@ -1262,34 +1261,6 @@ class TestGtk(unittest.TestCase):
 
         model[0] = (3, "three", -0.3)
 
-    def test_tree_model_unicode(self):
-        model = Gtk.ListStore(str)
-
-        text = (_unicode("just\na\tstring"),
-                _unicode("Tr") + _unichr(0xf6) + _unicode("del"),
-                _unicode("N") + _unichr(0xe1) + _unicode("m") + _unichr(0xe8),
-                _unichr(0xff) + _unichr(0xdf) + _unicode("er"),
-                _unichr(0x152) + _unichr(0x180) + _unichr(0x1d25))
-
-        for item in text:
-            model.append([item])
-
-        def byte_compare(have, expected):
-            if sys.version_info < (3, 0):
-                self.assertTrue(isinstance(have, unicode))
-            else:
-                self.assertTrue(isinstance(have, str))
-
-            self.assertEqual(len(have), len(expected))
-            for i in range(len(expected)):
-                a = have[i]
-                b = expected[i]
-                self.assertEqual(a, b)
-                self.assertEqual(ord(a), ord(b))
-
-        for i in range(len(model)):
-            byte_compare(model[i][0], text[i])
-
     def test_tree_row_slice(self):
         model = Gtk.ListStore(int, str, float)
         model.append([1, "one", -0.1])
-- 
1.7.7.3

