"""Module providing several layers of data access to the wiki."""## (C) Pywikibot team, 2007-2023## Distributed under the terms of the MIT license.#from__future__importannotationsimportpywikibot
[docs]classWaitingMixin:"""A mixin to implement wait cycles. .. versionadded:: 8.4 :ivar int max_retries: Maximum number of times to retry an API request before quitting. Defaults to ``config.max_retries`` if attribute is missing. :ivar int retry_wait: Minimum time to wait before resubmitting a failed API request. Defaults to ``config.retry_wait`` if attribute is missing. :ivar int current_retries: counter of retries made for the current request. Starting with 1 if attribute is missing. """
[docs]defwait(self,delay:int|None=None)->None:"""Determine how long to wait after a failed request. :param delay: Minimum time in seconds to wait. Overwrites ``retry_wait`` variable if given. The delay doubles each retry until ``retry_max`` seconds is reached. """ifnothasattr(self,'max_retries'):self.max_retries=pywikibot.config.max_retriesifnothasattr(self,'retry_wait'):self.retry_wait=pywikibot.config.retry_waitifnothasattr(self,'current_retries'):self.current_retries=1else:self.current_retries+=1ifself.current_retries>self.max_retries:raisepywikibot.exceptions.TimeoutError('Maximum retries attempted without success.')# double the next wait, but do not exceed config.retry_max secondsdelay=delayorself.retry_waitdelay*=2**(self.current_retries-1)delay=min(delay,pywikibot.config.retry_max)pywikibot.warning(f'Waiting {delay:.1f} seconds before retrying.')pywikibot.sleep(delay)