INI-config validator

configchecker的Python项目详细描述


buildcicoverallspyversions

DwnMonthDwnWeekDwnDay

license

此模块有助于检查configparser加载的配置。

用法

  1. 初始化有效配置的说明: schema = configchecker.ConfigSchema()
  2. 通过使用节名称验证器和布尔标志“section required”调用schema.section,添加可能节的信息。
  3. 在每个小节中,通过调用sect.value来描述可能的小节值。

名称/值验证器

有基本的验证器:

  • ItemDefaultValidator-始终返回true
  • ItemStringValidator-检查字符串是否等于给定值(可能不区分大小写)
  • ItemRegexValidator-检查字符串与给定regexp的匹配情况
  • ItemNumberValidator-检查字符串是否为非负整数

以及允许创建更复杂检查的验证程序生成器:

  • ItemNotValidatorItemAndValidatorItemOrValidator-验证器上的一阶逻辑
  • ItemCountValidator-接受一个验证器和一个函数,该函数检查验证器的真正数(即返回True

示例

importconfigparserimportconfigcheckerasvconfig=configparser.ConfigParser()config.read_file("config")schema=v.ConfigSchema()# Section with name „REQUIRED“ will be mandatorywithschema.section("REQUIRED")ass:# It must have keys matching regexp r'item_\d+' and numeric value and nothing mores.value(v.ItemRegexValidator(r'item_\d+',value_val=v.ItemNumberValidator()).no_other()# Section with name r'OPT_\w+' (check by regexp) will be optionalwithschema.section(v.ItemRegexValidator(r'OPT_\w+'),required=False)ass:# And it may have anythingpass# Other sections will be restrictedschema.no_other()# Run checksv.ConfigSchemaValidator(schema).validate(config)

此外,您可以在测试中找到许多示例(test_configchecker.py

作者

萨蒙·维克托,victor.samun@gmail.com

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

推荐PyPI第三方库


热门话题
java如何将cassandra中的行数据转换为与列相关的嵌套json   java如何使用jcr XPath在jcr:content/@jcr:data中搜索?   java在使用openCV进行安卓开发时如何利用手机的广角镜头   java解析扩展了接口,结束了一个潜在的无限循环   位置服务的@Override方法中存在java Android应用程序错误   java本地线程的用途和需求是什么   具有左右子访问的java节点树遍历   java验证JsonWebToken签名   JUL日志处理程序中的java日志记录   嵌入式Java读取给定时间段的串行数据。   java有没有办法从多个URL获取多个图像?   java线程通过等待intent阻止自己发送intent   java Spring MVC解析多部分内容请求   java JPA/Hibernate静态元模型属性未填充NullPointerException   java格式错误的字符(需要引号,得到I)~正在处理   java为什么PrintWriter对象抛出FileNotFoundException?   java Neo4j未正确保存标签   java IE不加载图像