[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/17] python/aqmp: take QMPBadPortError and parse_address from qe
From: |
John Snow |
Subject: |
[PULL 10/17] python/aqmp: take QMPBadPortError and parse_address from qemu.qmp |
Date: |
Thu, 21 Apr 2022 11:15:53 -0400 |
Shift these definitions over from the qmp package to the async qmp
package.
(Licensing: this is a lateral move, from GPLv2 (only) to GPLv2 (only))
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Beraldo Leal <bleal@redhat.com>
Message-id: 20220330172812.3427355-3-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/aqmp/aqmp_tui.py | 3 +--
python/qemu/aqmp/legacy.py | 30 ++++++++++++++++++++++++++----
python/qemu/qmp/__init__.py | 26 --------------------------
3 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py
index 946ba9af24e..59d3036be38 100644
--- a/python/qemu/aqmp/aqmp_tui.py
+++ b/python/qemu/aqmp/aqmp_tui.py
@@ -35,9 +35,8 @@
import urwid
import urwid_readline
-from qemu.qmp import QEMUMonitorProtocol, QMPBadPortError
-
from .error import ProtocolError
+from .legacy import QEMUMonitorProtocol, QMPBadPortError
from .message import DeserializationError, Message, UnexpectedTypeError
from .protocol import ConnectError, Runstate
from .qmp_client import ExecInterruptedError, QMPClient
diff --git a/python/qemu/aqmp/legacy.py b/python/qemu/aqmp/legacy.py
index f86cb298049..f0262749491 100644
--- a/python/qemu/aqmp/legacy.py
+++ b/python/qemu/aqmp/legacy.py
@@ -33,9 +33,6 @@
from .qmp_client import QMPClient
-# (Temporarily) Re-export QMPBadPortError
-QMPBadPortError = qemu.qmp.QMPBadPortError
-
#: QMPMessage is an entire QMP message of any kind.
QMPMessage = Dict[str, Any]
@@ -56,6 +53,12 @@
# pylint: disable=missing-docstring
+class QMPBadPortError(QMPError):
+ """
+ Unable to parse socket address: Port was non-numerical.
+ """
+
+
class QEMUMonitorProtocol(qemu.qmp.QEMUMonitorProtocol):
def __init__(self, address: SocketAddrT,
server: bool = False,
@@ -86,7 +89,26 @@ def _get_greeting(self) -> Optional[QMPMessage]:
return None
# __enter__ and __exit__ need no changes
- # parse_address needs no changes
+
+ @classmethod
+ def parse_address(cls, address: str) -> SocketAddrT:
+ """
+ Parse a string into a QMP address.
+
+ Figure out if the argument is in the port:host form.
+ If it's not, it's probably a file path.
+ """
+ components = address.split(':')
+ if len(components) == 2:
+ try:
+ port = int(components[1])
+ except ValueError:
+ msg = f"Bad port: '{components[1]}' in '{address}'."
+ raise QMPBadPortError(msg) from None
+ return (components[0], port)
+
+ # Treat as filepath.
+ return address
def connect(self, negotiate: bool = True) -> Optional[QMPMessage]:
self._aqmp.await_greeting = negotiate
diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py
index 358c0971d06..4e086411544 100644
--- a/python/qemu/qmp/__init__.py
+++ b/python/qemu/qmp/__init__.py
@@ -102,12 +102,6 @@ def __init__(self, reply: QMPMessage):
self.reply = reply
-class QMPBadPortError(QMPError):
- """
- Unable to parse socket address: Port was non-numerical.
- """
-
-
class QEMUMonitorProtocol:
"""
Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
@@ -237,26 +231,6 @@ def __exit__(self,
# Implement context manager exit function.
self.close()
- @classmethod
- def parse_address(cls, address: str) -> SocketAddrT:
- """
- Parse a string into a QMP address.
-
- Figure out if the argument is in the port:host form.
- If it's not, it's probably a file path.
- """
- components = address.split(':')
- if len(components) == 2:
- try:
- port = int(components[1])
- except ValueError:
- msg = f"Bad port: '{components[1]}' in '{address}'."
- raise QMPBadPortError(msg) from None
- return (components[0], port)
-
- # Treat as filepath.
- return address
-
def connect(self, negotiate: bool = True) -> Optional[QMPMessage]:
"""
Connect to the QMP Monitor and perform capabilities negotiation.
--
2.34.1
- [PULL 00/17] Python patches, John Snow, 2022/04/21
- [PULL 02/17] scripts/bench-block-job: switch to AQMP, John Snow, 2022/04/21
- [PULL 07/17] python/qmp-shell: relicense as LGPLv2+, John Snow, 2022/04/21
- [PULL 05/17] python/aqmp: add explicit GPLv2 license to legacy.py, John Snow, 2022/04/21
- [PULL 03/17] iotests/mirror-top-perms: switch to AQMP, John Snow, 2022/04/21
- [PULL 08/17] python/aqmp-tui: relicense as LGPLv2+, John Snow, 2022/04/21
- [PULL 06/17] python/aqmp: relicense as LGPLv2+, John Snow, 2022/04/21
- [PULL 12/17] python/aqmp: copy qmp docstrings to qemu.aqmp.legacy, John Snow, 2022/04/21
- [PULL 10/17] python/aqmp: take QMPBadPortError and parse_address from qemu.qmp,
John Snow <=
- [PULL 11/17] python/aqmp: fully separate from qmp.QEMUMonitorProtocol, John Snow, 2022/04/21
- [PULL 14/17] python: re-enable pylint duplicate-code warnings, John Snow, 2022/04/21
- [PULL 17/17] python/qmp: remove pylint workaround from legacy.py, John Snow, 2022/04/21
- [PULL 13/17] python: remove the old QMP package, John Snow, 2022/04/21
- [PULL 01/17] python/machine: permanently switch to AQMP, John Snow, 2022/04/21
- [PULL 04/17] iotests: switch to AQMP, John Snow, 2022/04/21
- [PULL 16/17] python: rename 'aqmp-tui' to 'qmp-tui', John Snow, 2022/04/21
- [PULL 09/17] python: temporarily silence pylint duplicate-code warnings, John Snow, 2022/04/21
- [PULL 15/17] python: rename qemu.aqmp to qemu.qmp, John Snow, 2022/04/21
- Re: [PULL 00/17] Python patches, Richard Henderson, 2022/04/21