Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
('content-type', 'application/grpc+proto'),
])
cs.client_conn.server_h2c.send_data(
stream_id,
grpc_encode(DummyReply(value='pong'), DummyReply),
)
cs.client_conn.server_h2c.send_headers(stream_id, [
('foo', 'bar'),
], end_stream=True)
cs.client_conn.server_flush()
await stream.recv_initial_metadata()
await stream.recv_message()
try:
await stream.recv_trailing_metadata()
except GRPCError as exc:
assert exc
assert exc.status == Status.UNKNOWN
assert exc.message == 'Missing grpc-status header'
raise ErrorDetected()
def translate_exception(self, exception: Exception) -> Exception:
if self.translate_exceptions and not isinstance(exception, GRPCError):
return GRPCError(Status.INTERNAL, exception.args[0])
return exception
exc_tb: Optional[TracebackType],
) -> Optional[bool]:
if (
self._send_trailing_metadata_done
or self._cancel_done
or self._stream._transport.is_closing()
):
# to suppress exception propagation
return True
protocol_error = None
if exc_val is not None:
# This error should be logged by ``request_handler``, here we
# have to convert it into trailers and send to the client using
# ``send_trailing_metadata`` method.
if isinstance(exc_val, GRPCError):
status = exc_val.status
status_message = exc_val.message
status_details = exc_val.details
elif isinstance(exc_val, Exception):
status = Status.UNKNOWN
status_message = 'Internal Server Error'
status_details = None
else:
# propagate exception
return None
elif (
# There is a possibility of a ``ProtocolError`` in the
# ``send_trailing_metadata`` method, so we are checking for such
# errors here
not self._cardinality.server_streaming
and not self._send_message_done
raise GRPCError(Status.UNKNOWN, ('Invalid grpc-status: {!r}'
.format(grpc_status)))
else:
if status is not Status.OK:
message = headers_map.get('grpc-message')
if message is not None:
message = decode_grpc_message(message)
details = None
if self._status_details_codec is not None:
details_bin = headers_map.get(_STATUS_DETAILS_KEY)
if details_bin is not None:
details = self._status_details_codec.decode(
status, message,
decode_bin_value(details_bin.encode('ascii'))
)
raise GRPCError(status, message, details)
async def func_wrapper_gen(*args: Any, **kwargs: Any) -> Any:
try:
async for item in func(*args, **kwargs):
yield item
except GRPCError as e:
raise IdbException(e.message) from e # noqa B306
except (ProtocolError, StreamTerminatedError) as e:
raise IdbException(e.args) from e
path: str, destination: Destination, logger: Logger
) -> AsyncIterator[InstallRequest]:
if destination == InstallRequest.APP:
if path.endswith(".ipa"):
return _generate_ipa_chunks(ipa_path=path, logger=logger)
elif path.endswith(".app"):
return _generate_app_chunks(app_path=path, logger=logger)
elif destination == InstallRequest.XCTEST:
return _generate_xctest_chunks(path=path, logger=logger)
elif destination == InstallRequest.DYLIB:
return _generate_dylib_chunks(path=path, logger=logger)
elif destination == InstallRequest.DSYM:
return _generate_dsym_chunks(path=path, logger=logger)
elif destination == InstallRequest.FRAMEWORK:
return _generate_framework_chunks(path=path, logger=logger)
raise GRPCError(
status=Status(Status.FAILED_PRECONDITION),
message=f"install invalid for {path} {destination}",
)
def translate_exception(self, exception: Exception) -> Exception:
if self.translate_exceptions and not isinstance(exception, GRPCError):
return GRPCError(Status.INTERNAL, exception.args[0])
return exception