lockss-pybasic 0.3.0.dev2__py3-none-any.whl → 0.3.0.dev4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lockss/pybasic/__init__.py +1 -1
- lockss/pybasic/nodeutil.py +167 -72
- {lockss_pybasic-0.3.0.dev2.dist-info → lockss_pybasic-0.3.0.dev4.dist-info}/METADATA +4 -3
- lockss_pybasic-0.3.0.dev4.dist-info/RECORD +10 -0
- {lockss_pybasic-0.3.0.dev2.dist-info → lockss_pybasic-0.3.0.dev4.dist-info}/WHEEL +1 -1
- lockss_pybasic-0.3.0.dev2.dist-info/RECORD +0 -10
- {lockss_pybasic-0.3.0.dev2.dist-info → lockss_pybasic-0.3.0.dev4.dist-info}/licenses/LICENSE +0 -0
lockss/pybasic/__init__.py
CHANGED
lockss/pybasic/nodeutil.py
CHANGED
|
@@ -33,89 +33,184 @@ LOCKSS node utilities.
|
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
35
|
from enum import Enum
|
|
36
|
-
from re import Pattern
|
|
36
|
+
from re import Match, Pattern
|
|
37
37
|
import re
|
|
38
|
-
from typing import Any, Optional
|
|
38
|
+
from typing import Annotated, Any, ClassVar, Literal, Optional, Union
|
|
39
39
|
|
|
40
|
-
from
|
|
40
|
+
from annotated_types import Ge, Le
|
|
41
|
+
from pydantic import BaseModel, BeforeValidator, Field, TypeAdapter, model_validator
|
|
41
42
|
|
|
42
|
-
from .errorutil import InternalError
|
|
43
43
|
|
|
44
|
+
#: An annotated type for port numbers (0-65535)
|
|
45
|
+
PortNumber = Annotated[int, Ge(0), Le(65535)]
|
|
44
46
|
|
|
45
|
-
RE_NODE_REFERENCE: Pattern = re.compile(r'((?P<protocol>https?)://)?(?P<host>[^:]+)(:(?P<repository>\d+|(?=:))(:(?P<configuration>\d+|(?=:))(:(?P<poller>\d+|(?=:))(:(?P<crawler>\d+|(?=:))(:(?P<metadata>\d+|(?=:))(:(?P<soap>\d+))?)?)?)?)?)?')
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
class NodeTypeEnum(Enum):
|
|
49
|
+
"""An enumerated type representing LOCKSS node types."""
|
|
50
|
+
#: An enumerated constant representing LOCKSS 1.x nodes.
|
|
49
51
|
V1 = 'v1'
|
|
52
|
+
#: An enumerated constant representing LOCKSS 2.x nodes.
|
|
50
53
|
V2 = 'v2'
|
|
51
54
|
|
|
52
55
|
|
|
53
|
-
class
|
|
56
|
+
class NodeProtocolEnum(Enum):
|
|
57
|
+
"""An enumerated type representing protocols for reaching LOCKSS nodes."""
|
|
58
|
+
#: An enumerated constant representing HTTP.
|
|
54
59
|
HTTP = 'http'
|
|
60
|
+
#: An enumerated constant representing HTTPS.
|
|
55
61
|
HTTPS = 'https'
|
|
56
62
|
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
class
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
64
|
+
class BaseNodeSpec(BaseModel):
|
|
65
|
+
|
|
66
|
+
DEFAULT_PROTOCOL: ClassVar[NodeProtocolEnum] = NodeProtocolEnum.HTTP
|
|
67
|
+
|
|
68
|
+
TYPE_FIELD: ClassVar[dict[str, str]] = dict(title='Type',
|
|
69
|
+
description="The node's type")
|
|
70
|
+
|
|
71
|
+
protocol: NodeProtocolEnum = Field(default=DEFAULT_PROTOCOL,
|
|
72
|
+
title='Protocol',
|
|
73
|
+
description="The protocol for reaching the node")
|
|
74
|
+
|
|
75
|
+
host: str = Field(title='Host',
|
|
76
|
+
description="The node's host")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class NodeSpec1(BaseNodeSpec):
|
|
80
|
+
|
|
81
|
+
DEFAULT_UI_PORT_V1: ClassVar[int] = 8081
|
|
82
|
+
|
|
83
|
+
type: Literal['v1'] = Field(**BaseNodeSpec.TYPE_FIELD)
|
|
84
|
+
|
|
85
|
+
ui: PortNumber = Field(default=DEFAULT_UI_PORT_V1,
|
|
86
|
+
title='UI Port',
|
|
87
|
+
description="The LOCKSS 1.x node's Web user interface port")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class NodeSpec2(BaseNodeSpec):
|
|
91
|
+
|
|
92
|
+
DEFAULT_REPO_PORT: ClassVar[int] = 24611
|
|
93
|
+
|
|
94
|
+
DEFAULT_CFG_PORT: ClassVar[int] = 24612
|
|
95
|
+
|
|
96
|
+
DEFAULT_POL_PORT: ClassVar[int] = 24613
|
|
97
|
+
|
|
98
|
+
DEFAULT_CRW_PORT: ClassVar[int] = 24614
|
|
99
|
+
|
|
100
|
+
DEFAULT_MD_PORT: ClassVar[int] = 24615
|
|
101
|
+
|
|
102
|
+
DEFAULT_SOAP_PORT: ClassVar[int] = 24616
|
|
103
|
+
|
|
104
|
+
type: Literal['v2'] = Field(**BaseNodeSpec.TYPE_FIELD)
|
|
105
|
+
|
|
106
|
+
repository: PortNumber = Field(default=DEFAULT_REPO_PORT,
|
|
107
|
+
title='Repository Port',
|
|
108
|
+
description="The node's Repository Service REST API Port")
|
|
109
|
+
|
|
110
|
+
configuration: PortNumber = Field(default=DEFAULT_CFG_PORT,
|
|
111
|
+
title='Configuration Port',
|
|
112
|
+
description="The node's Configuration Service REST API Port")
|
|
113
|
+
|
|
114
|
+
poller: PortNumber = Field(default=DEFAULT_POL_PORT,
|
|
115
|
+
title='Poller Port',
|
|
116
|
+
description="The node's Poller Service REST API Port")
|
|
117
|
+
|
|
118
|
+
crawler: PortNumber = Field(default=DEFAULT_CRW_PORT,
|
|
119
|
+
title='Crawler Port',
|
|
120
|
+
description="The node's Crawler Service REST API Port")
|
|
121
|
+
|
|
122
|
+
metadata: PortNumber = Field(default=DEFAULT_MD_PORT,
|
|
123
|
+
title='Metadata Port',
|
|
124
|
+
description="The node's Metadata Service REST API Port")
|
|
125
|
+
|
|
126
|
+
soap: PortNumber = Field(default=DEFAULT_SOAP_PORT,
|
|
127
|
+
title='SOAP Port',
|
|
128
|
+
description="The node's SOAP Compatibility Service REST API Port")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
_RE_NODE_REFERENCE: Pattern[str] = re.compile(r'((?P<protocol>https?)://)?(?P<host>[^:]+)(:(?P<repository>\d+|(?=:))(:(?P<configuration>\d+|(?=:))(:(?P<poller>\d+|(?=:))(:(?P<crawler>\d+|(?=:))(:(?P<metadata>\d+|(?=:))(:(?P<soap>\d+))?)?)?)?)?)?')
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
#: A type for LOCKSS node specification strings.
|
|
135
|
+
NodeSpecStr = str
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _parse_node_spec_string(node_spec_string: NodeSpecStr) -> dict[str, str]:
|
|
139
|
+
mat: Optional[Match[str]] = _RE_NODE_REFERENCE.fullmatch(node_spec_string)
|
|
140
|
+
if mat is None:
|
|
141
|
+
raise ValueError(f'Invalid node specification string: {node_spec_string}')
|
|
142
|
+
d = dict(host=mat.group('host'))
|
|
143
|
+
if prot := mat.group('protocol'):
|
|
144
|
+
d['protocol'] = prot
|
|
145
|
+
five = ('configuration', 'poller', 'crawler', 'metadata', 'soap')
|
|
146
|
+
if repo_or_ui := mat.group('repository'):
|
|
147
|
+
if any(mat.group(x) for x in five) or len(repo_or_ui) >= 5:
|
|
148
|
+
# 10000 or larger: assume V2
|
|
149
|
+
d['type'] = NodeTypeEnum.V2.value
|
|
150
|
+
d['repository'] = repo_or_ui
|
|
151
|
+
elif len(repo_or_ui) == 4:
|
|
152
|
+
# 1000 through 9999: assume V1
|
|
153
|
+
d['type'] = NodeTypeEnum.V1.value
|
|
154
|
+
d['ui'] = repo_or_ui
|
|
155
|
+
else:
|
|
156
|
+
raise ValueError(f'Invalid repository/UI port in node specification string: {repo_or_ui}')
|
|
157
|
+
else:
|
|
158
|
+
# Assume V2
|
|
159
|
+
d['type'] = NodeTypeEnum.V2.value
|
|
160
|
+
for k in five:
|
|
161
|
+
if p := mat.group(k):
|
|
162
|
+
d[k] = p # string okay, will be coerced to int
|
|
163
|
+
return d
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _maybe_deserialize_node_spec_string(value: Any) -> Any:
|
|
167
|
+
if isinstance(value, NodeSpecStr) and not value.startswith('{'):
|
|
168
|
+
return _parse_node_spec_string(value)
|
|
169
|
+
return value
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
#: A type for LOCKSS node specifications, that also accepts a compact LOCKSS
|
|
173
|
+
#: node specification string.
|
|
174
|
+
NodeSpec = Annotated[
|
|
175
|
+
Annotated[Union[NodeSpec1, NodeSpec2], Field(discriminator='type')],
|
|
176
|
+
BeforeValidator(_maybe_deserialize_node_spec_string)
|
|
177
|
+
]
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
#: A type adapter for the NodeSpec type.
|
|
181
|
+
_node_spec_adapter: TypeAdapter[NodeSpec] = TypeAdapter(NodeSpec)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def get_node_spec_adapter() -> TypeAdapter[NodeSpec]:
|
|
185
|
+
"""
|
|
186
|
+
Gets a type adapter for the NodeSpec type, which is a union type and cannot
|
|
187
|
+
be instantiated directly.
|
|
188
|
+
|
|
189
|
+
:return: A type adapter for the NodeSpec type.
|
|
190
|
+
"""
|
|
191
|
+
return _node_spec_adapter
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
NodeSetKind = Literal['NodeSet']
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
NodeSetIdentifier = str
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
NodeIdentifier = str
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class NodeSet(BaseModel):
|
|
204
|
+
|
|
205
|
+
kind: NodeSetKind = Field(title='Kind',
|
|
206
|
+
description="This object's kind")
|
|
207
|
+
|
|
208
|
+
id: NodeSetIdentifier = Field(title='Node Set Identifier',
|
|
209
|
+
description='An identifier for the node set')
|
|
210
|
+
|
|
211
|
+
name: str = Field(title='Node Set Name',
|
|
212
|
+
description='A name for the node set')
|
|
213
|
+
|
|
214
|
+
nodes: dict[NodeIdentifier, NodeSpec] = Field(min_length=1,
|
|
215
|
+
title='Nodes',
|
|
216
|
+
description='A non-empty list of nodes')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lockss-pybasic
|
|
3
|
-
Version: 0.3.0.
|
|
3
|
+
Version: 0.3.0.dev4
|
|
4
4
|
Summary: Basic Python utilities
|
|
5
5
|
License: BSD-3-Clause
|
|
6
6
|
License-File: LICENSE
|
|
@@ -16,7 +16,8 @@ Classifier: Intended Audience :: Developers
|
|
|
16
16
|
Classifier: License :: OSI Approved :: BSD License
|
|
17
17
|
Classifier: Programming Language :: Python
|
|
18
18
|
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
-
Requires-Dist:
|
|
19
|
+
Requires-Dist: annotated-types (>=0.7.0,<0.8.0)
|
|
20
|
+
Requires-Dist: click-extra (>=7.17.0,<7.18.0)
|
|
20
21
|
Requires-Dist: pydantic (>=2.13.0,<2.14.0)
|
|
21
22
|
Project-URL: Repository, https://github.com/lockss/lockss-pybasic
|
|
22
23
|
Description-Content-Type: text/x-rst
|
|
@@ -25,7 +26,7 @@ Description-Content-Type: text/x-rst
|
|
|
25
26
|
lockss-pybasic
|
|
26
27
|
==============
|
|
27
28
|
|
|
28
|
-
.. |RELEASE| replace:: 0.3.0-
|
|
29
|
+
.. |RELEASE| replace:: 0.3.0-dev4
|
|
29
30
|
.. |RELEASE_DATE| replace:: NOT YET RELEASED
|
|
30
31
|
|
|
31
32
|
**Latest release:** |RELEASE| (|RELEASE_DATE|)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
lockss/pybasic/__init__.py,sha256=NWFBmNQ6XEuQOYE0WVIYhe0Ci5wIxmzBewZ_oY8u-G8,1678
|
|
2
|
+
lockss/pybasic/auidutil.py,sha256=Q4vjjGfymiXVwPu35RyyLZBnViv8mDJKCjOyJb-sbS8,13921
|
|
3
|
+
lockss/pybasic/cliutil.py,sha256=F970MhLcQCYS3INLQT1Ij8nKt_ICmttiS3nSnuWuN7s,8106
|
|
4
|
+
lockss/pybasic/errorutil.py,sha256=4EaO0a1yIG1DbWltASeT15bg1bGg5kOYspsW0iJdVLc,1951
|
|
5
|
+
lockss/pybasic/fileutil.py,sha256=IIS2AFDgYtmBLPVHqQi1AkIFj6da04b6NQtjX9bIVqQ,2958
|
|
6
|
+
lockss/pybasic/nodeutil.py,sha256=snBT7OPttThBJXVxgLC6Onmuoa8Z-jOOM1LWdhIb-js,7928
|
|
7
|
+
lockss_pybasic-0.3.0.dev4.dist-info/METADATA,sha256=eZ1B2T-R5rn4u2ZXTkcWZFEGChVqOxbbV5FT-pusIpw,2338
|
|
8
|
+
lockss_pybasic-0.3.0.dev4.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
|
|
9
|
+
lockss_pybasic-0.3.0.dev4.dist-info/licenses/LICENSE,sha256=EOxPunNz3XP6AjgbPFolu-d9BS_AF9TtKn1WXgeYPsE,1506
|
|
10
|
+
lockss_pybasic-0.3.0.dev4.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
lockss/pybasic/__init__.py,sha256=c5oAL1taDdPzGD1IxLXhG8k-0GEdxr9duOohhsF4JA4,1678
|
|
2
|
-
lockss/pybasic/auidutil.py,sha256=Q4vjjGfymiXVwPu35RyyLZBnViv8mDJKCjOyJb-sbS8,13921
|
|
3
|
-
lockss/pybasic/cliutil.py,sha256=F970MhLcQCYS3INLQT1Ij8nKt_ICmttiS3nSnuWuN7s,8106
|
|
4
|
-
lockss/pybasic/errorutil.py,sha256=4EaO0a1yIG1DbWltASeT15bg1bGg5kOYspsW0iJdVLc,1951
|
|
5
|
-
lockss/pybasic/fileutil.py,sha256=IIS2AFDgYtmBLPVHqQi1AkIFj6da04b6NQtjX9bIVqQ,2958
|
|
6
|
-
lockss/pybasic/nodeutil.py,sha256=m9WCVbfSzOKklA9qstoOUUbF0v-l1TtePfx6rjEh_IU,5872
|
|
7
|
-
lockss_pybasic-0.3.0.dev2.dist-info/METADATA,sha256=mtfXJBQQ36ruZpFsntyU_-sF9FOdAS_O5XtdxmydcMY,2290
|
|
8
|
-
lockss_pybasic-0.3.0.dev2.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
|
|
9
|
-
lockss_pybasic-0.3.0.dev2.dist-info/licenses/LICENSE,sha256=EOxPunNz3XP6AjgbPFolu-d9BS_AF9TtKn1WXgeYPsE,1506
|
|
10
|
-
lockss_pybasic-0.3.0.dev2.dist-info/RECORD,,
|
{lockss_pybasic-0.3.0.dev2.dist-info → lockss_pybasic-0.3.0.dev4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|