retry-0.9.2/0000755000076500000240000000000012714635166013003 5ustar userstaff00000000000000retry-0.9.2/AUTHORS0000644000076500000240000000042112714635166014050 0ustar userstaff00000000000000Richard O'Dwyer Rémy Rémy Rémy Greinhofer invl invlpg invlpg@gmail.com williara retry-0.9.2/ChangeLog0000644000076500000240000000453712714635166014566 0ustar userstaff00000000000000CHANGES ======= 0.9.2 ----- * Update ChangeLog * Update AUTHORS * Don't pin pytest * tox: Add py35 * Bump version * Updating requirements.txt to allow for any decorators >=3.4.2 0.9.1 ----- * Updates setup.cfg version info * Updates authors and changelog * Adds version ranges to requirements, widening compatibility with other packages and their deps 0.9.0 ----- * Fix typo in classifier * Add AUTHORS and ChangeLog files * Packaging the application using PBR * Update documentation * Add retry_call function * Update tox.ini * Update requirements * Move the tests to the appropriate package * Add .gitignore file 0.8.1 ----- * v0.8.1 * Move try/import to compat 0.8.0 ----- * v0.8.0 * dos2unix * Add argument jitter for retry() * Add argument max_delay for retry() * Refactor retry() 0.7.0 ----- * v0.7.0 * Update README.rst * retry(): Update docstring * retry(): Change default tries to -1 * Move decorator() to .compat * Add test_tries_minus1() * Add test_tries_inf() * Mock time.sleep in test case * Refactor retry() 0.6.0 ----- * v0.6.0 * Fix inaccurate attempt counter * logger is now optional * Extract logging_logger * Make decorator module optional 0.5.0 ----- * v0.5.0 * Update README.rst * Add badges * Configurable logger * Update classifiers * Remove .hgignore and .hgtags * Faster test * Support Python 3.4 * Add tox.ini * Extract retry/api.py * Require pytest * Add test_retry.py * Added tag 0.4.2 for changeset 315f5f1229f6 0.4.2 ----- * Version 0.4.2 * (untested) python2.6 support * README.rst: Add installation * Add classifiers * Add LICENSE * Add requirements.txt * Fix rST h1 h2 for README.rst * Add url * Add README.rst * Ignore *.egg-info * Ignore .env * Ignore .ropeproject * Ignore .git * Added tag 0.4.1 for changeset 2765d4be1b4d 0.4.1 ----- * Version 0.4.1 * Add license * Add long_description * Add docstring for retry() * Added tag 0.4.0 for changeset e053cae4b105 0.4.0 ----- * Version 0.4.0 * Convert to a package * backoff defaults to 1 * Refactor: tries defaults to inf instead of None * Added tag 0.3.0 for changeset 60960fe42471 0.3.0 ----- * Version 0.3.0 * delay defaults to 0 * Use logging * tries can be None, for retry forever * Add ifmain * Refactor * Added tag 0.2.0 for changeset 87b6dd2bc30b 0.2.0 ----- * Fix typo * Refactor * Add description * Use decorator * Added tag 0.1.0 for changeset bf83184dd128 0.1.0 ----- * init retry-0.9.2/LICENSE0000600000076500000240000000104112500142620013751 0ustar userstaff00000000000000Copyright 2014 invl Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. retry-0.9.2/PKG-INFO0000644000076500000240000001547512714635166014114 0ustar userstaff00000000000000Metadata-Version: 1.1 Name: retry Version: 0.9.2 Summary: Easy to use retry decorator. Home-page: https://github.com/invl/retry Author: invl Author-email: invlpg@gmail.com License: Apache License 2.0 Description: retry ===== .. image:: https://pypip.in/d/retry/badge.png :target: https://pypi.python.org/pypi/retry/ .. image:: https://pypip.in/v/retry/badge.png :target: https://pypi.python.org/pypi/retry/ .. image:: https://pypip.in/license/retry/badge.png :target: https://pypi.python.org/pypi/retry/ Easy to use retry decorator. Features -------- - No external dependency (stdlib only). - (Optionally) Preserve function signatures (`pip install decorator`). - Original traceback, easy to debug. Installation ------------ .. code-block:: bash $ pip install retry API --- retry decorator ^^^^^^^^^^^^^^^ .. code:: python def retry(exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """Return a retry decorator. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. """ Various retrying logic can be achieved by combination of arguments. Examples """""""" .. code:: python from retry import retry .. code:: python @retry() def make_trouble(): '''Retry until succeed''' .. code:: python @retry(ZeroDivisionError, tries=3, delay=2) def make_trouble(): '''Retry on ZeroDivisionError, raise error after 3 attempts, sleep 2 seconds between attempts.''' .. code:: python @retry((ValueError, TypeError), delay=1, backoff=2) def make_trouble(): '''Retry on ValueError or TypeError, sleep 1, 2, 4, 8, ... seconds between attempts.''' .. code:: python @retry((ValueError, TypeError), delay=1, backoff=2, max_delay=4) def make_trouble(): '''Retry on ValueError or TypeError, sleep 1, 2, 4, 4, ... seconds between attempts.''' .. code:: python @retry(ValueError, delay=1, jitter=1) def make_trouble(): '''Retry on ValueError, sleep 1, 2, 3, 4, ... seconds between attempts.''' .. code:: python # If you enable logging, you can get warnings like 'ValueError, retrying in # 1 seconds' if __name__ == '__main__': import logging logging.basicConfig() make_trouble() retry_call ^^^^^^^^^^ .. code:: python def retry_call(f, fargs=None, fkwargs=None, exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """ Calls a function and re-executes it if it failed. :param f: the function to execute. :param fargs: the positional arguments of the function to execute. :param fkwargs: the named arguments of the function to execute. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. :returns: the result of the f function. """ This is very similar to the decorator, except that it takes a function and its arguments as parameters. The use case behind it is to be able to dynamically adjust the retry arguments. .. code:: python import requests from retry.api import retry_call def make_trouble(service, info=None): if not info: info = '' r = requests.get(service + info) return r.text def what_is_my_ip(approach=None): if approach == "optimistic": tries = 1 elif approach == "conservative": tries = 3 else: # skeptical tries = -1 result = retry_call(make_trouble, fargs=["http://ipinfo.io/"], fkwargs={"info": "ip"}, tries=tries) print(result) what_is_my_ip("conservative") Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Apache Software License Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development retry-0.9.2/README.rst0000600000076500000240000001143212517055645014462 0ustar userstaff00000000000000retry ===== .. image:: https://pypip.in/d/retry/badge.png :target: https://pypi.python.org/pypi/retry/ .. image:: https://pypip.in/v/retry/badge.png :target: https://pypi.python.org/pypi/retry/ .. image:: https://pypip.in/license/retry/badge.png :target: https://pypi.python.org/pypi/retry/ Easy to use retry decorator. Features -------- - No external dependency (stdlib only). - (Optionally) Preserve function signatures (`pip install decorator`). - Original traceback, easy to debug. Installation ------------ .. code-block:: bash $ pip install retry API --- retry decorator ^^^^^^^^^^^^^^^ .. code:: python def retry(exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """Return a retry decorator. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. """ Various retrying logic can be achieved by combination of arguments. Examples """""""" .. code:: python from retry import retry .. code:: python @retry() def make_trouble(): '''Retry until succeed''' .. code:: python @retry(ZeroDivisionError, tries=3, delay=2) def make_trouble(): '''Retry on ZeroDivisionError, raise error after 3 attempts, sleep 2 seconds between attempts.''' .. code:: python @retry((ValueError, TypeError), delay=1, backoff=2) def make_trouble(): '''Retry on ValueError or TypeError, sleep 1, 2, 4, 8, ... seconds between attempts.''' .. code:: python @retry((ValueError, TypeError), delay=1, backoff=2, max_delay=4) def make_trouble(): '''Retry on ValueError or TypeError, sleep 1, 2, 4, 4, ... seconds between attempts.''' .. code:: python @retry(ValueError, delay=1, jitter=1) def make_trouble(): '''Retry on ValueError, sleep 1, 2, 3, 4, ... seconds between attempts.''' .. code:: python # If you enable logging, you can get warnings like 'ValueError, retrying in # 1 seconds' if __name__ == '__main__': import logging logging.basicConfig() make_trouble() retry_call ^^^^^^^^^^ .. code:: python def retry_call(f, fargs=None, fkwargs=None, exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """ Calls a function and re-executes it if it failed. :param f: the function to execute. :param fargs: the positional arguments of the function to execute. :param fkwargs: the named arguments of the function to execute. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. :returns: the result of the f function. """ This is very similar to the decorator, except that it takes a function and its arguments as parameters. The use case behind it is to be able to dynamically adjust the retry arguments. .. code:: python import requests from retry.api import retry_call def make_trouble(service, info=None): if not info: info = '' r = requests.get(service + info) return r.text def what_is_my_ip(approach=None): if approach == "optimistic": tries = 1 elif approach == "conservative": tries = 3 else: # skeptical tries = -1 result = retry_call(make_trouble, fargs=["http://ipinfo.io/"], fkwargs={"info": "ip"}, tries=tries) print(result) what_is_my_ip("conservative") retry-0.9.2/requirements.txt0000644000076500000240000000004312714631222016251 0ustar userstaff00000000000000decorator>=3.4.2 py>=1.4.26,<2.0.0 retry-0.9.2/retry/0000755000076500000240000000000012714635166014150 5ustar userstaff00000000000000retry-0.9.2/retry/__init__.py0000600000076500000240000000055112457403772016252 0ustar userstaff00000000000000__all__ = ['retry'] import logging from .api import retry # Set default logging handler to avoid "No handler found" warnings. try: # Python 2.7+ from logging import NullHandler except ImportError: class NullHandler(logging.Handler): def emit(self, record): pass log = logging.getLogger(__name__) log.addHandler(NullHandler()) retry-0.9.2/retry/api.py0000600000076500000240000001044712517055645015270 0ustar userstaff00000000000000import logging import random import time from functools import partial from retry.compat import decorator logging_logger = logging.getLogger(__name__) def __retry_internal(f, exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """ Executes a function and retries it if it failed. :param f: the function to execute. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. :returns: the result of the f function. """ _tries, _delay = tries, delay while _tries: try: return f() except exceptions as e: _tries -= 1 if not _tries: raise if logger is not None: logger.warning('%s, retrying in %s seconds...', e, _delay) time.sleep(_delay) _delay *= backoff if isinstance(jitter, tuple): _delay += random.uniform(*jitter) else: _delay += jitter if max_delay is not None: _delay = min(_delay, max_delay) def retry(exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """Returns a retry decorator. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. :returns: a retry decorator. """ @decorator def retry_decorator(f, *fargs, **fkwargs): args = fargs if fargs else list() kwargs = fkwargs if fkwargs else dict() return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter, logger) return retry_decorator def retry_call(f, fargs=None, fkwargs=None, exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """ Calls a function and re-executes it if it failed. :param f: the function to execute. :param fargs: the positional arguments of the function to execute. :param fkwargs: the named arguments of the function to execute. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. :returns: the result of the f function. """ args = fargs if fargs else list() kwargs = fkwargs if fkwargs else dict() return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter, logger) retry-0.9.2/retry/compat.py0000600000076500000240000000073512500144244015763 0ustar userstaff00000000000000import functools try: from decorator import decorator except ImportError: def decorator(caller): """ Turns caller into a decorator. Unlike decorator module, function signature is not preserved. :param caller: caller(f, *args, **kwargs) """ def decor(f): @functools.wraps(f) def wrapper(*args, **kwargs): return caller(f, *args, **kwargs) return wrapper return decor retry-0.9.2/retry/tests/0000755000076500000240000000000012714635166015312 5ustar userstaff00000000000000retry-0.9.2/retry/tests/__init__.py0000644000076500000240000000000012714632421017400 0ustar userstaff00000000000000retry-0.9.2/retry/tests/test_retry.py0000644000076500000240000000722012714632421020060 0ustar userstaff00000000000000try: from unittest.mock import create_autospec except ImportError: from mock import create_autospec try: from unittest.mock import MagicMock except ImportError: from mock import MagicMock import time import pytest from retry.api import retry_call from retry.api import retry def test_retry(monkeypatch): mock_sleep_time = [0] def mock_sleep(seconds): mock_sleep_time[0] += seconds monkeypatch.setattr(time, 'sleep', mock_sleep) hit = [0] tries = 5 delay = 1 backoff = 2 @retry(tries=tries, delay=delay, backoff=backoff) def f(): hit[0] += 1 1 / 0 with pytest.raises(ZeroDivisionError): f() assert hit[0] == tries assert mock_sleep_time[0] == sum( delay * backoff ** i for i in range(tries - 1)) def test_tries_inf(): hit = [0] target = 10 @retry(tries=float('inf')) def f(): hit[0] += 1 if hit[0] == target: return target else: raise ValueError assert f() == target def test_tries_minus1(): hit = [0] target = 10 @retry(tries=-1) def f(): hit[0] += 1 if hit[0] == target: return target else: raise ValueError assert f() == target def test_max_delay(monkeypatch): mock_sleep_time = [0] def mock_sleep(seconds): mock_sleep_time[0] += seconds monkeypatch.setattr(time, 'sleep', mock_sleep) hit = [0] tries = 5 delay = 1 backoff = 2 max_delay = delay # Never increase delay @retry(tries=tries, delay=delay, max_delay=max_delay, backoff=backoff) def f(): hit[0] += 1 1 / 0 with pytest.raises(ZeroDivisionError): f() assert hit[0] == tries assert mock_sleep_time[0] == delay * (tries - 1) def test_fixed_jitter(monkeypatch): mock_sleep_time = [0] def mock_sleep(seconds): mock_sleep_time[0] += seconds monkeypatch.setattr(time, 'sleep', mock_sleep) hit = [0] tries = 10 jitter = 1 @retry(tries=tries, jitter=jitter) def f(): hit[0] += 1 1 / 0 with pytest.raises(ZeroDivisionError): f() assert hit[0] == tries assert mock_sleep_time[0] == sum(range(tries - 1)) def test_retry_call(): f_mock = MagicMock(side_effect=RuntimeError) tries = 2 try: retry_call(f_mock, exceptions=RuntimeError, tries=tries) except RuntimeError: pass assert f_mock.call_count == tries def test_retry_call_2(): side_effect = [RuntimeError, RuntimeError, 3] f_mock = MagicMock(side_effect=side_effect) tries = 5 result = None try: result = retry_call(f_mock, exceptions=RuntimeError, tries=tries) except RuntimeError: pass assert result == 3 assert f_mock.call_count == len(side_effect) def test_retry_call_with_args(): def f(value=0): if value < 0: return value else: raise RuntimeError return_value = -1 result = None f_mock = MagicMock(spec=f, return_value=return_value) try: result = retry_call(f_mock, fargs=[return_value]) except RuntimeError: pass assert result == return_value assert f_mock.call_count == 1 def test_retry_call_with_kwargs(): def f(value=0): if value < 0: return value else: raise RuntimeError kwargs = {'value': -1} result = None f_mock = MagicMock(spec=f, return_value=kwargs['value']) try: result = retry_call(f_mock, fkwargs=kwargs) except RuntimeError: pass assert result == kwargs['value'] assert f_mock.call_count == 1 retry-0.9.2/retry.egg-info/0000755000076500000240000000000012714635166015642 5ustar userstaff00000000000000retry-0.9.2/retry.egg-info/dependency_links.txt0000600000076500000240000000000112714635166021700 0ustar userstaff00000000000000 retry-0.9.2/retry.egg-info/not-zip-safe0000600000076500000240000000000112517056510020047 0ustar userstaff00000000000000 retry-0.9.2/retry.egg-info/pbr.json0000600000076500000240000000005612714635166017311 0ustar userstaff00000000000000{"is_release": true, "git_version": "00b2e8b"}retry-0.9.2/retry.egg-info/PKG-INFO0000600000076500000240000001547512714635166016743 0ustar userstaff00000000000000Metadata-Version: 1.1 Name: retry Version: 0.9.2 Summary: Easy to use retry decorator. Home-page: https://github.com/invl/retry Author: invl Author-email: invlpg@gmail.com License: Apache License 2.0 Description: retry ===== .. image:: https://pypip.in/d/retry/badge.png :target: https://pypi.python.org/pypi/retry/ .. image:: https://pypip.in/v/retry/badge.png :target: https://pypi.python.org/pypi/retry/ .. image:: https://pypip.in/license/retry/badge.png :target: https://pypi.python.org/pypi/retry/ Easy to use retry decorator. Features -------- - No external dependency (stdlib only). - (Optionally) Preserve function signatures (`pip install decorator`). - Original traceback, easy to debug. Installation ------------ .. code-block:: bash $ pip install retry API --- retry decorator ^^^^^^^^^^^^^^^ .. code:: python def retry(exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """Return a retry decorator. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. """ Various retrying logic can be achieved by combination of arguments. Examples """""""" .. code:: python from retry import retry .. code:: python @retry() def make_trouble(): '''Retry until succeed''' .. code:: python @retry(ZeroDivisionError, tries=3, delay=2) def make_trouble(): '''Retry on ZeroDivisionError, raise error after 3 attempts, sleep 2 seconds between attempts.''' .. code:: python @retry((ValueError, TypeError), delay=1, backoff=2) def make_trouble(): '''Retry on ValueError or TypeError, sleep 1, 2, 4, 8, ... seconds between attempts.''' .. code:: python @retry((ValueError, TypeError), delay=1, backoff=2, max_delay=4) def make_trouble(): '''Retry on ValueError or TypeError, sleep 1, 2, 4, 4, ... seconds between attempts.''' .. code:: python @retry(ValueError, delay=1, jitter=1) def make_trouble(): '''Retry on ValueError, sleep 1, 2, 3, 4, ... seconds between attempts.''' .. code:: python # If you enable logging, you can get warnings like 'ValueError, retrying in # 1 seconds' if __name__ == '__main__': import logging logging.basicConfig() make_trouble() retry_call ^^^^^^^^^^ .. code:: python def retry_call(f, fargs=None, fkwargs=None, exceptions=Exception, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=logging_logger): """ Calls a function and re-executes it if it failed. :param f: the function to execute. :param fargs: the positional arguments of the function to execute. :param fkwargs: the named arguments of the function to execute. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0. fixed if a number, random if a range tuple (min, max) :param logger: logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled. :returns: the result of the f function. """ This is very similar to the decorator, except that it takes a function and its arguments as parameters. The use case behind it is to be able to dynamically adjust the retry arguments. .. code:: python import requests from retry.api import retry_call def make_trouble(service, info=None): if not info: info = '' r = requests.get(service + info) return r.text def what_is_my_ip(approach=None): if approach == "optimistic": tries = 1 elif approach == "conservative": tries = 3 else: # skeptical tries = -1 result = retry_call(make_trouble, fargs=["http://ipinfo.io/"], fkwargs={"info": "ip"}, tries=tries) print(result) what_is_my_ip("conservative") Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Apache Software License Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development retry-0.9.2/retry.egg-info/requires.txt0000600000076500000240000000004312714635166020227 0ustar userstaff00000000000000decorator>=3.4.2 py>=1.4.26,<2.0.0 retry-0.9.2/retry.egg-info/SOURCES.txt0000600000076500000240000000061312714635166017516 0ustar userstaff00000000000000AUTHORS ChangeLog LICENSE README.rst requirements.txt setup.cfg setup.py test-requirements.txt tox.ini retry/__init__.py retry/api.py retry/compat.py retry.egg-info/PKG-INFO retry.egg-info/SOURCES.txt retry.egg-info/dependency_links.txt retry.egg-info/not-zip-safe retry.egg-info/pbr.json retry.egg-info/requires.txt retry.egg-info/top_level.txt retry/tests/__init__.py retry/tests/test_retry.pyretry-0.9.2/retry.egg-info/top_level.txt0000600000076500000240000000000612714635166020360 0ustar userstaff00000000000000retry retry-0.9.2/setup.cfg0000600000076500000240000000144412714635166014617 0ustar userstaff00000000000000[metadata] name = retry version = 0.9.2 author = invl author-email = invlpg@gmail.com summary = Easy to use retry decorator. license = Apache License 2.0 description-file = README.rst home-page = https://github.com/invl/retry requires-python = >=2.6 classifier = Development Status :: 4 - Beta Intended Audience :: Developers License :: OSI Approved :: Apache Software License Natural Language :: English Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 2.6 Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Programming Language :: Python :: 3.4 Programming Language :: Python :: Implementation :: PyPy Topic :: Software Development [wheel] universal = 1 [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 retry-0.9.2/setup.py0000600000076500000240000000022512517055645014503 0ustar userstaff00000000000000from setuptools import find_packages from setuptools import setup setup( packages=find_packages(), pbr=True, setup_requires=['pbr'], ) retry-0.9.2/test-requirements.txt0000600000076500000240000000003212714633711017221 0ustar userstaff00000000000000mock pbr pytest tox wheel retry-0.9.2/tox.ini0000644000076500000240000000116412714633621014312 0ustar userstaff00000000000000# Tox (http://tox.testrun.org/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] envlist = flake8, py26, py27, py34, py35, pypy [flake8] max-line-length = 120 exclude = *.cfg,*.egg,*.ini,*.log,*tests*,*.txt,*.xml,.tox,.venv,AUTHORS,build,ChangeLog,dist,doc,test-requirements.txt,src format = pylint [testenv] commands = py.test deps= -rrequirements.txt -rtest-requirements.txt [testenv:flake8] basepython = python3.4 commands = flake8 deps = flake8