diff options
author | Michael Opdenacker <michael.opdenacker@bootlin.com> | 2024-04-12 11:02:27 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-04-14 06:31:45 +0100 |
commit | d133dc7e7723f3f9b98fa0d0e72c9dce451e0889 (patch) | |
tree | a7b48b77c03a802c164a0cbed1207426d39b156e /bitbake | |
parent | 9a2d08995e552f395fdfe91f7c204b7e65459412 (diff) | |
download | poky-d133dc7e7723f3f9b98fa0d0e72c9dce451e0889.tar.gz |
bitbake: asyncrpc: include parse_address from hashserv
Moving the code and related definitions from
hashserv/__init__.py to asyncrpc/client.py,
allowing this function to be used in other asyncrpc clients.
(Bitbake rev: b67bb05e431414866b8e8c6a4c88d20b9cdb44a3)
Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
Suggested-by: Joshua Watt <JPEWhacker@gmail.com>
Cc: Tim Orling <ticotimo@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/asyncrpc/client.py | 23 | ||||
-rw-r--r-- | bitbake/lib/hashserv/__init__.py | 27 |
2 files changed, 24 insertions, 26 deletions
diff --git a/bitbake/lib/bb/asyncrpc/client.py b/bitbake/lib/bb/asyncrpc/client.py index 29a5ab76aa..a350b4fb12 100644 --- a/bitbake/lib/bb/asyncrpc/client.py +++ b/bitbake/lib/bb/asyncrpc/client.py | |||
@@ -10,11 +10,34 @@ import json | |||
10 | import os | 10 | import os |
11 | import socket | 11 | import socket |
12 | import sys | 12 | import sys |
13 | import re | ||
13 | import contextlib | 14 | import contextlib |
14 | from threading import Thread | 15 | from threading import Thread |
15 | from .connection import StreamConnection, WebsocketConnection, DEFAULT_MAX_CHUNK | 16 | from .connection import StreamConnection, WebsocketConnection, DEFAULT_MAX_CHUNK |
16 | from .exceptions import ConnectionClosedError, InvokeError | 17 | from .exceptions import ConnectionClosedError, InvokeError |
17 | 18 | ||
19 | UNIX_PREFIX = "unix://" | ||
20 | WS_PREFIX = "ws://" | ||
21 | WSS_PREFIX = "wss://" | ||
22 | |||
23 | ADDR_TYPE_UNIX = 0 | ||
24 | ADDR_TYPE_TCP = 1 | ||
25 | ADDR_TYPE_WS = 2 | ||
26 | |||
27 | def parse_address(addr): | ||
28 | if addr.startswith(UNIX_PREFIX): | ||
29 | return (ADDR_TYPE_UNIX, (addr[len(UNIX_PREFIX) :],)) | ||
30 | elif addr.startswith(WS_PREFIX) or addr.startswith(WSS_PREFIX): | ||
31 | return (ADDR_TYPE_WS, (addr,)) | ||
32 | else: | ||
33 | m = re.match(r"\[(?P<host>[^\]]*)\]:(?P<port>\d+)$", addr) | ||
34 | if m is not None: | ||
35 | host = m.group("host") | ||
36 | port = m.group("port") | ||
37 | else: | ||
38 | host, port = addr.split(":") | ||
39 | |||
40 | return (ADDR_TYPE_TCP, (host, int(port))) | ||
18 | 41 | ||
19 | class AsyncClient(object): | 42 | class AsyncClient(object): |
20 | def __init__( | 43 | def __init__( |
diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py index 552a33278f..74367eb6b4 100644 --- a/bitbake/lib/hashserv/__init__.py +++ b/bitbake/lib/hashserv/__init__.py | |||
@@ -5,39 +5,14 @@ | |||
5 | 5 | ||
6 | import asyncio | 6 | import asyncio |
7 | from contextlib import closing | 7 | from contextlib import closing |
8 | import re | ||
9 | import itertools | 8 | import itertools |
10 | import json | 9 | import json |
11 | from collections import namedtuple | 10 | from collections import namedtuple |
12 | from urllib.parse import urlparse | 11 | from urllib.parse import urlparse |
13 | 12 | from bb.asyncrpc.client import parse_address, ADDR_TYPE_UNIX, ADDR_TYPE_WS | |
14 | UNIX_PREFIX = "unix://" | ||
15 | WS_PREFIX = "ws://" | ||
16 | WSS_PREFIX = "wss://" | ||
17 | |||
18 | ADDR_TYPE_UNIX = 0 | ||
19 | ADDR_TYPE_TCP = 1 | ||
20 | ADDR_TYPE_WS = 2 | ||
21 | 13 | ||
22 | User = namedtuple("User", ("username", "permissions")) | 14 | User = namedtuple("User", ("username", "permissions")) |
23 | 15 | ||
24 | |||
25 | def parse_address(addr): | ||
26 | if addr.startswith(UNIX_PREFIX): | ||
27 | return (ADDR_TYPE_UNIX, (addr[len(UNIX_PREFIX) :],)) | ||
28 | elif addr.startswith(WS_PREFIX) or addr.startswith(WSS_PREFIX): | ||
29 | return (ADDR_TYPE_WS, (addr,)) | ||
30 | else: | ||
31 | m = re.match(r"\[(?P<host>[^\]]*)\]:(?P<port>\d+)$", addr) | ||
32 | if m is not None: | ||
33 | host = m.group("host") | ||
34 | port = m.group("port") | ||
35 | else: | ||
36 | host, port = addr.split(":") | ||
37 | |||
38 | return (ADDR_TYPE_TCP, (host, int(port))) | ||
39 | |||
40 | |||
41 | def create_server( | 16 | def create_server( |
42 | addr, | 17 | addr, |
43 | dbname, | 18 | dbname, |