copilot_share/utils/utils.py
2024-02-20 11:38:06 +08:00

26 lines
624 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File : utils.py
@Time : 2023/09/27 14:36:15
@Author : lvguanjun
@Desc : utils.py
"""
from typing import Optional
from werkzeug.test import EnvironBuilder
from werkzeug.wrappers import Request
def fake_request(method: str, headers: dict, json: Optional[dict] = None) -> Request:
"""
根据提供的json数据和headers构造一个request对象
"""
# 使用 EnvironBuilder 创建一个新的请求环境
builder = EnvironBuilder(method=method, headers=headers, json=json)
env = builder.get_environ()
return Request(env)