Skip to contentSkip to conversation

Provided python3 support for qmp.py 2/2]

PATCH Stefan Hajnoczi 1 participant 1 message Mar 24, 2017 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 1 line · Joannah Nanjekye

From: nanjekyejoannah <[email protected]>

Thanks for the patch!

Quoted 5 lines

The patch provides python 3 support for one of the scripts in scripts/qmp that is to say qmp.py. This is not a port to python 3 but rather the patch ensures that the script runs fine for both python 2 and 3.

Quoted 7 lines

Minimum Python Versions supported:

Python 2 : python 2.6 +
Python 3 : python 3.3 +

The two new imports future and builtins introduced refer to the future pip-installable package on PyPI.

Signed-off-by goes here (after the commit description).

scripts/qmp/qmp.py line 12

Quoted 12 lines

---

scripts/qmp/qmp.py +0 -2
index 6dcb870..57ac86b 100644
@@ -8,8 +8,6 @@
 # This work is licensed under the terms of the GNU GPL, version 2.  See
 # the COPYING file in the top-level directory.
 from __future__ import absolute_import, print_function, unicode_literals
-from future.utils import raise_from
-from builtins import str 

This looks like a patch on top of your previous patch.

Please send a v3 patch that applies directly to qemu.git/master. You may need to use "git rebase -i master" to squash intermediate commits you've made together into a single patch. Logically these changes are part of the same code change so there's no need for multiple patches.

The v3 patch email should be:

[PATCH v3] scripts/qmp: python3 support for qmp.py

Please also CC Markus Armbruster <[email protected]>. He is the maintainer of this file (you can check for maintainers using scripts/get_maintainer.pl -f scripts/qmp.py).

Quoted 65 lines
scripts/qmp/qmp.py +11 -11
 import json
 import errno
 import socket
@@ -58,13 +56,13 @@ class QEMUMonitorProtocol:
 
     def __negotiate_capabilities(self):
         greeting = self.__json_read()
-        if greeting is None or not greeting.has_key('QMP'):
-            raise_from(QMPConnectError())
+        if greeting is None or not 'QMP' in list(greeting):
+            raise QMPConnectError()
         # Greeting seems ok, negotiate capabilities
         resp = self.cmd('qmp_capabilities')
         if "return" in resp:
             return greeting
-        raise_from(QMPCapabilitiesError())
+        raise QMPCapabilitiesError()
 
     def __json_read(self, only_event=False):
         while True:
@@ -74,7 +72,7 @@ class QEMUMonitorProtocol:
             resp = json.loads(data)
             if 'event' in resp:
                 if self._debug:
-                    print(u"QMP:<<< %s" % str(resp), file=sys.stderr) 
+                    print(u"QMP:<<< %s" % resp, file=sys.stderr) 
                 self.__events.append(resp)
                 if not only_event:
                     continue
@@ -113,11 +111,11 @@ class QEMUMonitorProtocol:
             try:
                 ret = self.__json_read(only_event=True)
             except socket.timeout:
-                raise_from(QMPTimeoutError("Timeout waiting for event"))
+                raise QMPTimeoutError("Timeout waiting for event")
             except:
-                raise_from(QMPConnectError("Error while reading from socket"))
+                raise(QMPConnectError("Error while reading from socket"))
             if ret is None:
-                raise_from(QMPConnectError("Error while reading from socket"))
+                raise QMPConnectError("Error while reading from socket")
             self.__sock.settimeout(None)
 
     def connect(self, negotiate=True):
@@ -157,16 +155,16 @@ class QEMUMonitorProtocol:
                 been closed
         """
         if self._debug:
-            print(u"QMP:>>> %s" % str(qmp_cmd), file=sys.stderr) 
+            print(u"QMP:>>> %s" % qmp_cmd, file=sys.stderr) 
         try:
-            self.__sock.sendall(json.dumps(qmp_cmd))
+            self.__sock.sendall((json.dumps(qmp_cmd)).encode('latin-1'))
         except socket.error as err:
             if err[0] == errno.EPIPE:
                 return
-            raise_from(socket.error(), err)
+            raise (socket.error(), err)
         resp = self.__json_read()
         if self._debug:
-            print(u"QMP:<<< %s" % str(resp), file=sys.stderr)  
+            print(u"QMP:<<< %s" % resp, file=sys.stderr)  
         return resp
 
     def cmd(self, name, args=None, id=None):