Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

izen 库

izen, 封装一些常用功能

功能列表

  • 配置文件
  • 加密解密
  • 常用装饰器
  • 常用辅助功能
  • mqtt通信
  • redis通信
  • 定期任务

icfg.py

使用样例

>>>importlogzero>>>fromlogzeroimportloggeraslog>>>fromizen.icfgimportConf, LFormatter>>>pth_cfg='/tmp/.code.cnf'>>>cfg=Conf(
... pth=pth_cfg,
... dat={
... 'mg.host': '127.0.0.1',
... 'mg.port': 27027,
... 'mg.db': 'test_db',
... 'rds.host': '127.0.0.1',
... 'rds.port': 6379,
... 'rds.db': {
... 'val': 0,
... 'proto': str
... },
... }
... ).cfg>>>ifcfg.get('log.enabled', False):
... logzero.logfile(
... cfg.get('log.file_pth', '/tmp/.code.log'),
... maxBytes=cfg.get('log.file_size', 5) *1000000,
... backupCount=cfg.get('log.file_backups', 3),
... loglevel=cfg.get('log.level', 10),
... )
...
>>>bagua='🍺🍻♨️️😈☠'>>>formatter=LFormatter(bagua)
>>>logzero.formatter(formatter)
>>>>>>log.debug('hi')
🍺 D18041716:36:05<stdin>:1|hi>>>log.info('hi')
🍻 I18041716:37:21<stdin>:1|hi>>>log.warning('hi')
♨ W18041716:37:35<stdin>:1|hi>>>log.error('hi')
️ E18041716:37:41<stdin>:1|hi

装饰器

i.e. dec.catch, 自动捕获函数内程序错误, 并保证其他函数可以正常运行

>>>fromizenimportdec>>>>>>>>>@dec.catch(True, ZeroDivisionError)
... defterr():
... print('divide by 0')
... print(1/0)
... print('i can not go here.')
...
>>>>>>deft():
... terr()
... print('but i can go here.')
...
>>>t()
divideby0
[E18041716:25:41dec:457] <stdin>(1)>terr: haserr(divisionbyzero)
Traceback (mostrecentcalllast):
File"/Users/lihe/pan.weiyun/tinyc/smartwear/izen/izen/dec.py", line452, inwrapper_returnfn(*args, **kwargs)
File"<stdin>", line4, interrZeroDivisionError: divisionbyzerobuticangohere.

About

encapsulation of some useful features

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages