@@ -71,12 +71,12 @@ def safe_html(value: Any) -> str:
71
71
# 1e−10
72
72
"""
73
73
74
- def replace_amp_or_semi (match : re .Match ):
74
+ def _replace_amp_or_semi (match : re .Match ):
75
75
return "&" if match .group (0 ) == "&" else ";"
76
76
77
77
return (
78
78
# Replace initial & and ; together
79
- re .sub (r"&|;" , replace_amp_or_semi , str (value ))
79
+ re .sub (r"&|;" , _replace_amp_or_semi , str (value ))
80
80
# Replace other characters
81
81
.replace ('"' , """ )
82
82
.replace ("_" , "_" )
@@ -175,15 +175,15 @@ def safe_markdown(value: Any) -> str:
175
175
_PRECOMPILED_LSTRIP_BLOCK_PATTERN = re .compile (r"\n( )+$" )
176
176
177
177
178
- def _find_next_extends (template : str ):
178
+ def _find_extends (template : str ):
179
179
return _PRECOMPILED_EXTENDS_PATTERN .search (template )
180
180
181
181
182
- def _find_next_block (template : str ):
182
+ def _find_block (template : str ):
183
183
return _PRECOMPILED_BLOCK_PATTERN .search (template )
184
184
185
185
186
- def _find_next_include (template : str ):
186
+ def _find_include (template : str ):
187
187
return _PRECOMPILED_INCLUDE_PATTERN .search (template )
188
188
189
189
@@ -199,7 +199,7 @@ def _exists_and_is_file(path: str) -> bool:
199
199
200
200
201
201
def _resolve_includes (template : str ):
202
- while (include_match := _find_next_include (template )) is not None :
202
+ while (include_match := _find_include (template )) is not None :
203
203
template_path = include_match .group (0 )[12 :- 4 ]
204
204
205
205
# TODO: Restrict include to specific directory
@@ -218,15 +218,15 @@ def _resolve_includes(template: str):
218
218
219
219
220
220
def _check_for_unsupported_nested_blocks (template : str ):
221
- if _find_next_block (template ) is not None :
221
+ if _find_block (template ) is not None :
222
222
raise ValueError ("Nested blocks are not supported" )
223
223
224
224
225
225
def _resolve_includes_blocks_and_extends (template : str ):
226
226
block_replacements : "dict[str, str]" = {}
227
227
228
228
# Processing nested child templates
229
- while (extends_match := _find_next_extends (template )) is not None :
229
+ while (extends_match := _find_extends (template )) is not None :
230
230
extended_template_name = extends_match .group (0 )[12 :- 4 ]
231
231
232
232
# Load extended template
@@ -242,7 +242,7 @@ def _resolve_includes_blocks_and_extends(template: str):
242
242
template = _resolve_includes (template )
243
243
244
244
# Save block replacements
245
- while (block_match := _find_next_block (template )) is not None :
245
+ while (block_match := _find_block (template )) is not None :
246
246
block_name = block_match .group (0 )[9 :- 3 ]
247
247
248
248
endblock_match = _find_named_endblock (template , block_name )
@@ -275,7 +275,7 @@ def _resolve_includes_blocks_and_extends(template: str):
275
275
276
276
def _replace_blocks_with_replacements (template : str , replacements : "dict[str, str]" ):
277
277
# Replace blocks in top-level template
278
- while (block_match := _find_next_block (template )) is not None :
278
+ while (block_match := _find_block (template )) is not None :
279
279
block_name = block_match .group (0 )[9 :- 3 ]
280
280
281
281
# Self-closing block tag without default content
@@ -317,31 +317,31 @@ def _replace_blocks_with_replacements(template: str, replacements: "dict[str, st
317
317
return template
318
318
319
319
320
- def _find_next_hash_comment (template : str ):
320
+ def _find_hash_comment (template : str ):
321
321
return _PRECOMPILED_HASH_COMMENT_PATTERN .search (template )
322
322
323
323
324
- def _find_next_block_comment (template : str ):
324
+ def _find_block_comment (template : str ):
325
325
return _PRECOMPILED_BLOCK_COMMENT_PATTERN .search (template )
326
326
327
327
328
328
def _remove_comments (template : str ):
329
329
# Remove hash comments: {# ... #}
330
- while (comment_match := _find_next_hash_comment (template )) is not None :
330
+ while (comment_match := _find_hash_comment (template )) is not None :
331
331
template = template [: comment_match .start ()] + template [comment_match .end () :]
332
332
333
333
# Remove block comments: {% comment %} ... {% endcomment %}
334
- while (comment_match := _find_next_block_comment (template )) is not None :
334
+ while (comment_match := _find_block_comment (template )) is not None :
335
335
template = template [: comment_match .start ()] + template [comment_match .end () :]
336
336
337
337
return template
338
338
339
339
340
- def _find_next_token (template : str ):
340
+ def _find_token (template : str ):
341
341
return _PRECOMPILED_TOKEN_PATTERN .search (template )
342
342
343
343
344
- def _token_is_on_own_line (text_before_token : str ):
344
+ def _token_is_on_own_line (text_before_token : str ) -> bool :
345
345
return _PRECOMPILED_LSTRIP_BLOCK_PATTERN .search (text_before_token ) is not None
346
346
347
347
@@ -371,7 +371,7 @@ def _create_template_function( # pylint: disable=,too-many-locals,too-many-bran
371
371
last_token_was_block = False
372
372
373
373
# Resolve tokens
374
- while (token_match := _find_next_token (template )) is not None :
374
+ while (token_match := _find_token (template )) is not None :
375
375
token = token_match .group (0 )
376
376
377
377
# Add the text before the token
0 commit comments