当前位置: 首页>>代码示例>>Python>>正文


Python http_client.SERVICE_UNAVAILABLE属性代码示例

本文整理汇总了Python中six.moves.http_client.SERVICE_UNAVAILABLE属性的典型用法代码示例。如果您正苦于以下问题:Python http_client.SERVICE_UNAVAILABLE属性的具体用法?Python http_client.SERVICE_UNAVAILABLE怎么用?Python http_client.SERVICE_UNAVAILABLE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在six.moves.http_client的用法示例。


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

示例1: test__process_response_bad_status

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def test__process_response_bad_status(self):
        upload = _upload.UploadBase(SIMPLE_URL)
        _fix_up_virtual(upload)

        # Make sure **not finished** before.
        assert not upload.finished
        status_code = http_client.SERVICE_UNAVAILABLE
        response = _make_response(status_code=status_code)
        with pytest.raises(common.InvalidResponse) as exc_info:
            upload._process_response(response)

        error = exc_info.value
        assert error.response is response
        assert len(error.args) == 4
        assert error.args[1] == status_code
        assert error.args[3] == http_client.OK
        # Make sure **finished** after (even in failure).
        assert upload.finished 
开发者ID:googleapis,项目名称:google-resumable-media-python,代码行数:20,代码来源:test__upload.py

示例2: setUp

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def setUp(self):
        # Sample highly compressible data.
        self.sample_data = b'abc' * 200
        # Stream of the sample data.
        self.sample_stream = six.BytesIO(self.sample_data)
        # Sample url_builder.
        self.url_builder = base_api._UrlBuilder('http://www.uploads.com')
        # Sample request.
        self.request = http_wrapper.Request(
            'http://www.uploads.com',
            headers={'content-type': 'text/plain'})
        # Sample successful response.
        self.response = http_wrapper.Response(
            info={'status': http_client.OK,
                  'location': 'http://www.uploads.com'},
            content='',
            request_url='http://www.uploads.com',)
        # Sample failure response.
        self.fail_response = http_wrapper.Response(
            info={'status': http_client.SERVICE_UNAVAILABLE,
                  'location': 'http://www.uploads.com'},
            content='',
            request_url='http://www.uploads.com',) 
开发者ID:google,项目名称:apitools,代码行数:25,代码来源:transfer_test.py

示例3: leave_swarm

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def leave_swarm(self, force=False):
        """
        Leave a swarm.

        Args:
            force (bool): Leave the swarm even if this node is a manager.
                Default: ``False``

        Returns:
            ``True`` if the request went through.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        """
        url = self._url('/swarm/leave')
        response = self._post(url, params={'force': force})
        # Ignore "this node is not part of a swarm" error
        if force and response.status_code == http_client.NOT_ACCEPTABLE:
            return True
        # FIXME: Temporary workaround for 1.13.0-rc bug
        # https://github.com/docker/docker/issues/29192
        if force and response.status_code == http_client.SERVICE_UNAVAILABLE:
            return True
        self._raise_for_status(response)
        return True 
开发者ID:QData,项目名称:deepWordBug,代码行数:28,代码来源:swarm.py

示例4: test_success_with_retry

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def test_success_with_retry(self, randint_mock, sleep_mock):
        randint_mock.side_effect = [125, 625, 375]

        status_codes = (
            http_client.INTERNAL_SERVER_ERROR,
            http_client.BAD_GATEWAY,
            http_client.SERVICE_UNAVAILABLE,
            http_client.NOT_FOUND,
        )
        responses = [_make_response(status_code) for status_code in status_codes]
        func = mock.Mock(side_effect=responses, spec=[])

        retry_strategy = common.RetryStrategy()
        ret_val = _helpers.wait_and_retry(func, _get_status_code, retry_strategy)

        assert ret_val == responses[-1]
        assert status_codes[-1] not in _helpers.RETRYABLE

        assert func.call_count == 4
        assert func.mock_calls == [mock.call()] * 4

        assert randint_mock.call_count == 3
        assert randint_mock.mock_calls == [mock.call(0, 1000)] * 3

        assert sleep_mock.call_count == 3
        sleep_mock.assert_any_call(1.125)
        sleep_mock.assert_any_call(2.625)
        sleep_mock.assert_any_call(4.375) 
开发者ID:googleapis,项目名称:google-resumable-media-python,代码行数:30,代码来源:test__helpers.py

示例5: test_retry_exceeds_max_cumulative

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def test_retry_exceeds_max_cumulative(self, randint_mock, sleep_mock):
        randint_mock.side_effect = [875, 0, 375, 500, 500, 250, 125]

        status_codes = (
            http_client.SERVICE_UNAVAILABLE,
            http_client.GATEWAY_TIMEOUT,
            common.TOO_MANY_REQUESTS,
            http_client.INTERNAL_SERVER_ERROR,
            http_client.SERVICE_UNAVAILABLE,
            http_client.BAD_GATEWAY,
            http_client.GATEWAY_TIMEOUT,
            common.TOO_MANY_REQUESTS,
        )
        responses = [_make_response(status_code) for status_code in status_codes]
        func = mock.Mock(side_effect=responses, spec=[])

        retry_strategy = common.RetryStrategy(max_cumulative_retry=100.0)
        ret_val = _helpers.wait_and_retry(func, _get_status_code, retry_strategy)

        assert ret_val == responses[-1]
        assert status_codes[-1] in _helpers.RETRYABLE

        assert func.call_count == 8
        assert func.mock_calls == [mock.call()] * 8

        assert randint_mock.call_count == 7
        assert randint_mock.mock_calls == [mock.call(0, 1000)] * 7

        assert sleep_mock.call_count == 7
        sleep_mock.assert_any_call(1.875)
        sleep_mock.assert_any_call(2.0)
        sleep_mock.assert_any_call(4.375)
        sleep_mock.assert_any_call(8.5)
        sleep_mock.assert_any_call(16.5)
        sleep_mock.assert_any_call(32.25)
        sleep_mock.assert_any_call(64.125) 
开发者ID:googleapis,项目名称:google-resumable-media-python,代码行数:38,代码来源:test__helpers.py

示例6: test_create_resumable_upload_session_with_failure

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def test_create_resumable_upload_session_with_failure(self):
        from google.resumable_media import InvalidResponse
        from google.cloud import exceptions

        message = "5-oh-3 woe is me."
        response = self._mock_requests_response(
            status_code=http_client.SERVICE_UNAVAILABLE, headers={}
        )
        side_effect = InvalidResponse(response, message)

        with self.assertRaises(exceptions.ServiceUnavailable) as exc_info:
            self._create_resumable_upload_session_helper(side_effect=side_effect)

        self.assertIn(message, exc_info.exception.message)
        self.assertEqual(exc_info.exception.errors, []) 
开发者ID:googleapis,项目名称:python-storage,代码行数:17,代码来源:test_blob.py

示例7: test_http_interactions

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def test_http_interactions(self, http_503_server):
    """Test interactions with the http server when using hs2-http protocol.
    Check that there is an HttpError exception when the server returns a 503 error."""
    con = connect("localhost", http_503_server.PORT, use_http_transport=True)
    try:
      con.cursor()
      assert False, "Should have got exception"
    except HttpError as e:
      assert str(e) == "HTTP code 503: Service Unavailable"
      assert e.code == http_client.SERVICE_UNAVAILABLE
      assert e.body.decode("utf-8") == "extra text" 
开发者ID:cloudera,项目名称:impyla,代码行数:13,代码来源:test_http_connect.py

示例8: test_retry_on_503

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def test_retry_on_503(self, resp_mock):
        """Test retry for status code that should be retried (e.g. 503)"""
        resp_mock.return_value.status_code = http_client.SERVICE_UNAVAILABLE

        with self.assertRaises(restclient.MaxRequestRetriesError):
            restclient.get('http://foo.com', '/') 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:8,代码来源:restclient_test.py

示例9: http_503_server

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 别名]
def http_503_server():
  class RequestHandler503(SimpleHTTPServer.SimpleHTTPRequestHandler):
    """A custom http handler that checks for duplicate 'Host' headers from the most
    recent http request, and always returns a 503 http code"""

    def do_POST(self):
      # Ensure that only one 'Host' header is contained in the request before responding.
      request_headers = None
      host_hdr_count = 0
      if six.PY2:
        # The unfortunately named self.headers here is an instance of mimetools.Message that
        # contains the request headers.
        request_headers = self.headers.headers
        host_hdr_count = sum([header.startswith('Host:') for header in request_headers])
      if six.PY3:
        # In Python3 self.Headers is an HTTPMessage.
        request_headers = self.headers
        host_hdr_count = sum([header[0] == 'Host' for header in request_headers.items()])
      assert host_hdr_count == 1, "need single 'Host:' header in %s" % request_headers

      # Respond with 503.
      self.send_response(code=http_client.SERVICE_UNAVAILABLE, message="Service Unavailable")
      self.end_headers()
      self.wfile.write("extra text".encode('utf-8'))

  class TestHTTPServer503(object):
    def __init__(self):
      self.HOST = "localhost"
      self.PORT = get_unused_port()
      self.httpd = socketserver.TCPServer((self.HOST, self.PORT), RequestHandler503)

      self.http_server_thread = threading.Thread(target=self.httpd.serve_forever)
      self.http_server_thread.start()

  server = TestHTTPServer503()
  yield server

  # Cleanup after test.
  if server.httpd is not None:
    server.httpd.shutdown()
  if server.http_server_thread is not None:
    server.http_server_thread.join() 
开发者ID:cloudera,项目名称:impyla,代码行数:44,代码来源:test_http_connect.py


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