getpreferredencoding instead of utf-8
This commit is contained in:
parent
6b615a8d72
commit
047f7ce21e
1 changed files with 16 additions and 14 deletions
|
@ -43,11 +43,12 @@ from common import i18n
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
i18n.init()
|
i18n.init()
|
||||||
|
|
||||||
|
PREFERRED_ENCODING = locale.getpreferredencoding()
|
||||||
|
|
||||||
def send_error(error_message):
|
def send_error(error_message):
|
||||||
'''Writes error message to stderr and exits'''
|
'''Writes error message to stderr and exits'''
|
||||||
print >> sys.stderr, error_message.encode(
|
print >> sys.stderr, error_message.encode(PREFERRED_ENCODING)
|
||||||
locale.getpreferredencoding())
|
sys.exit()
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dbus
|
import dbus
|
||||||
|
@ -64,6 +65,7 @@ INTERFACE = 'org.gajim.dbus.RemoteInterface'
|
||||||
SERVICE = 'org.gajim.dbus'
|
SERVICE = 'org.gajim.dbus'
|
||||||
BASENAME = 'gajim-remote'
|
BASENAME = 'gajim-remote'
|
||||||
|
|
||||||
|
|
||||||
class GajimRemote:
|
class GajimRemote:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -215,10 +217,9 @@ class GajimRemote:
|
||||||
self.command = sys.argv[1]
|
self.command = sys.argv[1]
|
||||||
if self.command == 'help':
|
if self.command == 'help':
|
||||||
if self.argv_len == 3:
|
if self.argv_len == 3:
|
||||||
print self.help_on_command(sys.argv[2]).encode(
|
print self.help_on_command(sys.argv[2]).encode(PREFERRED_ENCODING)
|
||||||
locale.getpreferredencoding())
|
|
||||||
else:
|
else:
|
||||||
print self.compose_help().encode(locale.getpreferredencoding())
|
print self.compose_help().encode(PREFERRED_ENCODING)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
self.init_connection()
|
self.init_connection()
|
||||||
|
@ -385,7 +386,7 @@ class GajimRemote:
|
||||||
res += self.print_info(level+1, items)
|
res += self.print_info(level+1, items)
|
||||||
if res != '':
|
if res != '':
|
||||||
if isinstance(res, str):
|
if isinstance(res, str):
|
||||||
res = res.decode('utf-8')
|
res = res.decode(PREFERRED_ENCODING)
|
||||||
ret_str += '%s%s: \n%s' % (spacing, key, res)
|
ret_str += '%s%s: \n%s' % (spacing, key, res)
|
||||||
elif isinstance(val, dict):
|
elif isinstance(val, dict):
|
||||||
res = self.print_info(level+1, val)
|
res = self.print_info(level+1, val)
|
||||||
|
@ -395,8 +396,8 @@ class GajimRemote:
|
||||||
# utf-8 string come from gajim
|
# utf-8 string come from gajim
|
||||||
# FIXME: why we have strings instead of unicode?
|
# FIXME: why we have strings instead of unicode?
|
||||||
if isinstance(ret_str, str):
|
if isinstance(ret_str, str):
|
||||||
ret_str = ret_str.decode('utf-8')
|
return ret_str
|
||||||
return ret_str.encode(locale.getpreferredencoding())
|
return ret_str.encode(PREFERRED_ENCODING)
|
||||||
|
|
||||||
def unrepr(self, serialized_data):
|
def unrepr(self, serialized_data):
|
||||||
''' works the same as eval, but only for structural values,
|
''' works the same as eval, but only for structural values,
|
||||||
|
@ -490,9 +491,9 @@ class GajimRemote:
|
||||||
send_error('Wrong string: %s' % (value))
|
send_error('Wrong string: %s' % (value))
|
||||||
val, next = self.unrepr(next[1:])
|
val, next = self.unrepr(next[1:])
|
||||||
if isinstance(key, str):
|
if isinstance(key, str):
|
||||||
key = key.decode('utf-8')
|
key = key.decode(PREFERRED_ENCODING)
|
||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
val = val.decode('utf-8')
|
val = val.decode(PREFERRED_ENCODING)
|
||||||
_dict[key] = val
|
_dict[key] = val
|
||||||
next = next.strip()
|
next = next.strip()
|
||||||
if not next:
|
if not next:
|
||||||
|
@ -551,8 +552,9 @@ class GajimRemote:
|
||||||
args = self.commands[self.command][1]
|
args = self.commands[self.command][1]
|
||||||
if len(args) > argv_len:
|
if len(args) > argv_len:
|
||||||
if args[argv_len][2]:
|
if args[argv_len][2]:
|
||||||
send_error(_('Argument "%s" is not specified. \n\
|
send_error(_('Argument "%s" is not specified. \n'
|
||||||
Type "%s help %s" for more info') % (args[argv_len][0], BASENAME, self.command))
|
'Type "%s help %s" for more info') %
|
||||||
|
(args[argv_len][0], BASENAME, self.command))
|
||||||
|
|
||||||
def gobject_quit(self):
|
def gobject_quit(self):
|
||||||
if _version[1] >= 41:
|
if _version[1] >= 41:
|
||||||
|
|
Loading…
Add table
Reference in a new issue