Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.http.response

Module Contents

BatchResponse

class roboto.http.response.BatchResponse(/, **data)#View Source

Bases: pydantic.BaseModel, Generic[Model]

The response to a batch request, holding one element per request element, in the order the request sent them.

Every element of a batch is applied or refused on its own, so a batch can come back partly applied. succeeded and failed split the outcomes for a caller that does not care which request element produced which; read responses to trace an outcome back to the request element at its position.

Parameters

data Any

Properties

BatchResponse.failed

The exception the platform reported for each element it refused, in request order.

BatchResponse.map_data()

map_data(transform)#View Source

Convert what each applied element carries, leaving positions and failures untouched.

A batch call parses the platform’s answer into records and uses this to hand the caller domain objects instead: a SessionRecord becomes a Session. transform runs only on elements carrying data; a refused element keeps its exception, and every element keeps its position.

Parameters

transform collections.abc.Callable[[Model], MappedModel]

Builds the domain object an applied element’s record stands for.

Returns

A batch holding one element per element of this one, in the same order.

Attributes

BatchResponse.responses

responses list[BatchResponseElement[Model]] #

BatchResponse.single()

single()#View Source

The result carried by the only element of a one-element batch.

A singular call such as create_session() sends its one element through the plural counterpart and unwraps the answer with this, so its caller gets a raised exception rather than a batch to inspect.

Raises

Whatever the platform refused the element with.

The batch does not hold exactly one element, or holds one carrying neither a result nor an error.

Return type

Properties

BatchResponse.succeeded

succeeded list[Model] #

The result the platform returned for each element it applied, in request order.

Return type: list[Model]

BatchResponseElement

class roboto.http.response.BatchResponseElement(/, **data)#View Source

Bases: pydantic.BaseModel, Generic[Model]

One element of a response to a batch request, holding data when the operation succeeded and error when it failed, never both. An element holding neither reports an operation that returns no content, the batch equivalent of a 204 answer to a singular call.

Parameters

data Any

Attributes

BatchResponseElement.data

data Model | None = None #

BatchResponseElement.error

BatchResponseElement.model_config

model_config #

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

BatchResponseElement.serialize_error()

serialize_error(value, info)#View Source

Parameters

info pydantic.SerializationInfo

Return type

Optional[dict[str, Any]]

BatchResponseElement.validate_error()

validate_error(value)#View Source

Build the exception an element was refused with, in whichever form the failure arrived.

Three forms reach this: an exception object, which is what an element copied from another batch carries; the envelope RobotoDomainException.to_dict() produces; and that envelope as JSON text, which is what RobotoDomainException declares to pydantic. Only a literal None yields None, which is how an element the platform applied or answered with no content arrives.

Any other value is a refusal, whatever shape it has. An envelope naming an exception class this release does not define, one missing its code or message, JSON that is not an envelope, and text that is not JSON all read as a RobotoUnrecognizedErrorException carrying whatever code and message could be recovered, with the value’s own text as the message when no message could be. That way a refused element is always in BatchResponse.failed, so a caller checking failed before treating a batch as done cannot mistake a garbled refusal for success.

plain mode replaces the validation the error annotation would otherwise apply. That annotation reads JSON text, so it would reject the exception object returned here.

Parameters

value Any

DEFAULT_RESPONSE_JSONPATH

roboto.http.response.DEFAULT_RESPONSE_JSONPATH = ('data',)#View Source

HttpResponse

class roboto.http.response.HttpResponse(response)#View Source

Parameters

response urllib.response.addinfourl

Properties

HttpResponse.headers

headers dict[str, str] | None #
Return type: Optional[dict[str, str]]

HttpResponse.readable_response

readable_response urllib.response.addinfourl #
Return type: urllib.response.addinfourl

HttpResponse.status

status http.HTTPStatus #
Return type: http.HTTPStatus

HttpResponse.to_dict()

to_dict(json_path=None)#View Source

Parameters

json_path Optional[collections.abc.Sequence[str]]

Return type

Any

HttpResponse.to_int()

to_int()#View Source

Return type

int

HttpResponse.to_paginated_list()

to_paginated_list(record_type)#View Source

Parameters

record_type Type[PydanticModel]

HttpResponse.to_record()

to_record(record_type, json_path=DEFAULT_RESPONSE_JSONPATH)#View Source

Parameters

record_type Type[PydanticModel]
json_path Optional[collections.abc.Sequence[str]]

Return type

HttpResponse.to_record_list()

to_record_list(record_type, json_path=DEFAULT_RESPONSE_JSONPATH)#View Source

Parameters

record_type Type[PydanticModel]
json_path Optional[collections.abc.Sequence[str]]

Return type

HttpResponse.to_string()

to_string()#View Source

HttpResponse.to_string_list()

to_string_list()#View Source

Return type

list[str]

InvalidPaginationTokenError

exception roboto.http.response.InvalidPaginationTokenError#View Source

Bases: ValueError

Raised when a pagination token cannot be parsed.

A pagination token is opaque to clients, so one that fails to decode or carries an unsupported scheme reflects bad caller input — a fabricated, truncated, or stale token — rather than a server fault. Subclasses ValueError so existing callers that catch ValueError around PaginationToken.from_token() keep working unchanged, while callers that want to distinguish this recoverable input error (e.g. to surface an actionable message instead of a generic 500 or runtime exception) can catch it specifically.

MappedModel

roboto.http.response.MappedModel#View Source

Model

roboto.http.response.Model#View Source

PaginatedList

class roboto.http.response.PaginatedList(/, **data)#View Source

Bases: pydantic.BaseModel, Generic[Model]

A list of records pulled from a paginated result set. It may be a subset of that result set, in which case next_token will be set and can be used to fetch the next page.

Parameters

data Any

Attributes

PaginatedList.items

items list[Model] #

Roboto entities in this page of results.

PaginatedList.next_token

next_token str | None = None #

Opaque token to fetch the next page of results.

If None, then this is the last page of results.

PaginatedList.total_count

total_count int | None = None #

Total result set size, if available.

PaginationToken

class roboto.http.response.PaginationToken(scheme, encoding, data)#View Source

A pagination token that can be treated as a truly opaque token by clients, with support for evolving the token format over time.

Parameters

Properties

PaginationToken.data

data Any #
Return type: Any

PaginationToken.decode()

static decode(data)#View Source

Base64 decode the data, adding back any trailing padding (“=”) as necessary to make data properly Base64.

Parameters

data str

Return type

str

PaginationToken.empty()

static empty()#View Source

Return type

PaginationToken.encode()

static encode(data)#View Source

Base64 encode the data and strip all trailing padding (“=”).

Parameters

data str

Return type

str

PaginationToken.from_token()

classmethod from_token(token)#View Source

Parameters

token Optional[str]

Return type

PaginationToken.json_token()

classmethod json_token(data)#View Source

Parameters

data Any

Return type

PaginationToken.to_token()

to_token()#View Source

Return type

str

PaginationTokenEncoding

class roboto.http.response.PaginationTokenEncoding(*args, **kwds)#View Source

Bases: enum.Enum

Pagination token encoding enum

Attributes

PaginationTokenEncoding.Json

Json = 'json' #

PaginationTokenEncoding.Raw

Raw = 'raw' #

PaginationTokenScheme

class roboto.http.response.PaginationTokenScheme(*args, **kwds)#View Source

Bases: enum.Enum

Pagination token scheme enum

Attributes

PaginationTokenScheme.V1

V1 = 'v1' #

PydanticModel

roboto.http.response.PydanticModel#View Source

StreamedList

class roboto.http.response.StreamedList(/, **data)#View Source

Bases: pydantic.BaseModel, Generic[Model]

A StreamedList differs from a PaginatedList in that it represents a stream of data that is in process of being written to. Unlike a result set, which is finite and complete, a stream may be infinite, and it is unknown when or if it will complete.

Parameters

data Any

Attributes

StreamedList.has_next

has_next bool #

StreamedList.items

items list[Model] #

StreamedList.last_read

last_read str | None #

logger

roboto.http.response.logger#View Source

Was this page helpful?