Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def StreamUnary(self, stream):
raise GRPCError(Status.UNIMPLEMENTED)
async def UnaryUnary(self, stream):
raise GRPCError(Status.UNIMPLEMENTED)
async def UnaryStream(self, stream):
raise GRPCError(Status.UNIMPLEMENTED)
async def UnaryStream(self, stream):
raise GRPCError(Status.UNIMPLEMENTED)
async def StreamUnary(self, stream):
raise GRPCError(Status.UNIMPLEMENTED)
async def test_unimplemented_error(cs: ClientStream):
with pytest.raises(ErrorDetected):
async with cs.client_stream as stream:
await stream.send_request()
events = cs.client_conn.to_server_transport.events()
stream_id = events[-1].stream_id
cs.client_conn.server_h2c.send_headers(stream_id, [
(':status', '200'),
('content-type', 'application/grpc+proto'),
('grpc-status', str(Status.UNIMPLEMENTED.value)),
], end_stream=True)
cs.client_conn.server_flush()
try:
await stream.recv_initial_metadata()
except GRPCError as exc:
assert exc and exc.status == Status.UNIMPLEMENTED
raise ErrorDetected()
async def StreamStream(self, stream):
raise GRPCError(Status.UNIMPLEMENTED)
with pytest.raises(GRPCError) as err:
async with cs.client_stream as stream:
await stream.send_request()
events = cs.client_conn.to_server_transport.events()
stream_id = events[-1].stream_id
cs.client_conn.server_h2c.send_headers(stream_id, [
(':status', '200'),
('content-type', 'application/grpc+proto'),
('grpc-status', str(Status.UNIMPLEMENTED.value)),
], end_stream=True)
cs.client_conn.server_h2c.reset_stream(stream_id)
cs.client_conn.server_flush()
assert err.value.status == Status.UNIMPLEMENTED
if TYPE_CHECKING:
from ._typing import IReleaseStream # noqa
_H2_OK = '200'
# https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
_H2_TO_GRPC_STATUS_MAP = {
# 400
str(http.HTTPStatus.BAD_REQUEST.value): Status.INTERNAL,
# 401
str(http.HTTPStatus.UNAUTHORIZED.value): Status.UNAUTHENTICATED,
# 403
str(http.HTTPStatus.FORBIDDEN.value): Status.PERMISSION_DENIED,
# 404
str(http.HTTPStatus.NOT_FOUND.value): Status.UNIMPLEMENTED,
# 502
str(http.HTTPStatus.BAD_GATEWAY.value): Status.UNAVAILABLE,
# 503
str(http.HTTPStatus.SERVICE_UNAVAILABLE.value): Status.UNAVAILABLE,
# 504
str(http.HTTPStatus.GATEWAY_TIMEOUT.value): Status.UNAVAILABLE,
# 429
str(http.HTTPStatus.TOO_MANY_REQUESTS.value): Status.UNAVAILABLE,
}
class Handler(AbstractHandler):
connection_lost = False
def accept(self, stream: Any, headers: Any, release_stream: Any) -> None:
raise NotImplementedError('Client connection can not accept requests')
async def daemon(
context: DaemonContext, client: CompanionClient, request: BootRequest
) -> BootResponse:
if client.is_companion_available:
await none_throws(context.boot_manager).boot(udid=none_throws(client.udid))
return BootResponse()
else:
# TODO T41660845
raise GRPCError(
status=Status(Status.UNIMPLEMENTED),
message="boot with chained daemons hasn't been implemented yet",
)