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


Python Response.json_body方法代码示例

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


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

示例1: _advice

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import json_body [as 别名]
def _advice(request):
    referencer = pyramid_urireferencer.get_referencer(request.registry)
    uri = referencer.get_uri(request)
    registery_response = referencer.is_referenced(uri)
    if registery_response.has_references:
        if 'application/json' in request.accept:
            response = Response()
            response.status_code = 409
            response_json = {
                "message": "The uri {0} is still in use by other applications. "
                           "A total of {1} references have been found.".format(uri, registery_response.count),
                "errors": [],
                "registry_response": registery_response.to_json()
            }
            for app_response in registery_response.applications:
                if app_response.has_references:
                    error_string = "{0}: {1} references found, such as {2}" \
                        .format(app_response.uri,
                                app_response.count,
                                ', '.join([i.uri for i in app_response.items]))
                    response_json["errors"].append(error_string)
                response.json_body = response_json
                response.content_type = 'application/json'
            return response
        else:
            raise HTTPConflict(
                detail="Urireferencer: The uri {0} is still in use by other applications. "
                       "A total of {1} references have been found "
                       "in the following applications: {2}".format(uri, registery_response.count,
                                                                   ', '.join([app_response.title for app_response in
                                                                              registery_response.applications
                                                                              if app_response.has_references])))
    elif not registery_response.success:
        if 'application/json' in request.accept:
            response = Response()
            response.status_code = 500
            response_json = {
                "message": "Unable to verify the uri {0} is no longer being used.".format(uri),
                "errors": [],
                "registry_response": registery_response.to_json()
            }
            for app_response in registery_response.applications:
                if not app_response.success:
                    response_json["errors"].append(
                        "{}: Could not verify the uri is no longer being used.".format(app_response.uri))
            response.json_body = response_json
            response.content_type = 'application/json'
            return response
        else:
            log.error("Urireferencer: Unable to verify the uri {0} is no longer being used. "
                      "Could not verify with {1}".format(uri, ', '
                                                         .join(["{0} ({1})".format(app_response.uri,
                                                                                   app_response.service_url)
                                                                for app_response
                                                                in registery_response.applications if
                                                                not app_response.success])))
            raise HTTPInternalServerError(
                detail="Urireferencer: Unable to verify the uri {0} is no longer being used. "
                       "Could not verify with {1}".format(uri, ', '.join([app_response.uri for app_response
                                                                          in registery_response.applications if
                                                                          not app_response.success])))
开发者ID:OnroerendErfgoed,项目名称:pyramid_urireferencer,代码行数:63,代码来源:protected_resources.py


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