Esempio n. 1
0
 def next(self, deadline=float('+inf')):
   raw_event = self.completion_queue.next(deadline)
   if raw_event is None:
     return None
   event = _types.Event(*raw_event)
   if event.call is not None:
     event = event._replace(call=Call(event.call))
   if event.call_details is not None:
     event = event._replace(call_details=_types.CallDetails(*event.call_details))
   if event.results is not None:
     new_results = [_types.OpResult(*r) for r in event.results]
     new_results = [r if r.status is None else r._replace(status=_types.Status(_types.StatusCode(r.status[0]), r.status[1])) for r in new_results]
     event = event._replace(results=new_results)
   return event
Esempio n. 2
0
 def next(self, deadline=float('+inf')):
     raw_event = self.completion_queue.poll(cygrpc.Timespec(deadline))
     if raw_event.type == cygrpc.CompletionType.queue_timeout:
         return None
     event_type = raw_event.type
     event_tag = raw_event.tag
     event_call = Call(raw_event.operation_call)
     if raw_event.request_call_details:
         event_call_details = _types.CallDetails(
             raw_event.request_call_details.method,
             raw_event.request_call_details.host,
             float(raw_event.request_call_details.deadline))
     else:
         event_call_details = None
     event_success = raw_event.success
     event_results = []
     if raw_event.is_new_request:
         event_results.append(
             _types.OpResult(_types.OpType.RECV_INITIAL_METADATA,
                             raw_event.request_metadata, None, None, None,
                             None))
     else:
         if raw_event.batch_operations:
             for operation in raw_event.batch_operations:
                 result_type = operation.type
                 result_initial_metadata = operation.received_metadata_or_none
                 result_trailing_metadata = operation.received_metadata_or_none
                 result_message = operation.received_message_or_none
                 if result_message is not None:
                     result_message = result_message.bytes()
                 result_cancelled = operation.received_cancelled_or_none
                 if operation.has_status:
                     result_status = _types.Status(
                         operation.received_status_code_or_none,
                         operation.received_status_details_or_none)
                 else:
                     result_status = None
                 event_results.append(
                     _types.OpResult(result_type, result_initial_metadata,
                                     result_trailing_metadata,
                                     result_message, result_status,
                                     result_cancelled))
     return _types.Event(event_type, event_tag, event_call,
                         event_call_details, event_results, event_success)