(self)
| 292 | return nodes.Scope([node]) |
| 293 | |
| 294 | def parse_block(self) -> nodes.Block: |
| 295 | node = nodes.Block(lineno=next(self.stream).lineno) |
| 296 | node.name = self.stream.expect("name").value |
| 297 | node.scoped = self.stream.skip_if("name:scoped") |
| 298 | node.required = self.stream.skip_if("name:required") |
| 299 | |
| 300 | # common problem people encounter when switching from django |
| 301 | # to jinja. we do not support hyphens in block names, so let's |
| 302 | # raise a nicer error message in that case. |
| 303 | if self.stream.current.type == "sub": |
| 304 | self.fail( |
| 305 | "Block names in Jinja have to be valid Python identifiers and may not" |
| 306 | " contain hyphens, use an underscore instead." |
| 307 | ) |
| 308 | |
| 309 | node.body = self.parse_statements(("name:endblock",), drop_needle=True) |
| 310 | |
| 311 | # enforce that required blocks only contain whitespace or comments |
| 312 | # by asserting that the body, if not empty, is just TemplateData nodes |
| 313 | # with whitespace data |
| 314 | if node.required and not all( |
| 315 | isinstance(child, nodes.TemplateData) and child.data.isspace() |
| 316 | for body in node.body |
| 317 | for child in body.nodes # type: ignore |
| 318 | ): |
| 319 | self.fail("Required blocks can only contain comments or whitespace") |
| 320 | |
| 321 | self.stream.skip_if("name:" + node.name) |
| 322 | return node |
| 323 | |
| 324 | def parse_extends(self) -> nodes.Extends: |
| 325 | node = nodes.Extends(lineno=next(self.stream).lineno) |
nothing calls this directly
no test coverage detected