函数参数分析器
funcargpreprocessor的Python项目详细描述
函数参数预处理器
这是一个抽象库,需要在实际使用之前进行扩展。在
主要的用例是将其扩展为Flask Extenstion
,但它可以与任何其他需要处理http端点的环境/框架一起使用,例如:AWS Lambda
实施
安装
$ pip install funcargpreprocessor
或者下载并运行代码
^{pr2}$它的作用是什么?在
- 函数参数的提取和转换,并提出适当的异常
示例
- 请参考testimplementation.py和fieldtest.py以获取示例
说明
下面的解释使用test
文件夹中的示例
{"pageNo":{#Key name expected from the HTTP endpoint"data_type":int# Data type expected ,"min_val":0# Min validation for the key ,"max_val":20# Max validation for the key,'alias':'page_no'# Key for the function argument, to the function the argument will be 'page_no'# Need? most of the time the http request are expected json and the keys will be in camelCase},"start_date":{"data_type":DateArg('%Y-%m-%d')# Expects a date argument in <str>'YYYY-MM-DD' format or datetime.date object accepts '2020-01-10', datetime.date(2020, 1, 10) converts,in case of a string argument, to datetime.date(2020, 1, 10) and passes it to the function,"min_val":date(2020,1,1),"required":True# This key is required to be there in the input},"id_list":{"data_type":list# Expects list of value,"nested":int# The values in the list should be int same rule as `date_type`,"value_list":[0,1,2,3]# Accepted values, valid argument ex: [1,2], [1], [2,3,0]# Need? Multiselect options/ENUMS},'reg_time':{"data_type":DateTimeArg('%Y-%m-%d %H:%M:%S')},"location":{"data_type":list,"nested":{# Custom definition for objects in the list"address_line_1":{"data_type":str,"required":True},"address_line_2":{"data_type":str,"min_len":5#Mininum length expected for the argument,"max_len":10# Maximum length accepted for the argument},"latitude":{"data_type":DecimalArg(),"min_val":Decimal("-90"),"max_val":Decimal("90")},"longitude":{"data_type":DecimalArg(),"min_val":Decimal("-180"),"max_val":Decimal("180")},"pincode":{"data_type":int,"required":True},"contact_person":{"data_type":dict,"nested":{"first_name":{"data_type":str,"required":True},"last_name":{"data_type":str},"phone_number":{"data_type":str,"required":True,"regex":r"[0-9]{10,12}"# Regular expression validation,"regex_error_message":"<some message>"# Message when the RegEx validation fails }}}}}}
- 项目
标签: