Example #1
0
    def _convert_to_request_dict(self, api_params, operation_model,
                                 context=None):
        # Given the API params provided by the user and the operation_model
        # we can serialize the request to a request_dict.
        operation_name = operation_model.name

        # Emit an event that allows users to modify the parameters at the
        # beginning of the method. It allows handlers to modify existing
        # parameters or return a new set of parameters to use.
        responses = self.meta.events.emit(
            'provide-client-params.{endpoint_prefix}.{operation_name}'.format(
                endpoint_prefix=self._service_model.endpoint_prefix,
                operation_name=operation_name),
            params=api_params, model=operation_model, context=context)
        api_params = first_non_none_response(responses, default=api_params)

        event_name = (
            'before-parameter-build.{endpoint_prefix}.{operation_name}')
        self.meta.events.emit(
            event_name.format(
                endpoint_prefix=self._service_model.endpoint_prefix,
                operation_name=operation_name),
            params=api_params, model=operation_model, context=context)

        request_dict = self._serializer.serialize_to_request(
            api_params, operation_model)
        prepare_request_dict(request_dict, endpoint_url=self._endpoint.host,
                             user_agent=self._client_config.user_agent)
        return request_dict
Example #2
0
 def _needs_retry(self, attempts, operation_model, response=None,
                  caught_exception=None):
     event_name = 'needs-retry.%s.%s' % (self._endpoint_prefix,
                                         operation_model.name)
     responses = self._event_emitter.emit(
         event_name, response=response, endpoint=self,
         operation=operation_model, attempts=attempts,
         caught_exception=caught_exception)
     handler_response = first_non_none_response(responses)
     if handler_response is None:
         return False
     else:
         # Request needs to be retried, and we need to sleep
         # for the specified number of times.
         logger.debug("Response received to retry, sleeping for "
                      "%s seconds", handler_response)
         time.sleep(handler_response)
         return True
Example #3
0
 def emit_first_non_none_response(self, event_name, **kwargs):
     responses = self._events.emit(event_name, **kwargs)
     return first_non_none_response(responses)
Example #4
0
 def emit_first_non_none_response(self, event_name, **kwargs):
     responses = self._events.emit(event_name, **kwargs)
     return first_non_none_response(responses)