summaryrefslogtreecommitdiff
path: root/community/onboard/fix_encoding_mismatch.patch
blob: 01750598ce0638d354167b9df2cc8997d68fa352 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Subject: Fix string encodings so as to not have a mismatch without mousetweaks
Author: marmuta
Origin: upstream, http://bazaar.launchpad.net/~onboard/onboard/0.91/revision/764
Bug-Ubuntu: https://bugs.launchpad.net/bugs/958385

---
 Onboard/Config.py      |    9 +++++----
 Onboard/ConfigUtils.py |    9 ++++++---
 Onboard/Exceptions.py  |    5 +++--
 Onboard/OnboardGtk.py  |    5 +++--
 Onboard/settings.py    |    7 ++++---
 Onboard/utils.py       |   16 ++++++++++++++++
 6 files changed, 37 insertions(+), 14 deletions(-)

Index: onboard-0.97.0/Onboard/Config.py
===================================================================
--- onboard-0.97.0.orig/Onboard/Config.py
+++ onboard-0.97.0/Onboard/Config.py
@@ -12,7 +12,7 @@
 
 from gi.repository import GLib, Gtk
 
-from Onboard.utils        import show_confirmation_dialog, Version
+from Onboard.utils        import show_confirmation_dialog, Version, unicode_str
 from Onboard.WindowUtils  import Handle
 from Onboard.ConfigUtils  import ConfigObject
 from Onboard.MouseControl import Mousetweaks, ClickMapper
@@ -209,7 +209,7 @@
         try:
             ConfigObject.__init__(self)
         except SchemaError as e:
-            _logger.error(str(e))
+            _logger.error(unicode_str(e))
             sys.exit()
 
         # init paths
@@ -225,7 +225,8 @@
             try:
                 copytree(old_user_dir, user_dir)
             except OSError as ex: # python >2.5
-                _logger.error(_("Failed to migrate user directory. ") + str(ex))
+                _logger.error(_("Failed to migrate user directory. ") + \
+                              unicode_str(ex))
 
         # Load system defaults (if there are any, not required).
         # Used for distribution specific settings, aka branding.
@@ -347,7 +348,7 @@
             self.mousetweaks = Mousetweaks()
             self.children.append(self.mousetweaks)
         except (SchemaError, ImportError) as e:
-            _logger.warning(str(e))
+            _logger.warning(unicode_str(e))
             self.mousetweaks = None
 
         self.clickmapper = ClickMapper()
Index: onboard-0.97.0/Onboard/ConfigUtils.py
===================================================================
--- onboard-0.97.0.orig/Onboard/ConfigUtils.py
+++ onboard-0.97.0/Onboard/ConfigUtils.py
@@ -22,7 +22,8 @@
 from gi.repository import Gio
 
 from Onboard.Exceptions import SchemaError
-from Onboard.utils import pack_name_value_list, unpack_name_value_list
+from Onboard.utils import pack_name_value_list, unpack_name_value_list, \
+                          unicode_str
 
 _CAN_SET_HOOK       = "_can_set_"       # return true if value is valid
 _GSETTINGS_GET_HOOK = "_gsettings_get_" # retrieve from gsettings
@@ -388,7 +389,8 @@
         try:
             filename = parser.read(paths)
         except configparser.ParsingError as ex:
-            _logger.error(_("Failed to read system defaults. " + str(ex)))
+            _logger.error(_("Failed to read system defaults. " + \
+                            unicode_str(ex)))
 
         if not filename:
             _logger.info(_("No system defaults found."))
@@ -501,7 +503,8 @@
                 value = self.settings[self.key]
 
         except KeyError as ex:
-            _logger.error(_("Failed to get gsettings value. ") + str(ex))
+            _logger.error(_("Failed to get gsettings value. ") + \
+                          unicode_str(ex))
 
         return value
 
Index: onboard-0.97.0/Onboard/Exceptions.py
===================================================================
--- onboard-0.97.0.orig/Onboard/Exceptions.py
+++ onboard-0.97.0/Onboard/Exceptions.py
@@ -4,6 +4,7 @@
 
 from traceback import format_tb
 import sys
+from Onboard.utils import unicode_str
 
 class ChainableError(Exception):
     """
@@ -40,10 +41,10 @@
     traceback = property(_get_traceback)
 
     def __str__(self):
-        message = self._message + "\n"
+        message = unicode_str(self._message) + "\n"
         if self.chained_exception:
             message += "%s: %s" % (type(self.chained_exception).__name__,
-                str(self.chained_exception))
+                unicode_str(self.chained_exception))
         return message
 
 class SVGSyntaxError(ChainableError):
Index: onboard-0.97.0/Onboard/OnboardGtk.py
===================================================================
--- onboard-0.97.0.orig/Onboard/OnboardGtk.py
+++ onboard-0.97.0/Onboard/OnboardGtk.py
@@ -26,7 +26,8 @@
 from Onboard.KeyGtk import *
 from Onboard.KbdWindow import KbdWindow, KbdPlugWindow
 from Onboard.KeyboardSVG import KeyboardSVG
-from Onboard.utils       import show_confirmation_dialog, CallOnce, timeit
+from Onboard.utils       import show_confirmation_dialog, CallOnce, timeit, \
+                                unicode_str
 from Onboard.Appearance import Theme
 
 ### Config Singleton ###
@@ -485,7 +486,7 @@
             except virtkey.error as e:
                 t = time.time()
                 if t > self._vk_error_time + .2: # rate limit to once per 200ms
-                    _logger.warning("vk: "+str(e))
+                    _logger.warning("vk: " + unicode_str(e))
                     self._vk_error_time = t
 
         return self._vk
Index: onboard-0.97.0/Onboard/settings.py
===================================================================
--- onboard-0.97.0.orig/Onboard/settings.py
+++ onboard-0.97.0/Onboard/settings.py
@@ -24,7 +24,8 @@
 from Onboard.Appearance  import Theme, ColorScheme
 from Onboard.Scanner     import ScanMode, ScanDevice
 from Onboard.utils       import show_ask_string_dialog, \
-                                show_confirmation_dialog
+                                show_confirmation_dialog, \
+                                unicode_str
 
 from virtkey import virtkey
 from osk     import Devices
@@ -400,8 +401,8 @@
         try:
             Popen([filename, "universal-access"])
         except OSError as e:
-            _logger.warning(_("System settings not found"
-                              " ({}): {}").format(filename, str(e)))
+            _logger.warning(_("System settings not found ({}): {}") \
+                            .format(filename, unicode_str(e)))
 
     def update_num_resize_handles_combobox(self):
         self.num_resize_handles_list = Gtk.ListStore(str, int)
Index: onboard-0.97.0/Onboard/utils.py
===================================================================
--- onboard-0.97.0.orig/Onboard/utils.py
+++ onboard-0.97.0/Onboard/utils.py
@@ -961,4 +961,20 @@
             return 1
         return 0
 
+def unicode_str(obj, encoding = "utf-8"):
+    """ 
+    Safe str() function that always returns an unicode string.
+    Do nothing if the string was already unicode.
+    """
+    if sys.version_info.major >= 3:  # python 3?
+        return str(obj)
+    
+    if type(obj) == unicode:         # unicode string?
+        return obj
+
+    if hasattr(obj, "__unicode__"):  # Exception object?
+        return unicode(obj)
+
+    return str(obj).decode("utf-8")  # strings, numbers, ...
+