Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

James Iter's common library by python.

Project Description

添加自定义状态码示例

  • 枝叶状态码合并
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']
Release History

Release History

This version
History Node

0.63

History Node

0.62

History Node

0.61

History Node

0.60

History Node

0.59

History Node

0.58

History Node

0.57

History Node

0.56

History Node

0.55

History Node

0.54

History Node

0.53

History Node

0.52

History Node

0.51

History Node

0.50

History Node

0.49

History Node

0.48

History Node

0.47

History Node

0.46

History Node

0.45

History Node

0.44

History Node

0.43

History Node

0.42

History Node

0.41

History Node

0.40

History Node

0.39

History Node

0.38

History Node

0.37

History Node

0.36

History Node

0.35

History Node

0.34

History Node

0.33

History Node

0.32

History Node

0.31

History Node

0.30

History Node

0.29

History Node

0.28

History Node

0.27

History Node

0.26

History Node

0.25

History Node

0.24

History Node

0.23

History Node

0.22

History Node

0.21

History Node

0.20

History Node

0.19

History Node

0.18

History Node

0.17

History Node

0.16

History Node

0.15

History Node

0.14

History Node

0.13

History Node

0.12

History Node

0.11

History Node

0.10

History Node

0.9

History Node

0.8

History Node

0.7

History Node

0.6

History Node

0.5

History Node

0.4

History Node

0.3

History Node

0.2

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
jimit-0.63.tar.gz (13.6 kB) Copy SHA256 Checksum SHA256 Source Apr 7, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting