Skip to main content

A Python library for checking parameters.

Project description

validate_parameters
-------------------
校验函数参数的工具

- 校验类型

.. code :: python

@validParam(a=int)
def func(a, b=1, *args, **kwargs):
return Result().data = a, b, args, kwargs


| 正确时,返回值:func定义的Result()对象(由用户自己定义)
| 错误时,返回值:Result()对象,

.. code :: python

Result().flag = False,
Result().msg = 'func() parameter validation fails, param: a, value: a(str), msg(None)'
Result().code/status = -3000

* 自定义函数

.. code :: python

def max_11(x):
if x> 11:
return True, 'msg', 'code'
else:
return False, 'msg', 'code'

@validParam(a=int, b=max_11)
def func(a, b=1, *args, **kwargs)
return Result().data = a, b, args, kwargs

| 其中,msg和code为用户自定义,且为可选参数
| 正确时,返回值:func定义的Result()对象(由用户自己定义)
| 错误时,返回值:Result()对象,

.. code :: python

Result().flag = False,
Result().msg = 'func() parameter validation fails, param: a, value: a(str), msg(*{{ msg }}*)'
Result().code/status = *{{ code }}*

* 校验类型和函数

.. code :: python

@validParam(a=int, b=(int, max_11))
def func(a, b=1, *args, **kwargs)
return Result().data = a, b, args, kwargs

| 其中,msg和code为用户自定义,且为可选参数
| 正确时,返回值:func定义的Result()对象(由用户自己定义)
| 错误时,返回值:Result()对象,

.. code :: python

Result().flag = False,
Result().msg = 'func() parameter validation fails, param: a, value: a(str), msg(*{{ msg }}*)'
Result().code/status = *{{ code }}*

Result
------

- 返回值对象Result()
- 支持Result().code和Result()["code]取值
- 支持Result().code=1和Result()["code]=1赋值
- 支持转json格式,json.dumps(Result(), defaults=Result().to_json)
- 支持转dict对象,Result().dict()

- 默认参数包括:

.. code :: python

flag=True, data=None, code=None, msg=None, status=None, return_values=None

上传至pypi
------

::

python setup.py bdist_wheel --universal
twine upload dist/*

| *username: chenyang21 passwd: devops58ganji*
| *需要更新LICENSE里的version,否则上传会失败*


Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
validate_parameters-0.1.4-py2.py3-none-any.whl (7.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page