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