-------------------
校验函数参数的工具
- 校验类型
.. 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,否则上传会失败*
Metadata
Release files for validate-parameters 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| validate_parameters-0.1.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Release files / validate_parameters-0.1.4-py2.py3-none-any.whl
| Download URL | validate_parameters-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
441710ff99e1b34a8d65d5ed83298e82ccc0c6c1366e8c38634cf071f625f896
|
|
BLAKE2b-256 checksum How to use checksums |
8851ed712f225566711f570b6a0bd4e41ad6b52912ea061ef94342b91a715da4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.11
|
Security for validate-parameters 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.