404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.14.248.199: ~ $
# -*- coding: utf-8 -*-
"""
    jinja2.optimizer
    ~~~~~~~~~~~~~~~~

    The jinja optimizer is currently trying to constant fold a few expressions
    and modify the AST in place so that it should be easier to evaluate it.

    Because the AST does not contain all the scoping information and the
    compiler has to find that out, we cannot do all the optimizations we
    want.  For example loop unrolling doesn't work because unrolled loops would
    have a different scoping.

    The solution would be a second syntax tree that has the scoping rules stored.

    :copyright: (c) 2017 by the Jinja Team.
    :license: BSD.
"""
from jinja2 import nodes
from jinja2.visitor import NodeTransformer


def optimize(node, environment):
    """The context hint can be used to perform an static optimization
    based on the context given."""
    optimizer = Optimizer(environment)
    return optimizer.visit(node)


class Optimizer(NodeTransformer):

    def __init__(self, environment):
        self.environment = environment

    def fold(self, node, eval_ctx=None):
        """Do constant folding."""
        node = self.generic_visit(node)
        try:
            return nodes.Const.from_untrusted(node.as_const(eval_ctx),
                                              lineno=node.lineno,
                                              environment=self.environment)
        except nodes.Impossible:
            return node

    visit_Add = visit_Sub = visit_Mul = visit_Div = visit_FloorDiv = \
    visit_Pow = visit_Mod = visit_And = visit_Or = visit_Pos = visit_Neg = \
    visit_Not = visit_Compare = visit_Getitem = visit_Getattr = visit_Call = \
    visit_Filter = visit_Test = visit_CondExpr = fold
    del fold

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
__init__.py File 2.55 KB 0644
_compat.py File 2.54 KB 0644
_identifier.py File 1.69 KB 0644
asyncfilters.py File 4.05 KB 0644
asyncsupport.py File 7.69 KB 0644
bccache.py File 12.49 KB 0644
compiler.py File 63.85 KB 0644
constants.py File 1.59 KB 0644
debug.py File 11.76 KB 0644
defaults.py File 1.37 KB 0644
environment.py File 49.66 KB 0644
exceptions.py File 4.32 KB 0644
ext.py File 23.93 KB 0644
filters.py File 36.36 KB 0644
idtracking.py File 8.98 KB 0644
lexer.py File 27.89 KB 0644
loaders.py File 16.97 KB 0644
meta.py File 4.24 KB 0644
nativetypes.py File 7.14 KB 0644
nodes.py File 30.13 KB 0644
optimizer.py File 1.68 KB 0644
parser.py File 35.03 KB 0644
runtime.py File 27.1 KB 0644
sandbox.py File 16.71 KB 0644
tests.py File 4.14 KB 0644
utils.py File 20.29 KB 0644
visitor.py File 3.24 KB 0644