本文整理汇总了Python中webob.Response.status_code方法的典型用法代码示例。如果您正苦于以下问题:Python Response.status_code方法的具体用法?Python Response.status_code怎么用?Python Response.status_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.Response
的用法示例。
在下文中一共展示了Response.status_code方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: application
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import status_code [as 别名]
def application(self, environ, start_response):
req_webob = Request(environ)
res_webob = Response()
#addr tuple as glastopf expects it
remote_addr = (req_webob.remote_addr, int(environ["REMOTE_PORT"]))
if "SERVER_NAME" in environ and "SERVER_PORT" in environ:
# we could use socket.gethostbyname to get the ip...
sensor_addr = (environ["SERVER_NAME"], environ["SERVER_PORT"])
else:
sensor_addr = ("", "")
header, body = self.honeypot.handle_request(req_webob.as_text(),
remote_addr, sensor_addr)
header_list = header.splitlines()
try:
# format: http_version status_code description
res_webob.status_code = int(header_list[0].split()[1])
except ValueError:
# ['User-agent: *', 'Disallow:']
# default 200 OK
pass
for h in header_list:
if ":" in h:
h, v = h.split(":", 1)
res_webob.headers[str(h.strip())] = str(v.strip())
# this will adjust content-length header
res_webob.charset = "utf8"
res_webob.text = body.decode("utf-8", "ignore")
#WSGI applications are not allowed to create or modify hop-by-hop headers
self.remove_hop_by_hop_headers(res_webob.headers)
return res_webob(environ, start_response)
示例2: get_login_view
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import status_code [as 别名]
def get_login_view(req):
rsp = Response()
rsp.status_code = 200
rsp.content_type = 'text/html'
kw = {}
if 'username' in req.session:
kw['username'] = req.session['username']
rsp.unicode_body = xhtml.render_page('login', kw)
return rsp
示例3: post_login_view
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import status_code [as 别名]
def post_login_view(req):
rsp = Response()
username = req.POST['username']
password = req.POST['password']
try:
core.auth_user(username, password)
except:
LOGGER.exception('Fail to auth user!')
rsp.status_code = 200
rsp.content_type = 'text/html'
kw = {}
kw['auth_error'] = "Name or password not correct!"
rsp.unicode_body = xhtml.render_page('login', kw)
return rsp
req.session['username'] = username
rsp.status_code = 302
rsp.location = '/home'
return rsp
示例4: get_start_view
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import status_code [as 别名]
def get_start_view(req):
rsp = Response()
rsp.status_code = 200
rsp.content_type = 'text/html'
kw = {'menu':get_menu(),
'order_list':get_order_list(),
'today':datetime.date.today().isoformat()
}
if 'username' in req.session:
kw['username'] = req.session['username']
rsp.unicode_body = xhtml.render_page('start', kw)
return rsp
示例5: __call__
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import status_code [as 别名]
def __call__(self, environ, start_response):
"""Make a simple response for unit test code to trap and validate
against. If this method is executed then the HTTP Basic Auth step in
the upstream middleware has succeeded.
"""
response = Response(charset='utf8',
text=six.u(HTTPNotFound.explanation),
status=HTTPNotFound.code)
if environ['PATH_INFO'] == '/auth':
response.text = six.u('Authenticated!')
response.status_code = 200
start_response(response.status, response.headerlist)
return [response.body]
示例6: _advice
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import status_code [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])))