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


Python quart.Response方法代码示例

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


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

示例1: new_handle_http_exception

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def new_handle_http_exception(
    self: Quart, error: Union[WerkzeugHTTPException, QuartHTTPException]
) -> Response:
    if isinstance(error, WerkzeugHTTPException):
        handler = self._find_exception_handler(error)
        if handler is None:
            werkzeug_response = error.get_response()
            return await self.make_response(
                (
                    werkzeug_response.get_data(),
                    werkzeug_response.status_code,
                    werkzeug_response.headers,
                )
            )
        else:
            return await handler(error)
    else:
        return await old_handle_http_exception(self, error) 
开发者ID:pgjones,项目名称:quart,代码行数:20,代码来源:app.py

示例2: test_cookie_jar

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_cookie_jar() -> None:
    app = Quart(__name__)
    app.secret_key = "secret"

    @app.route("/", methods=["GET"])
    async def echo() -> Response:
        foo = session.get("foo")
        bar = request.cookies.get("bar")
        session["foo"] = "bar"
        response = jsonify({"foo": foo, "bar": bar})
        response.set_cookie("bar", "foo")
        return response

    client = Client(app)
    response = await client.get("/")
    assert (await response.get_json()) == {"foo": None, "bar": None}
    response = await client.get("/")
    assert (await response.get_json()) == {"foo": "bar", "bar": "foo"} 
开发者ID:pgjones,项目名称:quart,代码行数:20,代码来源:test_testing.py

示例3: test_redirect_cookie_jar

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_redirect_cookie_jar() -> None:
    app = Quart(__name__)
    app.secret_key = "secret"

    @app.route("/a")
    async def a() -> Response:
        response = redirect("/b")
        response.set_cookie("bar", "foo")
        return response

    @app.route("/b")
    async def echo() -> Response:
        bar = request.cookies.get("bar")
        response = jsonify({"bar": bar})
        return response

    client = Client(app)
    response = await client.get("/a", follow_redirects=True)
    assert (await response.get_json()) == {"bar": "foo"} 
开发者ID:pgjones,项目名称:quart,代码行数:21,代码来源:test_testing.py

示例4: expired_token_callback

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def expired_token_callback(expired_token: Dict[str, Any]) -> Response:
    """
    Log that an access attempt was made with an expired token and return
    the result from the default callback.

    Returns
    -------
    Response
    """

    current_app.access_logger.error(
        "EXPIRED_TOKEN",
        route=request.path,
        request_id=request.request_id,
        identity=expired_token["identity"],
        expired_token=expired_token,
        src_ip=request.headers.get("Remote-Addr"),
        json_payload=await request.json,
    )

    return default_expired_token_callback(expired_token) 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:23,代码来源:jwt_auth_callbacks.py

示例5: claims_verification_failed_callback

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def claims_verification_failed_callback() -> Tuple[Dict[str, str], int]:
    """
    Log that an access attempt was made with claims that failed verification and return
    a json error message and 401 error code.

    Returns
    -------
    Response
    """
    current_app.access_logger.error(
        "CLAIMS_VERIFICATION_FAILED",
        route=request.path,
        request_id=request.request_id,
        user=str(get_jwt_identity()),
        src_ip=request.headers.get("Remote-Addr"),
        json_payload=await request.json,
    )
    return {"msg": "User claims verification failed"}, 403 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:20,代码来源:jwt_auth_callbacks.py

示例6: invalid_token_callback

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def invalid_token_callback(error_string) -> Response:
    """
    Log that an access attempt was made with a token that was invalid and return
    the result from the default callback.

    Parameters
    ----------
    error_string : str
        Reason the token is invalid

    Returns
    -------
    Response

    """
    current_app.access_logger.error(
        "INVALID_TOKEN",
        error_string=error_string,
        route=request.path,
        request_id=request.request_id,
        user=str(get_jwt_identity()),
        src_ip=request.headers.get("Remote-Addr"),
        json_payload=await request.json,
    )
    return default_invalid_token_callback(error_string) 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:27,代码来源:jwt_auth_callbacks.py

示例7: revoked_token_callback

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def revoked_token_callback() -> Response:
    """
    Log that an access attempt was made with a revoked token and return
    the result from the default callback.

    Returns
    -------
    Response
    """
    current_app.access_logger.error(
        "REVOKED_TOKEN",
        route=request.path,
        request_id=request.request_id,
        user=str(get_jwt_identity()),
        src_ip=request.headers.get("Remote-Addr"),
        json_payload=await request.json,
    )
    return default_revoked_token_callback() 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:20,代码来源:jwt_auth_callbacks.py

示例8: unauthorized_callback

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def unauthorized_callback(error_string) -> Response:
    """
    Log that an access attempt was made without a token and return
    the result from the default callback.

    Returns
    -------
    Response
    """
    current_app.access_logger.error(
        "UNAUTHORISED",
        error_string=error_string,
        route=request.path,
        request_id=request.request_id,
        user=str(get_jwt_identity()),
        src_ip=request.headers.get("Remote-Addr"),
        json_payload=await request.json,
    )
    return default_unauthorized_callback(error_string) 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:21,代码来源:jwt_auth_callbacks.py

示例9: new_handle_user_exception

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def new_handle_user_exception(
    self: Quart, error: Union[Exception, WerkzeugHTTPException, QuartHTTPException]
) -> Response:
    if isinstance(error, WerkzeugHTTPException):
        return await new_handle_http_exception(self, error)
    else:
        return await old_handle_user_exception(self, error) 
开发者ID:pgjones,项目名称:quart,代码行数:9,代码来源:app.py

示例10: test_make_response_response

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_make_response_response(app: Quart) -> None:
    response = await app.make_response(Response("Result"))
    assert response.status_code == 200
    assert (await response.get_data()) == b"Result"  # type: ignore

    response = await app.make_response((Response("Result"), {"name": "value"}))
    assert response.status_code == 200
    assert (await response.get_data()) == b"Result"  # type: ignore
    assert response.headers["name"] == "value"

    response = await app.make_response((Response("Result"), 404, {"name": "value"}))
    assert response.status_code == 404
    assert (await response.get_data()) == b"Result"  # type: ignore
    assert response.headers["name"] == "value" 
开发者ID:pgjones,项目名称:quart,代码行数:16,代码来源:test_basic.py

示例11: test_abort_with_response

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_abort_with_response() -> None:
    with pytest.raises(HTTPException) as exc_info:
        abort(Response("Message", 205))
    assert exc_info.value.get_response().status_code == 205 
开发者ID:pgjones,项目名称:quart,代码行数:6,代码来源:test_exceptions.py

示例12: test_json

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_json() -> None:
    app = Quart(__name__)

    @app.route("/", methods=["POST"])
    async def echo() -> Response:
        data = await request.get_json()
        return jsonify(data)

    client = Client(app)
    response = await client.post("/", json={"a": "b"})
    assert (await response.get_json()) == {"a": "b"} 
开发者ID:pgjones,项目名称:quart,代码行数:13,代码来源:test_testing.py

示例13: test_data

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_data() -> None:
    app = Quart(__name__)

    @app.route("/", methods=["POST"])
    async def echo() -> Response:
        data = await request.get_data(True)
        return data

    client = Client(app)
    headers = {"Content-Type": "application/octet-stream"}
    response = await client.post("/", data=b"ABCDEFG", headers=headers)
    assert (await response.get_data(True)) == b"ABCDEFG"  # type: ignore 
开发者ID:pgjones,项目名称:quart,代码行数:14,代码来源:test_testing.py

示例14: test_query_string

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_query_string() -> None:
    app = Quart(__name__)

    @app.route("/", methods=["GET"])
    async def echo() -> Response:
        data = request.args
        return jsonify(**data)

    client = Client(app)
    response = await client.get("/", query_string={"a": "b"})
    assert (await response.get_json()) == {"a": "b"} 
开发者ID:pgjones,项目名称:quart,代码行数:13,代码来源:test_testing.py

示例15: test_redirect

# 需要导入模块: import quart [as 别名]
# 或者: from quart import Response [as 别名]
def test_redirect() -> None:
    app = Quart(__name__)

    @app.route("/", methods=["GET"])
    async def echo() -> str:
        return request.method

    @app.route("/redirect", methods=["GET"])
    async def redir() -> Response:
        return redirect("/")

    client = Client(app)
    assert (await client.get("/redirect", follow_redirects=True)).status_code == 200 
开发者ID:pgjones,项目名称:quart,代码行数:15,代码来源:test_testing.py


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