Onion Model in Python
Project description
Compose4py
Onion Model in Python.
::
pip install compose4py
Installation
Usage
Import compose4py
:
.. code:: python
from compose4py import Compose
All the usual function composition you know and love:
.. code:: python
def mw_1(ctx, loader_context):
print("mw_1: %s" % ctx)
print("mw_1 loader_context: %s" % loader_context)
ctx += ":mw1"
ctx = yield ctx
ctx += ":post_mw1"
return ctx
def mw_2(ctx):
print("mw_2: %s" % ctx)
ctx += ":mw2"
ctx = yield ctx
ctx += ":post_mw2"
return ctx
def mw_3(ctx):
print("mw_3: %s" % ctx)
ctx += ":mw3"
return ctx
compose = Compose(mw_1, mw_2, mw_3, loader_context = {"foo": "bar"})
result = compose("foo")
print("final: %s" % result)
# final: foo:mw1:mw2:mw3:post_mw2:post_mw1
Give credits to
开源许可协议
Copyright (2018-2020) 北京华夏春松科技有限公司
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
compose4py-1.1.1.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for compose4py-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9abb6aeef4adb121c1e916486e2fe29a2cfeb446e6eff3eee74e244cb57a8ef |
|
MD5 | 952d413cefc3f74616b61b80371bd797 |
|
BLAKE2b-256 | 37c2c893861acbec42755d29bbcee479135f93640a5be0a19bc04f0769dd9232 |