mirror of
https://github.com/gryf/wicd.git
synced 2026-03-13 21:25:46 +01:00
Tweak misc.to_unicode() so that it is more likely to encode to utf-8 correctly.
This commit is contained in:
21
wicd/misc.py
21
wicd/misc.py
@@ -302,13 +302,22 @@ def get_gettext():
|
|||||||
def to_unicode(x):
|
def to_unicode(x):
|
||||||
""" Attempts to convert a string to utf-8. """
|
""" Attempts to convert a string to utf-8. """
|
||||||
# If this is a unicode string, encode it and return
|
# If this is a unicode string, encode it and return
|
||||||
if type(x) == unicode:
|
if type(x) not in [unicode, str]:
|
||||||
|
return x
|
||||||
|
if isinstance(x, unicode):
|
||||||
return x.encode('utf-8')
|
return x.encode('utf-8')
|
||||||
encoding = locale.getpreferredencoding()
|
encoding = locale.getpreferredencoding()
|
||||||
try:
|
try:
|
||||||
ret = x.decode(encoding, 'replace').encode('utf-8')
|
ret = x.decode(encoding).encode('utf-8')
|
||||||
except:
|
except UnicodeError:
|
||||||
ret = x.decode('utf-8', 'replace').encode('utf-8')
|
try:
|
||||||
|
ret = x.decode('utf-8').encode('utf-8')
|
||||||
|
except UnicodeError:
|
||||||
|
try:
|
||||||
|
ret = x.decode('latin-1').encode('utf-8')
|
||||||
|
except UnicodeError:
|
||||||
|
ret = x.decode('utf-8', 'replace').encode('utf-8')
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def RenameProcess(new_name):
|
def RenameProcess(new_name):
|
||||||
@@ -509,8 +518,8 @@ def get_language_list_gui():
|
|||||||
language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)')
|
language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)')
|
||||||
language['done'] = _('Done connecting...')
|
language['done'] = _('Done connecting...')
|
||||||
language['scanning'] = _('Scanning')
|
language['scanning'] = _('Scanning')
|
||||||
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
|
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface. " + \
|
||||||
"This typically means there was a problem starting the daemon." + \
|
"This typically means there was a problem starting the daemon. " + \
|
||||||
"Check the wicd log for more info")
|
"Check the wicd log for more info")
|
||||||
language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user