當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。