GithubHelp home page GithubHelp logo

coghost / izen Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 80 KB

encapsulation of some useful features

License: GNU General Public License v3.0

Python 99.91% Shell 0.09%
python3 izen utils crawler mqtt chaos encrypt profig

izen's Introduction

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.

izen's People

Contributors

coghost avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

forgeries

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.