moat-kv 0.71.0__py3-none-any.whl → 0.71.7__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.
- moat/kv/__init__.py +6 -7
- moat/kv/_cfg.yaml +3 -2
- moat/kv/actor/__init__.py +2 -1
- moat/kv/actor/deletor.py +4 -1
- moat/kv/auth/__init__.py +12 -13
- moat/kv/auth/_test.py +4 -1
- moat/kv/auth/password.py +11 -7
- moat/kv/backend/mqtt.py +4 -5
- moat/kv/client.py +20 -39
- moat/kv/code.py +3 -3
- moat/kv/command/data.py +4 -3
- moat/kv/command/dump/__init__.py +36 -34
- moat/kv/command/internal.py +2 -3
- moat/kv/command/job.py +1 -2
- moat/kv/command/type.py +3 -6
- moat/kv/data.py +9 -8
- moat/kv/errors.py +16 -8
- moat/kv/mock/__init__.py +2 -12
- moat/kv/model.py +29 -33
- moat/kv/obj/__init__.py +3 -3
- moat/kv/obj/command.py +3 -3
- moat/kv/runner.py +4 -5
- moat/kv/server.py +106 -126
- moat/kv/types.py +10 -12
- {moat_kv-0.71.0.dist-info → moat_kv-0.71.7.dist-info}/METADATA +6 -2
- moat_kv-0.71.7.dist-info/RECORD +47 -0
- {moat_kv-0.71.0.dist-info → moat_kv-0.71.7.dist-info}/WHEEL +1 -1
- moat_kv-0.71.7.dist-info/licenses/LICENSE +3 -0
- moat_kv-0.71.7.dist-info/licenses/LICENSE.APACHE2 +202 -0
- moat_kv-0.71.7.dist-info/licenses/LICENSE.MIT +20 -0
- moat_kv-0.71.7.dist-info/top_level.txt +1 -0
- build/lib/docs/source/conf.py +0 -201
- build/lib/examples/pathify.py +0 -45
- build/lib/moat/kv/__init__.py +0 -19
- build/lib/moat/kv/_cfg.yaml +0 -93
- build/lib/moat/kv/_main.py +0 -91
- build/lib/moat/kv/actor/__init__.py +0 -98
- build/lib/moat/kv/actor/deletor.py +0 -139
- build/lib/moat/kv/auth/__init__.py +0 -444
- build/lib/moat/kv/auth/_test.py +0 -166
- build/lib/moat/kv/auth/password.py +0 -234
- build/lib/moat/kv/auth/root.py +0 -58
- build/lib/moat/kv/backend/__init__.py +0 -67
- build/lib/moat/kv/backend/mqtt.py +0 -71
- build/lib/moat/kv/client.py +0 -1025
- build/lib/moat/kv/code.py +0 -236
- build/lib/moat/kv/codec.py +0 -11
- build/lib/moat/kv/command/__init__.py +0 -1
- build/lib/moat/kv/command/acl.py +0 -180
- build/lib/moat/kv/command/auth.py +0 -261
- build/lib/moat/kv/command/code.py +0 -293
- build/lib/moat/kv/command/codec.py +0 -186
- build/lib/moat/kv/command/data.py +0 -265
- build/lib/moat/kv/command/dump/__init__.py +0 -143
- build/lib/moat/kv/command/error.py +0 -149
- build/lib/moat/kv/command/internal.py +0 -248
- build/lib/moat/kv/command/job.py +0 -433
- build/lib/moat/kv/command/log.py +0 -53
- build/lib/moat/kv/command/server.py +0 -114
- build/lib/moat/kv/command/type.py +0 -201
- build/lib/moat/kv/config.py +0 -46
- build/lib/moat/kv/data.py +0 -216
- build/lib/moat/kv/errors.py +0 -561
- build/lib/moat/kv/exceptions.py +0 -126
- build/lib/moat/kv/mock/__init__.py +0 -101
- build/lib/moat/kv/mock/mqtt.py +0 -159
- build/lib/moat/kv/mock/tracer.py +0 -63
- build/lib/moat/kv/model.py +0 -1069
- build/lib/moat/kv/obj/__init__.py +0 -646
- build/lib/moat/kv/obj/command.py +0 -241
- build/lib/moat/kv/runner.py +0 -1347
- build/lib/moat/kv/server.py +0 -2809
- build/lib/moat/kv/types.py +0 -513
- ci/rtd-requirements.txt +0 -4
- ci/test-requirements.txt +0 -7
- ci/travis.sh +0 -96
- debian/.gitignore +0 -7
- debian/changelog +0 -1435
- debian/control +0 -43
- debian/moat-kv/usr/lib/python3/dist-packages/docs/source/conf.py +0 -201
- debian/moat-kv/usr/lib/python3/dist-packages/examples/pathify.py +0 -45
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/__init__.py +0 -19
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/_cfg.yaml +0 -93
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/_main.py +0 -91
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/actor/__init__.py +0 -98
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/actor/deletor.py +0 -139
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/__init__.py +0 -444
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/_test.py +0 -166
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/password.py +0 -234
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/root.py +0 -58
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/backend/__init__.py +0 -67
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/backend/mqtt.py +0 -71
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/client.py +0 -1025
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/code.py +0 -236
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/codec.py +0 -11
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/__init__.py +0 -1
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/acl.py +0 -180
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/auth.py +0 -261
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/code.py +0 -293
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/codec.py +0 -186
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/data.py +0 -265
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/dump/__init__.py +0 -143
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/error.py +0 -149
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/internal.py +0 -248
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/job.py +0 -433
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/log.py +0 -53
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/server.py +0 -114
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/type.py +0 -201
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/config.py +0 -46
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/data.py +0 -216
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/errors.py +0 -561
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/exceptions.py +0 -126
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/__init__.py +0 -101
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/mqtt.py +0 -159
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/tracer.py +0 -63
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/model.py +0 -1069
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/obj/__init__.py +0 -646
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/obj/command.py +0 -241
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/runner.py +0 -1347
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/server.py +0 -2809
- debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/types.py +0 -513
- debian/moat-kv.postinst +0 -3
- debian/rules +0 -20
- debian/source/format +0 -1
- debian/watch +0 -4
- docs/Makefile +0 -20
- docs/make.bat +0 -36
- docs/source/TODO.rst +0 -61
- docs/source/_static/.gitkeep +0 -0
- docs/source/acls.rst +0 -80
- docs/source/auth.rst +0 -84
- docs/source/client_protocol.rst +0 -456
- docs/source/code.rst +0 -341
- docs/source/command_line.rst +0 -1187
- docs/source/common_protocol.rst +0 -47
- docs/source/conf.py +0 -201
- docs/source/debugging.rst +0 -70
- docs/source/extend.rst +0 -37
- docs/source/history.rst +0 -36
- docs/source/index.rst +0 -75
- docs/source/model.rst +0 -54
- docs/source/overview.rst +0 -83
- docs/source/related.rst +0 -89
- docs/source/server_protocol.rst +0 -450
- docs/source/startup.rst +0 -31
- docs/source/translator.rst +0 -244
- docs/source/tutorial.rst +0 -711
- docs/source/v3.rst +0 -168
- examples/code/transform.scale.yml +0 -21
- examples/code/transform.switch.yml +0 -82
- examples/code/transform.timeslot.yml +0 -63
- examples/pathify.py +0 -45
- moat/kv/codec.py +0 -11
- moat_kv-0.71.0.dist-info/RECORD +0 -188
- moat_kv-0.71.0.dist-info/top_level.txt +0 -9
- scripts/current +0 -15
- scripts/env +0 -8
- scripts/init +0 -39
- scripts/recover +0 -17
- scripts/rotate +0 -33
- scripts/run +0 -29
- scripts/run-all +0 -10
- scripts/run-any +0 -10
- scripts/run-single +0 -15
- scripts/success +0 -4
- systemd/moat-kv-recover.service +0 -21
- systemd/moat-kv-rotate.service +0 -20
- systemd/moat-kv-rotate.timer +0 -10
- systemd/moat-kv-run-all.service +0 -26
- systemd/moat-kv-run-all@.service +0 -25
- systemd/moat-kv-run-any.service +0 -26
- systemd/moat-kv-run-any@.service +0 -25
- systemd/moat-kv-run-single.service +0 -26
- systemd/moat-kv-run-single@.service +0 -25
- systemd/moat-kv.service +0 -27
- systemd/postinst +0 -7
- systemd/sysusers +0 -3
- {moat_kv-0.71.0.dist-info → moat_kv-0.71.7.dist-info}/licenses/LICENSE.txt +0 -0
build/lib/moat/kv/types.py
DELETED
@@ -1,513 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
import logging
|
3
|
-
import weakref
|
4
|
-
|
5
|
-
import jsonschema
|
6
|
-
from moat.util import NotGiven, P, Path, make_proc, singleton
|
7
|
-
|
8
|
-
from .exceptions import ACLError, ClientError
|
9
|
-
from .model import Entry
|
10
|
-
|
11
|
-
logger = logging.getLogger(__name__)
|
12
|
-
|
13
|
-
# TYPES
|
14
|
-
|
15
|
-
|
16
|
-
class MetaEntry(Entry):
|
17
|
-
def __init__(self, *a, **k):
|
18
|
-
super().__init__(*a, **k)
|
19
|
-
self._metaroot = self.parent._metaroot
|
20
|
-
|
21
|
-
@property
|
22
|
-
def metaroot(self):
|
23
|
-
"Stores a link to the meta root because some do need it."
|
24
|
-
return self._metaroot()
|
25
|
-
|
26
|
-
|
27
|
-
class TypeEntry(Entry):
|
28
|
-
"""I am a type-checking node."""
|
29
|
-
|
30
|
-
_code = None
|
31
|
-
_schema = None
|
32
|
-
|
33
|
-
def check_value(self, value, entry=None, **kv):
|
34
|
-
self.parent.check_value(value, entry=entry, **kv)
|
35
|
-
if self._schema is not None:
|
36
|
-
jsonschema.validate(instance=value, schema=self._schema)
|
37
|
-
if self._code is not None:
|
38
|
-
self._code(value, entry=entry, data=self._data, **kv)
|
39
|
-
|
40
|
-
async def set(self, value):
|
41
|
-
code = None
|
42
|
-
schema = None
|
43
|
-
if value is not NotGiven and (
|
44
|
-
value.get("code", None) is not None or value.get("schema", None) is not None
|
45
|
-
):
|
46
|
-
schema = value.get("schema", None)
|
47
|
-
if value.get("code", None) is None:
|
48
|
-
code = None
|
49
|
-
else:
|
50
|
-
code = make_proc(value.code, ("value",), self.path)
|
51
|
-
if len(value.good) < 2:
|
52
|
-
raise RuntimeError("Must have check-good values")
|
53
|
-
if not value.bad:
|
54
|
-
raise RuntimeError("Must have check-bad values")
|
55
|
-
for v in value["good"]:
|
56
|
-
self.parent.check_value(v)
|
57
|
-
try:
|
58
|
-
if schema is not None:
|
59
|
-
jsonschema.validate(instance=v, schema=schema)
|
60
|
-
if code is not None:
|
61
|
-
code(v, entry=None)
|
62
|
-
except Exception:
|
63
|
-
raise ValueError(f"failed on good value {v!r}")
|
64
|
-
for v in value["bad"]:
|
65
|
-
self.parent.check_value(v)
|
66
|
-
try:
|
67
|
-
if schema is not None:
|
68
|
-
jsonschema.validate(instance=v, schema=schema)
|
69
|
-
if code is not None:
|
70
|
-
code(v, entry=None)
|
71
|
-
except Exception:
|
72
|
-
pass
|
73
|
-
else:
|
74
|
-
raise ValueError(f"did not fail on {v!r}")
|
75
|
-
|
76
|
-
await super().set(value)
|
77
|
-
self._code = code
|
78
|
-
self._schema = schema
|
79
|
-
|
80
|
-
|
81
|
-
TypeEntry.SUBTYPE = TypeEntry
|
82
|
-
|
83
|
-
|
84
|
-
class TypeRoot(Entry):
|
85
|
-
"""I am the root of MoaT-KV's type hierarchy."""
|
86
|
-
|
87
|
-
SUBTYPE = TypeEntry
|
88
|
-
|
89
|
-
async def set(self, value):
|
90
|
-
if value is not NotGiven:
|
91
|
-
raise ValueError("This node can't have data.")
|
92
|
-
|
93
|
-
def check_value(self, value, entry=None, **kv):
|
94
|
-
pass
|
95
|
-
|
96
|
-
|
97
|
-
# MATCH (for types)
|
98
|
-
|
99
|
-
|
100
|
-
class MatchEntry(MetaEntry):
|
101
|
-
"""I represent a match from a path to a type.
|
102
|
-
|
103
|
-
My data requires a "type" attribute that's a path in the "type"
|
104
|
-
hierarchy that's next to my MatchRoot.
|
105
|
-
"""
|
106
|
-
|
107
|
-
async def set(self, value):
|
108
|
-
if value is NotGiven:
|
109
|
-
pass
|
110
|
-
elif isinstance(value.type, str):
|
111
|
-
value.type = P(value.type)
|
112
|
-
elif not isinstance(value.type, (Path, list, tuple)):
|
113
|
-
raise ValueError("Type of %r is not a list" % (value.type,))
|
114
|
-
try:
|
115
|
-
self.metaroot["type"].follow(value.type, create=False)
|
116
|
-
except KeyError:
|
117
|
-
logger.exception("Type %r doesn't exist", value.type)
|
118
|
-
raise ClientError("This type does not exist")
|
119
|
-
# crashes if nonexistent
|
120
|
-
await super().set(value)
|
121
|
-
|
122
|
-
|
123
|
-
MatchEntry.SUBTYPE = MatchEntry
|
124
|
-
|
125
|
-
|
126
|
-
class NodeFinder:
|
127
|
-
"""A generic object that can walk down a possibly-wildcard-equipped path.
|
128
|
-
|
129
|
-
Example: given a path `one.two.three` and a root `bar` with subtree `bar.#.three`,
|
130
|
-
`NodeFinder(bar).step(one).step(two).step(three)` will return the node
|
131
|
-
at `bar.#.three` (assuming that nothing more specific hangs off `bar`).
|
132
|
-
"""
|
133
|
-
|
134
|
-
def __init__(self, meta):
|
135
|
-
if isinstance(meta, list):
|
136
|
-
self.steps = meta
|
137
|
-
else:
|
138
|
-
self.steps = ((meta, False),)
|
139
|
-
|
140
|
-
def step(self, name, new=False):
|
141
|
-
steps = []
|
142
|
-
for node, keep in self.steps:
|
143
|
-
if name in node:
|
144
|
-
steps.append((node[name], False))
|
145
|
-
if name is None:
|
146
|
-
continue
|
147
|
-
if "+" in node:
|
148
|
-
steps.append((node["+"], False))
|
149
|
-
if "#" in node:
|
150
|
-
steps.append((node["#"], True))
|
151
|
-
if keep:
|
152
|
-
steps.append((node, True))
|
153
|
-
# Nodes found with '#' stay on the list
|
154
|
-
# so that they can match multiple entries.
|
155
|
-
# if not steps:
|
156
|
-
# raise KeyError(name)
|
157
|
-
if new:
|
158
|
-
return type(self)(steps, **self.copy_args)
|
159
|
-
else:
|
160
|
-
self.steps = steps
|
161
|
-
return self
|
162
|
-
|
163
|
-
@property
|
164
|
-
def copy_args(self):
|
165
|
-
return {}
|
166
|
-
|
167
|
-
@property
|
168
|
-
def result(self):
|
169
|
-
for node, _keep in self.steps:
|
170
|
-
if node._data is not NotGiven:
|
171
|
-
return node
|
172
|
-
return None
|
173
|
-
|
174
|
-
|
175
|
-
class ACLFinder(NodeFinder):
|
176
|
-
"""A NodeFinder which expects ACL strings as elements"""
|
177
|
-
|
178
|
-
_block = ""
|
179
|
-
|
180
|
-
@property
|
181
|
-
def copy_args(self):
|
182
|
-
return {"blocked": self._block}
|
183
|
-
|
184
|
-
def __init__(self, acl, blocked=None):
|
185
|
-
if isinstance(acl, ACLFinder):
|
186
|
-
if blocked is None:
|
187
|
-
blocked = acl._block
|
188
|
-
acl = acl.steps
|
189
|
-
super().__init__(acl)
|
190
|
-
if blocked is not None:
|
191
|
-
self._block = blocked
|
192
|
-
|
193
|
-
def allows(self, x):
|
194
|
-
if x in self._block:
|
195
|
-
return False
|
196
|
-
|
197
|
-
r = self.result
|
198
|
-
if r is None:
|
199
|
-
return True
|
200
|
-
return x in r.data
|
201
|
-
|
202
|
-
def block(self, c):
|
203
|
-
if c not in self._block:
|
204
|
-
self._block += c
|
205
|
-
|
206
|
-
def check(self, x):
|
207
|
-
if not self.allows(x):
|
208
|
-
raise ACLError(self.result, x)
|
209
|
-
|
210
|
-
|
211
|
-
class ACLStepper(ACLFinder):
|
212
|
-
"""An ACLFinder which returns a copy of itself at every `step`."""
|
213
|
-
|
214
|
-
def step(self, name, new=True):
|
215
|
-
return super().step(name, new=new)
|
216
|
-
|
217
|
-
|
218
|
-
@singleton
|
219
|
-
class NullACL(ACLStepper):
|
220
|
-
"""This singleton represents an ACL that never checks anything."""
|
221
|
-
|
222
|
-
result = "-"
|
223
|
-
|
224
|
-
def __init__(self): # pylint: disable=super-init-not-called
|
225
|
-
pass
|
226
|
-
|
227
|
-
def allows(self, x):
|
228
|
-
return x != "a"
|
229
|
-
|
230
|
-
def check(self, x):
|
231
|
-
return
|
232
|
-
|
233
|
-
def block(self, c):
|
234
|
-
pass
|
235
|
-
|
236
|
-
def step(self, name, new=None):
|
237
|
-
return self
|
238
|
-
|
239
|
-
|
240
|
-
class MetaPathEntry(MetaEntry):
|
241
|
-
def _find_node(self, entry):
|
242
|
-
"""Search for the most-specific match.
|
243
|
-
|
244
|
-
Match entries whose values are missing are not considered.
|
245
|
-
"""
|
246
|
-
f = NodeFinder(self)
|
247
|
-
for n in entry.path:
|
248
|
-
f.step(n)
|
249
|
-
return f.result
|
250
|
-
|
251
|
-
|
252
|
-
class MatchRoot(MetaPathEntry):
|
253
|
-
"""I am the root of MoaT-KV's type hierarchy."""
|
254
|
-
|
255
|
-
SUBTYPE = MatchEntry
|
256
|
-
|
257
|
-
async def set(self, value):
|
258
|
-
if value is not None:
|
259
|
-
raise ValueError("This node can't have data.")
|
260
|
-
|
261
|
-
def check_value(self, value, entry, **kv):
|
262
|
-
"""Check this value for this entry against my match hierarchy"""
|
263
|
-
match = self._find_node(entry)
|
264
|
-
if match is None:
|
265
|
-
return
|
266
|
-
typ = self.parent["type"].follow(match._data["type"])
|
267
|
-
return typ.check_value(value, entry=entry, match=match, **kv)
|
268
|
-
|
269
|
-
|
270
|
-
class CodecEntry(Entry):
|
271
|
-
"""I am a codec."""
|
272
|
-
|
273
|
-
_enc = None
|
274
|
-
_dec = None
|
275
|
-
|
276
|
-
def enc_value(self, value, entry=None, **kv):
|
277
|
-
if self._enc is not None:
|
278
|
-
try:
|
279
|
-
value = self._enc(value, entry=entry, data=self._data, **kv)
|
280
|
-
except TypeError:
|
281
|
-
if value is not None:
|
282
|
-
raise
|
283
|
-
return value
|
284
|
-
|
285
|
-
def dec_value(self, value, entry=None, **kv):
|
286
|
-
if self._dec is not None:
|
287
|
-
try:
|
288
|
-
value = self._dec(value, entry=entry, data=self._data, **kv)
|
289
|
-
except TypeError:
|
290
|
-
if value is not None:
|
291
|
-
raise
|
292
|
-
return value
|
293
|
-
|
294
|
-
async def set(self, value):
|
295
|
-
enc = None
|
296
|
-
dec = None
|
297
|
-
if value is not None and value.decode is not None:
|
298
|
-
if not value["in"]:
|
299
|
-
raise RuntimeError("Must have tests for decoding")
|
300
|
-
dec = make_proc(value.decode, ("value",), self.path)
|
301
|
-
for v, w in value["in"]:
|
302
|
-
try:
|
303
|
-
r = dec(v)
|
304
|
-
except Exception as exc:
|
305
|
-
raise ValueError(
|
306
|
-
f"failed decoder at {self.path} on {v!r} with {exc!r}",
|
307
|
-
) from exc
|
308
|
-
else:
|
309
|
-
if r != w:
|
310
|
-
raise ValueError(f"Decoding at {self.path}: {v!r} got {r!r}, not {w!r}")
|
311
|
-
|
312
|
-
if value is not None and value.encode is not None:
|
313
|
-
if not value["out"]:
|
314
|
-
raise RuntimeError("Must have tests for encoding")
|
315
|
-
enc = make_proc(value.encode, ("value",), self.path)
|
316
|
-
for v, w in value["out"]:
|
317
|
-
try:
|
318
|
-
r = enc(v)
|
319
|
-
except Exception as exc:
|
320
|
-
raise ValueError(
|
321
|
-
f"failed encoder at {self.path} on {v!r} with {exc!r}",
|
322
|
-
) from exc
|
323
|
-
else:
|
324
|
-
if r != w:
|
325
|
-
raise ValueError(f"Encoding at {self.path}: {v!r} got {r!r}, not {w!r}")
|
326
|
-
|
327
|
-
await super().set(value)
|
328
|
-
self._enc = enc
|
329
|
-
self._dec = dec
|
330
|
-
|
331
|
-
|
332
|
-
CodecEntry.SUBTYPE = CodecEntry
|
333
|
-
|
334
|
-
|
335
|
-
class CodecRoot(Entry):
|
336
|
-
"""I am the root of MoaT-KV's codec hierarchy."""
|
337
|
-
|
338
|
-
SUBTYPE = CodecEntry
|
339
|
-
|
340
|
-
async def set(self, value):
|
341
|
-
if value is not None:
|
342
|
-
raise ValueError("This node can't have data.")
|
343
|
-
|
344
|
-
def check_value(self, value, entry=None, **kv):
|
345
|
-
pass
|
346
|
-
|
347
|
-
|
348
|
-
# CONV (for codecs)
|
349
|
-
|
350
|
-
|
351
|
-
class ConvEntry(MetaEntry):
|
352
|
-
"""I represent a converter from a path to a type.
|
353
|
-
|
354
|
-
My data requires a "codec" attribute that's a path in the "codecs"
|
355
|
-
hierarchy that's next to my Root.
|
356
|
-
"""
|
357
|
-
|
358
|
-
async def set(self, value):
|
359
|
-
if value is not NotGiven:
|
360
|
-
# can't run a nonexistent value through a codec
|
361
|
-
|
362
|
-
if not hasattr(value, "codec"):
|
363
|
-
raise ValueError("Duh? " + repr(value))
|
364
|
-
if isinstance(value.codec, str):
|
365
|
-
value.codec = P(value.codec)
|
366
|
-
elif not isinstance(value.codec, (Path, list, tuple)):
|
367
|
-
raise ValueError("Codec %r is not a list" % (value.codec,))
|
368
|
-
try:
|
369
|
-
self.metaroot["codec"].follow(value.codec, create=False)
|
370
|
-
except KeyError:
|
371
|
-
logger.warning("Codec %r does not exist (yet?)", value.codec)
|
372
|
-
# raise ClientError("This codec does not exist")
|
373
|
-
# don't raise here
|
374
|
-
await super().set(value)
|
375
|
-
|
376
|
-
|
377
|
-
ConvEntry.SUBTYPE = ConvEntry
|
378
|
-
|
379
|
-
|
380
|
-
class ConvNull:
|
381
|
-
"""I am a dummy translator"""
|
382
|
-
|
383
|
-
@staticmethod
|
384
|
-
def enc_value(value, **_kw):
|
385
|
-
return value
|
386
|
-
|
387
|
-
@staticmethod
|
388
|
-
def dec_value(value, **_kw):
|
389
|
-
return value
|
390
|
-
|
391
|
-
|
392
|
-
ConvNull = ConvNull()
|
393
|
-
|
394
|
-
|
395
|
-
class ConvName(MetaPathEntry):
|
396
|
-
"""I am a named tree for conversion entries."""
|
397
|
-
|
398
|
-
SUBTYPE = ConvEntry
|
399
|
-
|
400
|
-
async def set(self, value):
|
401
|
-
if value is not None:
|
402
|
-
raise ValueError("This node can't have data.")
|
403
|
-
|
404
|
-
def enc_value(self, value, entry, **kv):
|
405
|
-
"""Check this value for this entry against my converter hierarchy"""
|
406
|
-
conv = self._find_node(entry)
|
407
|
-
if conv is None:
|
408
|
-
return value
|
409
|
-
codec = self.metaroot["codec"].follow(conv._data["codec"])
|
410
|
-
return codec.enc_value(value, entry=entry, conv=conv, **kv)
|
411
|
-
|
412
|
-
def dec_value(self, value, entry, **kv):
|
413
|
-
"""Check this value for this entry against my converter hierarchy"""
|
414
|
-
conv = self._find_node(entry)
|
415
|
-
if conv is None:
|
416
|
-
return value
|
417
|
-
codec = self.metaroot["codec"].follow(conv._data["codec"])
|
418
|
-
return codec.dec_value(value, entry=entry, conv=conv, **kv)
|
419
|
-
|
420
|
-
|
421
|
-
class ConvRoot(MetaEntry):
|
422
|
-
SUBTYPE = ConvName
|
423
|
-
|
424
|
-
async def set(self, value):
|
425
|
-
if value is not None:
|
426
|
-
raise ValueError("This node can't have data.")
|
427
|
-
|
428
|
-
|
429
|
-
class AclEntry(MetaPathEntry):
|
430
|
-
"""I represent an ACL.
|
431
|
-
|
432
|
-
My data must be a string of ACLish characters.
|
433
|
-
"""
|
434
|
-
|
435
|
-
async def set(self, value):
|
436
|
-
if value is NotGiven:
|
437
|
-
pass
|
438
|
-
elif not isinstance(value, str):
|
439
|
-
raise ValueError("ACL is not a string")
|
440
|
-
await super().set(value)
|
441
|
-
|
442
|
-
|
443
|
-
AclEntry.SUBTYPE = AclEntry
|
444
|
-
|
445
|
-
|
446
|
-
class AclName(AclEntry):
|
447
|
-
"""I am a named tree for ACL entries."""
|
448
|
-
|
449
|
-
SUBTYPE = AclEntry
|
450
|
-
|
451
|
-
async def check(self, entry, typ):
|
452
|
-
acl = self._find_node(entry)
|
453
|
-
if acl is None:
|
454
|
-
return None
|
455
|
-
return typ in acl.value
|
456
|
-
|
457
|
-
|
458
|
-
class AclRoot(MetaEntry):
|
459
|
-
SUBTYPE = AclName
|
460
|
-
|
461
|
-
async def set(self, value):
|
462
|
-
if value is not None:
|
463
|
-
raise ValueError("This node can't have data.")
|
464
|
-
|
465
|
-
|
466
|
-
class DelRoot(Entry):
|
467
|
-
SUBTYPE = None
|
468
|
-
|
469
|
-
async def set(self, value):
|
470
|
-
await super().set(value)
|
471
|
-
await self.root.server.del_check(value)
|
472
|
-
|
473
|
-
|
474
|
-
class ActorRoot(Entry):
|
475
|
-
SUBTYPE = None
|
476
|
-
SUBTYPES = {"del": DelRoot}
|
477
|
-
|
478
|
-
|
479
|
-
# ROOT
|
480
|
-
|
481
|
-
|
482
|
-
class MetaRootEntry(Entry): # not MetaEntry
|
483
|
-
"""I am the special node off the MoaT-KV root that's named ``None``."""
|
484
|
-
|
485
|
-
SUBTYPES = {
|
486
|
-
"type": TypeRoot,
|
487
|
-
"match": MatchRoot,
|
488
|
-
"acl": AclRoot,
|
489
|
-
"codec": CodecRoot,
|
490
|
-
"conv": ConvRoot,
|
491
|
-
"actor": ActorRoot,
|
492
|
-
}
|
493
|
-
|
494
|
-
def __init__(self, *a, **k):
|
495
|
-
super().__init__(*a, **k)
|
496
|
-
self._metaroot = weakref.ref(self)
|
497
|
-
|
498
|
-
|
499
|
-
Entry.SUBTYPES[None] = MetaRootEntry
|
500
|
-
|
501
|
-
|
502
|
-
class RootEntry(Entry):
|
503
|
-
"""I am the root of the MoaT-KV data tree."""
|
504
|
-
|
505
|
-
def __init__(self, server, *a, **k):
|
506
|
-
super().__init__("ROOT", None, *a, **k)
|
507
|
-
self._server = weakref.ref(server)
|
508
|
-
|
509
|
-
@property
|
510
|
-
def server(self):
|
511
|
-
return self._server()
|
512
|
-
|
513
|
-
SUBTYPES = {None: MetaRootEntry}
|
ci/rtd-requirements.txt
DELETED
ci/test-requirements.txt
DELETED
ci/travis.sh
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
set -ex
|
4
|
-
|
5
|
-
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
|
6
|
-
curl -Lo macpython.pkg https://www.python.org/ftp/python/${MACPYTHON}/python-${MACPYTHON}-macosx10.6.pkg
|
7
|
-
sudo installer -pkg macpython.pkg -target /
|
8
|
-
ls /Library/Frameworks/Python.framework/Versions/*/bin/
|
9
|
-
PYTHON_EXE=/Library/Frameworks/Python.framework/Versions/*/bin/python3
|
10
|
-
# The pip in older MacPython releases doesn't support a new enough TLS
|
11
|
-
curl https://bootstrap.pypa.io/get-pip.py | sudo $PYTHON_EXE
|
12
|
-
sudo $PYTHON_EXE -m pip install virtualenv
|
13
|
-
$PYTHON_EXE -m virtualenv testenv
|
14
|
-
source testenv/bin/activate
|
15
|
-
fi
|
16
|
-
|
17
|
-
if [ "$USE_PYPY_NIGHTLY" = "1" ]; then
|
18
|
-
curl -fLo pypy.tar.bz2 http://buildbot.pypy.org/nightly/py3.5/pypy-c-jit-latest-linux64.tar.bz2
|
19
|
-
if [ ! -s pypy.tar.bz2 ]; then
|
20
|
-
# We know:
|
21
|
-
# - curl succeeded (200 response code; -f means "exit with error if
|
22
|
-
# server returns 4xx or 5xx")
|
23
|
-
# - nonetheless, pypy.tar.bz2 does not exist, or contains no data
|
24
|
-
# This isn't going to work, and the failure is not informative of
|
25
|
-
# anything involving this package.
|
26
|
-
ls -l
|
27
|
-
echo "PyPy3 nightly build failed to download – something is wrong on their end."
|
28
|
-
echo "Skipping testing against the nightly build for right now."
|
29
|
-
exit 0
|
30
|
-
fi
|
31
|
-
tar xaf pypy.tar.bz2
|
32
|
-
# something like "pypy-c-jit-89963-748aa3022295-linux64"
|
33
|
-
PYPY_DIR=$(echo pypy-c-jit-*)
|
34
|
-
PYTHON_EXE=$PYPY_DIR/bin/pypy3
|
35
|
-
($PYTHON_EXE -m ensurepip \
|
36
|
-
&& $PYTHON_EXE -m pip install virtualenv \
|
37
|
-
&& $PYTHON_EXE -m virtualenv testenv) \
|
38
|
-
|| (echo "pypy nightly is broken; skipping tests"; exit 0)
|
39
|
-
source testenv/bin/activate
|
40
|
-
fi
|
41
|
-
|
42
|
-
if [ "$USE_PYPY_RELEASE_VERSION" != "" ]; then
|
43
|
-
curl -fLo pypy.tar.bz2 https://bitbucket.org/squeaky/portable-pypy/downloads/pypy3.5-${USE_PYPY_RELEASE_VERSION}-linux_x86_64-portable.tar.bz2
|
44
|
-
tar xaf pypy.tar.bz2
|
45
|
-
# something like "pypy3.5-5.7.1-beta-linux_x86_64-portable"
|
46
|
-
PYPY_DIR=$(echo pypy3.5-*)
|
47
|
-
PYTHON_EXE=$PYPY_DIR/bin/pypy3
|
48
|
-
$PYTHON_EXE -m ensurepip
|
49
|
-
$PYTHON_EXE -m pip install virtualenv
|
50
|
-
$PYTHON_EXE -m virtualenv testenv
|
51
|
-
source testenv/bin/activate
|
52
|
-
fi
|
53
|
-
|
54
|
-
pip install -U pip setuptools wheel
|
55
|
-
|
56
|
-
if [ "$CHECK_FORMATTING" = "1" ]; then
|
57
|
-
pip install black
|
58
|
-
if ! black setup.py moat.kv tests ; then
|
59
|
-
git diff
|
60
|
-
cat <<EOF
|
61
|
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
62
|
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
63
|
-
|
64
|
-
Formatting problems were found (listed above). To fix them, run
|
65
|
-
|
66
|
-
pip install black
|
67
|
-
black setup.py moat.kv
|
68
|
-
|
69
|
-
in your local checkout.
|
70
|
-
|
71
|
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
72
|
-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
73
|
-
EOF
|
74
|
-
exit 1
|
75
|
-
fi
|
76
|
-
exit 0
|
77
|
-
fi
|
78
|
-
|
79
|
-
python setup.py sdist --formats=zip
|
80
|
-
pip install dist/*.zip
|
81
|
-
|
82
|
-
if [ "$CHECK_DOCS" = "1" ]; then
|
83
|
-
pip install -Ur ci/rtd-requirements.txt
|
84
|
-
cd docs
|
85
|
-
# -n (nit-picky): warn on missing references
|
86
|
-
# -W: turn warnings into errors
|
87
|
-
#sphinx-build -nW -b html source build
|
88
|
-
sphinx-build -n -b html source build
|
89
|
-
else
|
90
|
-
# Actual tests
|
91
|
-
pip install -Ur ci/test-requirements.txt
|
92
|
-
|
93
|
-
pytest -W error -ra -v --pyargs tests --cov=moat.kv --cov-config=.coveragerc --verbose
|
94
|
-
|
95
|
-
bash <(curl -s https://codecov.io/bash)
|
96
|
-
fi
|