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


Python exc.HTTPNotFound方法代码示例

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


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

示例1: __call__

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def __call__(self, req):
        path = os.path.abspath(os.path.join(self.path,
                                            req.path_info.lstrip('/')))
        if os.path.isdir(path) and self.index_page:
            return self.index(req, path)
        if (self.index_page and self.hide_index_with_redirect
            and path.endswith(os.path.sep + self.index_page)):
            new_url = req.path_url.rsplit('/', 1)[0]
            new_url += '/'
            if req.query_string:
                new_url += '?' + req.query_string
            return Response(
                status=301,
                location=new_url)
        if not os.path.isfile(path):
            return exc.HTTPNotFound(comment=path)
        elif not path.startswith(self.path):
            return exc.HTTPForbidden()
        else:
            return self.make_fileapp(path) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:22,代码来源:static.py

示例2: delete

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def delete(self, req, id):
        """Delete a security service."""
        context = req.environ['manila.context']

        LOG.info("Delete security service with id: %s",
                 id, context=context)

        try:
            security_service = db.security_service_get(context, id)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        share_nets = db.share_network_get_all_by_security_service(
            context, id)
        if share_nets:
            msg = _("Cannot delete security service. It is "
                    "assigned to share network(s)")
            raise exc.HTTPForbidden(explanation=msg)
        policy.check_policy(context, RESOURCE_NAME,
                            'delete', security_service)
        db.security_service_delete(context, id)

        return webob.Response(status_int=http_client.ACCEPTED) 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:security_service.py

示例3: _update_share_metadata

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [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

示例4: delete

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def delete(self, req, share_id, id):
        """Deletes an existing metadata."""
        context = req.environ['manila.context']

        metadata = self._get_metadata(context, share_id)

        if id not in metadata:
            msg = _("Metadata item was not found")
            raise exc.HTTPNotFound(explanation=msg)

        try:
            share = self.share_api.get(context, share_id)
            self.share_api.delete_share_metadata(context, share, id)
        except exception.NotFound:
            msg = _('share does not exist')
            raise exc.HTTPNotFound(explanation=msg)
        return webob.Response(status_int=http_client.OK) 
开发者ID:openstack,项目名称:manila,代码行数:19,代码来源:share_metadata.py

示例5: show

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def show(self, req, id):
        """Return data about the requested share server."""
        context = req.environ['manila.context']
        try:
            server = db_api.share_server_get(context, id)
            share_network = db_api.share_network_get(
                context, server.share_network_subnet['share_network_id'])
            server.share_network_id = share_network['id']
            server.project_id = share_network['project_id']
            if share_network['name']:
                server.share_network_name = share_network['name']
            else:
                server.share_network_name = share_network['id']
        except exception.ShareServerNotFound as e:
            raise exc.HTTPNotFound(explanation=e.msg)
        except exception.ShareNetworkNotFound:
            msg = _("Share server %s could not be found. Its associated "
                    "share network does not "
                    "exist.") % server.share_network_subnet['share_network_id']
            raise exc.HTTPNotFound(explanation=msg)
        return self._view_builder.build_share_server(req, server) 
开发者ID:openstack,项目名称:manila,代码行数:23,代码来源:share_servers.py

示例6: delete

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def delete(self, req, id):
        """Delete specified share server."""
        context = req.environ['manila.context']
        try:
            share_server = db_api.share_server_get(context, id)
        except exception.ShareServerNotFound as e:
            raise exc.HTTPNotFound(explanation=e.msg)
        allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE]
        if share_server['status'] not in allowed_statuses:
            data = {
                'status': share_server['status'],
                'allowed_statuses': allowed_statuses,
            }
            msg = _("Share server's actual status is %(status)s, allowed "
                    "statuses for deletion are %(allowed_statuses)s.") % (data)
            raise exc.HTTPForbidden(explanation=msg)
        LOG.debug("Deleting share server with id: %s.", id)
        try:
            self.share_api.delete_share_server(context, share_server)
        except exception.ShareServerInUse as e:
            raise exc.HTTPConflict(explanation=e.msg)
        return webob.Response(status_int=http_client.ACCEPTED) 
开发者ID:openstack,项目名称:manila,代码行数:24,代码来源:share_servers.py

示例7: default

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def default(self, req):
        """Return default volume type."""
        context = req.environ['manila.context']

        try:
            share_type = share_types.get_default_share_type(context)
        except exception.NotFound:
            msg = _("Share type not found")
            raise exc.HTTPNotFound(explanation=msg)

        if not share_type:
            msg = _("Default share type not found")
            raise exc.HTTPNotFound(explanation=msg)

        share_type['id'] = six.text_type(share_type['id'])
        return self._view_builder.show(req, share_type) 
开发者ID:openstack,项目名称:manila,代码行数:18,代码来源:share_types.py

示例8: _delete

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [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

示例9: delete

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [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

示例10: promote

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [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

示例11: resync

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [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

示例12: _show

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def _show(self, req, share_id, export_location_uuid,
              ignore_secondary_replicas=False):
        context = req.environ['manila.context']
        self._verify_share(context, share_id)
        try:
            export_location = db_api.share_export_location_get_by_uuid(
                context, export_location_uuid,
                ignore_secondary_replicas=ignore_secondary_replicas)
        except exception.ExportLocationNotFound:
            msg = _("Export location '%s' not found.") % export_location_uuid
            raise exc.HTTPNotFound(explanation=msg)

        if export_location.is_admin_only and not context.is_admin:
            raise exc.HTTPForbidden()

        return self._view_builder.detail(req, export_location) 
开发者ID:openstack,项目名称:manila,代码行数:18,代码来源:share_export_locations.py

示例13: _remove_security_service

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [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_show_server_not_found

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def test_show_server_not_found(self, share_server_side_effect,
                                   share_net_side_effect):
        self.mock_object(db_api, 'share_server_get',
                         mock.Mock(side_effect=share_server_side_effect))
        request, ctxt = self._prepare_request('/show', use_admin_context=True)
        self.mock_object(db_api, 'share_network_get', mock.Mock(
            side_effect=share_net_side_effect))
        self.assertRaises(
            exc.HTTPNotFound, self.controller.show, request,
            fake_share_server_get_result['share_server']['id'])

        policy.check_policy.assert_called_once_with(
            ctxt, self.resource_name, 'show')
        db_api.share_server_get.assert_called_once_with(
            ctxt, fake_share_server_get_result['share_server']['id'])
        if isinstance(share_net_side_effect, exception.ShareNetworkNotFound):
            exp_share_net_id = (fake_share_server_get()
                                .share_network_subnet['share_network_id'])
            db_api.share_network_get.assert_called_once_with(
                ctxt, exp_share_net_id) 
开发者ID:openstack,项目名称:manila,代码行数:22,代码来源:test_share_servers.py

示例15: test_create_invalid_share_id

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotFound [as 别名]
def test_create_invalid_share_id(self):
        body = {
            'share_replica': {
                'share_id': 'FAKE_SHAREID',
                'availability_zone': 'FAKE_AZ'
            }
        }
        mock__view_builder_call = self.mock_object(
            share_replicas.replication_view.ReplicationViewBuilder,
            'detail_list')
        self.mock_object(share_replicas.db, 'share_get',
                         mock.Mock(side_effect=exception.NotFound))

        self.assertRaises(exc.HTTPNotFound,
                          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,代码行数:21,代码来源:test_share_replicas.py


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