diff mbox

[RFC,10/10] QMP/qmp.py: set locale for exceptions to display non-ascii messages correctly

Message ID 20130214061057.15062.77848.stgit@melchior2.sdl.hitachi.co.jp
State New
Headers show

Commit Message

Tomoki Sekiyama Feb. 14, 2013, 6:10 a.m. UTC
qemu-ga in Windows might return error message with multibyte characters
when the guest OS language is set to other than English. To display such
messages correctly, this decodes the message based on locale settings.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama.qu@hitachi.com>
---
 QMP/qmp.py |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/QMP/qmp.py b/QMP/qmp.py
index c551df1..ee21819 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -11,6 +11,7 @@ 
 import json
 import errno
 import socket
+import locale
 
 class QMPError(Exception):
     pass
@@ -133,7 +134,8 @@  class QEMUMonitorProtocol:
     def command(self, cmd, **kwds):
         ret = self.cmd(cmd, kwds)
         if ret.has_key('error'):
-            raise Exception(ret['error']['desc'])
+            enc = locale.getpreferredencoding()
+            raise Exception(ret['error']['desc'].encode(enc))
         return ret['return']
 
     def pull_event(self, wait=False):