• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python retry.Retry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中urllib3.util.retry.Retry的典型用法代码示例。如果您正苦于以下问题:Python Retry类的具体用法?Python Retry怎么用?Python Retry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Retry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_retry_higher_total_loses

 def test_retry_higher_total_loses(self):
     """ A lower connect timeout than the total is honored """
     error = ConnectTimeoutError()
     retry = Retry(connect=2, total=3)
     retry = retry.increment(error=error)
     retry = retry.increment(error=error)
     self.assertRaises(MaxRetryError, retry.increment, error=error)
开发者ID:birm,项目名称:urllib3,代码行数:7,代码来源:test_retry.py


示例2: test_string

 def test_string(self):
     """ Retry string representation looks the way we expect """
     retry = Retry()
     assert str(retry) == 'Retry(total=10, connect=None, read=None, redirect=None, status=None)'
     for _ in range(3):
         retry = retry.increment(method='GET')
     assert str(retry) == 'Retry(total=7, connect=None, read=None, redirect=None, status=None)'
开发者ID:cloudera,项目名称:hue,代码行数:7,代码来源:test_retry.py


示例3: test_retry_higher_total_loses_vs_read

 def test_retry_higher_total_loses_vs_read(self):
     """ A lower read timeout than the total is honored """
     error = ReadTimeoutError(None, "/", "read timed out")
     retry = Retry(read=2, total=3)
     retry = retry.increment(error=error)
     retry = retry.increment(error=error)
     self.assertRaises(MaxRetryError, retry.increment, error=error)
开发者ID:birm,项目名称:urllib3,代码行数:7,代码来源:test_retry.py


示例4: test_string

 def test_string(self):
     """ Retry string representation looks the way we expect """
     retry = Retry()
     self.assertEqual(str(retry), 'Retry(total=10, connect=None, read=None, redirect=None)')
     for _ in range(3):
         retry = retry.increment()
     self.assertEqual(str(retry), 'Retry(total=7, connect=None, read=None, redirect=None)')
开发者ID:birm,项目名称:urllib3,代码行数:7,代码来源:test_retry.py


示例5: test_retry_read_zero

 def test_retry_read_zero(self):
     """ No second chances on read timeouts, by default """
     error = ReadTimeoutError(None, "/", "read timed out")
     retry = Retry(read=0)
     with pytest.raises(MaxRetryError) as e:
         retry.increment(method='GET', error=error)
     assert e.value.reason == error
开发者ID:cloudera,项目名称:hue,代码行数:7,代码来源:test_retry.py


示例6: test_retry_higher_total_loses_vs_read

 def test_retry_higher_total_loses_vs_read(self):
     """ A lower read timeout than the total is honored """
     error = ReadTimeoutError(None, "/", "read timed out")
     retry = Retry(read=2, total=3)
     retry = retry.increment(method='GET', error=error)
     retry = retry.increment(method='GET', error=error)
     with pytest.raises(MaxRetryError):
         retry.increment(method='GET', error=error)
开发者ID:cloudera,项目名称:hue,代码行数:8,代码来源:test_retry.py


示例7: test_status_counter

 def test_status_counter(self):
     resp = HTTPResponse(status=400)
     retry = Retry(status=2)
     retry = retry.increment(response=resp)
     retry = retry.increment(response=resp)
     with pytest.raises(MaxRetryError) as e:
         retry.increment(response=resp)
     assert str(e.value.reason) == ResponseError.SPECIFIC_ERROR.format(status_code=400)
开发者ID:cloudera,项目名称:hue,代码行数:8,代码来源:test_retry.py


示例8: test_retry_both_specified

 def test_retry_both_specified(self):
     """Total can win if it's lower than the connect value"""
     error = ConnectTimeoutError()
     retry = Retry(connect=3, total=2)
     retry = retry.increment(error=error)
     retry = retry.increment(error=error)
     with pytest.raises(MaxRetryError) as e:
         retry.increment(error=error)
     assert e.value.reason == error
开发者ID:cloudera,项目名称:hue,代码行数:9,代码来源:test_retry.py


示例9: test_retry_read_zero

 def test_retry_read_zero(self):
     """ No second chances on read timeouts, by default """
     error = ReadTimeoutError(None, "/", "read timed out")
     retry = Retry(read=0)
     try:
         retry.increment(error=error)
         self.fail("Failed to raise error.")
     except MaxRetryError as e:
         self.assertEqual(e.reason, error)
开发者ID:birm,项目名称:urllib3,代码行数:9,代码来源:test_retry.py


示例10: test_retry_both_specified

 def test_retry_both_specified(self):
     """Total can win if it's lower than the connect value"""
     error = ConnectTimeoutError()
     retry = Retry(connect=3, total=2)
     retry = retry.increment(error=error)
     retry = retry.increment(error=error)
     try:
         retry.increment(error=error)
         self.fail("Failed to raise error.")
     except MaxRetryError as e:
         self.assertEqual(e.reason, error)
开发者ID:birm,项目名称:urllib3,代码行数:11,代码来源:test_retry.py


示例11: test_error_message

    def test_error_message(self):
        retry = Retry(total=0)
        with pytest.raises(MaxRetryError) as e:
            retry = retry.increment(method='GET',
                                    error=ReadTimeoutError(None, "/", "read timed out"))
        assert 'Caused by redirect' not in str(e.value)
        assert str(e.value.reason) == 'None: read timed out'

        retry = Retry(total=1)
        with pytest.raises(MaxRetryError) as e:
            retry = retry.increment('POST', '/')
            retry = retry.increment('POST', '/')
        assert 'Caused by redirect' not in str(e.value)
        assert isinstance(e.value.reason, ResponseError)
        assert str(e.value.reason) == ResponseError.GENERIC_ERROR

        retry = Retry(total=1)
        response = HTTPResponse(status=500)
        with pytest.raises(MaxRetryError) as e:
            retry = retry.increment('POST', '/', response=response)
            retry = retry.increment('POST', '/', response=response)
        assert 'Caused by redirect' not in str(e.value)
        msg = ResponseError.SPECIFIC_ERROR.format(status_code=500)
        assert str(e.value.reason) == msg

        retry = Retry(connect=1)
        with pytest.raises(MaxRetryError) as e:
            retry = retry.increment(error=ConnectTimeoutError('conntimeout'))
            retry = retry.increment(error=ConnectTimeoutError('conntimeout'))
        assert 'Caused by redirect' not in str(e.value)
        assert str(e.value.reason) == 'conntimeout'
开发者ID:cloudera,项目名称:hue,代码行数:31,代码来源:test_retry.py


示例12: test_history

 def test_history(self):
     retry = Retry(total=10)
     self.assertEqual(retry.history, tuple())
     connection_error = ConnectTimeoutError('conntimeout')
     retry = retry.increment('GET', '/test1', None, connection_error)
     self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),))
     read_error = ReadTimeoutError(None, "/test2", "read timed out")
     retry = retry.increment('POST', '/test2', None, read_error)
     self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
                                      RequestHistory('POST', '/test2', read_error, None, None)))
     response = HTTPResponse(status=500)
     retry = retry.increment('GET', '/test3', response, None)
     self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
                                      RequestHistory('POST', '/test2', read_error, None, None),
                                      RequestHistory('GET', '/test3', None, 500, None)))
开发者ID:birm,项目名称:urllib3,代码行数:15,代码来源:test_retry.py


示例13: test_parse_retry_after

    def test_parse_retry_after(self):
        invalid = [
            "-1",
            "+1",
            "1.0",
            six.u("\xb2"),  # \xb2 = ^2
        ]
        retry = Retry()

        for value in invalid:
            self.assertRaises(InvalidHeader, retry.parse_retry_after, value)

        self.assertEqual(retry.parse_retry_after("0"), 0)
        self.assertEqual(retry.parse_retry_after("1000"), 1000)
        self.assertEqual(retry.parse_retry_after("\t42 "), 42)
开发者ID:Lukasa,项目名称:urllib3,代码行数:15,代码来源:test_util.py


示例14: test_status_forcelist

    def test_status_forcelist(self):
        retry = Retry(status_forcelist=xrange(500,600))
        self.assertFalse(retry.is_forced_retry('GET', status_code=200))
        self.assertFalse(retry.is_forced_retry('GET', status_code=400))
        self.assertTrue(retry.is_forced_retry('GET', status_code=500))

        retry = Retry(total=1, status_forcelist=[418])
        self.assertFalse(retry.is_forced_retry('GET', status_code=400))
        self.assertTrue(retry.is_forced_retry('GET', status_code=418))

        # String status codes are not matched.
        retry = Retry(total=1, status_forcelist=['418'])
        self.assertFalse(retry.is_forced_retry('GET', status_code=418))
开发者ID:birm,项目名称:urllib3,代码行数:13,代码来源:test_retry.py


示例15: test_status_forcelist

    def test_status_forcelist(self):
        retry = Retry(status_forcelist=xrange(500, 600))
        assert not retry.is_retry('GET', status_code=200)
        assert not retry.is_retry('GET', status_code=400)
        assert retry.is_retry('GET', status_code=500)

        retry = Retry(total=1, status_forcelist=[418])
        assert not retry.is_retry('GET', status_code=400)
        assert retry.is_retry('GET', status_code=418)

        # String status codes are not matched.
        retry = Retry(total=1, status_forcelist=['418'])
        assert not retry.is_retry('GET', status_code=418)
开发者ID:cloudera,项目名称:hue,代码行数:13,代码来源:test_retry.py


示例16: test_history

    def test_history(self):
        retry = Retry(total=10, method_whitelist=frozenset(['GET', 'POST']))
        assert retry.history == tuple()
        connection_error = ConnectTimeoutError('conntimeout')
        retry = retry.increment('GET', '/test1', None, connection_error)
        history = (RequestHistory('GET', '/test1', connection_error, None, None),)
        assert retry.history == history

        read_error = ReadTimeoutError(None, "/test2", "read timed out")
        retry = retry.increment('POST', '/test2', None, read_error)
        history = (RequestHistory('GET', '/test1', connection_error, None, None),
                   RequestHistory('POST', '/test2', read_error, None, None))
        assert retry.history == history

        response = HTTPResponse(status=500)
        retry = retry.increment('GET', '/test3', response, None)
        history = (RequestHistory('GET', '/test1', connection_error, None, None),
                   RequestHistory('POST', '/test2', read_error, None, None),
                   RequestHistory('GET', '/test3', None, 500, None))
        assert retry.history == history
开发者ID:cloudera,项目名称:hue,代码行数:20,代码来源:test_retry.py


示例17: test_backoff_reset_after_redirect

 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
开发者ID:cloudera,项目名称:hue,代码行数:11,代码来源:test_retry.py


示例18: test_backoff_reset_after_redirect

 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)
开发者ID:birm,项目名称:urllib3,代码行数:11,代码来源:test_retry.py


示例19: test_retry_total_none

    def test_retry_total_none(self):
        """ if Total is none, connect error should take precedence """
        error = ConnectTimeoutError()
        retry = Retry(connect=2, total=None)
        retry = retry.increment(error=error)
        retry = retry.increment(error=error)
        with pytest.raises(MaxRetryError) as e:
            retry.increment(error=error)
        assert e.value.reason == error

        error = ReadTimeoutError(None, "/", "read timed out")
        retry = Retry(connect=2, total=None)
        retry = retry.increment(method='GET', error=error)
        retry = retry.increment(method='GET', error=error)
        retry = retry.increment(method='GET', error=error)
        assert not retry.is_exhausted()
开发者ID:cloudera,项目名称:hue,代码行数:16,代码来源:test_retry.py


示例20: test_status_forcelist

    def test_status_forcelist(self):
        retry = Retry(status_forcelist=xrange(500,600))
        self.assertFalse(retry.is_forced_retry('GET', status_code=200))
        self.assertFalse(retry.is_forced_retry('GET', status_code=400))
        self.assertTrue(retry.is_forced_retry('GET', status_code=500))

        retry = Retry(total=1, status_forcelist=[418])
        self.assertFalse(retry.is_forced_retry('GET', status_code=400))
        self.assertTrue(retry.is_forced_retry('GET', status_code=418))
开发者ID:Eyjafjallajokull,项目名称:urllib3,代码行数:9,代码来源:test_retry.py



注:本文中的urllib3.util.retry.Retry类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ssl_.ssl_wrap_socket函数代码示例发布时间:2022-05-27
下一篇:
Python util.parse_url函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap