encapsulation of some useful features
Project description
izen 库
izen, 封装一些常用功能
功能列表
- 配置文件
- 加密解密
- 常用装饰器
- 常用辅助功能
- mqtt通信
- redis通信
- 定期任务
icfg.py
使用样例
>>> import logzero
>>> from logzero import logger as log
>>> from izen.icfg import Conf, 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
>>> if cfg.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')
🍺 D 180417 16:36:05 <stdin>:1 | hi
>>> log.info('hi')
🍻 I 180417 16:37:21 <stdin>:1 | hi
>>> log.warning('hi')
♨ W 180417 16:37:35 <stdin>:1 | hi
>>> log.error('hi')
️ E 180417 16:37:41 <stdin>:1 | hi
装饰器
i.e. dec.catch
, 自动捕获函数内程序错误, 并保证其他函数可以正常运行
>>> from izen import dec
>>>
>>>
>>> @dec.catch(True, ZeroDivisionError)
... def terr():
... print('divide by 0')
... print(1 / 0)
... print('i can not go here.')
...
>>>
>>> def t():
... terr()
... print('but i can go here.')
...
>>> t()
divide by 0
[E 180417 16:25:41 dec:457] <stdin>(1)>terr: has err(division by zero)
Traceback (most recent call last):
File "/Users/lihe/pan.weiyun/tinyc/smartwear/izen/izen/dec.py", line 452, in wrapper_
return fn(*args, **kwargs)
File "<stdin>", line 4, in terr
ZeroDivisionError: division by zero
but i can go here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
izen-0.2.3.tar.gz
(42.2 kB
view details)
Built Distribution
izen-0.2.3-py3-none-any.whl
(57.8 kB
view details)
File details
Details for the file izen-0.2.3.tar.gz
.
File metadata
- Download URL: izen-0.2.3.tar.gz
- Upload date:
- Size: 42.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca56ae05f6b2eaed7202747cf24bcc94a36c409decdc9fc02a39edfff087e769 |
|
MD5 | b17c475ab7b648c5535623bcedca5362 |
|
BLAKE2b-256 | 1c80f9867e218f0bcee5f279c3dd13b5dfe982db90682a05063e6b8ba6b8f9ca |
File details
Details for the file izen-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: izen-0.2.3-py3-none-any.whl
- Upload date:
- Size: 57.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b336e9579d04b794a53ea38fb026c2192e9c5c48cc1c7757934cfb2e9fff5d6 |
|
MD5 | 82944b18d63b34d68879eca783de4c93 |
|
BLAKE2b-256 | b034c4e31f708e6a46d4b11b4ee7f17366ef57f572b08a7a76d8ad17bc8864af |