OXIESEC PANEL
- Current Dir:
/
/
snap
/
core24
/
988
/
usr
/
lib
/
python3
/
dist-packages
/
jinja2
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
05/04/2025 04:37:50 PM
rwxr-xr-x
📄
__init__.py
1.88 KB
04/28/2022 05:20:15 PM
rw-r--r--
📁
__pycache__
-
05/04/2025 04:37:50 PM
rwxr-xr-x
📄
_identifier.py
1.91 KB
03/24/2022 02:16:48 PM
rw-r--r--
📄
async_utils.py
2.41 KB
03/24/2022 02:16:48 PM
rw-r--r--
📄
bccache.py
13.73 KB
04/28/2022 02:08:26 PM
rw-r--r--
📄
compiler.py
70.83 KB
03/10/2025 04:56:35 PM
rw-r--r--
📄
constants.py
1.4 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
debug.py
6.15 KB
03/24/2022 02:16:48 PM
rw-r--r--
📄
defaults.py
1.24 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
environment.py
59.91 KB
04/25/2022 07:41:10 PM
rw-r--r--
📄
exceptions.py
4.95 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
ext.py
30.76 KB
03/24/2022 02:16:48 PM
rw-r--r--
📄
filters.py
53.34 KB
03/10/2025 04:56:35 PM
rw-r--r--
📄
idtracking.py
10.45 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
lexer.py
29.09 KB
03/10/2025 04:56:35 PM
rw-r--r--
📄
loaders.py
22.66 KB
04/28/2022 04:37:28 PM
rw-r--r--
📄
meta.py
4.29 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
nativetypes.py
4.13 KB
03/24/2022 02:16:48 PM
rw-r--r--
📄
nodes.py
33.81 KB
03/10/2025 04:56:35 PM
rw-r--r--
📄
optimizer.py
1.61 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
parser.py
38.67 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
py.typed
0 bytes
03/11/2022 10:53:03 PM
rw-r--r--
📄
runtime.py
32.69 KB
03/24/2022 02:16:48 PM
rw-r--r--
📄
sandbox.py
14.68 KB
03/10/2025 04:56:35 PM
rw-r--r--
📄
tests.py
5.77 KB
03/11/2022 10:53:03 PM
rw-r--r--
📄
utils.py
23.47 KB
03/10/2025 04:56:35 PM
rw-r--r--
📄
visitor.py
3.48 KB
04/25/2022 07:41:10 PM
rw-r--r--
Editing: optimizer.py
Close
"""The optimizer tries to constant fold expressions and modify the AST in place so that it should be faster to evaluate. 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 scope. The solution would be a second syntax tree that stored the scoping rules. """ import typing as t from . import nodes from .visitor import NodeTransformer if t.TYPE_CHECKING: from .environment import Environment def optimize(node: nodes.Node, environment: "Environment") -> nodes.Node: """The context hint can be used to perform an static optimization based on the context given.""" optimizer = Optimizer(environment) return t.cast(nodes.Node, optimizer.visit(node)) class Optimizer(NodeTransformer): def __init__(self, environment: "t.Optional[Environment]") -> None: self.environment = environment def generic_visit( self, node: nodes.Node, *args: t.Any, **kwargs: t.Any ) -> nodes.Node: node = super().generic_visit(node, *args, **kwargs) # Do constant folding. Some other nodes besides Expr have # as_const, but folding them causes errors later on. if isinstance(node, nodes.Expr): try: return nodes.Const.from_untrusted( node.as_const(args[0] if args else None), lineno=node.lineno, environment=self.environment, ) except nodes.Impossible: pass return node