本文整理汇总了Python中neubot.http.message.Message.compose_redirect方法的典型用法代码示例。如果您正苦于以下问题:Python Message.compose_redirect方法的具体用法?Python Message.compose_redirect怎么用?Python Message.compose_redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.http.message.Message
的用法示例。
在下文中一共展示了Message.compose_redirect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _api_index
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import compose_redirect [as 别名]
def _api_index(self, stream, request, query):
'''
Redirect either to /index.html or /privacy.html depending on
whether the user has already set privacy permissions or not
'''
response = Message()
if not privacy.allowed_to_run():
response.compose_redirect(stream, '/privacy.html')
else:
response.compose_redirect(stream, '/index.html')
stream.send_response(request, response)
示例2: _api_index
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import compose_redirect [as 别名]
def _api_index(self, stream, request, query):
'''
Redirect either to /index.html or /privacy.html depending on
whether the user has already set privacy permissions or not
'''
response = Message()
if (not utils.intify(CONFIG['privacy.informed']) or
not utils.intify(CONFIG['privacy.can_collect'])):
response.compose_redirect(stream, '/privacy.html')
else:
response.compose_redirect(stream, '/index.html')
stream.send_response(request, response)
示例3: process_request
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import compose_redirect [as 别名]
def process_request(self, stream, request):
''' Process a request and generate the response '''
response = Message()
if not request.uri.startswith("/"):
response.compose(code="403", reason="Forbidden",
body="403 Forbidden")
stream.send_response(request, response)
return
for prefix, child in self.childs.items():
if request.uri.startswith(prefix):
child.process_request(stream, request)
return
rootdir = self.conf.get("http.server.rootdir", "")
if not rootdir:
response.compose(code="403", reason="Forbidden",
body="403 Forbidden")
stream.send_response(request, response)
return
if request.uri == "/":
response.compose_redirect(stream, "/api/index")
stream.send_response(request, response)
return
if '?' in request.uri:
request_uri = request.uri.split('?')[0]
else:
request_uri = request.uri
fullpath = utils_path.append(rootdir, request_uri, True)
if not fullpath:
response.compose(code="403", reason="Forbidden",
body="403 Forbidden")
stream.send_response(request, response)
return
try:
filep = open(fullpath, "rb")
except (IOError, OSError):
logging.error("HTTP: Not Found: %s (WWWDIR: %s)",
fullpath, rootdir)
response.compose(code="404", reason="Not Found",
body="404 Not Found")
stream.send_response(request, response)
return
if self.conf.get("http.server.mime", True):
mimetype, encoding = mimetypes.guess_type(fullpath)
# Do not attempt SSI if the resource is, say, gzipped
if not encoding:
if mimetype == "text/html":
ssi = self.conf.get("http.server.ssi", False)
if ssi:
body = ssi_replace(rootdir, filep)
filep = StringIO.StringIO(body)
#XXX Do we need to enforce the charset?
if mimetype in ("text/html", "application/x-javascript"):
mimetype += "; charset=UTF-8"
else:
response["content-encoding"] = encoding
else:
mimetype = "text/plain"
response.compose(code="200", reason="Ok", body=filep,
mimetype=mimetype)
if request.method == "HEAD":
utils.safe_seek(filep, 0, os.SEEK_END)
stream.send_response(request, response)