Skip to main content

A data integrity check library

Project description

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Description: vlde: easy-to-use for validate data
=========

.. image:: https://travis-ci.org/xiaojieluo/vlde.svg?branch=master
:target: https://travis-ci.org/xiaojieluo/vlde
.. image:: https://codecov.io/gh/xiaojieluo/vlde/branch/master/graph/badge.svg
:target: https://codecov.io/gh/xiaojieluo/vlde

使用
-----

.. code-block:: python

v = Validator(return_format='object')
result = v.set_rules('hello', 'required|dict|max_length:3')
if result.status is False:
print('\n'.join(result.error))

或者捕获异常:

.. code-block:: python

v = Validator(return_format='exception')
try:
v.set_rules('hello', 'required|dict')
except ValidateError as e:
print(e)

validate 内置规则
------------------------

规则参考
^^^^^^^^^^^^^

下表列出了 vlde 可用的规则


| 规则 | 参数 | 描述 | 例子|
| :-- | :-- | :-- | :-- |
| required | | 如果变量值为空或者为 None, 验证不通过 | `v.set_rules(None, 'required')` |
| min_length | int | 如果变量值长度小于参数值, 验证不通过 | `v.set_rules('hello', 'min_length:6')` |
| max_length | int | 如果变量值长度大于参数值, 验证不通过 | `v.set_rules('hello', 'max_length:2')` |
| exact_length | int | 如果变量值长度不等于参数值, 验证不通过 | `v.set_rules('hello', 'exact_length:5')` |
| in_list | list | 如果变量值不在规定的列表中,验证不通过 | `v.set_rules('hello', 'in_list[hello, helloss]')`|
| str | | 如果变量类型不为 str, 验证不通过 | `v.set_rules('hello', 'str')` |
| dict | | 如果变量类型不为 dict, 验证不通过 | `v.set_rules({'name':'luo'}, 'dict')` |
| list | | 如果变量类型不为 list, 验证不通过 | `v.set_rules([1, 2, 3], 'list')` |
| bool | | 如果变量类型不为 bool, 验证不通过 | `v.set_rules(True, 'bool')` |
| float | | 如果变量类型不为 foat, 验证不通过 | `v.set_rules(1.1, 'float')` |
| int,integer | | 如果变量类型不为 int, 验证不通过 | `v.set_rules(10, 'int')` |
| tuple, tup | | 如果变量类型不为 tuple, 验证不通过 | `v.set_rules((1, 2, 3), 'tuple')` |
| ipv4 | str | 如果变量值不为 ipv4 地址, 验证不通过 | `v.set_rules('192.168.1.1', 'ipv4')` |
| ipv6 | str | 如果变量值不为 ipv6 地址, 验证不通过 | `v.set_rules('5e:0:0:0:0:0:5668:eeee', 'ipv6')` |
| email | str | 如果变量值不为邮箱地址, 验证不通过 | `v.set_rules('xiaojieluoff@gmail.com' 'email')` |

#### 规则容错
* `int , integer` 都指代 int 类型
* `tuple, tup` 都指代 tuple 类型

Keywords: simple data validate library
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vlde-0.0.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vlde-0.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file vlde-0.0.1.tar.gz.

File metadata

  • Download URL: vlde-0.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vlde-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4386cdd8dde6d7b7e821cd06062138937c6320387e62f8dcf3ff6426fba8fcfc
MD5 16eab3f7a0ea22d6942c2e0c9ebf0ab9
BLAKE2b-256 1abfce00bc58ee81b70bd0fab7e7417f8ca4197c66cab42ad92e0080b25c505f

See more details on using hashes here.

File details

Details for the file vlde-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: vlde-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vlde-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fc52ed1b9b0ec1649d708ed96bf61996c31f45fbeba9c8fddf7d44f0a873fc31
MD5 4ffe727bcd0812f1efe4fb8b79839891
BLAKE2b-256 56421fa1fe6b39bd1c9c345e7625a546d9fdac7e10b2956ef0f9499af5cbc634

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page