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


Python Response.status方法代码示例

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


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

示例1: getBadges

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def getBadges(req):
	'''Retrieve a user's badge information'''

	key = db.get(req.matchdict['user'])
	res = Response(status=404)
	if key.exists:

		# generate proper response body
		body = None
		if 'type' not in req.matchdict:
			body = {'badges': key.data['badges']}

		elif req.matchdict['type'] in ['achieved','inprogress','desired']:
			badgeType = 'inProgress' if req.matchdict['type'] == 'inprogress' else req.matchdict['type']
			body = {badgeType: key.data['badges'][badgeType]}

		if body != None:
			hash = util.genETag(body)
			if_none_match = req.headers['If-None-Match'] if 'If-None-Match' in req.headers.keys() else None
			if if_none_match not in ['*',hash]:
				res.status = 200
				res.content_type = 'application/json'
				res.headers['ETag'] = hash
				res.json = body
			else:
				res.status = 304

	return res
开发者ID:adlnet-archive,项目名称:learner-profile-concept,代码行数:30,代码来源:badges.py

示例2: test_json_xsrf

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
    def test_json_xsrf(self):
        def json_response(string_value):
            resp = Response(string_value)
            resp.status = 200
            resp.content_type = 'application/json'
            filter_json_xsrf(resp)

        # a view returning a vulnerable json response should issue a warning
        for value in [
            '["value1", "value2"]',  # json array
            '  \n ["value1", "value2"] ',  # may include whitespace
            '"value"',  # strings may contain nasty characters in UTF-7
            ]:
            resp = Response(value)
            resp.status = 200
            resp.content_type = 'application/json'
            filter_json_xsrf(resp)
            assert len(self.get_logs()) == 1, "Expected warning: %s" % value

        # a view returning safe json response should not issue a warning
        for value in [
            '{"value1": "value2"}',  # json object
            '  \n {"value1": "value2"} ',  # may include whitespace
            'true', 'false', 'null',  # primitives
            '123', '-123', '0.123',  # numbers
            ]:
            resp = Response(value)
            resp.status = 200
            resp.content_type = 'application/json'
            filter_json_xsrf(resp)
            assert len(self.get_logs()) == 0, "Unexpected warning: %s" % value
开发者ID:lrowe,项目名称:cornice,代码行数:33,代码来源:test_validation.py

示例3: test_json_xsrf

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
    def test_json_xsrf(self):
        # a view returning a json list should issue a warning
        resp = Response(json.dumps(('value1', 'value2')))
        resp.status = 200
        resp.content_type = 'application/json'
        filter_json_xsrf(resp)
        self.assertEquals(len(self.get_logs()), 1)

        # json lists can also start end end with spaces
        resp = Response(" ('value1', 'value2') ")
        resp.status = 200
        resp.content_type = 'application/json'
        filter_json_xsrf(resp)
        self.assertEquals(len(self.get_logs()), 1)
开发者ID:Electrosoup,项目名称:cornice,代码行数:16,代码来源:test_validation.py

示例4: httpexception_view

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def httpexception_view(exc, request):
    # This special case exists for the easter egg that appears on the 404
    # response page. We don't generally allow youtube embeds, but we make an
    # except for this one.
    if isinstance(exc, HTTPNotFound):
        request.find_service(name="csp").merge(
            {
                "frame-src": ["https://www.youtube-nocookie.com"],
                "script-src": ["https://www.youtube.com", "https://s.ytimg.com"],
            }
        )
    try:
        # Lightweight version of 404 page for `/simple/`
        if isinstance(exc, HTTPNotFound) and request.path.startswith("/simple/"):
            response = Response(body="404 Not Found", content_type="text/plain")
        else:
            response = render_to_response(
                "{}.html".format(exc.status_code), {}, request=request
            )
    except LookupError:
        # We don't have a customized template for this error, so we'll just let
        # the default happen instead.
        return exc

    # Copy over the important values from our HTTPException to our new response
    # object.
    response.status = exc.status
    response.headers.extend(
        (k, v) for k, v in exc.headers.items() if k not in response.headers
    )

    return response
开发者ID:craig5,项目名称:warehouse,代码行数:34,代码来源:views.py

示例5: response

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
    def response(self, request, error):
        """
            Render an API Response

            Create a Response object, similar to the JSONP renderer
            [TODO: re-factor in to the JSONP renderer]
            Return the Response object with the appropriate error code
        """

        jsonp_render = request.registry._jsonp_render

        default = jsonp_render._make_default(request)
        val = self.serializer(self.envelope(success=False, error=error.error),
                              default=default,
                              **jsonp_render.kw)
        callback = request.GET.get(jsonp_render.param_name)
        response = Response("", status=200)  # API Error code is always 200

        if callback is None:
            ct = 'application/json'
            response.status = error.code
            response.body = val
        else:
            ct = 'application/javascript'
            response.text = '%s(%s)' % (callback, val)

        if response.content_type == response.default_content_type:
            response.content_type = ct
        return response
开发者ID:mattjeffery,项目名称:hairy-octo-bear,代码行数:31,代码来源:wrapper.py

示例6: displayResponse

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def displayResponse(request, openid_response):
    """ Display an OpenID response.
    
    Errors will be displayed directly to the user.

    Successful responses and other protocol-level messages will be sent
    using the proper mechanism (i.e., direct response, redirection, etc.).
    """
    s = getServer(request)

    # Encode the response into something that is renderable.
    try:
        webresponse = s.encodeResponse(openid_response)
    except EncodingError as why:
        # If it couldn't be encoded, display an error.
        text = why.response.encodeToKVForm()
        return render_to_response('templates/endpoint.pt',
                                  dict(main_template=main_template(),
                                       error=text,
                                      ),
                                  request=request)

    # Construct and return a response onbject
    r = Response(body=webresponse.body)
    r.status = webresponse.code #XXX int vs. str?

    for header, value in webresponse.headers.iteritems():
        r.headers[str(header)] = str(value)

    return r
开发者ID:tseaver,项目名称:pyramident,代码行数:32,代码来源:views.py

示例7: modify_event

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def modify_event(request):
    dbase = Dbase()
    if 'event_uid' in request.POST and dbase.get_user_privelege(get_username()) == 1:
        event_uid = request.POST["event_uid"]
        if 'title' in request.POST:
            dbase.modifyEvent(event_uid, name=request.POST['title'])
        if 'location' in request.POST:
            dbase.modifyEvent(event_uid, location=request.POST['location'])
        if 'description' in request.POST:
            dbase.modifyEvent(event_uid, description=request.POST['description'])
        if 'event_start' in request.POST:
            newstart = parse(params["event_start"])
            dbase.modifyEvent(event_uid, event_start=newstart)
        if 'event_end' in request.POST:
            newend = parse(params["event_end"])
            dbase.modifyEvent(event_uid, event_end=newend)
        if 'event_registration_start' in request.POST:
            new_registration_start = parse(params["event_registration_start"])
            dbase.modifyEvent(event_uid, event_registration_start=new_registration_start)
        if 'event_registration_end' in request.POST:
            new_registration_end = parse(params["event_registration_end"])
            dbase.modifyEvent(event_uid, event_registration_end=new_registration_end)
        if 'event_approval_start' in request.POST:
            new_approval_start = parse(params["event_approval_start"])
            dbase.modifyEvent(event_uid, event_approval_start=new_approval_start)
        if 'event_approval_end' in request.POST:
            new_approval_end = parse(params["event_approval_end"])
            dbase.modifyEvent(event_uid, event_approval_end=new_approval_end)
        return Response()
    response = Response()
    response.status = 500
    return response
开发者ID:rlguarino,项目名称:PDP-Front-end,代码行数:34,代码来源:views.py

示例8: maps_by_post

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
 def maps_by_post(self):
     params = self._get_params()
     config = self.validate_config(params)
     res = Response(content_type='image/png')
     res.status = '200 OK'
     res.body = Generator.generateStream(config)
     return res
开发者ID:cedrikv,项目名称:static_map_generator,代码行数:9,代码来源:views.py

示例9: probe_status_view

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def probe_status_view(request):
    response = Response("OK")
    response.content_type = 'text/plain'
    try:
        DBSession.execute('select name from sys.cluster')
    except sqlalchemy.exc.DBAPIError as e:
        response.status = 503
        response.text = 'DBFailure {}'.format(e)
    return response
开发者ID:dobe,项目名称:ep2014tutorial,代码行数:11,代码来源:views.py

示例10: require_https_tween

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
    def require_https_tween(request):
        # If we have an :action URL and we're not using HTTPS, then we want to
        # return a 403 error.
        if request.params.get(":action", None) and request.scheme != "https":
            resp = Response("SSL is required.", status=403, content_type="text/plain")
            resp.status = "403 SSL is required"
            resp.headers["X-Fastly-Error"] = "803"
            return resp

        return handler(request)
开发者ID:dstufft,项目名称:warehouse,代码行数:12,代码来源:config.py

示例11: delete_event

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def delete_event(request):
    dbase = Dbase()
    if 'event_uid' in request.POST:
        event_uid = request.POST["event_uid"]
        if dbase.get_user_privelege(get_username()) == 1:
            dbase.deactivate_event(event_uid)
        return Response()
    response = Response()
    response.status = 500
    return response
开发者ID:rlguarino,项目名称:PDP-Front-end,代码行数:12,代码来源:views.py

示例12: undelete_user

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def undelete_user(request):
    dbase = Dbase()
    if 'user_uid' in request.POST:
        user_uid = request.POST["user_uid"]
        if dbase.get_user_privelege(get_username()) == 1:
            dbase.reactivate_user(user_uid)
        return Response()
    response = Response()
    response.status = 500
    return response
开发者ID:rlguarino,项目名称:PDP-Front-end,代码行数:12,代码来源:views.py

示例13: set_language

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def set_language(request):
    if request.POST:
        local_name = negotiate_locale_name(request)
        resp = Response()
        resp.headers = {'Location': request.referrer}
        resp.status = '302'
        resp.set_cookie('language', local_name)
        return resp
    else:
        return HTTPInternalServerError()
开发者ID:fabiobatalha,项目名称:CouchDB-Web,代码行数:12,代码来源:views.py

示例14: get_event

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def get_event(request):
    dbase = Dbase()
    if 'event_uid' in request.POST:
        event_uid = request.POST["event_uid"]
        if event_uid != '':
            event = dbase.get_event(event_uid)
            return Response(json.dumps(eventToDict(event)))
    response = Response()
    response.status = 500
    return response
开发者ID:rlguarino,项目名称:PDP-Front-end,代码行数:12,代码来源:views.py

示例15: register_user

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status [as 别名]
def register_user(request):
    dbase = Dbase()
    if 'event_uid' in request.POST:
        username = get_username(request)
        if username != '':
            event_uid = request.POST["event_uid"]
            dbase.register_user_for_event(username, event_uid)
            return Response()
    response = Response()
    response.status = 500
    return response
开发者ID:rlguarino,项目名称:PDP-Front-end,代码行数:13,代码来源:views.py


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