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


Python Message.compose_redirect方法代码示例

本文整理汇总了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)
开发者ID:felipebusnello,项目名称:neubot,代码行数:13,代码来源:server.py

示例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)
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:14,代码来源:server.py

示例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)
开发者ID:claudiuperta,项目名称:neubot,代码行数:77,代码来源:server.py


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