Beispiel #1
0
def DispatchWrapped(connection: ConnectionWrapper) -> None:
    """Dispatches a request to the proper OperationHandler."""
    state = State()
    while True:
        try:
            request = connection.Recv()

            if request.HasField("upload_signature_request"):
                handler_class = UploadSignatureHandler
            elif request.HasField("process_scan_request"):
                handler_class = ProcessScanHandler
            else:
                raise DispatchError("No request set.")

            handler = handler_class(state, request, connection)
            handler.Run()
        except:  # pylint: disable=bare-except
            exception = memory_pb2.Exception(
                message=str(sys.exc_info()[1]),
                formatted_exception=traceback.format_exc())
            connection.Send(memory_pb2.Response(exception=exception))
Beispiel #2
0
 def Recv(self) -> memory_pb2.Response:
   raw_response, _ = self._connection.Recv()
   response = memory_pb2.Response()
   response.ParseFromString(raw_response)
   return response
Beispiel #3
0
 def PackResponse(
         self, response: memory_pb2.UploadSignatureResponse
 ) -> memory_pb2.Response:
     return memory_pb2.Response(upload_signature_response=response)
Beispiel #4
0
 def PackResponse(
         self,
         response: memory_pb2.ProcessScanResponse) -> memory_pb2.Response:
     return memory_pb2.Response(process_scan_response=response)