From 85f6f7bd82eb129c4661857c76005afd9005dca1 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 29 Apr 2019 17:52:54 +0000 Subject: [PATCH] Make qwarc.utils.handle_response_limit_error_retries more useful by passing the deferring handler as an argument --- qwarc/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qwarc/utils.py b/qwarc/utils.py index 298970d..bf9e455 100644 --- a/qwarc/utils.py +++ b/qwarc/utils.py @@ -167,17 +167,17 @@ async def handle_response_ignore_redirects(url, attempt, response, exc): return action, writeToWarc -def handle_response_limit_error_retries(maxRetries): - '''A response handler that limits the number of retries on errors. It behaves as handle_response_default otherwise. +def handle_response_limit_error_retries(maxRetries, handler = handle_response_default): + '''A response handler that limits the number of retries on errors. It behaves as handler otherwise, which defaults to handle_response_default. Technically, this is actually a response handler factory. This is so that the intuitive use works: fetch(..., responseHandler = handle_response_limit_error_retries(5)) If you use the same limit many times, you should keep the return value (the response handler) of this method and reuse it to avoid creating a new function every time. ''' - async def handler(url, attempt, response, exc): - action, writeToWarc = await handle_response_default(url, attempt, response, exc) + async def _handler(url, attempt, response, exc): + action, writeToWarc = await handler(url, attempt, response, exc) if action == ACTION_RETRY and attempt > maxRetries: action = ACTION_IGNORE return action, writeToWarc - return handler + return _handler