示例#1
0
    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,
                        request,
                        global_endpoint_manager,
                        connection_policy,
                        requests_session,
                        method,
                        path,
                        request_data,
                        query_params,
                        headers):
    """Performs one synchronized http request according to the parameters.

    :param object client:
        Document client instance
    :param dict request:
    :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 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

    # 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, request, connection_policy, requests_session, path, request_options, request_body)
def SynchronizedRequest(client,
                        request,
                        global_endpoint_manager,
                        connection_policy,
                        requests_session,
                        method,
                        path,
                        request_data,
                        query_params,
                        headers):
    """Performs one synchronized http request according to the parameters.

    :param object client:
        Document client instance
    :param dict request:
    :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 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

    # 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, request, connection_policy, requests_session, path, 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)