python-liquid 2.3.6__py3-none-any.whl → 3.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.
Files changed (212) hide show
  1. liquid/__about__.py +1 -0
  2. liquid/__init__.py +161 -187
  3. liquid/_base_tag.py +66 -0
  4. liquid/{utils/chain_map.py → _chain_map.py} +18 -19
  5. liquid/_context.py +465 -0
  6. liquid/_drop.py +108 -0
  7. liquid/_filter.py +174 -0
  8. liquid/_io.py +18 -0
  9. liquid/_lax_parser_mixin.py +100 -0
  10. liquid/_lexer.py +93 -0
  11. liquid/_lexer_extended.py +623 -0
  12. liquid/_lexer_legacy.py +536 -0
  13. liquid/_loader.py +84 -0
  14. liquid/{utils/lru_cache.py → _lru_cache.py} +28 -36
  15. liquid/_markup.py +253 -0
  16. liquid/_messages.py +292 -0
  17. liquid/_missing.py +3 -0
  18. liquid/_nothing.py +28 -0
  19. liquid/_parser.py +460 -0
  20. liquid/_parser_extended.py +293 -0
  21. liquid/_parser_legacy.py +819 -0
  22. liquid/_resource_limits.py +50 -0
  23. liquid/_slice.py +41 -0
  24. liquid/_static_analysis.py +503 -0
  25. liquid/_strftime.py +186 -0
  26. liquid/_template.py +536 -0
  27. liquid/drops/__init__.py +20 -0
  28. liquid/drops/forloop.py +78 -0
  29. liquid/drops/iterable.py +25 -0
  30. liquid/drops/range.py +76 -0
  31. liquid/drops/self_.py +45 -0
  32. liquid/drops/tablerowloop.py +142 -0
  33. liquid/drops/undefined.py +228 -0
  34. liquid/environment.py +717 -551
  35. liquid/exceptions.py +67 -214
  36. liquid/expressions.py +1184 -0
  37. liquid/filters/__init__.py +134 -0
  38. liquid/filters/abs.py +7 -0
  39. liquid/filters/append.py +5 -0
  40. liquid/filters/at_least.py +9 -0
  41. liquid/filters/at_most.py +9 -0
  42. liquid/filters/babel.py +560 -0
  43. liquid/filters/base64.py +26 -0
  44. liquid/filters/capitalize.py +5 -0
  45. liquid/filters/ceil.py +8 -0
  46. liquid/filters/compact.py +25 -0
  47. liquid/filters/concat.py +11 -0
  48. liquid/filters/date.py +27 -0
  49. liquid/filters/default.py +25 -0
  50. liquid/filters/divided_by.py +21 -0
  51. liquid/filters/downcase.py +5 -0
  52. liquid/filters/escape.py +56 -0
  53. liquid/filters/find.py +56 -0
  54. liquid/filters/first.py +19 -0
  55. liquid/filters/floor.py +8 -0
  56. liquid/filters/html.py +23 -0
  57. liquid/filters/index.py +12 -0
  58. liquid/filters/join.py +13 -0
  59. liquid/filters/json_.py +30 -0
  60. liquid/filters/last.py +17 -0
  61. liquid/filters/map.py +5 -0
  62. liquid/filters/minus.py +13 -0
  63. liquid/filters/modulo.py +18 -0
  64. liquid/filters/newline_to_br.py +16 -0
  65. liquid/filters/plus.py +13 -0
  66. liquid/filters/prepend.py +5 -0
  67. liquid/filters/reject.py +19 -0
  68. liquid/filters/remove.py +36 -0
  69. liquid/filters/replace.py +32 -0
  70. liquid/filters/reverse.py +5 -0
  71. liquid/filters/round.py +35 -0
  72. liquid/filters/size.py +25 -0
  73. liquid/filters/slice.py +39 -0
  74. liquid/filters/sort.py +148 -0
  75. liquid/filters/split.py +34 -0
  76. liquid/filters/squish.py +9 -0
  77. liquid/filters/strip.py +13 -0
  78. liquid/filters/strip_html.py +19 -0
  79. liquid/filters/strip_newlines.py +17 -0
  80. liquid/filters/sum.py +21 -0
  81. liquid/filters/times.py +13 -0
  82. liquid/filters/translate.py +380 -0
  83. liquid/filters/truncate.py +39 -0
  84. liquid/filters/uniq.py +11 -0
  85. liquid/filters/upcase.py +5 -0
  86. liquid/filters/url.py +18 -0
  87. liquid/filters/where.py +18 -0
  88. liquid/loaders/__init__.py +17 -0
  89. liquid/loaders/caching_file_system_loader.py +64 -0
  90. liquid/loaders/choice_loader.py +93 -0
  91. liquid/loaders/dict_loader.py +56 -0
  92. liquid/{builtin/loaders → loaders}/file_system_loader.py +51 -55
  93. liquid/{builtin/loaders → loaders}/mixins.py +39 -51
  94. liquid/loaders/package_loader.py +110 -0
  95. liquid/tags/__init__.py +61 -0
  96. liquid/tags/assign.py +68 -0
  97. liquid/tags/capture.py +83 -0
  98. liquid/tags/case.py +199 -0
  99. liquid/tags/comment.py +56 -0
  100. liquid/tags/cycle.py +131 -0
  101. liquid/tags/decrement.py +55 -0
  102. liquid/tags/doc.py +56 -0
  103. liquid/tags/echo.py +65 -0
  104. liquid/tags/else_.py +53 -0
  105. liquid/tags/error.py +51 -0
  106. liquid/tags/extends.py +448 -0
  107. liquid/tags/for_.py +421 -0
  108. liquid/tags/if_.py +156 -0
  109. liquid/tags/ifchanged.py +69 -0
  110. liquid/tags/include.py +223 -0
  111. liquid/tags/increment.py +55 -0
  112. liquid/tags/inline_comment.py +70 -0
  113. liquid/tags/liquid.py +56 -0
  114. liquid/tags/macro.py +281 -0
  115. liquid/tags/output.py +58 -0
  116. liquid/tags/raw.py +60 -0
  117. liquid/tags/render.py +245 -0
  118. liquid/tags/tablerow.py +254 -0
  119. liquid/tags/template_comment.py +56 -0
  120. liquid/tags/translate.py +316 -0
  121. liquid/tags/unless.py +121 -0
  122. liquid/tags/with_.py +83 -0
  123. liquid/tokens.py +370 -0
  124. {python_liquid-2.3.6.dist-info → python_liquid-3.0.0.dist-info}/METADATA +32 -39
  125. python_liquid-3.0.0.dist-info/RECORD +128 -0
  126. {python_liquid-2.3.6.dist-info → python_liquid-3.0.0.dist-info}/WHEEL +1 -1
  127. {python_liquid-2.3.6.dist-info → python_liquid-3.0.0.dist-info}/licenses/LICENSE +1 -1
  128. liquid/analyze_tags.py +0 -214
  129. liquid/ast.py +0 -252
  130. liquid/builtin/__init__.py +0 -203
  131. liquid/builtin/content.py +0 -41
  132. liquid/builtin/drops/__init__.py +0 -3
  133. liquid/builtin/drops/drops.py +0 -13
  134. liquid/builtin/expressions/__init__.py +0 -47
  135. liquid/builtin/expressions/_tokenize.py +0 -186
  136. liquid/builtin/expressions/arguments.py +0 -207
  137. liquid/builtin/expressions/filtered.py +0 -387
  138. liquid/builtin/expressions/logical.py +0 -672
  139. liquid/builtin/expressions/loop.py +0 -275
  140. liquid/builtin/expressions/path.py +0 -163
  141. liquid/builtin/expressions/primitive.py +0 -417
  142. liquid/builtin/filters/__init__.py +0 -0
  143. liquid/builtin/filters/array.py +0 -329
  144. liquid/builtin/filters/extra.py +0 -83
  145. liquid/builtin/filters/math.py +0 -129
  146. liquid/builtin/filters/misc.py +0 -137
  147. liquid/builtin/filters/string.py +0 -416
  148. liquid/builtin/illegal.py +0 -28
  149. liquid/builtin/loaders/__init__.py +0 -0
  150. liquid/builtin/loaders/caching_file_system_loader.py +0 -61
  151. liquid/builtin/loaders/choice_loader.py +0 -94
  152. liquid/builtin/loaders/dict_loader.py +0 -64
  153. liquid/builtin/loaders/package_loader.py +0 -132
  154. liquid/builtin/output.py +0 -74
  155. liquid/builtin/tags/__init__.py +0 -0
  156. liquid/builtin/tags/assign_tag.py +0 -75
  157. liquid/builtin/tags/capture_tag.py +0 -98
  158. liquid/builtin/tags/case_tag.py +0 -287
  159. liquid/builtin/tags/comment_tag.py +0 -77
  160. liquid/builtin/tags/cycle_tag.py +0 -132
  161. liquid/builtin/tags/decrement_tag.py +0 -59
  162. liquid/builtin/tags/doc_tag.py +0 -68
  163. liquid/builtin/tags/echo_tag.py +0 -45
  164. liquid/builtin/tags/for_tag.py +0 -337
  165. liquid/builtin/tags/if_tag.py +0 -209
  166. liquid/builtin/tags/ifchanged_tag.py +0 -94
  167. liquid/builtin/tags/include_tag.py +0 -251
  168. liquid/builtin/tags/increment_tag.py +0 -60
  169. liquid/builtin/tags/inline_comment_tag.py +0 -47
  170. liquid/builtin/tags/liquid_tag.py +0 -183
  171. liquid/builtin/tags/render_tag.py +0 -371
  172. liquid/builtin/tags/tablerow_tag.py +0 -320
  173. liquid/builtin/tags/unless_tag.py +0 -218
  174. liquid/context.py +0 -615
  175. liquid/expression.py +0 -41
  176. liquid/extra/__init__.py +0 -98
  177. liquid/extra/filters/__init__.py +0 -33
  178. liquid/extra/filters/_json.py +0 -33
  179. liquid/extra/filters/array.py +0 -60
  180. liquid/extra/filters/babel.py +0 -552
  181. liquid/extra/filters/html.py +0 -32
  182. liquid/extra/filters/translate.py +0 -448
  183. liquid/extra/tags/__init__.py +0 -17
  184. liquid/extra/tags/_with.py +0 -80
  185. liquid/extra/tags/extends_tag.py +0 -576
  186. liquid/extra/tags/macro_tag.py +0 -270
  187. liquid/extra/tags/snippet_tag.py +0 -107
  188. liquid/extra/tags/translate_tag.py +0 -388
  189. liquid/filter.py +0 -230
  190. liquid/future/__init__.py +0 -3
  191. liquid/future/environment.py +0 -30
  192. liquid/future/filters/__init__.py +0 -1
  193. liquid/future/tags/__init__.py +0 -1
  194. liquid/lex.py +0 -260
  195. liquid/limits.py +0 -66
  196. liquid/loader.py +0 -141
  197. liquid/messages.py +0 -357
  198. liquid/mode.py +0 -12
  199. liquid/output.py +0 -35
  200. liquid/parser.py +0 -119
  201. liquid/span.py +0 -35
  202. liquid/static_analysis.py +0 -443
  203. liquid/stream.py +0 -148
  204. liquid/stringify.py +0 -31
  205. liquid/tag.py +0 -47
  206. liquid/template.py +0 -658
  207. liquid/token.py +0 -145
  208. liquid/undefined.py +0 -218
  209. liquid/utils/__init__.py +0 -15
  210. liquid/utils/html.py +0 -57
  211. liquid/utils/text.py +0 -28
  212. python_liquid-2.3.6.dist-info/RECORD +0 -96
liquid/lex.py DELETED
@@ -1,260 +0,0 @@
1
- """Tokenize Liquid templates.
2
-
3
- The template lexer generates a stream of template literals, tags, output statements and
4
- expressions, where each expression token is an unscanned string. Lexing of expression
5
- tokens is delegated to the "parse" method of each registered Tag.
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- import re
11
- from functools import lru_cache
12
- from functools import partial
13
- from typing import Callable
14
- from typing import Iterable
15
- from typing import Iterator
16
- from typing import Pattern
17
-
18
- from liquid.exceptions import LiquidSyntaxError
19
- from liquid.token import TOKEN_COMMENT
20
- from liquid.token import TOKEN_CONTENT
21
- from liquid.token import TOKEN_DOC
22
- from liquid.token import TOKEN_EOF
23
- from liquid.token import TOKEN_EXPRESSION
24
- from liquid.token import TOKEN_OUTPUT
25
- from liquid.token import TOKEN_TAG
26
- from liquid.token import Token
27
-
28
-
29
- def compile_liquid_rules(
30
- tag_start_string: str = r"{%",
31
- tag_end_string: str = r"%}",
32
- statement_start_string: str = r"{{",
33
- statement_end_string: str = r"}}",
34
- comment_start_string: str = r"",
35
- comment_end_string: str = r"",
36
- ) -> Pattern[str]:
37
- """Compile rules for lexing liquid templates."""
38
- tag_s = re.escape(tag_start_string)
39
- tag_e = re.escape(tag_end_string)
40
- stmt_s = re.escape(statement_start_string)
41
- stmt_e = re.escape(statement_end_string)
42
- comment_s = re.escape(comment_start_string)
43
- comment_e = re.escape(comment_end_string)
44
-
45
- raw_pattern = (
46
- rf"{tag_s}-?\s*raw\s*(?P<rsr>-?){tag_e}"
47
- r"(?P<raw>.*?)"
48
- rf"{tag_s}-?\s*endraw\s*(?P<rsr_e>-?){tag_e}"
49
- )
50
-
51
- doc_pattern = (
52
- rf"{tag_s}-?\s*doc\s*(?P<lsd>-?){tag_e}"
53
- r"(?P<doc>.*?)"
54
- rf"{tag_s}-?\s*enddoc\s*(?P<rsd>-?){tag_e}"
55
- )
56
-
57
- output_pattern = (
58
- rf"{stmt_s}-?\s*"
59
- rf"(?P<stmt>(?:(?!-?{stmt_e})[\s\S])*(?<!\s))\s*"
60
- rf"(?P<rss>-?){stmt_e}"
61
- )
62
-
63
- # The "name" group is zero or more characters so that a malformed tag (one
64
- # with no name) does not get treated as a literal.
65
- #
66
- # The `#` in the `name` group is specifically for the inline comment tag.
67
- tag_pattern = (
68
- rf"{tag_s}-?\s*"
69
- rf"(?P<name>#|\w+)\s*"
70
- rf"(?P<expr>(?:(?!-?{tag_e})[\s\S])*(?<!\s))\s*"
71
- rf"(?P<rst>-?){tag_e}"
72
- )
73
-
74
- if not comment_start_string:
75
- # Do not support shorthand comment syntax
76
- content_pattern = rf".+?(?=(({tag_s}|{stmt_s})(?P<rstrip>-?))|$)"
77
-
78
- liquid_rules = [
79
- ("RAW", raw_pattern),
80
- ("DOC", doc_pattern),
81
- (TOKEN_OUTPUT, output_pattern),
82
- ("TAG", tag_pattern),
83
- (TOKEN_CONTENT, content_pattern),
84
- ]
85
- else:
86
- content_pattern = rf".+?(?=(({tag_s}|{stmt_s}|{comment_s})(?P<rstrip>-?))|$)"
87
- comment_pattern = rf"{comment_s}(?P<comment>.*?)(?P<rsc>-?){comment_e}"
88
-
89
- liquid_rules = [
90
- ("RAW", raw_pattern),
91
- ("DOC", doc_pattern),
92
- ("COMMENT", comment_pattern),
93
- (TOKEN_OUTPUT, output_pattern),
94
- ("TAG", tag_pattern),
95
- (TOKEN_CONTENT, content_pattern),
96
- ]
97
-
98
- return _compile_rules(liquid_rules)
99
-
100
-
101
- def _compile_rules(rules: Iterable[tuple[str, str]]) -> Pattern[str]:
102
- """Compile the given rules into a single regular expression."""
103
- pattern = "|".join(f"(?P<{name}>{pattern})" for name, pattern in rules)
104
- return re.compile(pattern, re.DOTALL)
105
-
106
-
107
- def _tokenize_template(source: str, rules: Pattern[str]) -> Iterator[Token]: # noqa: PLR0912, PLR0915
108
- lstrip = False
109
- comment_index = 0
110
- comment_text: list[str] = []
111
- comment_depth = 0
112
-
113
- for match in rules.finditer(source):
114
- kind = match.lastgroup
115
- assert kind is not None
116
-
117
- value = match.group()
118
-
119
- if comment_depth:
120
- if kind == "TAG":
121
- name = match.group("name")
122
- if name == "endcomment":
123
- comment_depth -= 1
124
- if not comment_depth:
125
- yield Token(
126
- kind=TOKEN_COMMENT,
127
- value="".join(comment_text),
128
- start_index=comment_index,
129
- source=source,
130
- )
131
-
132
- comment_index = 0
133
- comment_text.clear()
134
-
135
- yield Token(
136
- kind=TOKEN_TAG,
137
- value=name,
138
- start_index=match.start("name"),
139
- source=source,
140
- )
141
-
142
- lstrip = bool(match.group("rst"))
143
- continue
144
- elif name == "comment":
145
- comment_depth += 1
146
-
147
- comment_text.append(value)
148
- continue
149
-
150
- if kind == TOKEN_OUTPUT:
151
- yield Token(
152
- kind=TOKEN_OUTPUT,
153
- value=match.group(),
154
- start_index=match.start(),
155
- source=source,
156
- )
157
-
158
- yield Token(
159
- TOKEN_EXPRESSION,
160
- match.group("stmt"),
161
- start_index=match.start("stmt"),
162
- source=source,
163
- )
164
-
165
- lstrip = bool(match.group("rss"))
166
- continue
167
-
168
- elif kind == "TAG":
169
- name = match.group("name")
170
- yield Token(
171
- kind=TOKEN_TAG,
172
- value=name,
173
- start_index=match.start("name"),
174
- source=source,
175
- )
176
-
177
- value = match.group("expr")
178
- lstrip = bool(match.group("rst"))
179
-
180
- if value:
181
- yield Token(
182
- kind=TOKEN_EXPRESSION,
183
- value=value,
184
- start_index=match.start("expr"),
185
- source=source,
186
- )
187
-
188
- if name == "comment":
189
- if not comment_depth:
190
- comment_index = match.end()
191
- comment_depth += 1
192
-
193
- continue
194
-
195
- elif kind == "COMMENT":
196
- lstrip = bool(match.group("rsc"))
197
- value = match.group("comment")
198
-
199
- elif kind == "RAW":
200
- kind = TOKEN_CONTENT
201
- value = match.group("raw")
202
- lstrip = bool(match.group("rsr"))
203
-
204
- elif kind == "DOC":
205
- kind = TOKEN_DOC
206
- value = match.group("doc")
207
- lstrip = bool(match.group("rsd"))
208
-
209
- elif kind == TOKEN_CONTENT:
210
- if lstrip:
211
- value = value.lstrip()
212
- if match.group("rstrip"):
213
- value = value.rstrip()
214
-
215
- if not value:
216
- continue
217
-
218
- if value.startswith(r"{{"):
219
- raise LiquidSyntaxError(
220
- "expected '}}', found end of file",
221
- token=Token(
222
- TOKEN_EOF,
223
- value=match.group(),
224
- start_index=match.start(),
225
- source=source,
226
- ),
227
- )
228
- if value.startswith(r"{%"):
229
- raise LiquidSyntaxError(
230
- "missing tag name or closing delimiter",
231
- token=Token(
232
- TOKEN_EOF,
233
- value=match.group(),
234
- start_index=match.start(),
235
- source=source,
236
- ),
237
- )
238
-
239
- yield Token(kind, value, start_index=match.start(), source=source)
240
-
241
-
242
- @lru_cache(maxsize=128)
243
- def get_lexer(
244
- tag_start_string: str = r"{%",
245
- tag_end_string: str = r"%}",
246
- statement_start_string: str = r"{{",
247
- statement_end_string: str = r"}}",
248
- comment_start_string: str = "",
249
- comment_end_string: str = "",
250
- ) -> Callable[[str], Iterator[Token]]:
251
- """Return a template lexer using the given tag and statement delimiters."""
252
- rules = compile_liquid_rules(
253
- tag_start_string,
254
- tag_end_string,
255
- statement_start_string,
256
- statement_end_string,
257
- comment_start_string,
258
- comment_end_string,
259
- )
260
- return partial(_tokenize_template, rules=rules)
liquid/limits.py DELETED
@@ -1,66 +0,0 @@
1
- """System wide limits.
2
-
3
- Ideally these limits would be configurable from a liquid.Environment, but our
4
- template parser functions, filter decorators and expression objects don't have
5
- access to an Environment. Changing that would require significant refactoring
6
- resulting in too many breaking changes.
7
- """
8
-
9
- import os
10
- import sys
11
- from typing import Any
12
-
13
- from liquid.exceptions import LiquidValueError
14
-
15
- _MIN_STR_INT = 640
16
- _DEFAULT_MAX_STR_INT = 4300
17
-
18
-
19
- def _init_int_max_str_digits() -> int:
20
- var = "LIQUIDINTMAXSTRDIGITS"
21
- env = os.environ.get(var)
22
-
23
- if env is None:
24
- if hasattr(sys, "get_int_max_str_digits"):
25
- return sys.get_int_max_str_digits() # type: ignore
26
-
27
- var = "PYTHONINTMAXSTRDIGITS"
28
- env = os.environ.get(var)
29
-
30
- if env is None:
31
- return _DEFAULT_MAX_STR_INT
32
-
33
- if not env.isdigit():
34
- raise TypeError(
35
- f"{var}: invalid limit; must be >= {_MIN_STR_INT} or 0 for unlimited"
36
- )
37
-
38
- max_digits = int(env)
39
-
40
- if max_digits == 0 or max_digits >= _MIN_STR_INT:
41
- return max_digits
42
-
43
- raise ValueError(
44
- f"{var}: invalid limit; must be >= {_MIN_STR_INT} or 0 for unlimited"
45
- )
46
-
47
-
48
- MAX_STR_INT = _init_int_max_str_digits()
49
-
50
-
51
- def to_int(val: Any) -> int:
52
- """Prevent DoS by very large str to int conversion.
53
-
54
- See https://github.com/python/cpython/issues/95778
55
- """
56
- if (
57
- isinstance(val, (str, bytes, bytearray))
58
- and MAX_STR_INT != 0
59
- and len(val) > MAX_STR_INT
60
- ):
61
- raise LiquidValueError(
62
- f"integer string conversion limit ({MAX_STR_INT}) reached: "
63
- f"value has {len(val)} digits",
64
- token=None,
65
- )
66
- return int(val)
liquid/loader.py DELETED
@@ -1,141 +0,0 @@
1
- """Base class for all template loaders."""
2
-
3
- from __future__ import annotations
4
-
5
- from abc import ABC
6
- from abc import abstractmethod
7
- from pathlib import Path
8
- from typing import TYPE_CHECKING
9
- from typing import Awaitable
10
- from typing import Callable
11
- from typing import Mapping
12
- from typing import NamedTuple
13
- from typing import Optional
14
- from typing import Union
15
-
16
- if TYPE_CHECKING:
17
- from .context import RenderContext
18
- from .environment import Environment
19
- from .template import BoundTemplate
20
-
21
-
22
- class BaseLoader(ABC):
23
- """Base class for all template loaders."""
24
-
25
- @abstractmethod
26
- def get_source(
27
- self,
28
- env: Environment,
29
- template_name: str,
30
- *,
31
- context: Optional[RenderContext] = None,
32
- **kwargs: object,
33
- ) -> TemplateSource:
34
- """Get source information for a template.
35
-
36
- Args:
37
- env: The `Environment` attempting to load the template source text.
38
- template_name: A name or identifier for a template's source text.
39
- context: An optional render context that can be used to narrow the template
40
- source search space.
41
- kwargs: Arbitrary arguments that can be used to narrow the template source
42
- search space.
43
- """
44
-
45
- async def get_source_async(
46
- self,
47
- env: Environment,
48
- template_name: str,
49
- *,
50
- context: Optional[RenderContext] = None,
51
- **kwargs: object,
52
- ) -> TemplateSource:
53
- """An async version of `get_source`.
54
-
55
- The default implementation delegates to `get_source()`.
56
- """
57
- return self.get_source(env, template_name, context=context, **kwargs)
58
-
59
- def load(
60
- self,
61
- env: Environment,
62
- name: str,
63
- *,
64
- globals: Optional[Mapping[str, object]] = None, # noqa: A002
65
- context: Optional[RenderContext] = None,
66
- **kwargs: object,
67
- ) -> BoundTemplate:
68
- """Find and parse template source code.
69
-
70
- Args:
71
- env: The `Environment` attempting to load the template source text.
72
- name: A name or identifier for a template's source text.
73
- globals: A mapping of render context variables attached to the
74
- resulting template.
75
- context: An optional render context that can be used to narrow the template
76
- source search space.
77
- kwargs: Arbitrary arguments that can be used to narrow the template source
78
- search space.
79
- """
80
- source, full_name, uptodate, matter = self.get_source(
81
- env, name, context=context, **kwargs
82
- )
83
-
84
- path = Path(full_name)
85
-
86
- template = env.from_string(
87
- source,
88
- name=path.name,
89
- path=path,
90
- globals=globals,
91
- matter=matter,
92
- )
93
-
94
- template.uptodate = uptodate
95
- return template
96
-
97
- async def load_async(
98
- self,
99
- env: Environment,
100
- name: str,
101
- *,
102
- globals: Union[Mapping[str, object], None] = None, # noqa: A002
103
- context: Union[RenderContext, None] = None,
104
- **kwargs: object,
105
- ) -> BoundTemplate:
106
- """An async version of `load()`."""
107
- source, full_name, uptodate, matter = await self.get_source_async(
108
- env, name, context=context, **kwargs
109
- )
110
-
111
- template = env.from_string(
112
- source,
113
- name=name,
114
- path=Path(full_name),
115
- globals=globals,
116
- matter=matter,
117
- )
118
-
119
- template.uptodate = uptodate
120
- return template
121
-
122
-
123
- UpToDate = Union[Callable[[], bool], Callable[[], Awaitable[bool]], None]
124
-
125
-
126
- class TemplateSource(NamedTuple):
127
- """A Liquid template source as returned by the `get_source` method of a `loader`.
128
-
129
- Attributes:
130
- text: The liquid template source code.
131
- name: The liquid template file name or other string identifying its origin.
132
- uptodate: Optional callable that will return `True` if the template is up to
133
- date, or `False` if it needs to be reloaded.
134
- matter: Optional mapping containing variables associated with the template.
135
- Could be "front matter" or other meta data.
136
- """
137
-
138
- text: str
139
- name: str
140
- uptodate: Union[Callable[[], bool], Callable[[], Awaitable[bool]], None]
141
- matter: Union[dict[str, object], None] = None