Skip to content
Snippets Groups Projects
Commit d88ddd1c authored by nimrod's avatar nimrod
Browse files

Merge branch 'feature/toml'

parents 00a42412 909569c2
Branches
Tags
No related merge requests found
......@@ -45,6 +45,8 @@ The following Jinja filters were added:
- :code:`from_json`: Convert from json.
- :code:`pprint`: Pretty print variable.
- :code:`combine`: Combine 2 dictionaries.
- :code:`to_toml`: Convert to toml.
- :code:`from_toml`: Convert from toml.
- :code:`jmespath`: Queries data using the `JMESPath <http://jmespath.org/>`_
query language.
......@@ -87,4 +89,3 @@ TODO
- Release on tagged commits to PyPI in Travis CI
(https://docs.travis-ci.com/user/deployment/pypi/ and
https://docs.travis-ci.com/user/encryption-keys/).
- Add TOML support?
......@@ -21,7 +21,7 @@ setup(
],
keywords='config configuration jinja template environment',
packages=find_packages(),
install_requires=['Jinja2', 'PyYAML', 'jmespath'],
install_requires=['Jinja2', 'PyYAML', 'jmespath', 'toml'],
extras_require={
'dev': ['tox'], },
entry_points={
......
......@@ -104,6 +104,29 @@ def combine(default, override):
return combined
def from_toml(value):
'''
Returns a data structure from the TOML string given.
Examples:
>>> from_toml('[table]\\nkey = "value"\\n') == {'table': {'key': 'value'}}
True
'''
from toml import loads
return loads(value)
def to_toml(value):
'''
Returns a string of the TOML representation for the data structure given.
Examples:
>>> import six
>>> to_toml({'key': [1, 2]}) == six.text_type("key = [ 1, 2,]\\n")
True
'''
from toml import dumps
return dumps(value)
def jmespath(value, query):
'''
Queries the data using the JMESPath query language.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment