python - 从 mongo 获取数据时对函数应用限制
问题描述
有一个具有 m 个 API 的 python 代码,它获取具有 n 个字段的请求模式并从 mongoDB 获取响应
我想写一个装饰器来限制来自 mongo 的响应
例如:
从 API 之一,如果请求模式中有 7 个字段并且预期字段为 2,即 id 和状态。2 个字段可处理的最大条目数为 250
装修师应该怎么做?
对装饰器一无所知。请建议
def decorator(func):
func = validate_parameters(request_schema)(func)
func = parse_query_parameters(request_schema)(func)
func = returns_json(func)
if requires_authentication:
func = jwt_required(func)
endpoint = str(uuid4())
for route in routes:
blueprint.route(route, methods=methods, endpoint=endpoint)(func)
flex_schema_by_endpoint[endpoint] = dict(request=request_schema, response=response_schema,
exceptions=exceptions, requires_authentication=requires_authentication)
return func
解决方案
推荐阅读
- regex - 正则表达式匹配孤立的 4 位数年份
- python-3.x - 更新 firestore 文档嵌套数据会覆盖它
- java - 有没有办法使用 mp3agic 获取通用 mp3 标签?
- angular - 使用多个 @input() 装饰器 - ionic 4
- scala - 使用 Spark 根据以前的列值设置列值,而不重复分组属性
- javascript - 如何在 Angular html 中动态更新 SVG Image href?
- wordpress - 控制台错误如何设置 SameSite 属性
- bluetooth - 如何使用 Azure IoT Edge 在树莓派上使用蓝牙连接到移动应用程序?
- html - CSS椭圆框阴影太模糊
- python - 我需要帮助创建一个循环,要求用户输入希望处理的文件