本文整理汇总了Python中urllib3.util.retry.Retry.get_backoff_time方法的典型用法代码示例。如果您正苦于以下问题:Python Retry.get_backoff_time方法的具体用法?Python Retry.get_backoff_time怎么用?Python Retry.get_backoff_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.util.retry.Retry
的用法示例。
在下文中一共展示了Retry.get_backoff_time方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_backoff_reset_after_redirect
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import get_backoff_time [as 别名]
def test_backoff_reset_after_redirect(self):
retry = Retry(total=100, redirect=5, backoff_factor=0.2)
retry = retry.increment()
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0.4)
redirect_response = HTTPResponse(status=302, headers={'location': 'test'})
retry = retry.increment(response=redirect_response)
self.assertEqual(retry.get_backoff_time(), 0)
retry = retry.increment()
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0.4)
示例2: test_backoff_reset_after_redirect
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import get_backoff_time [as 别名]
def test_backoff_reset_after_redirect(self):
retry = Retry(total=100, redirect=5, backoff_factor=0.2)
retry = retry.increment(method='GET')
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0.4
redirect_response = HTTPResponse(status=302, headers={'location': 'test'})
retry = retry.increment(method='GET', response=redirect_response)
assert retry.get_backoff_time() == 0
retry = retry.increment(method='GET')
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0.4
示例3: test_backoff
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import get_backoff_time [as 别名]
def test_backoff(self):
""" Backoff is computed correctly """
max_backoff = Retry.BACKOFF_MAX
retry = Retry(total=100, backoff_factor=0.2)
self.assertEqual(retry.get_backoff_time(), 0) # First request
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0) # First retry
retry = retry.increment()
self.assertEqual(retry.backoff_factor, 0.2)
self.assertEqual(retry.total, 98)
self.assertEqual(retry.get_backoff_time(), 0.4) # Start backoff
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0.8)
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 1.6)
for i in xrange(10):
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), max_backoff)
示例4: test_backoff
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import get_backoff_time [as 别名]
def test_backoff(self):
""" Backoff is computed correctly """
max_backoff = Retry.BACKOFF_MAX
retry = Retry(total=100, backoff_factor=0.2)
assert retry.get_backoff_time() == 0 # First request
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0 # First retry
retry = retry.increment(method='GET')
assert retry.backoff_factor == 0.2
assert retry.total == 98
assert retry.get_backoff_time() == 0.4 # Start backoff
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0.8
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 1.6
for _ in xrange(10):
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == max_backoff
示例5: test_zero_backoff
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import get_backoff_time [as 别名]
def test_zero_backoff(self):
retry = Retry()
self.assertEqual(retry.get_backoff_time(), 0)
retry = retry.increment()
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0)
示例6: test_zero_backoff
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import get_backoff_time [as 别名]
def test_zero_backoff(self):
retry = Retry()
assert retry.get_backoff_time() == 0
retry = retry.increment(method='GET')
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0