django-safe-template-engine 1.0.0__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,16 @@
1
+ from django.template.engine import Engine
2
+
3
+
4
+ class SafeTemplateEngine(Engine):
5
+
6
+ def __init__(self, **kwargs):
7
+ self.default_builtins = [
8
+ 'django_safe_template_engine.trusted_filters',
9
+ 'django_safe_template_engine.trusted_tags',
10
+ ]
11
+
12
+ super().__init__(**kwargs)
13
+
14
+ self.dirs = []
15
+ self.app_dirs = False
16
+ self.loaders = []
@@ -0,0 +1,72 @@
1
+ from django.template.defaultfilters import (
2
+ add, addslashes, capfirst, center, cut, date, default, default_if_none,
3
+ dictsort, dictsortreversed, divisibleby, escape_filter, escapejs_filter,
4
+ filesizeformat, first, floatformat, force_escape, get_digit, iriencode,
5
+ join, json_script, last, length, length_is, linebreaks_filter,
6
+ linebreaksbr, linenumbers, ljust, lower, make_list, phone2numeric_filter,
7
+ pluralize, random, rjust, safe, safeseq, slice_filter, slugify,
8
+ stringformat, striptags, time, timesince_filter, timeuntil_filter, title,
9
+ truncatechars, truncatechars_html, truncatewords, truncatewords_html,
10
+ unordered_list, upper, urlencode, urlize, urlizetrunc, wordcount, wordwrap,
11
+ yesno,
12
+ )
13
+ from django.template.library import Library
14
+
15
+ register = Library()
16
+
17
+ register.filter(addslashes, is_safe=True)
18
+ register.filter(capfirst, is_safe=True)
19
+ register.filter('escapejs', escapejs_filter)
20
+ register.filter(json_script, is_safe=True)
21
+ register.filter(floatformat, is_safe=True)
22
+ register.filter(iriencode, is_safe=True)
23
+ register.filter(linenumbers, is_safe=True, needs_autoescape=True)
24
+ register.filter(lower, is_safe=True)
25
+ register.filter(make_list, is_safe=False)
26
+ register.filter(slugify, is_safe=True)
27
+ register.filter(stringformat, is_safe=True)
28
+ register.filter(title, is_safe=True)
29
+ register.filter(truncatechars, is_safe=True)
30
+ register.filter(truncatechars_html, is_safe=True)
31
+ register.filter(truncatewords, is_safe=True)
32
+ register.filter(truncatewords_html, is_safe=True)
33
+ register.filter(upper, is_safe=False)
34
+ register.filter(urlencode, is_safe=False)
35
+ register.filter(urlize, is_safe=True, needs_autoescape=True)
36
+ register.filter(urlizetrunc, is_safe=True, needs_autoescape=True)
37
+ register.filter(wordcount, is_safe=False)
38
+ register.filter(wordwrap, is_safe=True)
39
+ register.filter(ljust, is_safe=True)
40
+ register.filter(rjust, is_safe=True)
41
+ register.filter(center, is_safe=True)
42
+ register.filter(cut)
43
+ register.filter('escape', escape_filter, is_safe=True)
44
+ register.filter(force_escape, is_safe=True)
45
+ register.filter('linebreaks', linebreaks_filter, is_safe=True, needs_autoescape=True)
46
+ register.filter(linebreaksbr, is_safe=True, needs_autoescape=True)
47
+ register.filter(safe, is_safe=True)
48
+ register.filter(safeseq, is_safe=True)
49
+ register.filter(striptags, is_safe=True)
50
+ register.filter(dictsort, is_safe=False)
51
+ register.filter(dictsortreversed, is_safe=False)
52
+ register.filter(first, is_safe=False)
53
+ register.filter(join, is_safe=True, needs_autoescape=True)
54
+ register.filter(last, is_safe=True)
55
+ register.filter(length, is_safe=False)
56
+ register.filter(length_is, is_safe=False)
57
+ register.filter(random, is_safe=True)
58
+ register.filter('slice', slice_filter, is_safe=True)
59
+ register.filter(unordered_list, is_safe=True, needs_autoescape=True)
60
+ register.filter(add, is_safe=False)
61
+ register.filter(get_digit, is_safe=False)
62
+ register.filter(date, expects_localtime=True, is_safe=False)
63
+ register.filter(time, expects_localtime=True, is_safe=False)
64
+ register.filter('timesince', timesince_filter, is_safe=False)
65
+ register.filter('timeuntil', timeuntil_filter, is_safe=False)
66
+ register.filter(default, is_safe=False)
67
+ register.filter(default_if_none, is_safe=False)
68
+ register.filter(divisibleby, is_safe=False)
69
+ register.filter(yesno, is_safe=False)
70
+ register.filter(filesizeformat, is_safe=True)
71
+ register.filter(pluralize, is_safe=False)
72
+ register.filter('phone2numeric', phone2numeric_filter, is_safe=True)
@@ -0,0 +1,27 @@
1
+ from django.template.defaulttags import (
2
+ autoescape, comment, cycle, do_filter, do_for, do_if, do_with, firstof,
3
+ ifchanged, lorem, now, regroup, resetcycle, spaceless, templatetag, url,
4
+ verbatim, widthratio,
5
+ )
6
+ from django.template.library import Library
7
+
8
+ register = Library()
9
+
10
+ register.tag(autoescape)
11
+ register.tag(comment)
12
+ register.tag(cycle)
13
+ register.tag('filter', do_filter)
14
+ register.tag(firstof)
15
+ register.tag('for', do_for)
16
+ register.tag('if', do_if)
17
+ register.tag(ifchanged)
18
+ register.tag(lorem)
19
+ register.tag(now)
20
+ register.tag(regroup)
21
+ register.tag(resetcycle)
22
+ register.tag(spaceless)
23
+ register.tag(templatetag)
24
+ register.tag(url)
25
+ register.tag(verbatim)
26
+ register.tag(widthratio)
27
+ register.tag('with', do_with)
@@ -0,0 +1,11 @@
1
+ from django.core.exceptions import ValidationError
2
+ from django.template import Template, TemplateSyntaxError
3
+
4
+ from django_safe_template_engine.engine import SafeTemplateEngine
5
+
6
+
7
+ def validate_safe_engine_template_syntax(source):
8
+ try:
9
+ Template(source, engine=SafeTemplateEngine())
10
+ except (TemplateSyntaxError) as err:
11
+ raise ValidationError(str(err))
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.3
2
+ Name: django_safe_template_engine
3
+ Version: 1.0.0
4
+ Summary: A Django template engine to render untrusted template code
5
+ Project-URL: Homepage, https://github.com/ronanboiteau/django_safe_template_engine
6
+ Project-URL: Documentation, https://github.com/ronanboiteau/django_safe_template_engine/blob/main/README.md
7
+ Project-URL: Repository, https://github.com/ronanboiteau/django_safe_template_engine.git
8
+ Project-URL: Issues, https://github.com/ronanboiteau/django_safe_template_engine/issues
9
+ Project-URL: Changelog, https://github.com/ronanboiteau/django_safe_template_engine/blob/main/CHANGELOG.md
10
+ Author-email: Ronan Boiteau <ronan@boiteau.eu>
11
+ Maintainer-email: Ronan Boiteau <ronan@boiteau.eu>
12
+ License: BSD 3-Clause License
13
+
14
+ Copyright (c) 2023, GuestReady
15
+
16
+ Redistribution and use in source and binary forms, with or without
17
+ modification, are permitted provided that the following conditions are met:
18
+
19
+ 1. Redistributions of source code must retain the above copyright notice, this
20
+ list of conditions and the following disclaimer.
21
+
22
+ 2. Redistributions in binary form must reproduce the above copyright notice,
23
+ this list of conditions and the following disclaimer in the documentation
24
+ and/or other materials provided with the distribution.
25
+
26
+ 3. Neither the name of the copyright holder nor the names of its
27
+ contributors may be used to endorse or promote products derived from
28
+ this software without specific prior written permission.
29
+
30
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
34
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
+ License-File: LICENSE
41
+ Keywords: django,engine,safe,template
42
+ Classifier: License :: OSI Approved :: BSD License
43
+ Classifier: Operating System :: OS Independent
44
+ Classifier: Programming Language :: Python :: 3
45
+ Requires-Python: >=3.8
46
+ Requires-Dist: django<3.1,>=3
47
+ Description-Content-Type: text/markdown
48
+
49
+ ![GitHub Actions build status](https://github.com/guestready/django_safe_template_engine/actions/workflows/build.yml/badge.svg?branch=main)
50
+
51
+ # Django Safe Template Engine
52
+
53
+ Django template engine to render untrusted template code
54
+
55
+ ## Requirements
56
+
57
+ - Python 3.8 to 3.11
58
+ - Django 3.0
59
+
60
+ ## Available tools
61
+
62
+ Template engine:
63
+
64
+ ```py
65
+ from django.template import Template
66
+ from django_safe_template_engine.engine import SafeTemplateEngine
67
+
68
+ safe_engine = SafeTemplateEngine()
69
+ Template(source, engine=safe_engine)
70
+ ```
71
+
72
+ Validator:
73
+
74
+ ```py
75
+ from django_safe_template_engine.validators import validate_safe_engine_template_syntax
76
+
77
+ template_code = '{% include "hacked.html" %}'
78
+ validate_safe_engine_template_syntax(template_code)
79
+ ```
80
+
81
+ ## Trusted built-ins
82
+
83
+ The following tags and filters are allowed by this template engine.
84
+
85
+ ### Trusted tags
86
+
87
+ - [`autoescape`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape)
88
+ - [`comment`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#comment)
89
+ - [`cycle`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#cycle)
90
+ - [`filter`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#filter)
91
+ - [`firstof`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#firstof)
92
+ - [`for`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for)
93
+ - [`for … empty`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for-empty)
94
+ - [`if`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#if)
95
+ - [`ifchanged`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifchanged)
96
+ - [`lorem`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#lorem)
97
+ - [`now`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#now)
98
+ - [`regroup`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup)
99
+ - [`resetcycle`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#resetcycle)
100
+ - [`spaceless`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#spaceless)
101
+ - [`templatetag`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag)
102
+ - [`url`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url)
103
+ - [`verbatim`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#verbatim)
104
+ - [`widthratio`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#widthratio)
105
+ - [`with`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#with)
106
+
107
+ ### Trusted filters
108
+
109
+ <!-- TODO: Check for dead links -->
110
+ <!-- TODO: Re-order? -->
111
+ - [`addslashes`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#addslashes)
112
+ - [`capfirst`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#capfirst)
113
+ - [`escapejs`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs)
114
+ - [`json_script`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#json_script)
115
+ - [`floatformat`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#floatformat)
116
+ - [`iriencode`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#iriencode)
117
+ - [`linenumbers`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#linenumbers)
118
+ - [`lower`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#lower)
119
+ - [`make_list`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#make_list)
120
+ - [`slugify`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#slugify)
121
+ - [`stringformat`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#stringformat)
122
+ - [`title`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#title)
123
+ - [`truncatechars`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#truncatechars)
124
+ - [`truncatechars_html`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#truncatechars_html)
125
+ - [`truncatewords`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#truncatewords)
126
+ - [`truncatewords_html`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#truncatewords_html)
127
+ - [`upper`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#upper)
128
+ - [`urlencode`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlencode)
129
+ - [`urlize`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlize)
130
+ - [`urlizetrunc`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlizetrunc)
131
+ - [`wordcount`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#wordcount)
132
+ - [`wordwrap`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#wordwrap)
133
+ - [`ljust`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#ljust)
134
+ - [`rjust`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#rjust)
135
+ - [`center`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#center)
136
+ - [`cut`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#cut)
137
+ - [`escape`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape)
138
+ - [`force_escape`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#force_escape)
139
+ - [`linebreaks`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#linebreaks)
140
+ - [`linebreaksbr`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#linebreaksbr)
141
+ - [`safe`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe)
142
+ - [`safeseq`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safeseq)
143
+ - [`striptags`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#striptags)
144
+ - [`dictsort`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#dictsort)
145
+ - [`dictsortreversed`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#dictsortreversed)
146
+ - [`first`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#first)
147
+ - [`join`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#join)
148
+ - [`last`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#last)
149
+ - [`length`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#length)
150
+ - [`length_is`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#length_is)
151
+ - [`random`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#random)
152
+ - [`slice`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#slice)
153
+ - [`unordered_list`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#unordered_list)
154
+ - [`add`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#add)
155
+ - [`get_digit`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#get_digit)
156
+ - [`date`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date)
157
+ - [`time`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#time)
158
+ - [`timesince`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#timesince)
159
+ - [`timeuntil`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#timeuntil)
160
+ - [`default`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#default)
161
+ - [`default_if_none`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#default_if_none)
162
+ - [`divisibleby`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#divisibleby)
163
+ - [`yesno`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#yesno)
164
+ - [`filesizeformat`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#filesizeformat)
165
+ - [`pluralize`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#pluralize)
166
+ - [`phone2numeric`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/#phone2numeric)
@@ -0,0 +1,9 @@
1
+ django_safe_template_engine/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ django_safe_template_engine/engine.py,sha256=2THW686FAjzkQGh7QAu1zWuzoPFySRofeIuS3RK0y5M,388
3
+ django_safe_template_engine/trusted_filters.py,sha256=sT_9cwdg4ot8TQ0Ghdyolfb-MPVTsbvk3VVV-hYeVsU,3413
4
+ django_safe_template_engine/trusted_tags.py,sha256=VFtyZTUo1EB1LvcrM1ycPN8xKgXu4XyBAlkODUoYjoo,722
5
+ django_safe_template_engine/validators.py,sha256=SYima2sJ3PvULQ7MdPZ03tuXFzKB1hx6uxMWZ3YQgVQ,372
6
+ django_safe_template_engine-1.0.0.dist-info/METADATA,sha256=ESMb4gWlOcRodfq2N_8ChlLwJPsFTXyYKFe5eoJRBoY,10196
7
+ django_safe_template_engine-1.0.0.dist-info/WHEEL,sha256=K0BPUNF1N3kQ9olb8aVEtkObePEjdr2JOLT1N83EVws,87
8
+ django_safe_template_engine-1.0.0.dist-info/licenses/LICENSE,sha256=oyFQJQVffHM_hYM8U0pjee7NGRzEcE8a_pagH6EvKQc,1497
9
+ django_safe_template_engine-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.24.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, GuestReady
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.