[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 19/23] python/aqmp: take QMPBadPortError and parse_address from q
From: |
John Snow |
Subject: |
[PATCH 19/23] python/aqmp: take QMPBadPortError and parse_address from qemu.qmp |
Date: |
Wed, 24 Nov 2021 14:26:13 -0500 |
Shift these definitions over from the qmp package to the async qmp
package.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/aqmp/aqmp_tui.py | 2 +-
python/qemu/aqmp/legacy.py | 30 ++++++++++++++++++++++++++----
python/qemu/qmp/__init__.py | 26 --------------------------
3 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py
index a2929f771c..184a3e4690 100644
--- a/python/qemu/aqmp/aqmp_tui.py
+++ b/python/qemu/aqmp/aqmp_tui.py
@@ -35,8 +35,8 @@
import urwid
import urwid_readline
-from ..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 5d358d63db..c8183de19a 100644
--- a/python/qemu/aqmp/legacy.py
+++ b/python/qemu/aqmp/legacy.py
@@ -22,9 +22,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]
@@ -45,6 +42,12 @@
# pylint: disable=missing-docstring
+class QMPBadPortError(AQMPError):
+ """
+ Unable to parse socket address: Port was non-numerical.
+ """
+
+
class QEMUMonitorProtocol(qemu.qmp.QEMUMonitorProtocol):
def __init__(self, address: SocketAddrT,
server: bool = False,
@@ -72,7 +75,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 358c0971d0..4e08641154 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.31.1
- [PATCH 13/23] scripts/cpu-x86-uarch-abi: switch to AQMP, (continued)
- [PATCH 13/23] scripts/cpu-x86-uarch-abi: switch to AQMP, John Snow, 2021/11/24
- [PATCH 02/23] python/aqmp: handle asyncio.TimeoutError on execute(), John Snow, 2021/11/24
- [PATCH 03/23] python/aqmp: copy type definitions from qmp, John Snow, 2021/11/24
- [PATCH 06/23] python/qmp: switch qemu-ga-client to AQMP, John Snow, 2021/11/24
- [PATCH 07/23] python/qmp: switch qom tools to AQMP, John Snow, 2021/11/24
- [PATCH 09/23] python: move qmp utilities to python/qemu/utils, John Snow, 2021/11/24
- [PATCH 14/23] scripts/render-block-graph: switch to AQMP, John Snow, 2021/11/24
- [PATCH 11/23] python/machine: permanently switch to AQMP, John Snow, 2021/11/24
- [PATCH 12/23] scripts/cpu-x86-uarch-abi: fix CLI parsing, John Snow, 2021/11/24
- [PATCH 17/23] iotests: switch to AQMP, John Snow, 2021/11/24
- [PATCH 19/23] python/aqmp: take QMPBadPortError and parse_address from qemu.qmp,
John Snow <=
- [PATCH 15/23] scripts/bench-block-job: switch to AQMP, John Snow, 2021/11/24
- [PATCH 18/23] python: temporarily silence pylint duplicate-code warnings, John Snow, 2021/11/24
- [PATCH 21/23] python/aqmp: copy qmp docstrings to qemu.aqmp.legacy, John Snow, 2021/11/24
- [PATCH 16/23] iotests/mirror-top-perms: switch to AQMP, John Snow, 2021/11/24
- [PATCH 20/23] python/aqmp: fully separate from qmp.QEMUMonitorProtocol, John Snow, 2021/11/24
- [PATCH 23/23] python: re-enable pylint duplicate-code warnings, John Snow, 2021/11/24
- [PATCH 22/23] python: remove the old QMP package, John Snow, 2021/11/24