def _wrap(cls, method_name, wrapper):
    original = getattr(cls, method_name)
    wrapper = wrapt.FunctionWrapper(original, wrapper)
    wrapt.apply_patch(cls, method_name, wrapper)
Ejemplo n.º 2
0
    log.debug("%s %s" % (method, url))
    # make and send the request
    max_retries = 12
    retries = max_retries
    while retries > 0:
        try:
            response = self._session.request(method,
                                             url,
                                             data=data,
                                             timeout=self.timeout,
                                             headers=headers)
            break
        except (ConnectTimeout, ReadTimeout):
            retries -= 1
            if retries <= 0:
                raise
            else:
                time.sleep(12)
        except ConnectionError:
            retries -= 1
            if hasattr(self, '_reset_session'):
                self._reset_session()
            continue

    return response


apply_patch(Connection, 'make_request', make_request)
apply_patch(Connection, '_run_method', _run_method)
apply_patch(ApiResource, '_make_request', _make_request)