函数参数分析器

funcargpreprocessor的Python项目详细描述


函数参数预处理器

这是一个抽象库,需要在实际使用之前进行扩展。在

主要的用例是将其扩展为Flask Extenstion,但它可以与任何其他需要处理http端点的环境/框架一起使用,例如:AWS Lambda

实施

flask_requestpreprocesser

安装

 $ pip install funcargpreprocessor

或者下载并运行代码

^{pr2}$

它的作用是什么?在

  • 函数参数的提取和转换,并提出适当的异常

示例

说明

下面的解释使用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 }}}}}}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java收回EhCache中的所有元素   java创建带有箭头的组合框,以在其中增加值   在Java中使用JsonPath解析JSON中的数组   java如何在应用程序类不可见的模块中获取上下文?   exoplayer中的java Recyclerview不起作用   java MS Access无法打开更多表   从xmlschema到java的unicode拉丁脚本子集的正则表达式   在spring sts模型中,java时间戳格式必须为yyyymmdd hh:mm:ss   java将XPath转换为Jsoup的CssSelector   java Solr运算符类似于SQL中的类反向运算符   java使第三方类不可变   java跳过自定义卡片堆栈视图的动画   java如何修复“使用Spring AOP,我想更改返回值,但返回类不是我的返回方法”   java使用正则表达式解析字符串   java泛型与遗留代码的兼容性为什么foreach在运行时失败,而迭代器工作正常   hibernate如何使用java持久性重试锁定等待超时?