Skip to content

Commit 29236f7

Browse files
committed
[ot] python/qemu: ot.spi.spi_device: fix error message with not-integral port value
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 76e518f commit 29236f7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

python/qemu/ot/spi/spi_device.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def connect(self, host: str, port: Optional[int] = None) -> None:
101101
if self._socket:
102102
raise RuntimeError('Cannot open multiple comm port at once')
103103
if port is not None:
104+
if not isinstance(port, int):
105+
raise ValueError('Invalid port type')
104106
try:
105107
self._socket = create_connection((host, port),
106108
timeout=self.CONN_TIMEOUT)
@@ -113,10 +115,11 @@ def connect(self, host: str, port: Optional[int] = None) -> None:
113115
try:
114116
if sock_args[0] == 'tcp':
115117
try:
116-
host, port = sock_args[1:]
118+
host, sport = sock_args[1:]
119+
port = int(sport)
117120
except ValueError as exc:
118121
raise ValueError('TCP port not specified') from exc
119-
self._socket = create_connection((host, int(port)),
122+
self._socket = create_connection((host, port),
120123
timeout=self.TIMEOUT)
121124
self._socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
122125
elif sock_args[0] == 'unix':

0 commit comments

Comments
 (0)