MCPcopy Create free account
hub / github.com/Tong89/smartNode / _parse_positive_int

Function _parse_positive_int

backend/api.py:195–207  ·  view source on GitHub ↗

将查询参数解析为正整数,非法时返回校验错误响应(None 表示解析成功)。

(raw, name: str, default: int, maximum: int = 200)

Source from the content-addressed store, hash-verified

193
194
195def _parse_positive_int(raw, name: str, default: int, maximum: int = 200):
196 """将查询参数解析为正整数,非法时返回校验错误响应(None 表示解析成功)。"""
197 if raw is None:
198 return default, None
199 try:
200 value = int(raw)
201 except (ValueError, TypeError):
202 return None, ({"field": name, "message": "须为整数"}, 400)
203 if value < 1:
204 return None, ({"field": name, "message": "须为正整数(≥1)"}, 400)
205 if value > maximum:
206 return None, ({"field": name, "message": f"不得超过 {maximum}"}, 400)
207 return value, None
208
209
210@app.route('/api/v1/requests', methods=['GET'])

Callers 1

get_requests_paginatedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected