Schemas of the HTTP values (Effect's Schema.Headers, Cookie,
Cookies, RecordFromCookies, UrlParams, JsonFromUrlParamsField,
RecordFromUrlParams, RetryAfter, RetryAfterFromString and
DateTimeUtcFromHttpDate). They live here, not in pyfect.schema,
because pyfect.http is built on pyfect.schema::
from pyfect.http import schema as HS
S.decode_unknown_sync(HS.RecordFromCookies)(cookies) # {"session": "abc"}RetryAfter is a declaration of headers.RetryAfterDuration /
RetryAfterDateTime (Effect's is a union of tagged structs of the same
shape): the duration must be finite and non-negative.
Values#
| Attribute | Type | Description |
|---|---|---|
Headers | Bottom[_headers.Headers] |
|
Cookie | Bottom[_cookies.Cookie] | A |
Cookies | Bottom[_cookies.Cookies] |
|
RecordFromCookies | DecodeToSchema[dict[str, str], _cookies.Cookies] | The cookies' values by name; encoding makes plain cookies. |
UrlParams | Bottom[_url_params.UrlParams] |
|
RecordFromUrlParams | DecodeToSchema[dict[str, str | tuple[str, ...]], _url_params.UrlParams] | The params by key: one value, or a tuple of a repeated key's values. |
RetryAfter | Bottom[_headers.RetryAfter] | A parsed |
RetryAfterFromString | DecodeToSchema[_headers.RetryAfter, str] | A |
DateTimeUtcFromHttpDate | DecodeToSchema[datetime, str] | A UTC |
Functions#
JsonFromUrlParamsField#
JsonFromUrlParamsField(field) -> DecodeToSchema[object, _url_params.UrlParams]The JSON text of the params' first field value, parsed (missing:
a MissingKey at field). Effect's reviver option is not
ported, as for S.from_json_string.
| Parameter | Type | Description |
|---|---|---|
field | str |
Returns DecodeToSchema[object, _url_params.UrlParams]
def JsonFromUrlParamsField(field: str, /) -> DecodeToSchema[object, _url_params.UrlParams]:
"""The JSON text of the params' first ``field`` value, parsed (missing:
a ``MissingKey`` at ``field``). Effect's ``reviver`` option is not
ported, as for ``S.from_json_string``."""
def decode(params: _url_params.UrlParams, _: ParseOptions) -> Exit[str, Issue]:
value = params.get_first(field)
if value is None:
return fail_exit(Pointer((field,), MissingKey()))
return Success(value)
def encode(value: str, _: ParseOptions) -> Exit[_url_params.UrlParams, Issue]:
return Success(_url_params.make([(field, value)]))
json = from_json_string(Unknown)
return UrlParams.pipe(decode_to(json, T.transform_effect(decode=decode, encode=encode)))