ap-client 0.7.1.dev5__tar.gz → 0.7.1.dev7__tar.gz
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.
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/PKG-INFO +5 -5
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/__init__.py +1 -1
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/api.py +1 -136
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/canonical_put.py +35 -75
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/cli.py +209 -57
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/irepo_sdk.py +59 -4
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/submission_metadata.py +35 -15
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/pyproject.toml +4 -4
- ap_client-0.7.1.dev5/.gitignore +0 -260
- ap_client-0.7.1.dev5/ap_client/control_http.py +0 -415
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/akpool_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/canonical_get.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/cluster_layout_fetcher.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/cluster_region_resolver.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/config.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/dataset_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/dataset_name.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/dataset_register.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/dfs_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/exporter.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/fs_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/fs_storage.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/fs_transfer.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/instance_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/instance_options.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/managed_ak.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/manifest_view.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/ossutil_hash.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/ossutil_io.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_cascade_all.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_cascade_cli.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_cascade_display.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_cascade_state.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_diagnostics.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_display.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/profile_references.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/replica_policy.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/repo_read_guard.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/share_api.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/shared_adapter.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/shared_commands.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/split_publish.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/tbb.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/tool_manifest.py +0 -0
- {ap_client-0.7.1.dev5 → ap_client-0.7.1.dev7}/ap_client/waiter.py +0 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: ap-client
|
|
3
|
-
Version: 0.7.1.
|
|
3
|
+
Version: 0.7.1.dev7
|
|
4
4
|
Summary: Agent Platform API Client & CLI
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Requires-Dist: click<8.2.0,>=8.1.8
|
|
7
|
-
Requires-Dist: irepo-artifact==0.2.
|
|
7
|
+
Requires-Dist: irepo-artifact==0.2.5
|
|
8
8
|
Requires-Dist: pyyaml>=6.0
|
|
9
9
|
Requires-Dist: requests>=2.28.0
|
|
10
10
|
Requires-Dist: rich>=13.0.0
|
|
11
11
|
Requires-Dist: typer<0.21.0,>=0.20.1
|
|
12
12
|
Requires-Dist: websockets>=13.0
|
|
13
13
|
Provides-Extra: all
|
|
14
|
-
Requires-Dist: instance-repo[oss]
|
|
14
|
+
Requires-Dist: instance-repo[oss]<2.0.0,>=1.4.0; extra == 'all'
|
|
15
15
|
Provides-Extra: dataset
|
|
16
|
-
Requires-Dist: instance-repo[oss]
|
|
16
|
+
Requires-Dist: instance-repo[oss]<2.0.0,>=1.4.0; extra == 'dataset'
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
|
|
19
19
|
A lightweight Python SDK and command line interface for Agent Platform. It provides helpers for configuring API access and managing templates, datasets, jobs, and groups.
|
|
@@ -6,7 +6,6 @@ import os
|
|
|
6
6
|
import platform
|
|
7
7
|
import re
|
|
8
8
|
import sys
|
|
9
|
-
import threading
|
|
10
9
|
import time
|
|
11
10
|
import uuid
|
|
12
11
|
from email.utils import parsedate_to_datetime
|
|
@@ -288,14 +287,6 @@ class APIError(Exception):
|
|
|
288
287
|
return f"API Error {self.status_code}: {self.detail} (request_id={self.request_id})"
|
|
289
288
|
|
|
290
289
|
|
|
291
|
-
class CanonicalControlAPIError(APIError):
|
|
292
|
-
"""Operation-only sanitized error; never holds a native response or cause."""
|
|
293
|
-
def __init__(self, reason, *, status_code=None, biz_code=None):
|
|
294
|
-
self.reason = reason
|
|
295
|
-
detail = {"code": biz_code} if type(biz_code) is int else "canonical control request failed"
|
|
296
|
-
super().__init__(status_code, detail, None, None)
|
|
297
|
-
|
|
298
|
-
|
|
299
290
|
class PaginationProtocolError(RuntimeError):
|
|
300
291
|
"""The server stopped honoring a pagination protocol already in use."""
|
|
301
292
|
|
|
@@ -380,8 +371,6 @@ class APIClient:
|
|
|
380
371
|
|
|
381
372
|
def __init__(self, config: Config):
|
|
382
373
|
self.config = config
|
|
383
|
-
self._control_channel = None
|
|
384
|
-
self._control_channel_lock = threading.Lock()
|
|
385
374
|
self.session = requests.Session()
|
|
386
375
|
headers = dict(config.headers)
|
|
387
376
|
user_agent = _build_user_agent(headers.get("User-Agent"))
|
|
@@ -437,13 +426,8 @@ class APIClient:
|
|
|
437
426
|
timeout: TimeoutType = None,
|
|
438
427
|
deadline: Optional[float] = None,
|
|
439
428
|
_return_response: bool = False,
|
|
440
|
-
max_response_bytes: Optional[int] = None,
|
|
441
429
|
) -> Any:
|
|
442
|
-
"""Send through the normal
|
|
443
|
-
if max_response_bytes is not None:
|
|
444
|
-
return self._request_control_json(method, path, params=params,
|
|
445
|
-
json_body=json_body, timeout=timeout, deadline=deadline,
|
|
446
|
-
max_response_bytes=max_response_bytes, return_response=_return_response)
|
|
430
|
+
"""Send through the normal authenticated HTTP channel."""
|
|
447
431
|
self._require_cluster_config()
|
|
448
432
|
return self._request_http(
|
|
449
433
|
method,
|
|
@@ -612,125 +596,6 @@ class APIClient:
|
|
|
612
596
|
raise APIError(resp.status_code, detail, request_id, resp) from exc
|
|
613
597
|
raise RuntimeError("unreachable retry state")
|
|
614
598
|
|
|
615
|
-
def _request_control_json(self, method, path, *, params, json_body, timeout,
|
|
616
|
-
deadline, max_response_bytes, return_response):
|
|
617
|
-
from .control_http import (ControlHTTPError, OwnedControlChannel, validate_limit,
|
|
618
|
-
_check_deadline)
|
|
619
|
-
|
|
620
|
-
if return_response:
|
|
621
|
-
raise CanonicalControlAPIError("invalid_request")
|
|
622
|
-
self._require_cluster_config()
|
|
623
|
-
failure = None
|
|
624
|
-
try:
|
|
625
|
-
validate_limit(max_response_bytes)
|
|
626
|
-
_check_deadline(deadline)
|
|
627
|
-
if isinstance(timeout, bool):
|
|
628
|
-
raise ControlHTTPError('invalid_deadline')
|
|
629
|
-
if isinstance(timeout, (int, float)):
|
|
630
|
-
if not math.isfinite(timeout) or timeout < 0:
|
|
631
|
-
raise ControlHTTPError('invalid_deadline')
|
|
632
|
-
if deadline is None:
|
|
633
|
-
# A finite SDK per-request remaining duration owns one
|
|
634
|
-
# deadline across this request's retries, never per attempt.
|
|
635
|
-
deadline = time.monotonic() + timeout
|
|
636
|
-
_check_deadline(deadline)
|
|
637
|
-
except ControlHTTPError as exc:
|
|
638
|
-
failure = CanonicalControlAPIError(exc.reason)
|
|
639
|
-
if failure is not None:
|
|
640
|
-
raise failure
|
|
641
|
-
with self._control_channel_lock:
|
|
642
|
-
if self._control_channel is None:
|
|
643
|
-
self._control_channel = OwnedControlChannel(self.session)
|
|
644
|
-
channel = self._control_channel
|
|
645
|
-
timeout = _default_timeout() if timeout is None else _normalize_explicit_timeout(timeout)
|
|
646
|
-
url = self._url(path)
|
|
647
|
-
attempts = self._max_attempts_for(method)
|
|
648
|
-
for attempt in range(1, attempts + 1):
|
|
649
|
-
if deadline is not None and time.monotonic() >= deadline:
|
|
650
|
-
raise CanonicalControlAPIError("deadline")
|
|
651
|
-
failure = response = None
|
|
652
|
-
try:
|
|
653
|
-
response = channel.request(method, url, headers={"X-Request-ID": str(uuid.uuid4())},
|
|
654
|
-
params=params, json_body=json_body,
|
|
655
|
-
timeout=_deadline_timeout(timeout, deadline), deadline=deadline,
|
|
656
|
-
max_response_bytes=max_response_bytes)
|
|
657
|
-
except ControlHTTPError as exc:
|
|
658
|
-
failure = CanonicalControlAPIError(exc.reason, status_code=exc.status)
|
|
659
|
-
retryable = exc.retryable or (exc.status is not None and
|
|
660
|
-
_is_retryable_status(exc.status) and exc.reason != "redirect")
|
|
661
|
-
except APIError:
|
|
662
|
-
failure = CanonicalControlAPIError("deadline")
|
|
663
|
-
retryable = False
|
|
664
|
-
if failure is not None:
|
|
665
|
-
if attempt < attempts and retryable:
|
|
666
|
-
delay = _retry_delay(attempt)
|
|
667
|
-
if deadline is not None:
|
|
668
|
-
remaining = deadline - time.monotonic()
|
|
669
|
-
if remaining <= 0:
|
|
670
|
-
raise CanonicalControlAPIError("deadline")
|
|
671
|
-
delay = min(delay, remaining)
|
|
672
|
-
time.sleep(delay)
|
|
673
|
-
continue
|
|
674
|
-
raise failure
|
|
675
|
-
if deadline is not None and time.monotonic() >= deadline:
|
|
676
|
-
raise CanonicalControlAPIError("deadline")
|
|
677
|
-
if not 200 <= response.status_code < 300:
|
|
678
|
-
if attempt < attempts and _is_retryable_status(response.status_code):
|
|
679
|
-
try:
|
|
680
|
-
delay = _retry_delay(attempt, response)
|
|
681
|
-
except (ValueError, TypeError, OverflowError, OSError):
|
|
682
|
-
delay = _retry_delay(attempt)
|
|
683
|
-
if not math.isfinite(delay):
|
|
684
|
-
delay = _retry_delay(attempt)
|
|
685
|
-
if deadline is not None:
|
|
686
|
-
remaining = deadline - time.monotonic()
|
|
687
|
-
if remaining <= 0:
|
|
688
|
-
raise CanonicalControlAPIError("deadline")
|
|
689
|
-
delay = min(delay, remaining)
|
|
690
|
-
time.sleep(delay)
|
|
691
|
-
continue
|
|
692
|
-
parsed = None
|
|
693
|
-
if response.refusal is None:
|
|
694
|
-
try:
|
|
695
|
-
parsed = json.loads(response.content.decode("utf-8", errors="replace"))
|
|
696
|
-
except (ValueError, UnicodeError, RecursionError):
|
|
697
|
-
pass
|
|
698
|
-
# Preserve both existing API envelope shapes while retaining
|
|
699
|
-
# only the typed numeric classification, never message/data.
|
|
700
|
-
detail = parsed.get("detail", parsed) if isinstance(parsed, dict) else None
|
|
701
|
-
if isinstance(detail, str):
|
|
702
|
-
decoded = None
|
|
703
|
-
try:
|
|
704
|
-
decoded = json.loads(detail)
|
|
705
|
-
except (ValueError, RecursionError):
|
|
706
|
-
pass
|
|
707
|
-
detail = decoded
|
|
708
|
-
code = detail.get("code") if isinstance(detail, dict) else None
|
|
709
|
-
raise CanonicalControlAPIError("http_error", status_code=response.status_code,
|
|
710
|
-
biz_code=code if type(code) is int else None)
|
|
711
|
-
if not response.content:
|
|
712
|
-
return None
|
|
713
|
-
text = None
|
|
714
|
-
try:
|
|
715
|
-
text = response.content.decode("utf-8", errors="strict")
|
|
716
|
-
except UnicodeError:
|
|
717
|
-
pass
|
|
718
|
-
if text is None:
|
|
719
|
-
raise CanonicalControlAPIError("invalid_utf8", status_code=response.status_code)
|
|
720
|
-
parsed = None
|
|
721
|
-
valid_json = False
|
|
722
|
-
try:
|
|
723
|
-
parsed = json.loads(text)
|
|
724
|
-
valid_json = True
|
|
725
|
-
except (ValueError, RecursionError):
|
|
726
|
-
pass
|
|
727
|
-
if not valid_json:
|
|
728
|
-
raise CanonicalControlAPIError("invalid_json", status_code=response.status_code)
|
|
729
|
-
if deadline is not None and time.monotonic() >= deadline:
|
|
730
|
-
raise CanonicalControlAPIError("deadline")
|
|
731
|
-
return parsed
|
|
732
|
-
raise CanonicalControlAPIError("network")
|
|
733
|
-
|
|
734
599
|
def _max_attempts_for(self, method: str) -> int:
|
|
735
600
|
if method.upper() not in _RETRYABLE_METHODS:
|
|
736
601
|
return 1
|
|
@@ -30,6 +30,7 @@ import math
|
|
|
30
30
|
import time
|
|
31
31
|
import uuid
|
|
32
32
|
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
|
|
33
|
+
from dataclasses import dataclass
|
|
33
34
|
from pathlib import Path
|
|
34
35
|
from typing import Any, Callable, Optional
|
|
35
36
|
from urllib.parse import parse_qsl
|
|
@@ -70,6 +71,25 @@ class CanonicalPutIncomplete(Exception):
|
|
|
70
71
|
# Adapter: SDK Transport surface over the accepted APIClient channel
|
|
71
72
|
# ---------------------------------------------------------------------------
|
|
72
73
|
|
|
74
|
+
@dataclass(frozen=True, repr=False)
|
|
75
|
+
class CanonicalControlDiagnostic:
|
|
76
|
+
"""Finite operation metadata used by CLI error projection."""
|
|
77
|
+
endpoint: str
|
|
78
|
+
reason: str
|
|
79
|
+
status: Optional[int]
|
|
80
|
+
biz_code: Optional[int]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _control_endpoint_label(path):
|
|
84
|
+
labels = {"/apis/v1/user-data/storage-layout": "storage_layout",
|
|
85
|
+
"/apis/v1/user-data/entries": "entries",
|
|
86
|
+
"/apis/v1/user-data/directories": "directories",
|
|
87
|
+
"/apis/v1/user-data/reads/resolve": "read_resolve",
|
|
88
|
+
"/apis/v1/user-data/writes/begin": "write_begin",
|
|
89
|
+
"/apis/v1/role-bindings": "role_bindings",
|
|
90
|
+
"/apis/v1/me/identity": "identity"}
|
|
91
|
+
return labels.get(path, "control")
|
|
92
|
+
|
|
73
93
|
|
|
74
94
|
class APIClientTransportAdapter:
|
|
75
95
|
"""Bridge B's SDK client transport contract onto APIClient._request.
|
|
@@ -82,15 +102,10 @@ class APIClientTransportAdapter:
|
|
|
82
102
|
error text never reaches user output.
|
|
83
103
|
"""
|
|
84
104
|
|
|
85
|
-
def __init__(self, api_client: Any, *, base_deadline: Optional[float] = None
|
|
86
|
-
max_response_bytes: int = 8 * 1024 * 1024):
|
|
105
|
+
def __init__(self, api_client: Any, *, base_deadline: Optional[float] = None):
|
|
87
106
|
_validate_absolute_deadline(base_deadline)
|
|
88
107
|
from .api import APIClient
|
|
89
|
-
|
|
90
|
-
validate_limit(max_response_bytes)
|
|
91
|
-
self._native_control = isinstance(api_client, APIClient)
|
|
92
|
-
self._max_response_bytes = max_response_bytes
|
|
93
|
-
if self._native_control:
|
|
108
|
+
if isinstance(api_client, APIClient):
|
|
94
109
|
# Preserve the established authenticated session, but suppress all
|
|
95
110
|
# credential-bearing request/response logging for this operation.
|
|
96
111
|
# Always isolate Config, including when initially quiet: a later
|
|
@@ -101,9 +116,6 @@ class APIClientTransportAdapter:
|
|
|
101
116
|
from dataclasses import replace
|
|
102
117
|
operation_client = copy.copy(api_client)
|
|
103
118
|
operation_client.config = replace(api_client.config, verbose=False)
|
|
104
|
-
import threading
|
|
105
|
-
operation_client._control_channel = None
|
|
106
|
-
operation_client._control_channel_lock = threading.Lock()
|
|
107
119
|
api_client = operation_client
|
|
108
120
|
self._client = api_client
|
|
109
121
|
self._base_deadline = base_deadline # ABSOLUTE monotonic (or None)
|
|
@@ -120,21 +132,15 @@ class APIClientTransportAdapter:
|
|
|
120
132
|
"""
|
|
121
133
|
from instance_repo.clients.user_data_writes import TransportError
|
|
122
134
|
|
|
123
|
-
reason = getattr(exc, "reason", None)
|
|
124
|
-
if reason == "deadline":
|
|
125
|
-
from instance_repo.errors import RequestDeadlineExceeded
|
|
126
|
-
return RequestDeadlineExceeded("canonical control request deadline exhausted")
|
|
127
|
-
if reason in ("response_limit", "encoding", "invalid_utf8", "invalid_json",
|
|
128
|
-
"invalid_limit", "invalid_deadline", "unsupported", "invalid_request", "redirect") and not (
|
|
129
|
-
type(getattr(exc, "status_code", None)) is int and
|
|
130
|
-
getattr(exc, "status_code") >= 400):
|
|
131
|
-
from instance_repo.errors import SchemaError
|
|
132
|
-
return SchemaError("canonical control response or channel refused")
|
|
133
135
|
status = getattr(exc, "status_code", None)
|
|
134
136
|
detail = getattr(exc, "detail", None)
|
|
135
137
|
biz_code = None
|
|
138
|
+
data = None
|
|
136
139
|
if isinstance(detail, dict):
|
|
137
140
|
biz_code = detail.get("code")
|
|
141
|
+
candidate = detail.get("data")
|
|
142
|
+
if isinstance(candidate, dict):
|
|
143
|
+
data = {key: candidate[key] for key in ("reason", "apply_url") if key in candidate}
|
|
138
144
|
elif isinstance(detail, str) and detail.strip():
|
|
139
145
|
import json
|
|
140
146
|
|
|
@@ -142,18 +148,16 @@ class APIClientTransportAdapter:
|
|
|
142
148
|
parsed = json.loads(detail)
|
|
143
149
|
if isinstance(parsed, dict):
|
|
144
150
|
biz_code = parsed.get("code")
|
|
151
|
+
candidate = parsed.get("data")
|
|
152
|
+
if isinstance(candidate, dict):
|
|
153
|
+
data = {key: candidate[key] for key in ("reason", "apply_url") if key in candidate}
|
|
145
154
|
except (TypeError, ValueError):
|
|
146
155
|
biz_code = None
|
|
147
156
|
if isinstance(biz_code, bool) or not isinstance(biz_code, int):
|
|
148
157
|
biz_code = None
|
|
149
158
|
# Message is a fixed short label — raw API text is never forwarded.
|
|
150
159
|
label = "apiserver rejected the request"
|
|
151
|
-
return TransportError(label, status=status, biz_code=biz_code)
|
|
152
|
-
|
|
153
|
-
def close(self):
|
|
154
|
-
channel = getattr(self._client, '_control_channel', None)
|
|
155
|
-
if self._native_control and channel is not None:
|
|
156
|
-
channel.close()
|
|
160
|
+
return TransportError(label, status=status, biz_code=biz_code, data=data)
|
|
157
161
|
|
|
158
162
|
def _call(self, method: str, path: str, *, json_body=None,
|
|
159
163
|
timeout: float | None = None, params=None):
|
|
@@ -162,59 +166,18 @@ class APIClientTransportAdapter:
|
|
|
162
166
|
options['json_body'] = json_body
|
|
163
167
|
if params is not None:
|
|
164
168
|
options['params'] = params
|
|
165
|
-
if self._native_control:
|
|
166
|
-
options['max_response_bytes'] = self._max_response_bytes
|
|
167
|
-
failure = None
|
|
168
169
|
try:
|
|
169
|
-
|
|
170
|
+
return self._client._request(method, path, **options)
|
|
170
171
|
except Exception as exc:
|
|
171
172
|
from .api import APIError
|
|
172
173
|
if isinstance(exc, APIError) or getattr(exc, 'status_code', None) is not None:
|
|
173
|
-
|
|
174
|
+
raise self._translate_api_error(exc) from None
|
|
174
175
|
else:
|
|
175
176
|
raise
|
|
176
|
-
if failure is not None:
|
|
177
|
-
raise failure
|
|
178
|
-
return result
|
|
179
177
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
# pagination or discarding malformed rows. The typed client validates it.
|
|
184
|
-
if type(payload) is dict and "data" in payload and set(payload) <= {
|
|
185
|
-
"code", "message", "data", "pagination"}:
|
|
186
|
-
return payload["data"], payload.get("pagination")
|
|
187
|
-
return payload, None
|
|
188
|
-
|
|
189
|
-
def _control_request(self, method, path, body, timeout):
|
|
190
|
-
if type(path) is not str or not path.startswith("/") or "#" in path:
|
|
191
|
-
from instance_repo.errors import SchemaError
|
|
192
|
-
raise SchemaError("invalid canonical control request")
|
|
193
|
-
base, _, query = path.partition("?")
|
|
194
|
-
pairs = parse_qsl(query, keep_blank_values=True)
|
|
195
|
-
if len({key for key, _ in pairs}) != len(pairs):
|
|
196
|
-
from instance_repo.errors import SchemaError
|
|
197
|
-
raise SchemaError("duplicate canonical control query")
|
|
198
|
-
return self._call(method, base, json_body=body, timeout=timeout,
|
|
199
|
-
params=dict(pairs) if pairs else None)
|
|
200
|
-
|
|
201
|
-
def request(self, method, path, body=None, *, idempotent, timeout=None):
|
|
202
|
-
# This additive surface is deliberately the actual ACL ABI. APIClient
|
|
203
|
-
# owns GET retries; mutation methods are always one attempt.
|
|
204
|
-
if (type(idempotent) is not bool or type(method) is not str or
|
|
205
|
-
not ((method == "GET" and idempotent and body is None) or
|
|
206
|
-
(method == "POST" and not idempotent and type(body) is dict) or
|
|
207
|
-
(method == "DELETE" and not idempotent and body is None))):
|
|
208
|
-
from instance_repo.errors import SchemaError
|
|
209
|
-
raise SchemaError("unsupported canonical control request")
|
|
210
|
-
payload = self._control_request(method, path, body, timeout)
|
|
211
|
-
return self._control_projection(payload)[0]
|
|
212
|
-
|
|
213
|
-
def request_with_meta(self, method, path, *, timeout=None):
|
|
214
|
-
if method != "GET" or type(method) is not str:
|
|
215
|
-
from instance_repo.errors import SchemaError
|
|
216
|
-
raise SchemaError("unsupported canonical metadata request")
|
|
217
|
-
return self._control_projection(self._control_request(method, path, None, timeout))
|
|
178
|
+
def close(self):
|
|
179
|
+
"""Compatibility no-op; the shared requests session is caller-owned."""
|
|
180
|
+
return None
|
|
218
181
|
|
|
219
182
|
# -- SDK Transport surface ---------------------------------------------
|
|
220
183
|
|
|
@@ -237,9 +200,6 @@ class APIClientTransportAdapter:
|
|
|
237
200
|
|
|
238
201
|
def post(self, path: str, body: dict, *, idempotent: bool = False,
|
|
239
202
|
headers: dict | None = None, timeout: float | None = None) -> dict:
|
|
240
|
-
if headers is not None and headers != {}:
|
|
241
|
-
from instance_repo.errors import SchemaError
|
|
242
|
-
raise SchemaError("custom headers are unsupported by the canonical adapter")
|
|
243
203
|
return self._call("POST", path, json_body=body, timeout=timeout)
|
|
244
204
|
|
|
245
205
|
|