<s> import time <EOL> import logging <EOL> from mwclient . errors import MaximumRetriesExceeded <EOL> log = logging . getLogger ( __name__ ) <EOL> class Sleepers ( object ) : <EOL> def __init__ ( self , max_retries , retry_timeout , callback = lambda * x : None ) : <EOL> self . max_retries = max_retries <EOL> self . retry_timeout = retry_timeout <EOL> self . callback = callback <EOL> def make ( self , args = None ) : <EOL> return Sleeper ( args , self . max_retries , self . retry_timeout , self . callback ) <EOL> class Sleeper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , args , max_retries , retry_timeout , callback ) : <EOL> self . args = args <EOL> self . retries = <NUM_LIT:0> <EOL> self . max_retries = max_retries <EOL> self . retry_timeout = retry_timeout <EOL> self . callback = callback <EOL> def sleep ( self , min_time = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . retries += <NUM_LIT:1> <EOL> if self . retries > self . max_retries : <EOL> raise MaximumRetriesExceeded ( self , self . args ) <EOL> self . callback ( self , self . retries , self . args ) <EOL> timeout = self . retry_timeout * ( self . retries - <NUM_LIT:1> ) <EOL> if timeout < min_time : <EOL> timeout = min_time <EOL> log . debug ( '<STR_LIT>' , timeout ) <EOL> time . sleep ( timeout ) </s>
