(self, node, frame)
| 1219 | self.visit(node.node, frame) |
| 1220 | |
| 1221 | def visit_Output(self, node, frame): |
| 1222 | # if we have a known extends statement, we don't output anything |
| 1223 | # if we are in a require_output_check section |
| 1224 | if self.has_known_extends and frame.require_output_check: |
| 1225 | return |
| 1226 | |
| 1227 | allow_constant_finalize = True |
| 1228 | if self.environment.finalize: |
| 1229 | func = self.environment.finalize |
| 1230 | if getattr(func, 'contextfunction', False) or \ |
| 1231 | getattr(func, 'evalcontextfunction', False): |
| 1232 | allow_constant_finalize = False |
| 1233 | elif getattr(func, 'environmentfunction', False): |
| 1234 | finalize = lambda x: text_type( |
| 1235 | self.environment.finalize(self.environment, x)) |
| 1236 | else: |
| 1237 | finalize = lambda x: text_type(self.environment.finalize(x)) |
| 1238 | else: |
| 1239 | finalize = text_type |
| 1240 | |
| 1241 | # if we are inside a frame that requires output checking, we do so |
| 1242 | outdent_later = False |
| 1243 | if frame.require_output_check: |
| 1244 | self.writeline('if parent_template is None:') |
| 1245 | self.indent() |
| 1246 | outdent_later = True |
| 1247 | |
| 1248 | # try to evaluate as many chunks as possible into a static |
| 1249 | # string at compile time. |
| 1250 | body = [] |
| 1251 | for child in node.nodes: |
| 1252 | try: |
| 1253 | if not allow_constant_finalize: |
| 1254 | raise nodes.Impossible() |
| 1255 | const = child.as_const(frame.eval_ctx) |
| 1256 | except nodes.Impossible: |
| 1257 | body.append(child) |
| 1258 | continue |
| 1259 | # the frame can't be volatile here, becaus otherwise the |
| 1260 | # as_const() function would raise an Impossible exception |
| 1261 | # at that point. |
| 1262 | try: |
| 1263 | if frame.eval_ctx.autoescape: |
| 1264 | if hasattr(const, '__html__'): |
| 1265 | const = const.__html__() |
| 1266 | else: |
| 1267 | const = escape(const) |
| 1268 | const = finalize(const) |
| 1269 | except Exception: |
| 1270 | # if something goes wrong here we evaluate the node |
| 1271 | # at runtime for easier debugging |
| 1272 | body.append(child) |
| 1273 | continue |
| 1274 | if body and isinstance(body[-1], list): |
| 1275 | body[-1].append(const) |
| 1276 | else: |
| 1277 | body.append([const]) |
| 1278 |
nothing calls this directly
no test coverage detected