encapsulation of some useful features
Project description
izen 库
=====
> izen, 封装一些常用功能
## 功能列表
- [x] 配置文件
- [x] 加密解密
- [x] 常用装饰器
- [x] 常用辅助功能
- [x] mqtt通信
- [x] redis通信
- [x] 定期任务
### `icfg.py`
使用样例
```python
>>> 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`, 自动捕获函数内程序错误, 并保证其他函数可以正常运行
```python
>>> 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.
```
=====
> izen, 封装一些常用功能
## 功能列表
- [x] 配置文件
- [x] 加密解密
- [x] 常用装饰器
- [x] 常用辅助功能
- [x] mqtt通信
- [x] redis通信
- [x] 定期任务
### `icfg.py`
使用样例
```python
>>> 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`, 自动捕获函数内程序错误, 并保证其他函数可以正常运行
```python
>>> 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.1.20181103.tar.gz
(41.8 kB
view details)
Built Distribution
File details
Details for the file izen-0.1.20181103.tar.gz
.
File metadata
- Download URL: izen-0.1.20181103.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea2d4bdd23bd10441d822702cdb30e476eb25fa77747e83d2b37d0746b4ce0ac |
|
MD5 | be9600a09e7c9dc102418fbf4801d816 |
|
BLAKE2b-256 | feb886ede9c3a46abe151da75c4370bffdb01c9fc0b8b2d88e318106a63b46a3 |
File details
Details for the file izen-0.1.20181103-py3-none-any.whl
.
File metadata
- Download URL: izen-0.1.20181103-py3-none-any.whl
- Upload date:
- Size: 45.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f88b12d42a7275be6643320a7acee13912f66fc9592aaa4940acf0f3b93c7dd0 |
|
MD5 | be3d7a17a1e709f2c72b10351b3a348a |
|
BLAKE2b-256 | e65d48d05bae9b3833be0a29d4b648fddf0e98be6c7b85048eb9d9c9f066e073 |