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

Python utils.to_json函数代码示例

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

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



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

示例1: on_get

    def on_get(self, req, resp, project_id, queue_name, claim_id):
        LOG.debug(
            u"Claim item GET - claim: %(claim_id)s, " u"queue: %(queue_name)s, project: %(project_id)s",
            {"queue_name": queue_name, "project_id": project_id, "claim_id": claim_id},
        )
        try:
            meta, msgs = self.claim_controller.get(queue_name, claim_id=claim_id, project=project_id)

            # Buffer claimed messages
            # TODO(kgriffs): Optimize along with serialization (see below)
            meta["messages"] = list(msgs)

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()
        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Claim could not be queried.")
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Serialize claimed messages
        # TODO(kgriffs): Optimize
        for msg in meta["messages"]:
            msg["href"] = _msg_uri_from_claim(req.path.rsplit("/", 2)[0], msg["id"], meta["id"])
            del msg["id"]

        meta["href"] = req.path
        del meta["id"]

        resp.content_location = req.relative_uri
        resp.body = utils.to_json(meta)
开发者ID:mramu111,项目名称:marconi,代码行数:31,代码来源:claims.py


示例2: on_get

    def on_get(self, req, resp, project_id, queue_name):
        try:
            resp_dict = self.queue_ctrl.stats(queue_name,
                                              project=project_id)

            message_stats = resp_dict['messages']

            if message_stats['total'] != 0:
                base_path = req.path[:req.path.rindex('/')] + '/messages/'

                newest = message_stats['newest']
                newest['href'] = base_path + newest['id']
                del newest['id']

                oldest = message_stats['oldest']
                oldest['href'] = base_path + oldest['id']
                del oldest['id']

            resp.content_location = req.path
            resp.body = utils.to_json(resp_dict)
            # status defaults to 200

        except storage_errors.DoesNotExist:
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Queue stats could not be read.')
            raise wsgi_errors.HTTPServiceUnavailable(description)
开发者ID:AndreMouche,项目名称:marconi,代码行数:29,代码来源:stats.py


示例3: on_get

    def on_get(self, request, response, project_id):
        """Returns a pool listing as objects embedded in an array:

        [
            {"href": "", "weight": 100, "uri": ""},
            ...
        ]

        :returns: HTTP | [200, 204]
        """
        LOG.debug(u'LIST pools')

        store = {}
        request.get_param('marker', store=store)
        request.get_param_as_int('limit', store=store)
        request.get_param_as_bool('detailed', store=store)

        results = {}
        results['pools'] = list(self._ctrl.list(**store))
        for entry in results['pools']:
            entry['href'] = request.path + '/' + entry.pop('name')

        if not results['pools']:
            response.status = falcon.HTTP_204
            return

        response.content_location = request.relative_uri
        response.body = transport_utils.to_json(results)
        response.status = falcon.HTTP_200
开发者ID:PrashanthRaghu,项目名称:marconi-redis,代码行数:29,代码来源:pools.py


示例4: on_get

    def on_get(self, req, resp, project_id, queue_name, message_id):
        LOG.debug(_(u'Messages item GET - message: %(message)s, '
                    u'queue: %(queue)s, project: %(project)s'),
                  {'message': message_id,
                   'queue': queue_name,
                   'project': project_id})
        try:
            message = self.message_controller.get(
                queue_name,
                message_id,
                project=project_id)

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Message could not be retrieved.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Prepare response
        message['href'] = req.path
        del message['id']

        resp.content_location = req.relative_uri
        resp.body = utils.to_json(message)
开发者ID:docstack,项目名称:marconi,代码行数:27,代码来源:messages.py


示例5: on_get

    def on_get(self, req, resp, project_id, queue_name, claim_id):
        LOG.debug(_(u'Claim item GET - claim: %(claim_id)s, '
                    u'queue: %(queue_name)s, project: %(project_id)s') %
                  {'queue_name': queue_name,
                   'project_id': project_id,
                   'claim_id': claim_id})
        try:
            meta, msgs = self.claim_controller.get(
                queue_name,
                claim_id=claim_id,
                project=project_id)

            # Buffer claimed messages
            # TODO(kgriffs): Optimize along with serialization (see below)
            meta['messages'] = list(msgs)

        except storage_exceptions.DoesNotExist:
            raise falcon.HTTPNotFound()
        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Claim could not be queried.')
            raise wsgi_exceptions.HTTPServiceUnavailable(description)

        # Serialize claimed messages
        # TODO(kgriffs): Optimize
        for msg in meta['messages']:
            msg['href'] = _msg_uri_from_claim(
                req.path.rsplit('/', 2)[0], msg['id'], meta['id'])
            del msg['id']

        meta['href'] = req.path
        del meta['id']

        resp.content_location = req.relative_uri
        resp.body = utils.to_json(meta)
开发者ID:chadlung,项目名称:marconi,代码行数:35,代码来源:claims.py


示例6: on_post

    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(_(u'Claims collection POST - queue: %(queue)s, '
                    u'project: %(project)s'),
                  {'queue': queue_name, 'project': project_id})

        # Check for an explicit limit on the # of messages to claim
        limit = req.get_param_as_int('limit')
        claim_options = {} if limit is None else {'limit': limit}

        # Place JSON size restriction before parsing
        if req.content_length > self._metadata_max_length:
            description = _(u'Claim metadata size is too large.')
            raise wsgi_errors.HTTPBadRequestBody(description)

        # Read claim metadata (e.g., TTL) and raise appropriate
        # HTTP errors as needed.
        metadata, = wsgi_utils.filter_stream(req.stream, req.content_length,
                                             CLAIM_POST_SPEC)

        # Claim some messages
        try:
            self._validate.claim_creation(metadata, **claim_options)
            cid, msgs = self.claim_controller.create(
                queue_name,
                metadata=metadata,
                project=project_id,
                **claim_options)

            # Buffer claimed messages
            # TODO(kgriffs): optimize, along with serialization (below)
            resp_msgs = list(msgs)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Claim could not be created.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Serialize claimed messages, if any. This logic assumes
        # the storage driver returned well-formed messages.
        if len(resp_msgs) != 0:
            for msg in resp_msgs:
                msg['href'] = _msg_uri_from_claim(
                    req.path.rpartition('/')[0], msg['id'], cid)

                del msg['id']

            resp.location = req.path + '/' + cid
            resp.body = utils.to_json(resp_msgs)
            resp.status = falcon.HTTP_201
        else:
            resp.status = falcon.HTTP_204
开发者ID:Sookyung,项目名称:marconi,代码行数:55,代码来源:claims.py


示例7: on_get

    def on_get(self, req, resp, project_id):
        LOG.debug(u'Queue collection GET - project: %(project)s',
                  {'project': project_id})

        kwargs = {}

        # NOTE(kgriffs): This syntax ensures that
        # we don't clobber default values with None.
        req.get_param('marker', store=kwargs)
        req.get_param_as_int('limit', store=kwargs)
        req.get_param_as_bool('detailed', store=kwargs)

        try:
            self._validate.queue_listing(**kwargs)
            results = self.queue_controller.list(project=project_id, **kwargs)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Queues could not be listed.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Buffer list of queues
        queues = list(next(results))

        # Check for an empty list
        if len(queues) == 0:
            resp.status = falcon.HTTP_204
            return

        # Got some. Prepare the response.
        kwargs['marker'] = next(results)
        for each_queue in queues:
            each_queue['href'] = req.path + '/' + each_queue['name']

        response_body = {
            'queues': queues,
            'links': [
                {
                    'rel': 'next',
                    'href': req.path + falcon.to_query_str(kwargs)
                }
            ]
        }

        resp.content_location = req.relative_uri
        resp.body = utils.to_json(response_body)
开发者ID:PrashanthRaghu,项目名称:marconi-redis,代码行数:50,代码来源:queues.py


示例8: on_post

    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(
            u"Claims collection POST - queue: %(queue)s, " u"project: %(project)s",
            {"queue": queue_name, "project": project_id},
        )

        # Check for an explicit limit on the # of messages to claim
        limit = req.get_param_as_int("limit")
        claim_options = {} if limit is None else {"limit": limit}

        # Read claim metadata (e.g., TTL) and raise appropriate
        # HTTP errors as needed.
        metadata, = wsgi_utils.filter_stream(req.stream, req.content_length, CLAIM_POST_SPEC)

        # Claim some messages
        try:
            self._validate.claim_creation(metadata, limit=limit)
            cid, msgs = self.claim_controller.create(queue_name, metadata=metadata, project=project_id, **claim_options)

            # Buffer claimed messages
            # TODO(kgriffs): optimize, along with serialization (below)
            resp_msgs = list(msgs)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Claim could not be created.")
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Serialize claimed messages, if any. This logic assumes
        # the storage driver returned well-formed messages.
        if len(resp_msgs) != 0:
            for msg in resp_msgs:
                msg["href"] = _msg_uri_from_claim(req.path.rpartition("/")[0], msg["id"], cid)

                del msg["id"]

            resp.location = req.path + "/" + cid
            resp.body = utils.to_json(resp_msgs)
            resp.status = falcon.HTTP_201
        else:
            resp.status = falcon.HTTP_204
开发者ID:mramu111,项目名称:marconi,代码行数:45,代码来源:claims.py


示例9: on_get

    def on_get(self, req, resp, project_id, queue_name):
        LOG.debug(_(u'Queue metadata GET - queue: %(queue)s, '
                    u'project: %(project)s'),
                  {'queue': queue_name, 'project': project_id})

        try:
            resp_dict = self.queue_ctrl.get_metadata(queue_name,
                                                     project=project_id)

        except storage_exceptions.DoesNotExist:
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Queue metadata could not be retrieved.')
            raise wsgi_exceptions.HTTPServiceUnavailable(description)

        resp.content_location = req.path
        resp.body = utils.to_json(resp_dict)
开发者ID:joshbrand,项目名称:marconi,代码行数:19,代码来源:metadata.py


示例10: on_get

    def on_get(self, request, response):
        """Returns a partition listing as a JSON object:

        [
            {"name": "", "weight": 100, "location": ""},
            ...
        ]

        :returns: HTTP | [200, 204]
        """
        LOG.debug(u'LIST shards')
        resp = list(self._ctrl.list())

        if not resp:
            response.status = falcon.HTTP_204
            return

        response.body = transport_utils.to_json(resp)
        response.status = falcon.HTTP_200
开发者ID:larsbutler,项目名称:marconi,代码行数:19,代码来源:shards.py


示例11: on_get

    def on_get(self, req, resp, project_id, queue_name):
        LOG.debug(
            _(u"Messages collection GET - queue: %(queue)s, " u"project: %(project)s"),
            {"queue": queue_name, "project": project_id},
        )

        resp.content_location = req.relative_uri

        ids = req.get_param_as_list("ids")
        if ids is None:
            response = self._get(req, project_id, queue_name)
        else:
            base_path = req.path + "/messages"
            response = self._get_by_id(base_path, project_id, queue_name, ids)

        if response is None:
            resp.status = falcon.HTTP_204
            return

        resp.body = utils.to_json(response)
开发者ID:joshbrand,项目名称:marconi,代码行数:20,代码来源:messages.py


示例12: on_get

    def on_get(self, req, resp, project_id, queue_name):
        LOG.debug(
            u"Queue metadata GET - queue: %(queue)s, " u"project: %(project)s",
            {"queue": queue_name, "project": project_id},
        )

        try:
            resp_dict = self.queue_ctrl.get_metadata(queue_name, project=project_id)

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Queue metadata could not be retrieved.")
            raise wsgi_errors.HTTPServiceUnavailable(description)

        resp.content_location = req.path
        resp.body = utils.to_json(resp_dict)
开发者ID:mramu111,项目名称:marconi,代码行数:20,代码来源:metadata.py


示例13: _pop_messages

    def _pop_messages(self, queue_name, project_id, pop_limit):
        try:
            LOG.debug(
                u"POP messages - queue: %(queue)s, " u"project: %(project)s",
                {"queue": queue_name, "project": project_id},
            )

            messages = self.message_controller.pop(queue_name, project=project_id, limit=pop_limit)

        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Messages could not be popped.")
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Prepare response
        if not messages:
            messages = []
        body = {"messages": messages}
        body = utils.to_json(body)

        return falcon.HTTP_200, body
开发者ID:peoplemerge,项目名称:marconi,代码行数:21,代码来源:messages.py


示例14: on_get

    def on_get(self, req, resp, project_id, queue_name):
        LOG.debug(u'Messages collection GET - queue: %(queue)s, '
                  u'project: %(project)s',
                  {'queue': queue_name, 'project': project_id})

        resp.content_location = req.relative_uri

        ids = req.get_param_as_list('ids')

        if ids is None:
            response = self._get(req, project_id, queue_name)

        else:
            response = self._get_by_id(req.path, project_id, queue_name, ids)

        if response is None:
            # NOTE(TheSriram): Trying to get a message by id, should
            # return the message if its present, otherwise a 404 since
            # the message might have been deleted.
            resp.status = falcon.HTTP_404

        else:
            resp.body = utils.to_json(response)
开发者ID:PrashanthRaghu,项目名称:marconi-redis,代码行数:23,代码来源:messages.py


示例15: on_post

    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(
            _(u"Messages collection POST - queue:  %(queue)s, " u"project: %(project)s"),
            {"queue": queue_name, "project": project_id},
        )

        client_uuid = wsgi_utils.get_client_uuid(req)

        # Place JSON size restriction before parsing
        if req.content_length > self._wsgi_conf.content_max_length:
            description = _(u"Message collection size is too large.")
            raise wsgi_exceptions.HTTPBadRequestBody(description)

        # Pull out just the fields we care about
        messages = wsgi_utils.filter_stream(
            req.stream, req.content_length, MESSAGE_POST_SPEC, doctype=wsgi_utils.JSONArray
        )

        # Enqueue the messages
        partial = False

        try:
            # No need to check each message's size if it
            # can not exceed the request size limit
            self._validate.message_posting(
                messages,
                check_size=(self._validate._limits_conf.message_size_uplimit < self._wsgi_conf.content_max_length),
            )

            message_ids = self.message_controller.post(
                queue_name, messages=messages, project=project_id, client_uuid=client_uuid
            )

        except validation.ValidationFailed as ex:
            raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex))

        except storage_exceptions.DoesNotExist:
            raise falcon.HTTPNotFound()

        except storage_exceptions.MessageConflict as ex:
            LOG.exception(ex)
            partial = True
            message_ids = ex.succeeded_ids

            if not message_ids:
                # TODO(kgriffs): Include error code that is different
                # from the code used in the generic case, below.
                description = _(u"No messages could be enqueued.")
                raise wsgi_exceptions.HTTPServiceUnavailable(description)

        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Messages could not be enqueued.")
            raise wsgi_exceptions.HTTPServiceUnavailable(description)

        # Prepare the response
        ids_value = ",".join(message_ids)
        resp.location = req.path + "?ids=" + ids_value

        hrefs = [req.path + "/" + id for id in message_ids]
        body = {"resources": hrefs, "partial": partial}
        resp.body = utils.to_json(body)
        resp.status = falcon.HTTP_201
开发者ID:joshbrand,项目名称:marconi,代码行数:63,代码来源:messages.py


示例16: on_post

    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(_(u'Messages collection POST - queue:  %(queue)s, '
                    u'project: %(project)s'),
                  {'queue': queue_name, 'project': project_id})

        client_uuid = wsgi_utils.get_client_uuid(req)

        try:
            # Place JSON size restriction before parsing
            self._validate.message_length(req.content_length)
        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        # Pull out just the fields we care about
        messages = wsgi_utils.filter_stream(
            req.stream,
            req.content_length,
            MESSAGE_POST_SPEC,
            doctype=wsgi_utils.JSONArray)

        # Enqueue the messages
        partial = False

        try:
            self._validate.message_posting(messages)

            message_ids = self.message_controller.post(
                queue_name,
                messages=messages,
                project=project_id,
                client_uuid=client_uuid)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except storage_errors.MessageConflict as ex:
            LOG.exception(ex)
            partial = True
            message_ids = ex.succeeded_ids

            if not message_ids:
                # TODO(kgriffs): Include error code that is different
                # from the code used in the generic case, below.
                description = _(u'No messages could be enqueued.')
                raise wsgi_errors.HTTPServiceUnavailable(description)

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Messages could not be enqueued.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Prepare the response
        ids_value = ','.join(message_ids)
        resp.location = req.path + '?ids=' + ids_value

        hrefs = [req.path + '/' + id for id in message_ids]
        body = {'resources': hrefs, 'partial': partial}
        resp.body = utils.to_json(body)
        resp.status = falcon.HTTP_201
开发者ID:docstack,项目名称:marconi,代码行数:65,代码来源:messages.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tests.expect函数代码示例发布时间:2022-05-27
下一篇:
Python utils.scope_queue_name函数代码示例发布时间: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