def backoff(<EOL>max_tries=constants.BACKOFF_DEFAULT_MAXTRIES,<EOL>delay=constants.BACKOFF_DEFAULT_DELAY,<EOL>factor=constants.BACKOFF_DEFAULT_FACTOR,<EOL>exceptions=None):
if max_tries <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(max_tries))<EOL><DEDENT>if delay <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(delay))<EOL><DEDENT>if factor <= <NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(factor))<EOL><DEDENT>def outter(f):<EOL><INDENT>def inner(*args, **kwargs):<EOL><INDENT>m_max_tries, m_delay = max_tries, delay <EOL>while m_max_tries > <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>retval = f(*args, **kwargs)<EOL><DEDENT>except exceptions:<EOL><INDENT>logger.exception('<STR_LIT>'<EOL>'<STR_LIT>', f, max_tries, delay, factor, exceptions)<EOL>m_max_tries -= <NUM_LIT:1> <EOL>if m_max_tries <= <NUM_LIT:0>:<EOL><INDENT>raise <EOL><DEDENT>time.sleep(m_delay) <EOL>m_delay *= factor <EOL><DEDENT>else:<EOL><INDENT>return retval<EOL><DEDENT><DEDENT><DEDENT>return inner<EOL><DEDENT>return outter<EOL>
Implements an exponential backoff decorator which will retry decorated
    function upon given exceptions. This implementation is based on
    `Retry <https://wiki.python.org/moin/PythonDecoratorLibrary#Retry>`_ from
    the *Python Decorator Library*.

    :param int max_tries: Number of tries before give up. Defaults to
        :const:`~escpos.constants.BACKOFF_DEFAULT_MAXTRIES`.

    :param int delay: Delay between retries (in seconds). Defaults to
        :const:`~escpos.constants.BACKOFF_DEFAULT_DELAY`.

    :param int factor: Multiply factor in which delay will be increased for the
        next retry. Defaults to :const:`~escpos.constants.BACKOFF_DEFAULT_FACTOR`.

    :param exceptions: Tuple of exception types to catch that triggers retry.
        Any exception not listed will break the decorator and retry routines
        will not run.

    :type exceptions: tuple[Exception]