chickinfry 0.5.0.dev1__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.
- chickinfry/__init__.py +18 -0
- chickinfry/_auth_database.py +765 -0
- chickinfry/_conformance.py +208 -0
- chickinfry/_device.py +1405 -0
- chickinfry/_device_windows.py +250 -0
- chickinfry/_error_details.py +76 -0
- chickinfry/_http_common.py +165 -0
- chickinfry/_input.py +129 -0
- chickinfry/_origin.py +60 -0
- chickinfry/_password.py +38 -0
- chickinfry/_request_logs.py +66 -0
- chickinfry/_request_state.py +32 -0
- chickinfry/_sync_http.py +546 -0
- chickinfry/_sync_network.py +288 -0
- chickinfry/_workerd.py +731 -0
- chickinfry/auth.py +1227 -0
- chickinfry/errors.py +101 -0
- chickinfry/http.py +427 -0
- chickinfry/orm.py +506 -0
- chickinfry/postgres.py +281 -0
- chickinfry/py.typed +0 -0
- chickinfry/realtime.py +522 -0
- chickinfry/server.py +540 -0
- chickinfry/session.py +465 -0
- chickinfry/signup.py +134 -0
- chickinfry/wire.py +23 -0
- chickinfry-0.5.0.dev1.dist-info/METADATA +375 -0
- chickinfry-0.5.0.dev1.dist-info/RECORD +30 -0
- chickinfry-0.5.0.dev1.dist-info/WHEEL +4 -0
- chickinfry-0.5.0.dev1.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
from collections.abc import Awaitable, Callable, Iterable
|
|
4
|
+
from contextvars import ContextVar
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from .errors import _MESSAGES, ClientError, OperationError
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from ._request_state import _RequestState
|
|
12
|
+
from .session import SessionCredentials
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _HookError(Exception):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(repr=False)
|
|
20
|
+
class _ClearAttempt:
|
|
21
|
+
call_id: str
|
|
22
|
+
expected: "SessionCredentials"
|
|
23
|
+
removed: bool
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(repr=False)
|
|
27
|
+
class _Observation:
|
|
28
|
+
deadline: float
|
|
29
|
+
status: int | None = None
|
|
30
|
+
details: list[str] = field(default_factory=list)
|
|
31
|
+
body_checked: bool = False
|
|
32
|
+
call_id: str = ""
|
|
33
|
+
barrier: Callable[[str, dict[str, object]], None] | None = None
|
|
34
|
+
async_barrier: Callable[[str, dict[str, object]], Awaitable[None]] | None = None
|
|
35
|
+
flight: object | None = None
|
|
36
|
+
flight_ref: Callable[[object], str] | None = None
|
|
37
|
+
hook_failed: bool = False
|
|
38
|
+
transport: Callable[[str, object], None] | None = None
|
|
39
|
+
refusal: str | None = None
|
|
40
|
+
sealed: bool = False
|
|
41
|
+
|
|
42
|
+
def release(self) -> None:
|
|
43
|
+
self.sealed = True
|
|
44
|
+
self.details.clear()
|
|
45
|
+
self.barrier = None
|
|
46
|
+
self.async_barrier = None
|
|
47
|
+
self.flight = None
|
|
48
|
+
self.flight_ref = None
|
|
49
|
+
|
|
50
|
+
def notify(self, point: str, value: object = None) -> None:
|
|
51
|
+
if self.transport is not None:
|
|
52
|
+
try:
|
|
53
|
+
self.transport(point, value)
|
|
54
|
+
except Exception:
|
|
55
|
+
self.hook_failed = True
|
|
56
|
+
raise _HookError() from None
|
|
57
|
+
|
|
58
|
+
def arrive(self, point: str, facts: dict[str, object]) -> None:
|
|
59
|
+
if self.barrier is not None:
|
|
60
|
+
try:
|
|
61
|
+
self.barrier(point, facts)
|
|
62
|
+
except Exception:
|
|
63
|
+
self.hook_failed = True
|
|
64
|
+
raise _HookError() from None
|
|
65
|
+
|
|
66
|
+
async def aarrive(self, point: str, facts: dict[str, object]) -> None:
|
|
67
|
+
if self.async_barrier is not None:
|
|
68
|
+
try:
|
|
69
|
+
await self.async_barrier(point, facts)
|
|
70
|
+
except Exception:
|
|
71
|
+
self.hook_failed = True
|
|
72
|
+
raise _HookError() from None
|
|
73
|
+
|
|
74
|
+
def trace(
|
|
75
|
+
self,
|
|
76
|
+
state: "_RequestState",
|
|
77
|
+
event: str,
|
|
78
|
+
info: dict[str, object],
|
|
79
|
+
*,
|
|
80
|
+
refresh: bool = True,
|
|
81
|
+
) -> None:
|
|
82
|
+
state.trace(event, info)
|
|
83
|
+
self.notify("trace", (event, info))
|
|
84
|
+
if (
|
|
85
|
+
refresh
|
|
86
|
+
and self.flight is not None
|
|
87
|
+
and self.flight_ref is not None
|
|
88
|
+
and event.endswith(".receive_response_headers.started")
|
|
89
|
+
):
|
|
90
|
+
self.arrive("refresh-joined", {"refreshRef": self.flight_ref(self.flight)})
|
|
91
|
+
|
|
92
|
+
async def atrace(
|
|
93
|
+
self,
|
|
94
|
+
state: "_RequestState",
|
|
95
|
+
event: str,
|
|
96
|
+
info: dict[str, object],
|
|
97
|
+
*,
|
|
98
|
+
refresh: bool = True,
|
|
99
|
+
) -> None:
|
|
100
|
+
state.trace(event, info)
|
|
101
|
+
self.notify("trace", (event, info))
|
|
102
|
+
if (
|
|
103
|
+
refresh
|
|
104
|
+
and self.flight is not None
|
|
105
|
+
and self.flight_ref is not None
|
|
106
|
+
and event.endswith(".receive_response_headers.started")
|
|
107
|
+
):
|
|
108
|
+
await self.aarrive(
|
|
109
|
+
"refresh-joined", {"refreshRef": self.flight_ref(self.flight)}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def _detail(self, value: str) -> None:
|
|
113
|
+
if self.sealed:
|
|
114
|
+
return
|
|
115
|
+
self.details.append(value)
|
|
116
|
+
self.details.extend(re.findall(r"[\w]+(?:[./:+-][\w]+)*", value))
|
|
117
|
+
|
|
118
|
+
def record_headers(self, status: int, values: Iterable[str]) -> None:
|
|
119
|
+
self.status = status
|
|
120
|
+
self.body_checked = False
|
|
121
|
+
self.refusal = None
|
|
122
|
+
for value in values:
|
|
123
|
+
self._detail(value)
|
|
124
|
+
|
|
125
|
+
def record_body(self, data: bytes) -> None:
|
|
126
|
+
if self.sealed:
|
|
127
|
+
return
|
|
128
|
+
text = data.decode("utf-8", "replace")
|
|
129
|
+
self.details.append(text)
|
|
130
|
+
try:
|
|
131
|
+
value: object = json.loads(data)
|
|
132
|
+
except (ValueError, UnicodeError, RecursionError):
|
|
133
|
+
self._detail(text)
|
|
134
|
+
self.body_checked = True
|
|
135
|
+
return
|
|
136
|
+
pending = [value]
|
|
137
|
+
while pending:
|
|
138
|
+
value = pending.pop()
|
|
139
|
+
if isinstance(value, str):
|
|
140
|
+
self._detail(value)
|
|
141
|
+
elif isinstance(value, (int, float)):
|
|
142
|
+
self._detail(str(value))
|
|
143
|
+
elif isinstance(value, dict):
|
|
144
|
+
pending.extend(value.values())
|
|
145
|
+
elif isinstance(value, list):
|
|
146
|
+
pending.extend(value)
|
|
147
|
+
self.body_checked = True
|
|
148
|
+
|
|
149
|
+
def raw_details(self, error: Exception) -> bool | None:
|
|
150
|
+
seen: set[int] = set()
|
|
151
|
+
pending: list[tuple[BaseException, int]] = [(error, 0)]
|
|
152
|
+
fixed = True
|
|
153
|
+
while pending:
|
|
154
|
+
current, depth = pending.pop()
|
|
155
|
+
if id(current) in seen:
|
|
156
|
+
continue
|
|
157
|
+
if depth >= 32 or len(seen) >= 32:
|
|
158
|
+
return None
|
|
159
|
+
seen.add(id(current))
|
|
160
|
+
visible = list(getattr(current, "__notes__", ()))
|
|
161
|
+
if visible:
|
|
162
|
+
fixed = False
|
|
163
|
+
if isinstance(current, BaseExceptionGroup):
|
|
164
|
+
fixed = False
|
|
165
|
+
visible.append(current.message)
|
|
166
|
+
# Only an unchanged diagnostic argument is known to be safe.
|
|
167
|
+
elif not (
|
|
168
|
+
isinstance(current, ClientError)
|
|
169
|
+
and type(current) in (ClientError, OperationError)
|
|
170
|
+
and len(current.args) == 1
|
|
171
|
+
and type(current.args[0]) is str
|
|
172
|
+
and current.args == (_MESSAGES.get(current._reason),)
|
|
173
|
+
):
|
|
174
|
+
fixed = False
|
|
175
|
+
visible.extend(
|
|
176
|
+
(
|
|
177
|
+
str(current),
|
|
178
|
+
repr(current).removeprefix(type(current).__name__ + "("),
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
# Even short response values must fail closed in every visible error.
|
|
182
|
+
if any(
|
|
183
|
+
detail.strip() and any(detail in text for text in visible)
|
|
184
|
+
for detail in self.details
|
|
185
|
+
):
|
|
186
|
+
return True
|
|
187
|
+
if isinstance(current, BaseExceptionGroup):
|
|
188
|
+
pending.extend((child, depth + 1) for child in current.exceptions)
|
|
189
|
+
cause = current.__cause__ or (
|
|
190
|
+
None if current.__suppress_context__ else current.__context__
|
|
191
|
+
)
|
|
192
|
+
if cause is not None:
|
|
193
|
+
pending.append((cause, depth + 1))
|
|
194
|
+
if self.status is not None and not self.body_checked:
|
|
195
|
+
if (
|
|
196
|
+
fixed
|
|
197
|
+
and not getattr(error, "__notes__", ())
|
|
198
|
+
and isinstance(error, ClientError)
|
|
199
|
+
and self.refusal == error.code
|
|
200
|
+
):
|
|
201
|
+
return False
|
|
202
|
+
return None
|
|
203
|
+
return False if isinstance(error, ClientError) else None
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
_observer: ContextVar[_Observation | None] = ContextVar(
|
|
207
|
+
"chickinfry_conformance_observer", default=None
|
|
208
|
+
)
|