當前位置: 首頁>>代碼示例>>Python>>正文


Python exc.HTTPBadRequest方法代碼示例

本文整理匯總了Python中webob.exc.HTTPBadRequest方法的典型用法代碼示例。如果您正苦於以下問題:Python exc.HTTPBadRequest方法的具體用法?Python exc.HTTPBadRequest怎麽用?Python exc.HTTPBadRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在webob.exc的用法示例。


在下文中一共展示了exc.HTTPBadRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def update(self, req, share_id, id, body):
        try:
            meta_item = body['meta']
        except (TypeError, KeyError):
            expl = _('Malformed request body')
            raise exc.HTTPBadRequest(explanation=expl)

        if id not in meta_item:
            expl = _('Request body and URI mismatch')
            raise exc.HTTPBadRequest(explanation=expl)

        if len(meta_item) > 1:
            expl = _('Request body contains too many items')
            raise exc.HTTPBadRequest(explanation=expl)

        context = req.environ['manila.context']
        self._update_share_metadata(context,
                                    share_id,
                                    meta_item,
                                    delete=False)

        return {'meta': meta_item} 
開發者ID:openstack,項目名稱:manila,代碼行數:24,代碼來源:share_metadata.py

示例2: _update_share_metadata

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _update_share_metadata(self, context,
                               share_id, metadata,
                               delete=False):
        try:
            share = self.share_api.get(context, share_id)
            return self.share_api.update_share_metadata(context,
                                                        share,
                                                        metadata,
                                                        delete)
        except exception.NotFound:
            msg = _('share does not exist')
            raise exc.HTTPNotFound(explanation=msg)

        except (ValueError, AttributeError):
            msg = _("Malformed request body")
            raise exc.HTTPBadRequest(explanation=msg)

        except exception.InvalidMetadata as error:
            raise exc.HTTPBadRequest(explanation=error.msg)

        except exception.InvalidMetadataSize as error:
            raise exc.HTTPBadRequest(explanation=error.msg) 
開發者ID:openstack,項目名稱:manila,代碼行數:24,代碼來源:share_metadata.py

示例3: _parse_is_public

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _parse_is_public(is_public):
        """Parse is_public into something usable.

        :returns:
            - True: API should list public share group types only
            - False: API should list private share group types only
            - None: API should list both public and private share group types
        """
        if is_public is None:
            # preserve default value of showing only public types
            return True
        elif six.text_type(is_public).lower() == "all":
            return None
        else:
            try:
                return strutils.bool_from_string(is_public, strict=True)
            except ValueError:
                msg = _('Invalid is_public filter [%s]') % is_public
                raise exc.HTTPBadRequest(explanation=msg) 
開發者ID:openstack,項目名稱:manila,代碼行數:21,代碼來源:share_group_types.py

示例4: _parse_is_public

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _parse_is_public(is_public):
        """Parse is_public into something usable.

        * True: API should list public share types only
        * False: API should list private share types only
        * None: API should list both public and private share types
        """
        if is_public is None:
            # preserve default value of showing only public types
            return True
        elif six.text_type(is_public).lower() == "all":
            return None
        else:
            try:
                return strutils.bool_from_string(is_public, strict=True)
            except ValueError:
                msg = _('Invalid is_public filter [%s]') % is_public
                raise exc.HTTPBadRequest(explanation=msg) 
開發者ID:openstack,項目名稱:manila,代碼行數:20,代碼來源:share_types.py

示例5: _delete

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _delete(self, req, id):
        """Deletes an existing share type."""
        context = req.environ['manila.context']

        try:
            share_type = share_types.get_share_type(context, id)
            share_types.destroy(context, share_type['id'])
            self._notify_share_type_info(
                context, 'share_type.delete', share_type)
        except exception.ShareTypeInUse as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.delete',
                                          notifier_err)
            msg = 'Target share type is still in use.'
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as err:
            notifier_err = dict(id=id, error_message=six.text_type(err))
            self._notify_share_type_error(context, 'share_type.delete',
                                          notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=http_client.ACCEPTED) 
開發者ID:openstack,項目名稱:manila,代碼行數:25,代碼來源:share_types.py

示例6: _validate_revert_parameters

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _validate_revert_parameters(self, context, body):
        if not (body and self.is_valid_body(body, 'revert')):
            msg = _("Revert entity not found in request body.")
            raise exc.HTTPBadRequest(explanation=msg)

        required_parameters = ('snapshot_id',)
        data = body['revert']

        for parameter in required_parameters:
            if parameter not in data:
                msg = _("Required parameter %s not found.") % parameter
                raise exc.HTTPBadRequest(explanation=msg)
            if not data.get(parameter):
                msg = _("Required parameter %s is empty.") % parameter
                raise exc.HTTPBadRequest(explanation=msg)

        return data 
開發者ID:openstack,項目名稱:manila,代碼行數:19,代碼來源:shares.py

示例7: delete

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def delete(self, req, id):
        """Delete a replica."""
        context = req.environ['manila.context']

        try:
            replica = db.share_replica_get(context, id)
        except exception.ShareReplicaNotFound:
            msg = _("No replica exists with ID %s.")
            raise exc.HTTPNotFound(explanation=msg % id)

        try:
            self.share_api.delete_share_replica(context, replica)
        except exception.ReplicationException as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e))

        return webob.Response(status_int=http_client.ACCEPTED) 
開發者ID:openstack,項目名稱:manila,代碼行數:18,代碼來源:share_replicas.py

示例8: promote

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def promote(self, req, id, body):
        """Promote a replica to active state."""
        context = req.environ['manila.context']

        try:
            replica = db.share_replica_get(context, id)
        except exception.ShareReplicaNotFound:
            msg = _("No replica exists with ID %s.")
            raise exc.HTTPNotFound(explanation=msg % id)

        replica_state = replica.get('replica_state')

        if replica_state == constants.REPLICA_STATE_ACTIVE:
            return webob.Response(status_int=http_client.OK)

        try:
            replica = self.share_api.promote_share_replica(context, replica)
        except exception.ReplicationException as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e))
        except exception.AdminRequired as e:
            raise exc.HTTPForbidden(explanation=six.text_type(e))

        return self._view_builder.detail(req, replica) 
開發者ID:openstack,項目名稱:manila,代碼行數:25,代碼來源:share_replicas.py

示例9: resync

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def resync(self, req, id, body):
        """Attempt to update/sync the replica with its source."""
        context = req.environ['manila.context']
        try:
            replica = db.share_replica_get(context, id)
        except exception.ShareReplicaNotFound:
            msg = _("No replica exists with ID %s.")
            raise exc.HTTPNotFound(explanation=msg % id)

        replica_state = replica.get('replica_state')

        if replica_state == constants.REPLICA_STATE_ACTIVE:
            return webob.Response(status_int=http_client.OK)

        try:
            self.share_api.update_share_replica(context, replica)
        except exception.InvalidHost as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e)) 
開發者ID:openstack,項目名稱:manila,代碼行數:20,代碼來源:share_replicas.py

示例10: _update_share_group

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _update_share_group(self, req, id, body):
        """Update a share group."""
        context = req.environ['manila.context']

        if not self.is_valid_body(body, 'share_group'):
            msg = _("'share_group' is missing from the request body.")
            raise exc.HTTPBadRequest(explanation=msg)

        share_group_data = body['share_group']
        valid_update_keys = {'name', 'description'}
        invalid_fields = set(share_group_data.keys()) - valid_update_keys
        if invalid_fields:
            msg = _("The fields %s are invalid or not allowed to be updated.")
            raise exc.HTTPBadRequest(explanation=msg % invalid_fields)

        share_group = self._get_share_group(context, id)
        share_group = self.share_group_api.update(
            context, share_group, share_group_data)
        return self._view_builder.detail(req, share_group) 
開發者ID:openstack,項目名稱:manila,代碼行數:21,代碼來源:share_groups.py

示例11: _update_group_snapshot

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _update_group_snapshot(self, req, id, body):
        """Update a share group snapshot."""
        context = req.environ['manila.context']
        key = 'share_group_snapshot'
        if not self.is_valid_body(body, key):
            msg = _("'%s' is missing from the request body.") % key
            raise exc.HTTPBadRequest(explanation=msg)

        sg_snapshot_data = body[key]
        valid_update_keys = {
            'name',
            'description',
        }
        invalid_fields = set(sg_snapshot_data.keys()) - valid_update_keys
        if invalid_fields:
            msg = _("The fields %s are invalid or not allowed to be updated.")
            raise exc.HTTPBadRequest(explanation=msg % invalid_fields)

        sg_snapshot = self._get_share_group_snapshot(context, id)
        sg_snapshot = self.share_group_api.update_share_group_snapshot(
            context, sg_snapshot, sg_snapshot_data)
        return self._view_builder.detail(req, sg_snapshot) 
開發者ID:openstack,項目名稱:manila,代碼行數:24,代碼來源:share_group_snapshots.py

示例12: _manage

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _manage(self, req, body):
        """Manage a share server."""
        LOG.debug("Manage Share Server with id: %s", id)

        context = req.environ['manila.context']
        identifier, host, share_network, driver_opts, network_subnet = (
            self._validate_manage_share_server_parameters(context, body))

        try:
            result = self.share_api.manage_share_server(
                context, identifier, host, network_subnet, driver_opts)
        except exception.InvalidInput as e:
            raise exc.HTTPBadRequest(explanation=e.msg)
        except exception.PolicyNotAuthorized as e:
            raise exc.HTTPForbidden(explanation=e.msg)

        result.project_id = share_network["project_id"]
        result.share_network_id = share_network["id"]
        if share_network['name']:
            result.share_network_name = share_network['name']
        else:
            result.share_network_name = share_network['id']
        return self._view_builder.build_share_server(req, result) 
開發者ID:openstack,項目名稱:manila,代碼行數:25,代碼來源:share_servers.py

示例13: _remove_security_service

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def _remove_security_service(self, req, id, data):
        """Dissociate share network from a given security service."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'remove_security_service')
        share_network = db_api.share_network_get(context, id)

        if self._share_network_subnets_contain_share_servers(share_network):
            msg = _("Cannot remove security services. Share network is used.")
            raise exc.HTTPForbidden(explanation=msg)
        try:
            share_network = db_api.share_network_remove_security_service(
                context,
                id,
                data['security_service_id'])
        except KeyError:
            msg = "Malformed request body"
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))
        except exception.ShareNetworkSecurityServiceDissociationError as e:
            raise exc.HTTPBadRequest(explanation=six.text_type(e))

        return self._view_builder.build_share_network(req, share_network) 
開發者ID:openstack,項目名稱:manila,代碼行數:25,代碼來源:share_networks.py

示例14: test_create_no_share_id

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def test_create_no_share_id(self):
        body = {
            'share_replica': {
                'share_id': None,
                'availability_zone': None,
            }
        }
        mock__view_builder_call = self.mock_object(
            share_replicas.replication_view.ReplicationViewBuilder,
            'detail_list')

        self.assertRaises(exc.HTTPBadRequest,
                          self.controller.create,
                          self.replicas_req, body)
        self.assertFalse(mock__view_builder_call.called)
        self.mock_policy_check.assert_called_once_with(
            self.member_context, self.resource_name, 'create') 
開發者ID:openstack,項目名稱:manila,代碼行數:19,代碼來源:test_share_replicas.py

示例15: test_create_exception_path

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPBadRequest [as 別名]
def test_create_exception_path(self, exception_type):
        fake_replica, _ = self._get_fake_replica(
            replication_type='writable')
        mock__view_builder_call = self.mock_object(
            share_replicas.replication_view.ReplicationViewBuilder,
            'detail_list')
        body = {
            'share_replica': {
                'share_id': 'FAKE_SHAREID',
                'availability_zone': 'FAKE_AZ'
            }
        }
        exc_args = {'id': 'xyz', 'reason': 'abc'}
        self.mock_object(share_replicas.db, 'share_get',
                         mock.Mock(return_value=fake_replica))
        self.mock_object(share.API, 'create_share_replica',
                         mock.Mock(side_effect=exception_type(**exc_args)))

        self.assertRaises(exc.HTTPBadRequest,
                          self.controller.create,
                          self.replicas_req, body)
        self.assertFalse(mock__view_builder_call.called)
        self.mock_policy_check.assert_called_once_with(
            self.member_context, self.resource_name, 'create') 
開發者ID:openstack,項目名稱:manila,代碼行數:26,代碼來源:test_share_replicas.py


注:本文中的webob.exc.HTTPBadRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。