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


Python response.file_stream方法代码示例

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


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

示例1: model_server_app

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def model_server_app(model_path: Text, model_hash: Text = "somehash"):
    app = Sanic(__name__)
    app.number_of_model_requests = 0

    @app.route("/model", methods=['GET'])
    async def model(request):
        """Simple HTTP model server responding with a trained model."""

        if model_hash == request.headers.get("If-None-Match"):
            return response.text("", 204)

        app.number_of_model_requests += 1

        return await response.file_stream(
            location=model_path,
            headers={'ETag': model_hash,
                     'filename': model_path},
            mime_type='application/zip')

    return app 
开发者ID:RasaHQ,项目名称:rasa_core,代码行数:22,代码来源:test_agent.py

示例2: model_server_app

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def model_server_app(model_path: Text, model_hash: Text = "somehash") -> Sanic:
    app = Sanic(__name__)
    app.number_of_model_requests = 0

    @app.route("/model", methods=["GET"])
    async def model(request: Request) -> StreamingHTTPResponse:
        """Simple HTTP model server responding with a trained model."""

        if model_hash == request.headers.get("If-None-Match"):
            return response.text("", 204)

        app.number_of_model_requests += 1

        return await response.file_stream(
            location=model_path,
            headers={"ETag": model_hash, "filename": model_path},
            mime_type="application/gzip",
        )

    return app 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:22,代码来源:test_agent.py

示例3: handler_file_stream

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def handler_file_stream(request):
    return await response.file_stream(
        Path("../") / "setup.py", chunk_size=1024
    ) 
开发者ID:huge-success,项目名称:sanic,代码行数:6,代码来源:run_asgi.py

示例4: test_file_stream

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def test_file_stream(request):
    return await response.file_stream(os.path.abspath("setup.py"),
                                      chunk_size=1024)

# ----------------------------------------------- #
# Exceptions
# ----------------------------------------------- # 
开发者ID:huge-success,项目名称:sanic,代码行数:9,代码来源:try_everything.py

示例5: cb_index_handler

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def cb_index_handler(request, project_uuid=None, host=None):
        return await response.file_stream(os.path.abspath('./public/index.html')) 
开发者ID:c0rvax,项目名称:project-black,代码行数:4,代码来源:static.py

示例6: cb_bundle_handler

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def cb_bundle_handler(request):
        return await response.file_stream(os.path.abspath('./public/bundle.js')) 
开发者ID:c0rvax,项目名称:project-black,代码行数:4,代码来源:static.py

示例7: cb_serve_media_file

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def cb_serve_media_file(request, filename=""):
        return await response.file_stream(os.path.join('./public', os.path.basename(request.path))) 
开发者ID:c0rvax,项目名称:project-black,代码行数:4,代码来源:static.py

示例8: _setup_blueprint_routes

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import file_stream [as 别名]
def _setup_blueprint_routes(self, blueprint: Blueprint, config: Config) -> None:
        """Add routes to the application blueprint"""

        @blueprint.websocket("/stream")  # type: ignore
        async def model_stream(
            request: request.Request, socket: WebSocketCommonProtocol
        ) -> None:
            async def sock_recv() -> LayoutEvent:
                message = json.loads(await socket.recv())
                event = message["body"]["event"]
                return LayoutEvent(event["target"], event["data"])

            async def sock_send(data: Dict[str, Any]) -> None:
                message = {"header": {}, "body": {"render": data}}
                await socket.send(json.dumps(message, separators=(",", ":")))

            param_dict = {k: request.args.get(k) for k in request.args}
            await self._run_renderer(sock_send, sock_recv, param_dict)

        def handler_name(function: Any) -> str:
            return f"{blueprint.name}.{function.__name__}"

        if config["server_static_files"]:

            @blueprint.route("/client/<path:path>")  # type: ignore
            async def client_files(
                request: request.Request, path: str
            ) -> response.HTTPResponse:
                file_extensions = [".html", ".js", ".json"]
                abs_path = find_path(path)
                return (
                    (await response.file_stream(str(abs_path)))
                    if abs_path is not None and abs_path.suffix in file_extensions
                    else response.text(f"Could not find: {path!r}", status=404)
                )

        if config["redirect_root_to_index"]:

            @blueprint.route("/")  # type: ignore
            def redirect_to_index(request: request.Request) -> response.HTTPResponse:
                return response.redirect(
                    request.app.url_for(handler_name(client_files), path="index.html")
                ) 
开发者ID:rmorshea,项目名称:idom,代码行数:45,代码来源:sanic.py


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