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


Python client.ACCEPTED属性代码示例

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


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

示例1: add

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def add(self):
        try:
            params = self._prepare_request()
        except Exception:
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            vif = self.plugin.add(params)
            data = jsonutils.dumps(vif.obj_to_primitive())
        except exception.ResourceNotReady:
            LOG.error('Error when processing addNetwork request')
            return '', httplib.GATEWAY_TIMEOUT, self.headers
        except Exception:
            LOG.exception('Error when processing addNetwork request. CNI '
                          'Params: %s', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers

        return data, httplib.ACCEPTED, self.headers 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:service.py

示例2: add

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def add(self):
        try:
            params = self._prepare_request()
        except Exception:
            self._check_failure()
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            vif = self.plugin.add(params)
            data = jsonutils.dumps(vif.obj_to_primitive())
        except exceptions.ResourceNotReady:
            self._check_failure()
            LOG.error('Error when processing addNetwork request')
            return '', httplib.GATEWAY_TIMEOUT, self.headers
        except Exception:
            self._check_failure()
            LOG.exception('Error when processing addNetwork request. CNI '
                          'Params: %s', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers

        return data, httplib.ACCEPTED, self.headers 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:24,代码来源:service.py

示例3: test_delete_v2

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def test_delete_v2(self):
        """What happens if the server returns an HTTP ACCEPTED status code?"""
        response = mock.Mock()
        response.status_code = http_client.ACCEPTED
        response.json.return_value = {'id': gen_integer()}
        with mock.patch.object(
            entity_mixins.EntityDeleteMixin,
            'delete_raw',
            return_value=response,
        ) as delete_raw:
            with mock.patch.object(entity_mixins, '_poll_task') as poll_task:
                self.entity.delete()
        self.assertEqual(delete_raw.call_count, 1)
        self.assertEqual(poll_task.call_count, 1)
        self.assertEqual(
            poll_task.call_args[0],  # a tuple of (positional, keyword) args
            (response.json.return_value['id'], self.entity._server_config)
        ) 
开发者ID:SatelliteQE,项目名称:nailgun,代码行数:20,代码来源:test_entity_mixins.py

示例4: test_accepted_v1

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def test_accepted_v1(self):
        """Give the response an HTTP "ACCEPTED" status code.

        Call ``_handle_response`` twice:

        * Do not pass the ``synchronous`` argument.
        * Pass ``synchronous=False``.

        """
        response = mock.Mock()
        response.status_code = ACCEPTED
        response.headers = {'content-type': 'application/json'}
        for args in [response, 'foo'], [response, 'foo', False]:
            self.assertEqual(
                entities._handle_response(*args),
                response.json.return_value,
            )
            self.assertEqual(
                response.mock_calls,
                [mock.call.raise_for_status(), mock.call.json()],
            )
            response.reset_mock() 
开发者ID:SatelliteQE,项目名称:nailgun,代码行数:24,代码来源:test_entities.py

示例5: _add

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def _add(self, params):
        resp = self._make_request('addNetwork', params, httplib.ACCEPTED)
        vif = base.VersionedObject.obj_from_primitive(resp.json())
        return self._vif_data(vif, params) 
开发者ID:openstack,项目名称:zun,代码行数:6,代码来源:api.py

示例6: test_accepted_v2

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def test_accepted_v2(self):
        """Give the response an HTTP "ACCEPTED" status code.

        Pass ``synchronous=True`` as an argument.

        """
        response = mock.Mock()
        response.status_code = ACCEPTED
        response.json.return_value = {'id': gen_integer()}
        with mock.patch.object(entities, 'ForemanTask') as foreman_task:
            self.assertEqual(
                foreman_task.return_value.poll.return_value,
                entities._handle_response(response, 'foo', True),
            ) 
开发者ID:SatelliteQE,项目名称:nailgun,代码行数:16,代码来源:test_entities.py

示例7: delete

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def delete(self, synchronous=True):
        """Delete the current entity.

        Call :meth:`delete_raw` and check for an HTTP 4XX or 5XX response.
        Return either the JSON-decoded response or information about a
        completed foreman task.

        :param synchronous: A boolean. What should happen if the server returns
            an HTTP 202 (accepted) status code? Wait for the task to complete
            if ``True``. Immediately return a response otherwise.
        :returns: A dict. Either the JSON-decoded response or information about
            a foreman task.
        :raises: ``requests.exceptions.HTTPError`` if the response has an HTTP
            4XX or 5XX status code.
        :raises: ``ValueError`` If an HTTP 202 response is received and the
            response JSON can not be decoded.
        :raises nailgun.entity_mixins.TaskTimedOutError: If an HTTP 202
            response is received, ``synchronous is True`` and the task times
            out.

        """

        response = self.delete_raw()
        response.raise_for_status()

        if (synchronous is True and
                response.status_code == http_client.ACCEPTED):
            return _poll_task(response.json()['id'], self._server_config)
        elif (response.status_code == http_client.NO_CONTENT or
              (response.status_code == http_client.OK and
               hasattr(response, 'content') and
               not response.content.strip())):
            # "The server successfully processed the request, but is not
            # returning any content. Usually used as a response to a successful
            # delete request."
            return
        return response.json() 
开发者ID:SatelliteQE,项目名称:nailgun,代码行数:39,代码来源:entity_mixins.py

示例8: test_blocking_no_location_header

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import ACCEPTED [as 别名]
def test_blocking_no_location_header(self):
        self.request.return_value.status_code = http_client.ACCEPTED
        self.request.return_value.headers = {'retry-after': 5}
        with self.assertRaisesRegex(exceptions.ConnectionError,
                                    'status 202, but no Location header'):
            self.conn._op('POST', 'http://foo.bar', blocking=True) 
开发者ID:openstack,项目名称:sushy,代码行数:8,代码来源:test_connector.py


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