marceline 0.1.0__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.
- marceline/__init__.py +644 -0
- marceline/_endpoint.py +76 -0
- marceline/_macos.py +87 -0
- marceline/py.typed +0 -0
- marceline-0.1.0.dist-info/METADATA +52 -0
- marceline-0.1.0.dist-info/RECORD +10 -0
- marceline-0.1.0.dist-info/WHEEL +5 -0
- marceline-0.1.0.dist-info/licenses/LICENSE-APACHE +201 -0
- marceline-0.1.0.dist-info/licenses/LICENSE-MIT +21 -0
- marceline-0.1.0.dist-info/top_level.txt +1 -0
marceline/__init__.py
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
"""Invoke published plugin actions through a local Marcellus session."""
|
|
2
|
+
|
|
3
|
+
import _thread
|
|
4
|
+
from collections.abc import Generator, Iterator
|
|
5
|
+
from contextlib import contextmanager, suppress
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
from functools import partial
|
|
8
|
+
import os
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
import re
|
|
11
|
+
import socket
|
|
12
|
+
import sys
|
|
13
|
+
from threading import Lock, RLock, TIMEOUT_MAX, local
|
|
14
|
+
import time
|
|
15
|
+
from types import GeneratorType
|
|
16
|
+
from weakref import ReferenceType, ref
|
|
17
|
+
|
|
18
|
+
from . import _endpoint
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"Client",
|
|
22
|
+
"ClientError",
|
|
23
|
+
"ClientUnavailableError",
|
|
24
|
+
"InvokeReceipt",
|
|
25
|
+
"OutcomeUnknownError",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class InvokeReceipt(StrEnum):
|
|
30
|
+
"""Idaemon's receipt for one plugin action invocation."""
|
|
31
|
+
|
|
32
|
+
ACCEPTED = "accepted"
|
|
33
|
+
UNAVAILABLE = "unavailable"
|
|
34
|
+
DENIED = "denied"
|
|
35
|
+
BUSY = "busy"
|
|
36
|
+
OUTCOME_UNKNOWN = "outcome-unknown"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ClientError(RuntimeError):
|
|
40
|
+
"""The local client could not obtain a receipt."""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ClientUnavailableError(ClientError):
|
|
44
|
+
"""The local client could not prepare the invocation."""
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class OutcomeUnknownError(ClientError):
|
|
48
|
+
"""The invocation may have reached Idaemon, and its outcome is unknown."""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# Idaemon's invocation wire format is documented in its README.
|
|
52
|
+
_SUPPORTED_PLATFORMS = ("darwin", "linux")
|
|
53
|
+
_PLUGIN = re.compile(r"[a-z0-9][a-z0-9._-]{0,127}")
|
|
54
|
+
_ACTION = re.compile(r"[a-z0-9][a-z0-9._-]{0,31}")
|
|
55
|
+
_READY = b"ADY1"
|
|
56
|
+
_MAGIC = b"ADA1"
|
|
57
|
+
_INVOKE = b"\x03"
|
|
58
|
+
_RECEIPTS = {
|
|
59
|
+
3: InvokeReceipt.UNAVAILABLE,
|
|
60
|
+
7: InvokeReceipt.BUSY,
|
|
61
|
+
8: InvokeReceipt.OUTCOME_UNKNOWN,
|
|
62
|
+
10: InvokeReceipt.ACCEPTED,
|
|
63
|
+
11: InvokeReceipt.DENIED,
|
|
64
|
+
}
|
|
65
|
+
_MAX_CONNECTIONS = 32
|
|
66
|
+
# Socket polling takes a signed 32-bit millisecond timeout.
|
|
67
|
+
_MAX_POLL_TIMEOUT_MS = 2**31 - 1
|
|
68
|
+
_MAX_TIMEOUT = min(TIMEOUT_MAX, _MAX_POLL_TIMEOUT_MS // 1_000)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _remaining(deadline: float) -> float:
|
|
72
|
+
remaining = deadline - time.monotonic()
|
|
73
|
+
if remaining <= 0:
|
|
74
|
+
raise TimeoutError("Idaemon invocation deadline elapsed")
|
|
75
|
+
# Adding the timeout to the monotonic clock can round the deadline up.
|
|
76
|
+
return min(remaining, _MAX_TIMEOUT)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class _Invocation:
|
|
80
|
+
def __init__(self, pid: int) -> None:
|
|
81
|
+
self.pid = pid
|
|
82
|
+
self.delivery_possible = False
|
|
83
|
+
self.execution: ReferenceType[GeneratorType]
|
|
84
|
+
self.interrupt: tuple[int, BaseException] | None = None
|
|
85
|
+
|
|
86
|
+
def running(self) -> bool:
|
|
87
|
+
# The interpreter ends this execution even if every Python cleanup
|
|
88
|
+
# is interrupted and a traceback retains the connection.
|
|
89
|
+
execution = self.execution()
|
|
90
|
+
return execution is not None and execution.gi_running
|
|
91
|
+
|
|
92
|
+
def raise_interrupt(self) -> None:
|
|
93
|
+
pending = self.interrupt
|
|
94
|
+
if pending is not None and pending[0] == os.getpid():
|
|
95
|
+
raise pending[1]
|
|
96
|
+
|
|
97
|
+
def checkpoint(self) -> None:
|
|
98
|
+
self.raise_interrupt()
|
|
99
|
+
if os.getpid() != self.pid:
|
|
100
|
+
raise ConnectionError("Idaemon invocation was interrupted by fork")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class _SocketRecord:
|
|
104
|
+
def __init__(self, stream: socket.socket, socket_use: _thread.RLock, pid: int) -> None:
|
|
105
|
+
self.stream = stream
|
|
106
|
+
self.socket_use = socket_use
|
|
107
|
+
self.pid = pid
|
|
108
|
+
self.descriptor_may_be_hidden = True
|
|
109
|
+
self.inherited_close_pid: int | None = None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class _PreparedConnection:
|
|
113
|
+
"""Hold one socket until preparation and the caller's use have ended."""
|
|
114
|
+
|
|
115
|
+
def __init__(self, caller: _Invocation) -> None:
|
|
116
|
+
self.stream: socket.socket | None = None
|
|
117
|
+
self.pid = caller.pid
|
|
118
|
+
self._caller = caller
|
|
119
|
+
self._ready = Lock()
|
|
120
|
+
self._ready.acquire()
|
|
121
|
+
self._failure: BaseException | None = None
|
|
122
|
+
self._socket_use = RLock()
|
|
123
|
+
self._caller_finished = False
|
|
124
|
+
self._ticket = object()
|
|
125
|
+
self._preparation_done = False
|
|
126
|
+
|
|
127
|
+
def _caller_has_finished(self) -> bool:
|
|
128
|
+
return self._caller_finished or os.getpid() != self.pid or not self._caller.running()
|
|
129
|
+
|
|
130
|
+
def _has_resources(self) -> bool:
|
|
131
|
+
return not self._preparation_done or self._ticket in _fork_sockets
|
|
132
|
+
|
|
133
|
+
def _forget_if_idle(self) -> None:
|
|
134
|
+
if not self._has_resources():
|
|
135
|
+
_connections.pop(self._ticket, None)
|
|
136
|
+
|
|
137
|
+
def start(self, directory: Path, address: bytes, deadline: float) -> None:
|
|
138
|
+
_remaining(deadline)
|
|
139
|
+
if not _has_capacity():
|
|
140
|
+
raise ClientUnavailableError("too many outstanding Idaemon connections")
|
|
141
|
+
self._caller.checkpoint()
|
|
142
|
+
_connections[self._ticket] = ref(self, partial(_reap_orphan, self._ticket))
|
|
143
|
+
if not _has_capacity(before=self._ticket):
|
|
144
|
+
raise ClientUnavailableError("too many outstanding Idaemon connections")
|
|
145
|
+
|
|
146
|
+
_remaining(deadline)
|
|
147
|
+
self._caller.checkpoint()
|
|
148
|
+
try:
|
|
149
|
+
_thread.start_new_thread(self.prepare, (directory, address, deadline))
|
|
150
|
+
except (OSError, RuntimeError):
|
|
151
|
+
raise ClientUnavailableError("could not start Idaemon endpoint preparation") from None
|
|
152
|
+
|
|
153
|
+
def _open_socket(self, deadline: float) -> socket.socket | None:
|
|
154
|
+
while not self._caller_has_finished():
|
|
155
|
+
_remaining(deadline)
|
|
156
|
+
generation = _fork_generation
|
|
157
|
+
if _forking:
|
|
158
|
+
raise ConnectionError("Idaemon preparation overlapped a fork")
|
|
159
|
+
_remaining(deadline)
|
|
160
|
+
# Give fork cleanup a reference before initialization opens the
|
|
161
|
+
# descriptor. Initialization can run host audit hooks.
|
|
162
|
+
candidate = socket.socket.__new__(socket.socket)
|
|
163
|
+
record = _SocketRecord(candidate, self._socket_use, self.pid)
|
|
164
|
+
try:
|
|
165
|
+
_fork_sockets[self._ticket] = record
|
|
166
|
+
if self._caller_has_finished():
|
|
167
|
+
return None
|
|
168
|
+
try:
|
|
169
|
+
candidate.__init__(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
170
|
+
except OSError:
|
|
171
|
+
raise ClientUnavailableError("could not open an Idaemon client socket") from None
|
|
172
|
+
record.descriptor_may_be_hidden = False
|
|
173
|
+
if self._caller_has_finished():
|
|
174
|
+
return None
|
|
175
|
+
# A fork starting after this check can already identify the
|
|
176
|
+
# descriptor. A fork during initialization invalidates it.
|
|
177
|
+
if generation is _fork_generation:
|
|
178
|
+
self.stream = candidate
|
|
179
|
+
return candidate
|
|
180
|
+
finally:
|
|
181
|
+
if self.stream is not candidate:
|
|
182
|
+
_dispose_socket(self._ticket, record)
|
|
183
|
+
return None
|
|
184
|
+
|
|
185
|
+
def prepare(self, directory: Path, address: bytes, deadline: float) -> None:
|
|
186
|
+
if self._caller_has_finished():
|
|
187
|
+
return
|
|
188
|
+
try:
|
|
189
|
+
if not self._socket_use.acquire(blocking=False) or self._caller_has_finished():
|
|
190
|
+
return
|
|
191
|
+
stream = self._open_socket(deadline)
|
|
192
|
+
if stream is None:
|
|
193
|
+
return
|
|
194
|
+
_remaining(deadline)
|
|
195
|
+
uid = os.geteuid()
|
|
196
|
+
_endpoint.check_directory(directory, uid)
|
|
197
|
+
if self._caller_has_finished():
|
|
198
|
+
return
|
|
199
|
+
stream.settimeout(_remaining(deadline))
|
|
200
|
+
if self._caller_has_finished():
|
|
201
|
+
return
|
|
202
|
+
stream.connect(address)
|
|
203
|
+
if not self._caller_has_finished():
|
|
204
|
+
_endpoint.check_peer(stream, uid)
|
|
205
|
+
except BaseException as error:
|
|
206
|
+
self._failure = error
|
|
207
|
+
finally:
|
|
208
|
+
if self._socket_use._recursion_count():
|
|
209
|
+
self._preparation_done = True
|
|
210
|
+
self._socket_use.release()
|
|
211
|
+
if self._caller_has_finished():
|
|
212
|
+
self._close_if_unused()
|
|
213
|
+
self._forget_if_idle()
|
|
214
|
+
self._ready.release()
|
|
215
|
+
|
|
216
|
+
def wait(self, deadline: float) -> socket.socket:
|
|
217
|
+
waiting = getattr(_fork_state, "waiting", None)
|
|
218
|
+
try:
|
|
219
|
+
_fork_state.waiting = self, waiting
|
|
220
|
+
# A primitive lock lets SIGINT propagate without a condition
|
|
221
|
+
# variable's release and restore.
|
|
222
|
+
acquired = os.getpid() == self.pid and self._ready.acquire(timeout=_remaining(deadline))
|
|
223
|
+
if os.getpid() != self.pid:
|
|
224
|
+
raise ConnectionError("Idaemon preparation was interrupted by fork")
|
|
225
|
+
finally:
|
|
226
|
+
_fork_state.waiting = waiting
|
|
227
|
+
if not acquired:
|
|
228
|
+
raise TimeoutError("Idaemon invocation deadline elapsed")
|
|
229
|
+
failure = self._failure
|
|
230
|
+
self._failure = None
|
|
231
|
+
if failure is not None:
|
|
232
|
+
raise failure
|
|
233
|
+
assert self.stream is not None
|
|
234
|
+
return self.stream
|
|
235
|
+
|
|
236
|
+
def finish(self) -> None:
|
|
237
|
+
if os.getpid() != self.pid:
|
|
238
|
+
_connections.pop(self._ticket, None)
|
|
239
|
+
return
|
|
240
|
+
# A worker holding the lock can dispose of the socket as soon as it
|
|
241
|
+
# finishes preparing, including while the caller is still unwinding.
|
|
242
|
+
self._caller_finished = True
|
|
243
|
+
self._close_if_unused()
|
|
244
|
+
self._forget_if_idle()
|
|
245
|
+
|
|
246
|
+
def _close_if_unused(self) -> None:
|
|
247
|
+
_dispose_if_idle(self._ticket, self)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
_fork_generation = object()
|
|
251
|
+
# Weak reservations last for endpoint work or caller use.
|
|
252
|
+
_connections: dict[object, ReferenceType[_PreparedConnection]] = {}
|
|
253
|
+
# Own the socket from before native initialization until after native close.
|
|
254
|
+
_fork_sockets: dict[object, _SocketRecord] = {}
|
|
255
|
+
_inherited_socket_slots: set[object] = set()
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class _ForkClaim:
|
|
259
|
+
def __init__(self) -> None:
|
|
260
|
+
self.interrupt: tuple[int, BaseException] | None = None
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
_fork_state = local()
|
|
264
|
+
# The child keeps enclosing calls on its surviving thread and drops the
|
|
265
|
+
# markers copied from other threads in the parent.
|
|
266
|
+
_forking: dict[_ForkClaim, int] = {}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _running_invocations() -> Iterator[_Invocation]:
|
|
270
|
+
# Weak entries let even interrupted unwinds keep enclosing calls visible
|
|
271
|
+
# without rooting their exceptions. Each entry prunes the retired scopes.
|
|
272
|
+
for reference in getattr(_fork_state, "invocations", ()):
|
|
273
|
+
caller = reference()
|
|
274
|
+
if caller is not None and caller.running():
|
|
275
|
+
yield caller
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _fork_claims() -> list[_ForkClaim]:
|
|
279
|
+
claims = getattr(_fork_state, "claims", None)
|
|
280
|
+
if claims is None:
|
|
281
|
+
claims = _fork_state.claims = []
|
|
282
|
+
return claims
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _has_capacity(*, before: object | None = None) -> bool:
|
|
286
|
+
remaining = _MAX_CONNECTIONS - len(_inherited_socket_slots)
|
|
287
|
+
if remaining <= 0:
|
|
288
|
+
return False
|
|
289
|
+
# Insertion and snapshot are single builtin dict operations. The second
|
|
290
|
+
# check counts each earlier live reservation, including launches in flight.
|
|
291
|
+
for ticket, reference in _connections.copy().items():
|
|
292
|
+
if ticket is before:
|
|
293
|
+
break
|
|
294
|
+
connection = reference()
|
|
295
|
+
if connection is None:
|
|
296
|
+
_dispose_if_idle(ticket)
|
|
297
|
+
if ticket not in _fork_sockets:
|
|
298
|
+
continue
|
|
299
|
+
else:
|
|
300
|
+
if connection.pid != os.getpid() and ticket not in _fork_sockets:
|
|
301
|
+
# A fork can precede publication by the inherited caller.
|
|
302
|
+
_connections.pop(ticket, None)
|
|
303
|
+
continue
|
|
304
|
+
# An interrupt can stop the caller before it marks preparation
|
|
305
|
+
# done. The socket-use claim decides whether disposal is safe.
|
|
306
|
+
if connection._caller_has_finished():
|
|
307
|
+
connection._close_if_unused()
|
|
308
|
+
if not connection._has_resources():
|
|
309
|
+
_connections.pop(ticket, None)
|
|
310
|
+
continue
|
|
311
|
+
remaining -= 1
|
|
312
|
+
if remaining == 0:
|
|
313
|
+
return False
|
|
314
|
+
return True
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _close_socket(stream: socket.socket) -> None:
|
|
318
|
+
# The raw method handles partially initialized sockets and keeps ownership
|
|
319
|
+
# of the descriptor in the native call until close returns.
|
|
320
|
+
with suppress(OSError):
|
|
321
|
+
socket.SocketType.close(stream)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _dispose_socket(ticket: object, record: _SocketRecord) -> None:
|
|
325
|
+
# Native close can hide the descriptor before the kernel closes it.
|
|
326
|
+
# Keep the slot visible to fork and admission for that whole operation.
|
|
327
|
+
record.descriptor_may_be_hidden = True
|
|
328
|
+
_close_socket(record.stream)
|
|
329
|
+
record.descriptor_may_be_hidden = False
|
|
330
|
+
_fork_sockets.pop(ticket, None)
|
|
331
|
+
# If an initializer forked inside an audit hook, its worker can
|
|
332
|
+
# finish closing the candidate after that hook returns in the child.
|
|
333
|
+
_inherited_socket_slots.discard(ticket)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _reap_orphan(ticket: object, _reference: ReferenceType[_PreparedConnection]) -> None:
|
|
337
|
+
_dispose_if_idle(ticket)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _dispose_if_idle(ticket: object, connection: _PreparedConnection | None = None) -> None:
|
|
341
|
+
record = _fork_sockets.get(ticket)
|
|
342
|
+
if connection is not None:
|
|
343
|
+
socket_use = connection._socket_use
|
|
344
|
+
pid = connection.pid
|
|
345
|
+
elif record is not None:
|
|
346
|
+
socket_use = record.socket_use
|
|
347
|
+
pid = record.pid
|
|
348
|
+
else:
|
|
349
|
+
_connections.pop(ticket, None)
|
|
350
|
+
return
|
|
351
|
+
if pid != os.getpid():
|
|
352
|
+
return
|
|
353
|
+
|
|
354
|
+
# Treat the lock as non-reentrant. Its owner count lets us release a
|
|
355
|
+
# claim even if an interrupt arrives before acquire() returns to Python.
|
|
356
|
+
if socket_use._recursion_count():
|
|
357
|
+
return
|
|
358
|
+
try:
|
|
359
|
+
if not socket_use.acquire(blocking=False):
|
|
360
|
+
return
|
|
361
|
+
if connection is not None:
|
|
362
|
+
connection._preparation_done = True
|
|
363
|
+
record = _fork_sockets.get(ticket)
|
|
364
|
+
if record is not None:
|
|
365
|
+
with suppress(OSError):
|
|
366
|
+
record.stream.shutdown(socket.SHUT_RDWR)
|
|
367
|
+
_dispose_socket(ticket, record)
|
|
368
|
+
_connections.pop(ticket, None)
|
|
369
|
+
finally:
|
|
370
|
+
if socket_use._recursion_count():
|
|
371
|
+
socket_use.release()
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _before_fork() -> None:
|
|
375
|
+
global _fork_generation
|
|
376
|
+
# Mark the full fork interval before invalidating in-progress candidates.
|
|
377
|
+
# Neither callback waits for a worker or another thread's fork.
|
|
378
|
+
claim = None
|
|
379
|
+
caught = None
|
|
380
|
+
while True:
|
|
381
|
+
try:
|
|
382
|
+
if claim is None:
|
|
383
|
+
claim = _ForkClaim()
|
|
384
|
+
claims = _fork_claims()
|
|
385
|
+
if not claims or claims[-1] is not claim:
|
|
386
|
+
claims.append(claim)
|
|
387
|
+
_forking[claim] = os.getpid()
|
|
388
|
+
_fork_generation = object()
|
|
389
|
+
if claim.interrupt is None:
|
|
390
|
+
claim.interrupt = caught
|
|
391
|
+
return
|
|
392
|
+
except BaseException as interrupt:
|
|
393
|
+
if caught is None:
|
|
394
|
+
caught = (os.getpid(), interrupt)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _wake_inherited_waiters() -> None:
|
|
398
|
+
# The surviving thread can resume a native acquire on this exact lock.
|
|
399
|
+
# On older CPython and PyPy, native release and fork hold the GIL.
|
|
400
|
+
# Newer CPython resets its lock parking lot before Python child hooks.
|
|
401
|
+
waiting = getattr(_fork_state, "waiting", None)
|
|
402
|
+
while waiting is not None:
|
|
403
|
+
connection, waiting = waiting
|
|
404
|
+
if connection._ready.locked():
|
|
405
|
+
connection._ready.release()
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _close_inherited_sockets() -> None:
|
|
409
|
+
# Close the child's copies without shutting down the parent's connections.
|
|
410
|
+
pid = os.getpid()
|
|
411
|
+
for ticket, record in _fork_sockets.copy().items():
|
|
412
|
+
if record.pid == pid:
|
|
413
|
+
continue
|
|
414
|
+
if record.stream.fileno() >= 0:
|
|
415
|
+
# Preserve this close as ambiguous in a descendant, while a
|
|
416
|
+
# retry here knows that this child found and closed the descriptor.
|
|
417
|
+
record.inherited_close_pid = pid
|
|
418
|
+
_dispose_socket(ticket, record)
|
|
419
|
+
continue
|
|
420
|
+
if record.descriptor_may_be_hidden and record.inherited_close_pid != pid:
|
|
421
|
+
_inherited_socket_slots.add(ticket)
|
|
422
|
+
_fork_sockets.pop(ticket, None)
|
|
423
|
+
for ticket, reference in _connections.copy().items():
|
|
424
|
+
connection = reference()
|
|
425
|
+
if connection is None or connection.pid != pid:
|
|
426
|
+
_connections.pop(ticket, None)
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def _after_fork(*, child: bool = False) -> None:
|
|
430
|
+
claims = None
|
|
431
|
+
claim = None
|
|
432
|
+
caught = None
|
|
433
|
+
child_cleanup_done = not child
|
|
434
|
+
# Retire this exact claim even if interrupted during cleanup. An
|
|
435
|
+
# enclosing callback may still be preparing another fork.
|
|
436
|
+
while True:
|
|
437
|
+
try:
|
|
438
|
+
if claims is None:
|
|
439
|
+
claims = _fork_claims()
|
|
440
|
+
if claim is None and claims:
|
|
441
|
+
claim = claims[-1]
|
|
442
|
+
if not child_cleanup_done:
|
|
443
|
+
_close_inherited_sockets()
|
|
444
|
+
_wake_inherited_waiters()
|
|
445
|
+
pid = os.getpid()
|
|
446
|
+
for inherited, owner_pid in _forking.copy().items():
|
|
447
|
+
if owner_pid != pid and inherited not in claims:
|
|
448
|
+
_forking.pop(inherited, None)
|
|
449
|
+
child_cleanup_done = True
|
|
450
|
+
if claim is not None:
|
|
451
|
+
_forking.pop(claim, None)
|
|
452
|
+
if claims and claims[-1] is claim:
|
|
453
|
+
claims.pop()
|
|
454
|
+
|
|
455
|
+
pid = os.getpid()
|
|
456
|
+
if not child and claim is not None and claim.interrupt is not None and claim.interrupt[0] == pid:
|
|
457
|
+
caught = claim.interrupt
|
|
458
|
+
if caught is None:
|
|
459
|
+
return
|
|
460
|
+
caller = next(_running_invocations(), None)
|
|
461
|
+
if caller is not None:
|
|
462
|
+
pending = caller.interrupt
|
|
463
|
+
if pending is None or pending[0] != pid:
|
|
464
|
+
caller.interrupt = caught
|
|
465
|
+
return
|
|
466
|
+
if claims:
|
|
467
|
+
# Report the interrupt after the enclosing fork's cleanup.
|
|
468
|
+
pending = claims[-1].interrupt
|
|
469
|
+
if pending is None or pending[0] != pid:
|
|
470
|
+
claims[-1].interrupt = caught
|
|
471
|
+
return
|
|
472
|
+
break
|
|
473
|
+
except BaseException as interrupt:
|
|
474
|
+
if caught is None:
|
|
475
|
+
caught = (os.getpid(), interrupt)
|
|
476
|
+
|
|
477
|
+
# Python reports exceptions escaping a fork callback as unraisable.
|
|
478
|
+
raise caught[1]
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
if sys.platform in _SUPPORTED_PLATFORMS:
|
|
482
|
+
os.register_at_fork(
|
|
483
|
+
before=_before_fork,
|
|
484
|
+
after_in_parent=_after_fork,
|
|
485
|
+
after_in_child=partial(_after_fork, child=True),
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
@contextmanager
|
|
490
|
+
def _connect(
|
|
491
|
+
directory: Path, address: bytes, deadline: float, *, caller: _Invocation
|
|
492
|
+
) -> Iterator[socket.socket]:
|
|
493
|
+
caller.checkpoint()
|
|
494
|
+
preparation = _PreparedConnection(caller)
|
|
495
|
+
try:
|
|
496
|
+
# Unix path lookup can block inside the kernel even with a socket timeout.
|
|
497
|
+
# The preparation worker can connect, but only the caller can send.
|
|
498
|
+
preparation.start(directory, address, deadline)
|
|
499
|
+
caller.checkpoint()
|
|
500
|
+
stream = preparation.wait(deadline)
|
|
501
|
+
caller.checkpoint()
|
|
502
|
+
yield stream
|
|
503
|
+
finally:
|
|
504
|
+
try:
|
|
505
|
+
preparation.finish()
|
|
506
|
+
except BaseException:
|
|
507
|
+
# Retry an interrupted close before handing cleanup to a later
|
|
508
|
+
# admission check or the collection callback.
|
|
509
|
+
preparation.finish()
|
|
510
|
+
raise
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def _read_frame(stream: socket.socket, size: int, deadline: float) -> bytes:
|
|
514
|
+
frame = bytearray()
|
|
515
|
+
while len(frame) < size:
|
|
516
|
+
stream.settimeout(_remaining(deadline))
|
|
517
|
+
chunk = stream.recv(size - len(frame))
|
|
518
|
+
if not chunk:
|
|
519
|
+
raise ConnectionError("Idaemon closed an incomplete frame")
|
|
520
|
+
frame.extend(chunk)
|
|
521
|
+
return bytes(frame)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
class Client:
|
|
525
|
+
"""Select an explicit private Idaemon runtime directory."""
|
|
526
|
+
|
|
527
|
+
def __init__(
|
|
528
|
+
self,
|
|
529
|
+
runtime_directory: str | os.PathLike[str],
|
|
530
|
+
*,
|
|
531
|
+
timeout: float = 33.0,
|
|
532
|
+
) -> None:
|
|
533
|
+
directory = os.fspath(runtime_directory)
|
|
534
|
+
if not isinstance(directory, str):
|
|
535
|
+
raise TypeError("runtime_directory must be a text path")
|
|
536
|
+
if not os.path.isabs(directory) or "\0" in directory:
|
|
537
|
+
raise ValueError("runtime_directory must be an absolute path without NUL")
|
|
538
|
+
if not 0 < timeout:
|
|
539
|
+
raise ValueError("timeout must be finite and positive")
|
|
540
|
+
if timeout > _MAX_TIMEOUT:
|
|
541
|
+
raise ValueError(f"timeout must be at most {_MAX_TIMEOUT} seconds")
|
|
542
|
+
|
|
543
|
+
self._directory = (
|
|
544
|
+
_endpoint.socket_directory(directory) if sys.platform in _SUPPORTED_PLATFORMS else None
|
|
545
|
+
)
|
|
546
|
+
self._timeout = timeout
|
|
547
|
+
|
|
548
|
+
def invoke(self, plugin: str, action: str) -> InvokeReceipt:
|
|
549
|
+
"""Ask the editor owner to accept one currently advertised plugin action.
|
|
550
|
+
|
|
551
|
+
An invocation belongs to the process captured on entry. In a child
|
|
552
|
+
forked with Python's callbacks, an inherited invocation returns
|
|
553
|
+
UNAVAILABLE before possible submission or raises OutcomeUnknownError
|
|
554
|
+
if submission may have begun. The child can make a new invocation.
|
|
555
|
+
"""
|
|
556
|
+
pid = os.getpid()
|
|
557
|
+
caller = _Invocation(pid)
|
|
558
|
+
|
|
559
|
+
def execute() -> Generator[None, None, InvokeReceipt]:
|
|
560
|
+
_fork_state.invocations = (ref(caller), *(ref(active) for active in _running_invocations()))
|
|
561
|
+
# Give the synchronous call a generator's running state without suspending.
|
|
562
|
+
yield from ()
|
|
563
|
+
return self._invoke(plugin, action, caller)
|
|
564
|
+
|
|
565
|
+
execution = execute()
|
|
566
|
+
caller.execution = ref(execution)
|
|
567
|
+
try:
|
|
568
|
+
next(execution)
|
|
569
|
+
except StopIteration as completed:
|
|
570
|
+
receipt = completed.value
|
|
571
|
+
except Exception:
|
|
572
|
+
if os.getpid() == pid:
|
|
573
|
+
raise
|
|
574
|
+
# An inherited operation can fail before its next checkpoint.
|
|
575
|
+
receipt = InvokeReceipt.UNAVAILABLE
|
|
576
|
+
else:
|
|
577
|
+
raise AssertionError("invocation execution suspended")
|
|
578
|
+
finally:
|
|
579
|
+
# Once the generator stops running, no fork can defer another
|
|
580
|
+
# interrupt to this caller. Cover early returns and transport errors.
|
|
581
|
+
caller.raise_interrupt()
|
|
582
|
+
|
|
583
|
+
if os.getpid() != pid:
|
|
584
|
+
if caller.delivery_possible:
|
|
585
|
+
raise OutcomeUnknownError("Idaemon invocation was interrupted by fork")
|
|
586
|
+
return InvokeReceipt.UNAVAILABLE
|
|
587
|
+
return receipt
|
|
588
|
+
|
|
589
|
+
def _invoke(self, plugin: str, action: str, caller: _Invocation) -> InvokeReceipt:
|
|
590
|
+
caller.checkpoint()
|
|
591
|
+
if _PLUGIN.fullmatch(plugin) is None:
|
|
592
|
+
raise ValueError("invalid plugin identity")
|
|
593
|
+
if _ACTION.fullmatch(action) is None:
|
|
594
|
+
raise ValueError("invalid plugin action")
|
|
595
|
+
if sys.platform not in _SUPPORTED_PLATFORMS:
|
|
596
|
+
raise ClientUnavailableError("the Idaemon client requires macOS or Linux")
|
|
597
|
+
|
|
598
|
+
deadline = time.monotonic() + self._timeout
|
|
599
|
+
directory = self._directory
|
|
600
|
+
if directory is None:
|
|
601
|
+
return InvokeReceipt.UNAVAILABLE
|
|
602
|
+
try:
|
|
603
|
+
address = _endpoint.command_address(directory)
|
|
604
|
+
except UnicodeEncodeError:
|
|
605
|
+
raise ClientUnavailableError("runtime directory cannot be encoded for Idaemon") from None
|
|
606
|
+
if address is None:
|
|
607
|
+
return InvokeReceipt.UNAVAILABLE
|
|
608
|
+
|
|
609
|
+
payload = bytes((len(plugin),)) + plugin.encode("ascii") + action.encode("ascii")
|
|
610
|
+
request = memoryview(_MAGIC + _INVOKE + len(payload).to_bytes(2, "big") + payload)
|
|
611
|
+
try:
|
|
612
|
+
caller.checkpoint()
|
|
613
|
+
with _connect(directory, address, deadline, caller=caller) as stream:
|
|
614
|
+
caller.checkpoint()
|
|
615
|
+
ready = _read_frame(stream, len(_READY), deadline)
|
|
616
|
+
caller.checkpoint()
|
|
617
|
+
if ready != _READY:
|
|
618
|
+
return InvokeReceipt.UNAVAILABLE
|
|
619
|
+
while request:
|
|
620
|
+
stream.settimeout(_remaining(deadline))
|
|
621
|
+
previously_written = caller.delivery_possible
|
|
622
|
+
caller.checkpoint()
|
|
623
|
+
# The relative socket timeout can be stale after the checkpoint.
|
|
624
|
+
_remaining(deadline)
|
|
625
|
+
# An exception can arrive after the write and before its count.
|
|
626
|
+
caller.delivery_possible = True
|
|
627
|
+
sent = stream.send(request, socket.MSG_NOSIGNAL)
|
|
628
|
+
if not sent:
|
|
629
|
+
caller.delivery_possible = previously_written
|
|
630
|
+
raise ConnectionError("Idaemon accepted no request bytes")
|
|
631
|
+
caller.checkpoint()
|
|
632
|
+
request = request[sent:]
|
|
633
|
+
reply = _read_frame(stream, 5, deadline)
|
|
634
|
+
caller.checkpoint()
|
|
635
|
+
except (OSError, OverflowError):
|
|
636
|
+
if not caller.delivery_possible:
|
|
637
|
+
return InvokeReceipt.UNAVAILABLE
|
|
638
|
+
raise OutcomeUnknownError("Idaemon invocation ended without a receipt") from None
|
|
639
|
+
|
|
640
|
+
if reply[:4] == _MAGIC:
|
|
641
|
+
receipt = _RECEIPTS.get(reply[4])
|
|
642
|
+
if receipt is not None:
|
|
643
|
+
return receipt
|
|
644
|
+
raise OutcomeUnknownError("Idaemon returned an unrecognized invocation receipt")
|
marceline/_endpoint.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Trust checks for an explicitly selected local Idaemon endpoint."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import re
|
|
6
|
+
import socket
|
|
7
|
+
import stat
|
|
8
|
+
import struct
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
if sys.platform == "darwin":
|
|
12
|
+
from . import _macos
|
|
13
|
+
|
|
14
|
+
# Linux's SO_PEERCRED returns struct ucred: pid_t, uid_t, gid_t.
|
|
15
|
+
_LINUX_CREDENTIALS = struct.Struct("=iII")
|
|
16
|
+
# Leave room for the terminating NUL in sockaddr_un.sun_path.
|
|
17
|
+
_SOCKET_PATH_LIMITS = {"darwin": 103, "linux": 107}
|
|
18
|
+
_COMMAND_SOCKET = "command.sock"
|
|
19
|
+
_COMPONENT = re.compile(r"[^/]+")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def socket_directory(directory: str) -> Path | None:
|
|
23
|
+
limit = _SOCKET_PATH_LIMITS[sys.platform]
|
|
24
|
+
# Match Path's POSIX normalization while keeping only components that
|
|
25
|
+
# could fit. Check spans before copying their text.
|
|
26
|
+
root = "//" if directory.startswith("//") and not directory.startswith("///") else "/"
|
|
27
|
+
length = len(root) + len(_COMMAND_SOCKET) + 1
|
|
28
|
+
parts: list[str] = []
|
|
29
|
+
for match in _COMPONENT.finditer(directory):
|
|
30
|
+
start, end = match.span()
|
|
31
|
+
if end == start + 1 and directory[start] == ".":
|
|
32
|
+
continue
|
|
33
|
+
length += end - start + bool(parts)
|
|
34
|
+
if length > limit:
|
|
35
|
+
return None
|
|
36
|
+
parts.append(match[0])
|
|
37
|
+
return Path(root, *parts)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def command_address(directory: Path) -> bytes | None:
|
|
41
|
+
address = os.fsencode(directory / _COMMAND_SOCKET)
|
|
42
|
+
if len(address) > _SOCKET_PATH_LIMITS[sys.platform]:
|
|
43
|
+
return None
|
|
44
|
+
return address
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def check_directory(directory: Path, uid: int) -> None:
|
|
48
|
+
# Check ancestors from the root before trusting descendants' metadata.
|
|
49
|
+
for path in (*reversed(directory.parents), directory):
|
|
50
|
+
encoded = os.fsencode(path)
|
|
51
|
+
metadata = os.lstat(encoded)
|
|
52
|
+
mode = metadata.st_mode
|
|
53
|
+
owner = metadata.st_uid
|
|
54
|
+
private = path == directory
|
|
55
|
+
if not stat.S_ISDIR(mode) or owner not in (0, uid):
|
|
56
|
+
raise PermissionError("runtime directory has an untrusted ancestor")
|
|
57
|
+
if mode & 0o022 and not (owner == 0 and mode & stat.S_ISVTX):
|
|
58
|
+
raise PermissionError("runtime directory has a writable ancestor")
|
|
59
|
+
if private and (owner != uid or mode & 0o077):
|
|
60
|
+
raise PermissionError("runtime directory must belong to this user and be private")
|
|
61
|
+
if sys.platform == "darwin":
|
|
62
|
+
_macos.check_acl(encoded, private=private)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def check_peer(stream: socket.socket, uid: int) -> None:
|
|
66
|
+
if sys.platform == "darwin":
|
|
67
|
+
peer = _macos.peer_uid(stream.fileno())
|
|
68
|
+
else:
|
|
69
|
+
credentials = stream.getsockopt(
|
|
70
|
+
socket.SOL_SOCKET, socket.SO_PEERCRED, _LINUX_CREDENTIALS.size
|
|
71
|
+
)
|
|
72
|
+
if len(credentials) != _LINUX_CREDENTIALS.size:
|
|
73
|
+
raise PermissionError("incomplete Idaemon peer credentials")
|
|
74
|
+
_, peer, _ = _LINUX_CREDENTIALS.unpack(credentials)
|
|
75
|
+
if peer != uid:
|
|
76
|
+
raise PermissionError("Idaemon endpoint belongs to a different user")
|
marceline/_macos.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Darwin's ACL and Unix peer credential interfaces."""
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import errno
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
_libc = ctypes.CDLL(None, use_errno=True)
|
|
8
|
+
|
|
9
|
+
_get_acl = _libc.acl_get_link_np
|
|
10
|
+
_get_acl.argtypes = (ctypes.c_char_p, ctypes.c_int)
|
|
11
|
+
_get_acl.restype = ctypes.c_void_p
|
|
12
|
+
|
|
13
|
+
_get_entry = _libc.acl_get_entry
|
|
14
|
+
_get_entry.argtypes = (ctypes.c_void_p, ctypes.c_int, ctypes.POINTER(ctypes.c_void_p))
|
|
15
|
+
_get_entry.restype = ctypes.c_int
|
|
16
|
+
|
|
17
|
+
_get_tag = _libc.acl_get_tag_type
|
|
18
|
+
_get_tag.argtypes = (ctypes.c_void_p, ctypes.POINTER(ctypes.c_int))
|
|
19
|
+
_get_tag.restype = ctypes.c_int
|
|
20
|
+
|
|
21
|
+
_get_permissions = _libc.acl_get_permset_mask_np
|
|
22
|
+
_get_permissions.argtypes = (ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint64))
|
|
23
|
+
_get_permissions.restype = ctypes.c_int
|
|
24
|
+
|
|
25
|
+
_free_acl = _libc.acl_free
|
|
26
|
+
_free_acl.argtypes = (ctypes.c_void_p,)
|
|
27
|
+
_free_acl.restype = ctypes.c_int
|
|
28
|
+
|
|
29
|
+
_get_peer_ids = _libc.getpeereid
|
|
30
|
+
_get_peer_ids.argtypes = (ctypes.c_int, ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint))
|
|
31
|
+
_get_peer_ids.restype = ctypes.c_int
|
|
32
|
+
|
|
33
|
+
# sys/acl.h: write data, delete, append, delete child, write attributes,
|
|
34
|
+
# write extended attributes, write security, and change owner.
|
|
35
|
+
_MUTATION_PERMISSIONS = 0x3574
|
|
36
|
+
_ACL_TYPE_EXTENDED = 0x100
|
|
37
|
+
_ACL_FIRST_ENTRY = 0
|
|
38
|
+
_ACL_NEXT_ENTRY = -1
|
|
39
|
+
_ACL_EXTENDED_ALLOW = 1
|
|
40
|
+
_ACL_EXTENDED_DENY = 2
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _check_status(status: int) -> None:
|
|
44
|
+
if status != 0:
|
|
45
|
+
error = ctypes.get_errno()
|
|
46
|
+
raise OSError(error, os.strerror(error))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def check_acl(path: bytes, *, private: bool) -> None:
|
|
50
|
+
acl = _get_acl(path, _ACL_TYPE_EXTENDED)
|
|
51
|
+
if acl is None:
|
|
52
|
+
error = ctypes.get_errno()
|
|
53
|
+
if error == errno.ENOENT:
|
|
54
|
+
# Darwin also reports ENOENT when an existing item simply has no ACL.
|
|
55
|
+
os.lstat(path)
|
|
56
|
+
return
|
|
57
|
+
raise OSError(error, os.strerror(error))
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
entry = ctypes.c_void_p()
|
|
61
|
+
entry_id = _ACL_FIRST_ENTRY
|
|
62
|
+
tag = ctypes.c_int()
|
|
63
|
+
permissions = ctypes.c_uint64()
|
|
64
|
+
protected = -1 if private else _MUTATION_PERMISSIONS
|
|
65
|
+
while True:
|
|
66
|
+
status = _get_entry(acl, entry_id, ctypes.byref(entry))
|
|
67
|
+
if status == -1 and ctypes.get_errno() == errno.EINVAL:
|
|
68
|
+
# The kernel supplied the ACL and the index names its next entry.
|
|
69
|
+
break
|
|
70
|
+
_check_status(status)
|
|
71
|
+
_check_status(_get_tag(entry, ctypes.byref(tag)))
|
|
72
|
+
if tag.value == _ACL_EXTENDED_ALLOW:
|
|
73
|
+
_check_status(_get_permissions(entry, ctypes.byref(permissions)))
|
|
74
|
+
if permissions.value & protected:
|
|
75
|
+
raise PermissionError("runtime directory has an access-widening ACL")
|
|
76
|
+
elif tag.value != _ACL_EXTENDED_DENY:
|
|
77
|
+
raise PermissionError("unrecognized Darwin ACL entry")
|
|
78
|
+
entry_id = _ACL_NEXT_ENTRY
|
|
79
|
+
finally:
|
|
80
|
+
_free_acl(acl)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def peer_uid(descriptor: int) -> int:
|
|
84
|
+
uid = ctypes.c_uint()
|
|
85
|
+
gid = ctypes.c_uint()
|
|
86
|
+
_check_status(_get_peer_ids(descriptor, ctypes.byref(uid), ctypes.byref(gid)))
|
|
87
|
+
return uid.value
|
marceline/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: marceline
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for interacting with Marceline plugins in Marcellus.
|
|
5
|
+
License-Expression: MIT OR Apache-2.0
|
|
6
|
+
Project-URL: Source, https://github.com/almanaculum/marcellus
|
|
7
|
+
Classifier: Operating System :: MacOS
|
|
8
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE-MIT
|
|
14
|
+
License-File: LICENSE-APACHE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Marceline for Python
|
|
18
|
+
|
|
19
|
+
Marceline is the plugin platform for Marcellus, an editor, IDE, and agentic
|
|
20
|
+
harness. It brings development tools into the workspace where you write and
|
|
21
|
+
review code. A plugin can mark the line where a test failed, turn a
|
|
22
|
+
patch into proposed edits, or send the paragraph under your cursor to a coding
|
|
23
|
+
agent and show its reply. You choose what each plugin can access.
|
|
24
|
+
|
|
25
|
+
## Connect a Python tool
|
|
26
|
+
|
|
27
|
+
Use this client when a script, test runner, or coding agent needs to interact
|
|
28
|
+
with a plugin in a running Marcellus session. The plugin offers actions in
|
|
29
|
+
Marcellus. Your Python code can invoke those same actions and check whether
|
|
30
|
+
Marcellus accepted the request.
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
python -m pip install marceline
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The client supports Python 3.11 or later on macOS and Linux. The Python
|
|
37
|
+
guide walks through connecting to a session, invoking a plugin action,
|
|
38
|
+
and handling the result. [Python usage guide][python]
|
|
39
|
+
|
|
40
|
+
## Build plugins and hosts
|
|
41
|
+
|
|
42
|
+
To add a feature to Marcellus, start with the WebAssembly plugin guide.
|
|
43
|
+
To run Marceline plugins in a Rust application, start with the host guide.
|
|
44
|
+
[Write your first plugin][plugins] · [Build a Rust host][hosts]
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
Marceline for Python is available under the MIT License or the Apache License 2.0.
|
|
49
|
+
|
|
50
|
+
[python]: https://docs.rs/marceline/0.1.0/marceline/guides/python/
|
|
51
|
+
[plugins]: https://docs.rs/marceline/0.1.0/marceline/guides/plugins/
|
|
52
|
+
[hosts]: https://docs.rs/marceline/0.1.0/marceline/guides/hosts/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
marceline/__init__.py,sha256=K9bElnypecxOlFGRMsIr54JFq4nG6zNL2UaFYBChGe0,24577
|
|
2
|
+
marceline/_endpoint.py,sha256=XzubUAolkFGcQJcAMPqUusvgwPRp5AQ_2BKs6nRlU1k,2894
|
|
3
|
+
marceline/_macos.py,sha256=ZrgX-kZLR76NRiKz5A-7iqygJ-EAVX1mC8FsgPB_o20,3017
|
|
4
|
+
marceline/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
marceline-0.1.0.dist-info/licenses/LICENSE-APACHE,sha256=pg7qgXUUUxZo1-AHZXMUSf4U0FnTJJ4LyTs23kX3WfI,10847
|
|
6
|
+
marceline-0.1.0.dist-info/licenses/LICENSE-MIT,sha256=gtPL5azdqoEE3OM1dsr6N9CXrtZlUIMyvYba6ExuYrs,1079
|
|
7
|
+
marceline-0.1.0.dist-info/METADATA,sha256=ZoEVZ8sH1bsdaj8cNUcXNsGhg7kHDzU1JGt_VCQw4uA,1997
|
|
8
|
+
marceline-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
marceline-0.1.0.dist-info/top_level.txt,sha256=R-vappBTXm8JyonMOi75xMiixtzQ30jPvl1oelKU6uc,10
|
|
10
|
+
marceline-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marceline contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
marceline
|