@@ -71,12 +71,12 @@ def safe_html(value: Any) -> str:
7171 # 1e−10
7272 """
7373
74- def replace_amp_or_semi (match : re .Match ):
74+ def _replace_amp_or_semi (match : re .Match ):
7575 return "&" if match .group (0 ) == "&" else ";"
7676
7777 return (
7878 # Replace initial & and ; together
79- re .sub (r"&|;" , replace_amp_or_semi , str (value ))
79+ re .sub (r"&|;" , _replace_amp_or_semi , str (value ))
8080 # Replace other characters
8181 .replace ('"' , """ )
8282 .replace ("_" , "_" )
@@ -175,15 +175,15 @@ def safe_markdown(value: Any) -> str:
175175_PRECOMPILED_LSTRIP_BLOCK_PATTERN = re .compile (r"\n( )+$" )
176176
177177
178- def _find_next_extends (template : str ):
178+ def _find_extends (template : str ):
179179 return _PRECOMPILED_EXTENDS_PATTERN .search (template )
180180
181181
182- def _find_next_block (template : str ):
182+ def _find_block (template : str ):
183183 return _PRECOMPILED_BLOCK_PATTERN .search (template )
184184
185185
186- def _find_next_include (template : str ):
186+ def _find_include (template : str ):
187187 return _PRECOMPILED_INCLUDE_PATTERN .search (template )
188188
189189
@@ -199,7 +199,7 @@ def _exists_and_is_file(path: str) -> bool:
199199
200200
201201def _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 :
203203 template_path = include_match .group (0 )[12 :- 4 ]
204204
205205 # TODO: Restrict include to specific directory
@@ -218,15 +218,15 @@ def _resolve_includes(template: str):
218218
219219
220220def _check_for_unsupported_nested_blocks (template : str ):
221- if _find_next_block (template ) is not None :
221+ if _find_block (template ) is not None :
222222 raise ValueError ("Nested blocks are not supported" )
223223
224224
225225def _resolve_includes_blocks_and_extends (template : str ):
226226 block_replacements : "dict[str, str]" = {}
227227
228228 # 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 :
230230 extended_template_name = extends_match .group (0 )[12 :- 4 ]
231231
232232 # Load extended template
@@ -242,7 +242,7 @@ def _resolve_includes_blocks_and_extends(template: str):
242242 template = _resolve_includes (template )
243243
244244 # Save block replacements
245- while (block_match := _find_next_block (template )) is not None :
245+ while (block_match := _find_block (template )) is not None :
246246 block_name = block_match .group (0 )[9 :- 3 ]
247247
248248 endblock_match = _find_named_endblock (template , block_name )
@@ -275,7 +275,7 @@ def _resolve_includes_blocks_and_extends(template: str):
275275
276276def _replace_blocks_with_replacements (template : str , replacements : "dict[str, str]" ):
277277 # 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 :
279279 block_name = block_match .group (0 )[9 :- 3 ]
280280
281281 # Self-closing block tag without default content
@@ -317,31 +317,31 @@ def _replace_blocks_with_replacements(template: str, replacements: "dict[str, st
317317 return template
318318
319319
320- def _find_next_hash_comment (template : str ):
320+ def _find_hash_comment (template : str ):
321321 return _PRECOMPILED_HASH_COMMENT_PATTERN .search (template )
322322
323323
324- def _find_next_block_comment (template : str ):
324+ def _find_block_comment (template : str ):
325325 return _PRECOMPILED_BLOCK_COMMENT_PATTERN .search (template )
326326
327327
328328def _remove_comments (template : str ):
329329 # 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 :
331331 template = template [: comment_match .start ()] + template [comment_match .end () :]
332332
333333 # 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 :
335335 template = template [: comment_match .start ()] + template [comment_match .end () :]
336336
337337 return template
338338
339339
340- def _find_next_token (template : str ):
340+ def _find_token (template : str ):
341341 return _PRECOMPILED_TOKEN_PATTERN .search (template )
342342
343343
344- def _token_is_on_own_line (text_before_token : str ):
344+ def _token_is_on_own_line (text_before_token : str ) -> bool :
345345 return _PRECOMPILED_LSTRIP_BLOCK_PATTERN .search (text_before_token ) is not None
346346
347347
@@ -371,7 +371,7 @@ def _create_template_function( # pylint: disable=,too-many-locals,too-many-bran
371371 last_token_was_block = False
372372
373373 # Resolve tokens
374- while (token_match := _find_next_token (template )) is not None :
374+ while (token_match := _find_token (template )) is not None :
375375 token = token_match .group (0 )
376376
377377 # Add the text before the token
0 commit comments