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


Python quart.jsonify方法代码示例

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


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

示例1: test_cookie_jar

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [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

示例2: test_redirect_cookie_jar

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [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

示例3: broadcast

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def broadcast():
    data = await request.get_json()
    for queue in app.clients:
        await queue.put(data['message'])
    return jsonify(True) 
开发者ID:pgjones,项目名称:quart,代码行数:7,代码来源:broadcast.py

示例4: check_status

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def check_status():
    global aredis, sr
    status = dict()
    try:
        if await aredis.get('state') == b'running':
            if await aredis.get('processed') != await aredis.get('lastProcessed'):
                await aredis.set('percent', round(
                    int(await aredis.get('processed')) / int(await aredis.get('length_of_work')) * 100, 2))
                await aredis.set('lastProcessed', str(await aredis.get('processed')))
    except:
        pass

    try:
        status['state'] = sr.get('state').decode()
        status['processed'] = sr.get('processed').decode()
        status['length_of_work'] = sr.get('length_of_work').decode()
        status['percent_complete'] = sr.get('percent').decode()
    except:
        status['state'] = sr.get('state')
        status['processed'] = sr.get('processed')
        status['length_of_work'] = sr.get('length_of_work')
        status['percent_complete'] = sr.get('percent')

    status['hint'] = 'refresh me.'

    return jsonify(status) 
开发者ID:pgjones,项目名称:quart,代码行数:28,代码来源:progress_bar.py

示例5: test_json

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [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

示例6: test_form

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

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

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

示例7: test_set_cookie

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

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

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

示例8: weather

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def weather(zip_code: str, country: str):
    weather_data = await weather_service.get_current(zip_code, country)
    if not weather_data:
        quart.abort(404)
    return quart.jsonify(weather_data) 
开发者ID:talkpython,项目名称:async-techniques-python-course,代码行数:7,代码来源:city_api.py

示例9: sun

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def sun(zip_code: str, country: str):
    lat, long = await location_service.get_lat_long(zip_code, country)
    sun_data = await sun_service.for_today(lat, long)
    if not sun_data:
        quart.abort(404)
    return quart.jsonify(sun_data) 
开发者ID:talkpython,项目名称:async-techniques-python-course,代码行数:8,代码来源:city_api.py

示例10: replicas

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def replicas():
    return jsonify(await get_replicas(int(request.args.get("type", "1")))) 
开发者ID:NightTeam,项目名称:cellular-network-proxy_docker,代码行数:4,代码来源:server.py

示例11: _handle_http_event

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def _handle_http_event(self) -> Response:
        if self._secret:
            if 'X-Signature' not in request.headers:
                self.logger.warning('signature header is missed')
                abort(401)

            sec = self._secret
            sec = sec.encode('utf-8') if isinstance(sec, str) else sec
            sig = hmac.new(sec, await request.get_data(), 'sha1').hexdigest()
            if request.headers['X-Signature'] != 'sha1=' + sig:
                self.logger.warning('signature header is invalid')
                abort(403)

        payload = await request.json
        if not isinstance(payload, dict):
            abort(400)

        if request.headers['X-Self-ID'] in self._wsr_api_clients:
            self.logger.warning(
                'there is already a reverse websocket api connection, '
                'so the event may be handled twice.')

        response = await self._handle_event(payload)
        if isinstance(response, dict):
            return jsonify(response)
        return Response('', 204) 
开发者ID:nonebot,项目名称:aiocqhttp,代码行数:28,代码来源:__init__.py

示例12: usage

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def usage():
    return quart.jsonify({"info": banner}), 201 
开发者ID:intel,项目名称:stacks-usecase,代码行数:4,代码来源:rest.py

示例13: recog

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def recog():
    if quart.request.files.get("img"):
        img = quart.request.files["img"].read()
        img = Image.open(io.BytesIO(img))
        y_hat = classify(img)
        return quart.jsonify({"class": y_hat[0], "prob": y_hat[1]}), 201
    return quart.jsonify({"status": "not an image file"}) 
开发者ID:intel,项目名称:stacks-usecase,代码行数:9,代码来源:rest.py

示例14: not_found

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def not_found(error):
    return quart.make_response(quart.jsonify({"error": "Not found"}), 404) 
开发者ID:intel,项目名称:stacks-usecase,代码行数:4,代码来源:rest.py

示例15: index

# 需要导入模块: import quart [as 别名]
# 或者: from quart import jsonify [as 别名]
def index():
    return quart.jsonify(banner), 201 
开发者ID:intel,项目名称:stacks-usecase,代码行数:4,代码来源:rest.py


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