boaconstructor-0.3.0
توضیحات
The boacontructor is a templating library for *data*, i.e. templating for dictionaries.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | boaconstructor-0.3.0 |
| نام | boaconstructor |
| نسخه کتابخانه | 0.3.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Oisin Mulvihill |
| ایمیل نویسنده | oisin dot mulvihill a-t gmail d-ot com |
| آدرس صفحه اصلی | UNKNOWN |
| آدرس اینترنتی | https://pypi.org/project/boaconstructor/ |
| مجوز | Apache License v2.0 |
The boacontructor is a templating library for *data*.
It allows you to construct Python dictionaries from other templates,
dictionaries or instances.
Source code is available on github:
* https://github.com/oisinmulvihill/boaconstructor
Documentation is available here:
* http://packages.python.org/boaconstructor
An Example
----------
I'll let the code and comments do the talking::
from boaconstructor import Template
# Some shared information in a dict. This could also be a class instance
# or something else that supports getattr and hasattr.
#
common = dict(
timeout = 30,
email = "admin@example.com"
)
# This is a template created in a module. You need one of these. I pass in
# references that are available at this stage. The 'host.$.name' I will pass
# in at render time.
#
webserver_data = Template('webserver',
dict(
interface = 'host.$.name',
port = 32189,
timeout = 'common.$.timeout',
alert_email = 'common.$.email',
),
# This is uses common as an 'internal' reference
references={'common':common}
)
# At run time I can pass 'external' references to resolve the hostnames.
# Maybe I got these from a database or some other source.
#
machine_1 = webserver_data.render({'host': {'name': 'myserver1'}}),
# {'alert_email': 'admin@example.com', 'interface': 'myserver1', 'port': 32189, 'timeout': 30}
machine_2 = webserver_data.render({'host': {'name': 'myserver2'}}),
# {'alert_email': 'admin@example.com', 'interface': 'myserver2', 'port': 32189, 'timeout': 30}
# Now I can pass these to Cheetah/Mako/etc to render a specific type of
# XML/INI/Text configuration files.
نحوه نصب
نصب پکیج whl boaconstructor-0.3.0:
pip install boaconstructor-0.3.0.whl
نصب پکیج tar.gz boaconstructor-0.3.0:
pip install boaconstructor-0.3.0.tar.gz