James Iter’s library by python
添加自定义状态码示例
枝叶状态码合并
import jimit as ji
own_state_branch = {
'41250': {
'code': '41250',
'zh-cn': '账密不匹配'
}
}
ji.state_code.index_state['branch'] = dict(ji.state_code.index_state['branch'], **own_state_branch)
print json.dumps(ji.Commons.exchange_state(41250), ensure_ascii=False)
{
"code": "412",
"zh-cn": "先决条件失败",
"en-us": "Precondition Failed",
"sub": {
"zh-cn": "账密不匹配",
"code": "41250"
}
}
自定义状态码建议
基于各主干的枝叶状态码从50开始,如412主干,则用户自定义枝叶状态码由41250起。
路由器示例
from jimit.router import Router, router_table
from jimit.ji_time import JITime
import unittest
reload(sys)
sys.setdefaultencoding('utf8')
'''
首先配置路由表
'''
router_table['today'] = JITime.today
'''
:param action: 目标路由地址
:param content: 传给目标的参数内容(content可以是一个字典,这样对于给目标传参更为灵活;示例: {'name': 'James', 'gender': 'M'})
'''
print Router.launcher(action='today', content='-')
类型判断示例
参数说明
args_rules = [
(类型[int|long|str|basestring|list|dict...](必须), 变量名(必须), 取值范围(可选), 必须存在(可选,默认为True))
]
取值范围: 列表为枚举['male', 'female', 'other'], 元组为起止范围(10, 100)
必须存在: 布尔值,默认为True, 当该值为True时,则表示该变量必须存在; 否则,仅当该变量存在时,才匹配该条策略
args = {
'变量名': 变量值
}
try:
ji.Check.previewing(args_rules, args)
except ji.PreviewingError, e:
ret = json.loads(e.message)
异常处理域
示例1
状态码200为正常,其它都为异常
详细描述在ret['state']['sub']中
异常会于PreviewingError类型抛出,可通过json.loads(e.message)来结构化异常描述
更多异常用法请移步参考:
https://github.com/jamesiter/jimitlib-py/blob/master/tests/test_check.py
import jimit as ji
form_rules = [
(int, 'k', (10, 100))
]
form = {
'k': 10
}
assert '200' == ji.Check.previewing(form_rules, form)['state']['code'])
示例2
form_rules = [
(str, 'k')
]
form = {
'k': 123
}
try:
ji.Check.previewing(form_rules, form)
except ji.PreviewingError, e:
ret = json.loads(e.message)
assert '41202' == ret['state']['sub']['code']
Metadata
Release files for jimit 6.10.2
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 | Actions Reset |
|---|---|---|---|---|
| jimit-6.10.2-py3-none-any.whl | Python 3 | none | any | Details for jimit-6.10.2-py3-none-any.whl |
Release files / jimit-6.10.2-py3-none-any.whl
| Download URL | jimit-6.10.2-py3-none-any.whl |
|---|---|
| Size | 56.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1131dbda24f5971c049d8c9eac0785b5fd2e785166cc1dd5e0e091de55798506
|
|
BLAKE2b-256 checksum How to use checksums |
1bb2460cdd2d4bc950a081ac357cf2aa7c1a67c596a7d02fc586dbd8338b4146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for jimit 6.10.2
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.