jinja2-eval 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+
2
+ Creative Commons Legal Code
3
+
4
+ CC0 1.0 Universal
5
+
6
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
7
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
8
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
9
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
10
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
11
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
12
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
13
+ HEREUNDER.
14
+
15
+ Statement of Purpose
16
+
17
+ The laws of most jurisdictions throughout the world automatically confer
18
+ exclusive Copyright and Related Rights (defined below) upon the creator
19
+ and subsequent owner(s) (each and all, an "owner") of an original work of
20
+ authorship and/or a database (each, a "Work").
21
+
22
+ Certain owners wish to permanently relinquish those rights to a Work for
23
+ the purpose of contributing to a commons of creative, cultural and
24
+ scientific works ("Commons") that the public can reliably and without fear
25
+ of later claims of infringement build upon, modify, incorporate in other
26
+ works, reuse and redistribute as freely as possible in any form whatsoever
27
+ and for any purposes, including without limitation commercial purposes.
28
+ These owners may contribute to the Commons to promote the ideal of a free
29
+ culture and the further production of creative, cultural and scientific
30
+ works, or to gain reputation or greater distribution for their Work in
31
+ part through the use and efforts of others.
32
+
33
+ For these and/or other purposes and motivations, and without any
34
+ expectation of additional consideration or compensation, the person
35
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
36
+ is an owner of Copyright and Related Rights in the Work, voluntarily
37
+ elects to apply CC0 to the Work and publicly distribute the Work under its
38
+ terms, with knowledge of his or her Copyright and Related Rights in the
39
+ Work and the meaning and intended legal effect of CC0 on those rights.
40
+
41
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
42
+ protected by copyright and related or neighboring rights ("Copyright and
43
+ Related Rights"). Copyright and Related Rights include, but are not
44
+ limited to, the following:
45
+
46
+ i. the right to reproduce, adapt, distribute, perform, display,
47
+ communicate, and translate a Work;
48
+ ii. moral rights retained by the original author(s) and/or performer(s);
49
+ iii. publicity and privacy rights pertaining to a person's image or
50
+ likeness depicted in a Work;
51
+ iv. rights protecting against unfair competition in regards to a Work,
52
+ subject to the limitations in paragraph 4(a), below;
53
+ v. rights protecting the extraction, dissemination, use and reuse of data
54
+ in a Work;
55
+ vi. database rights (such as those arising under Directive 96/9/EC of the
56
+ European Parliament and of the Council of 11 March 1996 on the legal
57
+ protection of databases, and under any national implementation
58
+ thereof, including any amended or successor version of such
59
+ directive); and
60
+ vii. other similar, equivalent or corresponding rights throughout the
61
+ world based on applicable law or treaty, and any national
62
+ implementations thereof.
63
+
64
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
65
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
66
+ irrevocably and unconditionally waives, abandons, and surrenders all of
67
+ Affirmer's Copyright and Related Rights and associated claims and causes
68
+ of action, whether now known or unknown (including existing as well as
69
+ future claims and causes of action), in the Work (i) in all territories
70
+ worldwide, (ii) for the maximum duration provided by applicable law or
71
+ treaty (including future time extensions), (iii) in any current or future
72
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
73
+ including without limitation commercial, advertising or promotional
74
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
75
+ member of the public at large and to the detriment of Affirmer's heirs and
76
+ successors, fully intending that such Waiver shall not be subject to
77
+ revocation, rescission, cancellation, termination, or any other legal or
78
+ equitable action to disrupt the quiet enjoyment of the Work by the public
79
+ as contemplated by Affirmer's express Statement of Purpose.
80
+
81
+ 3. Public License Fallback. Should any part of the Waiver for any reason
82
+ be judged legally invalid or ineffective under applicable law, then the
83
+ Waiver shall be preserved to the maximum extent permitted taking into
84
+ account Affirmer's express Statement of Purpose. In addition, to the
85
+ extent the Waiver is so judged Affirmer hereby grants to each affected
86
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
87
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
88
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
89
+ maximum duration provided by applicable law or treaty (including future
90
+ time extensions), (iii) in any current or future medium and for any number
91
+ of copies, and (iv) for any purpose whatsoever, including without
92
+ limitation commercial, advertising or promotional purposes (the
93
+ "License"). The License shall be deemed effective as of the date CC0 was
94
+ applied by Affirmer to the Work. Should any part of the License for any
95
+ reason be judged legally invalid or ineffective under applicable law, such
96
+ partial invalidity or ineffectiveness shall not invalidate the remainder
97
+ of the License, and in such case Affirmer hereby affirms that he or she
98
+ will not (i) exercise any of his or her remaining Copyright and Related
99
+ Rights in the Work or (ii) assert any associated claims and causes of
100
+ action with respect to the Work, in either case contrary to Affirmer's
101
+ express Statement of Purpose.
102
+
103
+ 4. Limitations and Disclaimers.
104
+
105
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
106
+ surrendered, licensed or otherwise affected by this document.
107
+ b. Affirmer offers the Work as-is and makes no representations or
108
+ warranties of any kind concerning the Work, express, implied,
109
+ statutory or otherwise, including without limitation warranties of
110
+ title, merchantability, fitness for a particular purpose, non
111
+ infringement, or the absence of latent or other defects, accuracy, or
112
+ the present or absence of errors, whether or not discoverable, all to
113
+ the greatest extent permissible under applicable law.
114
+ c. Affirmer disclaims responsibility for clearing rights of other persons
115
+ that may apply to the Work or any use thereof, including without
116
+ limitation any person's Copyright and Related Rights in the Work.
117
+ Further, Affirmer disclaims responsibility for obtaining any necessary
118
+ consents, permissions or other rights required for any use of the
119
+ Work.
120
+ d. Affirmer understands and acknowledges that Creative Commons is not a
121
+ party to this document and has no duty or obligation with respect to
122
+ this CC0 or use of the Work.
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.1
2
+ Name: jinja2-eval
3
+ Version: 0.1.0
4
+ Summary: Jinja2 Extension for getting eval() result.
5
+ Home-page: https://github.com/34j/jinja2-eval
6
+ License: CC0 1.0 Universal
7
+ Author: 34j
8
+ Author-email: 34j.95a2p@simplelogin.com
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: Other/Proprietary License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Dist: jinja2
22
+ Project-URL: Bug Tracker, https://github.com/34j/jinja2-eval/issues
23
+ Project-URL: Changelog, https://github.com/34j/jinja2-eval/blob/main/CHANGELOG.md
24
+ Project-URL: Documentation, https://jinja2-eval.readthedocs.io
25
+ Project-URL: Repository, https://github.com/34j/jinja2-eval
26
+ Description-Content-Type: text/markdown
27
+
28
+ # jinja2-eval
29
+
30
+ <p align="center">
31
+ <a href="https://github.com/34j/jinja2-eval/actions/workflows/ci.yml?query=branch%3Amain">
32
+ <img src="https://img.shields.io/github/actions/workflow/status/34j/jinja2-eval/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >
33
+ </a>
34
+ <a href="https://jinja2-eval.readthedocs.io">
35
+ <img src="https://img.shields.io/readthedocs/jinja2-eval.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
36
+ </a>
37
+ <a href="https://codecov.io/gh/34j/jinja2-eval">
38
+ <img src="https://img.shields.io/codecov/c/github/34j/jinja2-eval.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
39
+ </a>
40
+ </p>
41
+ <p align="center">
42
+ <a href="https://python-poetry.org/">
43
+ <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">
44
+ </a>
45
+ <a href="https://github.com/ambv/black">
46
+ <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">
47
+ </a>
48
+ <a href="https://github.com/pre-commit/pre-commit">
49
+ <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
50
+ </a>
51
+ </p>
52
+ <p align="center">
53
+ <a href="https://pypi.org/project/jinja2-eval/">
54
+ <img src="https://img.shields.io/pypi/v/jinja2-eval.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
55
+ </a>
56
+ <img src="https://img.shields.io/pypi/pyversions/jinja2-eval.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
57
+ <img src="https://img.shields.io/pypi/l/jinja2-eval.svg?style=flat-square" alt="License">
58
+ </p>
59
+
60
+ Jinja2 Extension for getting `eval()` result.
61
+
62
+ ## Installation
63
+
64
+ Install this via pip (or your favourite package manager):
65
+
66
+ ```shell
67
+ pip install jinja2-eval
68
+ ```
69
+
70
+ ## Usage
71
+
72
+ Basic usage:
73
+
74
+ ```jinja2
75
+ {% eval "1 + 1" %}
76
+ {{ "1 + 1" | eval }}
77
+ ```
78
+
79
+ ```text
80
+ 2
81
+ 2
82
+ ```
83
+
84
+ Importing modules:
85
+
86
+ ```jinja2
87
+ {% eval "exec('import math') or math.pi" %}
88
+ {{ "exec('import math') or math.pi" | eval }}
89
+ ```
90
+
91
+ ```text
92
+ 3.141592653589793
93
+ 3.141592653589793
94
+ ```
95
+
96
+ ## Contributors ✨
97
+
98
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
99
+
100
+ <!-- prettier-ignore-start -->
101
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
102
+ <!-- prettier-ignore-start -->
103
+ <!-- markdownlint-disable -->
104
+ <table>
105
+ <tbody>
106
+ <tr>
107
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/34j"><img src="https://avatars.githubusercontent.com/u/55338215?v=4?s=80" width="80px;" alt="34j"/><br /><sub><b>34j</b></sub></a><br /><a href="https://github.com/34j/jinja2-eval/commits?author=34j" title="Code">💻</a> <a href="#ideas-34j" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/34j/jinja2-eval/commits?author=34j" title="Documentation">📖</a></td>
108
+ </tr>
109
+ </tbody>
110
+ </table>
111
+
112
+ <!-- markdownlint-restore -->
113
+ <!-- prettier-ignore-end -->
114
+
115
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
116
+ <!-- prettier-ignore-end -->
117
+
118
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
119
+
@@ -0,0 +1,91 @@
1
+ # jinja2-eval
2
+
3
+ <p align="center">
4
+ <a href="https://github.com/34j/jinja2-eval/actions/workflows/ci.yml?query=branch%3Amain">
5
+ <img src="https://img.shields.io/github/actions/workflow/status/34j/jinja2-eval/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >
6
+ </a>
7
+ <a href="https://jinja2-eval.readthedocs.io">
8
+ <img src="https://img.shields.io/readthedocs/jinja2-eval.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
9
+ </a>
10
+ <a href="https://codecov.io/gh/34j/jinja2-eval">
11
+ <img src="https://img.shields.io/codecov/c/github/34j/jinja2-eval.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
12
+ </a>
13
+ </p>
14
+ <p align="center">
15
+ <a href="https://python-poetry.org/">
16
+ <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">
17
+ </a>
18
+ <a href="https://github.com/ambv/black">
19
+ <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">
20
+ </a>
21
+ <a href="https://github.com/pre-commit/pre-commit">
22
+ <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
23
+ </a>
24
+ </p>
25
+ <p align="center">
26
+ <a href="https://pypi.org/project/jinja2-eval/">
27
+ <img src="https://img.shields.io/pypi/v/jinja2-eval.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
28
+ </a>
29
+ <img src="https://img.shields.io/pypi/pyversions/jinja2-eval.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
30
+ <img src="https://img.shields.io/pypi/l/jinja2-eval.svg?style=flat-square" alt="License">
31
+ </p>
32
+
33
+ Jinja2 Extension for getting `eval()` result.
34
+
35
+ ## Installation
36
+
37
+ Install this via pip (or your favourite package manager):
38
+
39
+ ```shell
40
+ pip install jinja2-eval
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ Basic usage:
46
+
47
+ ```jinja2
48
+ {% eval "1 + 1" %}
49
+ {{ "1 + 1" | eval }}
50
+ ```
51
+
52
+ ```text
53
+ 2
54
+ 2
55
+ ```
56
+
57
+ Importing modules:
58
+
59
+ ```jinja2
60
+ {% eval "exec('import math') or math.pi" %}
61
+ {{ "exec('import math') or math.pi" | eval }}
62
+ ```
63
+
64
+ ```text
65
+ 3.141592653589793
66
+ 3.141592653589793
67
+ ```
68
+
69
+ ## Contributors ✨
70
+
71
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
72
+
73
+ <!-- prettier-ignore-start -->
74
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
75
+ <!-- prettier-ignore-start -->
76
+ <!-- markdownlint-disable -->
77
+ <table>
78
+ <tbody>
79
+ <tr>
80
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/34j"><img src="https://avatars.githubusercontent.com/u/55338215?v=4?s=80" width="80px;" alt="34j"/><br /><sub><b>34j</b></sub></a><br /><a href="https://github.com/34j/jinja2-eval/commits?author=34j" title="Code">💻</a> <a href="#ideas-34j" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/34j/jinja2-eval/commits?author=34j" title="Documentation">📖</a></td>
81
+ </tr>
82
+ </tbody>
83
+ </table>
84
+
85
+ <!-- markdownlint-restore -->
86
+ <!-- prettier-ignore-end -->
87
+
88
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
89
+ <!-- prettier-ignore-end -->
90
+
91
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
@@ -0,0 +1,107 @@
1
+ [tool.poetry]
2
+ name = "jinja2-eval"
3
+ version = "0.1.0"
4
+ description = "Jinja2 Extension for getting eval() result."
5
+ authors = ["34j <34j.95a2p@simplelogin.com>"]
6
+ license = "CC0 1.0 Universal"
7
+ readme = "README.md"
8
+ repository = "https://github.com/34j/jinja2-eval"
9
+ documentation = "https://jinja2-eval.readthedocs.io"
10
+ classifiers = [
11
+ "Development Status :: 2 - Pre-Alpha",
12
+ "Intended Audience :: Developers",
13
+ "Natural Language :: English",
14
+ "Operating System :: OS Independent",
15
+ "Topic :: Software Development :: Libraries",
16
+ ]
17
+ packages = [
18
+ { include = "jinja2_eval", from = "src" },
19
+ ]
20
+
21
+ [tool.poetry.urls]
22
+ "Bug Tracker" = "https://github.com/34j/jinja2-eval/issues"
23
+ "Changelog" = "https://github.com/34j/jinja2-eval/blob/main/CHANGELOG.md"
24
+
25
+ [tool.poetry.dependencies]
26
+ python = "^3.8"
27
+ jinja2 = "*"
28
+
29
+ [tool.poetry.group.dev.dependencies]
30
+ pre-commit = ">=3"
31
+ pytest = "^7.0"
32
+ pytest-cov = "^3.0"
33
+ parameterized = "^0.9.0"
34
+
35
+ [tool.poetry.group.docs]
36
+ optional = true
37
+
38
+ [tool.poetry.group.docs.dependencies]
39
+ myst-parser = ">=0.16"
40
+ sphinx = ">=4.0"
41
+ sphinx-rtd-theme = ">=1.0"
42
+
43
+ [tool.semantic_release]
44
+ branch = "main"
45
+ version_toml = ["pyproject.toml:tool.poetry.version"]
46
+ version_variable = "src/jinja2_eval/__init__.py:__version__"
47
+ build_command = "pip install poetry && poetry build"
48
+
49
+ [tool.semantic_release.changelog]
50
+ exclude_commit_patterns = [
51
+ "chore*",
52
+ "ci*",
53
+ ]
54
+
55
+ [tool.semantic_release.changelog.environment]
56
+ keep_trailing_newline = true
57
+
58
+ [tool.pytest.ini_options]
59
+ addopts = "-v -Wdefault --cov=jinja2_eval --cov-report=term-missing:skip-covered"
60
+ pythonpath = ["src"]
61
+
62
+ [tool.coverage.run]
63
+ branch = true
64
+
65
+ [tool.coverage.report]
66
+ exclude_lines = [
67
+ "pragma: no cover",
68
+ "@overload",
69
+ "if TYPE_CHECKING",
70
+ "raise NotImplementedError",
71
+ 'if __name__ == "__main__":',
72
+ ]
73
+
74
+ [tool.isort]
75
+ profile = "black"
76
+ known_first_party = ["jinja2_eval", "tests"]
77
+
78
+ [tool.autoflake]
79
+ expand_star_imports = true
80
+ remove_all_unused_imports = true
81
+
82
+ [tool.mypy]
83
+ check_untyped_defs = true
84
+ disallow_any_generics = true
85
+ disallow_incomplete_defs = true
86
+ disallow_untyped_defs = true
87
+ mypy_path = "src/"
88
+ no_implicit_optional = true
89
+ show_error_codes = true
90
+ warn_unreachable = true
91
+ warn_unused_ignores = true
92
+ exclude = [
93
+ 'docs/.*',
94
+ 'setup.py',
95
+ ]
96
+
97
+ [[tool.mypy.overrides]]
98
+ module = "tests.*"
99
+ allow_untyped_defs = true
100
+
101
+ [[tool.mypy.overrides]]
102
+ module = "docs.*"
103
+ ignore_errors = true
104
+
105
+ [build-system]
106
+ requires = ["poetry-core>=1.0.0"]
107
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,4 @@
1
+ __version__ = "0.0.0"
2
+ from ._main import EvalExtension
3
+
4
+ __all__ = ["EvalExtension"]
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Mapping
4
+
5
+ from jinja2 import Environment, nodes
6
+ from jinja2.ext import Extension
7
+ from jinja2.parser import Parser
8
+
9
+
10
+ class EvalExtension(Extension):
11
+ """Jinja2 extension to evaluate expressions and statements."""
12
+
13
+ tags = {"eval"}
14
+ """A set of names that trigger the extension."""
15
+
16
+ def __init__(self, environment: Environment) -> None:
17
+ super().__init__(environment)
18
+ environment.filters["eval"] = eval # nosec
19
+
20
+ def parse(self, parser: Parser) -> nodes.Output:
21
+ lineno = next(parser.stream).lineno
22
+
23
+ __source = parser.parse_expression()
24
+
25
+ if parser.stream.skip_if("comma"):
26
+ __globals = parser.parse_expression()
27
+ else:
28
+ __globals = nodes.Const(None)
29
+
30
+ if parser.stream.skip_if("comma"):
31
+ __locals = parser.parse_expression()
32
+ else:
33
+ __locals = nodes.Const(None)
34
+
35
+ return nodes.Output(
36
+ [self.call_method("_eval", [__source, __globals, __locals])], lineno=lineno
37
+ )
38
+
39
+ def _eval(
40
+ self,
41
+ __source: str,
42
+ __globals: dict[str, Any] | None = None,
43
+ __locals: Mapping[str, object] | None = None,
44
+ ) -> str:
45
+ return eval(__source, __globals, __locals) # nosec
File without changes