def _fetch_items_helper_with_retries(self, fetch_function):
        def callback():
            return self._fetch_items_helper_no_retries(fetch_function)

        return retry_utility._Execute(self._client,
                                      self._client._global_endpoint_manager,
                                      callback)
def SynchronizedRequest(client,
                        global_endpoint_manager,
                        connection_policy,
                        method,
                        base_url,
                        path,
                        request_data,
                        query_params,
                        headers):
    """Performs one synchronized http request according to the parameters.

    :Parameters:
        - `client`: object, document client instance
        - `global_endpoint_manager`: _GlobalEndpointManager
        - `connection_policy`: documents.ConnectionPolicy
        - `method`: str
        - `base_url`: str
        - `path`: str
        - `request_data`: str, unicode, file-like stream object, dict, list
          or None
        - `query_params`: dict
        - `headers`: dict

    :Returns:
        tuple of (result, headers), where both result and headers
        are dicts.

    """
    request_body = None
    if request_data:
        request_body = _RequestBodyFromData(request_data)
        if not request_body:
           raise errors.UnexpectedDataType(
               'parameter data must be a JSON object, string or' +
               ' readable stream.')

    request_options = {}
    parse_result = urlparse.urlparse(base_url)
    request_options['host'] = parse_result.hostname
    request_options['port'] = parse_result.port
    request_options['path'] = path
    request_options['method'] = method
    if query_params:
        request_options['path'] += '?' + urllib.urlencode(query_params)

    request_options['headers'] = headers
    if request_body and (type(request_body) is str or
                         type(request_body) is unicode):
        request_options['headers'][http_constants.HttpHeaders.ContentLength] = (
            len(request_body))
    elif request_body == None:
        request_options['headers'][http_constants.HttpHeaders.ContentLength] = 0
    # Pass _InternalRequest function with it's parameters to retry_utility's Execute method that wraps the call with retries
    return retry_utility._Execute(client, global_endpoint_manager, _InternalRequest, connection_policy, request_options, request_body)
        def next(self):
            def callback():
                if not self._iterable.fetch_next_block():
                    self._finished = True

            if self._finished:
                # Must keep raising once we have ended
                raise StopIteration

            if (self._current >= len(self._iterable._results) and
                    not self._finished):
                retry_utility._Execute(self._iterable._client, self._iterable._client._global_endpoint_manager, callback)
                self._current = 0

            if self._finished:
                raise StopIteration

            result = self._iterable._results[self._current]
            self._current += 1
            return result
Ejemplo n.º 4
0
def SynchronizedRequest(client, global_endpoint_manager, connection_policy,
                        requests_session, method, base_url, path, request_data,
                        query_params, headers):
    """Performs one synchronized http request according to the parameters.

    :param object client:
        Document client instance
    :param _GlobalEndpointManager global_endpoint_manager: 
    :param  documents.ConnectionPolicy connection_policy:
    :param requests.Session requests_session:
        Session object in requests module
    :param str method:
    :param str base_url:
    :param str path:
    :param (str, unicode, file-like stream object, dict, list or None) request_data:
    :param dict query_params:
    :param dict headers:

    :return:
        tuple of (result, headers)
    :rtype:
        tuple of (dict dict)

    """
    request_body = None
    if request_data:
        request_body = _RequestBodyFromData(request_data)
        if not request_body:
            raise errors.UnexpectedDataType(
                'parameter data must be a JSON object, string or' +
                ' readable stream.')

    request_options = {}
    request_options['path'] = path
    request_options['method'] = method
    if query_params:
        request_options['path'] += '?' + urlencode(query_params)

    request_options['headers'] = headers
    if request_body and (type(request_body) is str
                         or type(request_body) is six.text_type):
        request_options['headers'][
            http_constants.HttpHeaders.ContentLength] = (len(request_body))
    elif request_body is None:
        request_options['headers'][
            http_constants.HttpHeaders.ContentLength] = 0

    if request_options['path'] is not None:
        resource_url = base_url + request_options['path']
    # Pass _Request function with it's parameters to retry_utility's Execute method that wraps the call with retries
    return retry_utility._Execute(client, global_endpoint_manager, _Request,
                                  connection_policy, requests_session,
                                  resource_url, request_options, request_body)
def SynchronizedRequest(client, global_endpoint_manager, connection_policy,
                        requests_session, method, base_url, path, request_data,
                        query_params, headers):
    """Performs one synchronized http request according to the parameters.

    :Parameters:
        - `client`: object, document client instance
        - `global_endpoint_manager`: _GlobalEndpointManager
        - `connection_policy`: documents.ConnectionPolicy
        - `requests_session`: requests.Session, Session object in requests module
        - `method`: str
        - `base_url`: str
        - `path`: str
        - `request_data`: str, unicode, file-like stream object, dict, list
          or None
        - `query_params`: dict
        - `headers`: dict

    :Returns:
        tuple of (result, headers), where both result and headers
        are dicts.

    """
    request_body = None
    if request_data:
        request_body = _RequestBodyFromData(request_data)
        if not request_body:
            raise errors.UnexpectedDataType(
                'parameter data must be a JSON object, string or' +
                ' readable stream.')

    request_options = {}
    request_options['path'] = path
    request_options['method'] = method
    if query_params:
        request_options['path'] += '?' + urlencode(query_params)

    request_options['headers'] = headers
    if request_body and (type(request_body) is str
                         or type(request_body) is six.text_type):
        request_options['headers'][
            http_constants.HttpHeaders.ContentLength] = (len(request_body))
    elif request_body is None:
        request_options['headers'][
            http_constants.HttpHeaders.ContentLength] = 0

    if request_options['path'] is not None:
        resource_url = base_url + request_options['path']
    # Pass _Request function with it's parameters to retry_utility's Execute method that wraps the call with retries
    return retry_utility._Execute(client, global_endpoint_manager, _Request,
                                  connection_policy, requests_session,
                                  resource_url, request_options, request_body)
 def _fetch_items_helper_with_retries(self, fetch_function):
     def callback():
         return self._fetch_items_helper_no_retries(fetch_function)
             
     return retry_utility._Execute(self._client, self._client._global_endpoint_manager, callback)