Esempio n. 1
0
 def __call__(self,
              request_iterator,
              timeout=None,
              metadata=None,
              credentials=None,
              wait_for_ready=None,
              compression=None):
     deadline = _deadline(timeout)
     state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None)
     initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
         wait_for_ready)
     augmented_metadata = _compression.augment_metadata(
         metadata, compression)
     operationses = (
         (
             cygrpc.SendInitialMetadataOperation(augmented_metadata,
                                                 initial_metadata_flags),
             cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),
         ),
         (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS), ),
     )
     event_handler = _event_handler(state, self._response_deserializer)
     call = self._channel.managed_call(
         cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method,
         None, _determine_deadline(deadline), augmented_metadata,
         None if credentials is None else credentials._credentials,
         operationses, event_handler, self._context)
     _consume_request_iterator(request_iterator, state, call,
                               self._request_serializer, event_handler)
     return _MultiThreadedRendezvous(state, call,
                                     self._response_deserializer, deadline)
Esempio n. 2
0
    def _blocking(self, request_iterator, timeout, metadata, credentials,
                  wait_for_ready, compression):
        deadline = _deadline(timeout)
        state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None)
        initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
            wait_for_ready)
        augmented_metadata = _compression.augment_metadata(
            metadata, compression)

        call = self._channel.segregated_call(
            cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method,
            None, _determine_deadline(deadline), augmented_metadata,
            None if credentials is None else credentials._credentials,
            _stream_unary_invocation_operationses_and_tags(
                augmented_metadata, initial_metadata_flags), self._context)
        _consume_request_iterator(request_iterator, state, call,
                                  self._request_serializer, None)
        while True:
            event = call.next_event()
            with state.condition:
                _handle_event(event, state, self._response_deserializer)
                state.condition.notify_all()
                if not state.due:
                    break
        return state, call
Esempio n. 3
0
 def future(self,
            request_iterator,
            timeout=None,
            metadata=None,
            credentials=None,
            wait_for_ready=None,
            compression=None):
     deadline = _deadline(timeout)
     state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None)
     event_handler = _event_handler(state, self._response_deserializer)
     initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
         wait_for_ready)
     augmented_metadata = _compression.augment_metadata(
         metadata, compression)
     call = self._channel.managed_call(
         cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method,
         None, deadline, augmented_metadata,
         None if credentials is None else credentials._credentials,
         _stream_unary_invocation_operationses(metadata,
                                               initial_metadata_flags),
         event_handler, self._context)
     _consume_request_iterator(request_iterator, state, call,
                               self._request_serializer, event_handler)
     return _MultiThreadedRendezvous(state, call,
                                     self._response_deserializer, deadline)
Esempio n. 4
0
    def __call__(self,
                 request,
                 timeout=None,
                 metadata=None,
                 credentials=None,
                 wait_for_ready=None,
                 compression=None):
        deadline, serialized_request, rendezvous = _start_unary_request(
            request, timeout, self._request_serializer)
        initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
            wait_for_ready)
        if serialized_request is None:
            raise rendezvous
        else:
            augmented_metadata = _compression.augment_metadata(
                metadata, compression)
            state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None,
                              None)
            operationses = (
                (
                    cygrpc.SendInitialMetadataOperation(
                        augmented_metadata, initial_metadata_flags),
                    cygrpc.SendMessageOperation(serialized_request,
                                                _EMPTY_FLAGS),
                    cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS),
                    cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),
                ),
                (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS), ),
            )

            call = self._channel.managed_call(
                cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS,
                self._method, None, _determine_deadline(deadline), metadata,
                None if credentials is None else credentials._credentials,
                operationses, _event_handler(state,
                                             self._response_deserializer),
                self._context)
            return _MultiThreadedRendezvous(state, call,
                                            self._response_deserializer,
                                            deadline)
Esempio n. 5
0
 def _prepare(self, request, timeout, metadata, wait_for_ready,
              compression):
     deadline, serialized_request, rendezvous = _start_unary_request(
         request, timeout, self._request_serializer)
     initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
         wait_for_ready)
     augmented_metadata = _compression.augment_metadata(
         metadata, compression)
     if serialized_request is None:
         return None, None, None, rendezvous
     else:
         state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None)
         operations = (
             cygrpc.SendInitialMetadataOperation(augmented_metadata,
                                                 initial_metadata_flags),
             cygrpc.SendMessageOperation(serialized_request, _EMPTY_FLAGS),
             cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS),
             cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS),
             cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS),
             cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),
         )
         return state, operations, deadline, None