GRAYBYTE WORDPRESS FILE MANAGER2984

Server IP : 198.54.121.189 / Your IP : 216.73.216.224
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/cloudlinux/venv/lib/python3.11/site-packages/jinja2/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/jinja2//nativetypes.py
import typing as t
from ast import literal_eval
from ast import parse
from itertools import chain
from itertools import islice

from . import nodes
from .compiler import CodeGenerator
from .compiler import Frame
from .compiler import has_safe_repr
from .environment import Environment
from .environment import Template


def native_concat(values: t.Iterable[t.Any]) -> t.Optional[t.Any]:
    """Return a native Python type from the list of compiled nodes. If
    the result is a single node, its value is returned. Otherwise, the
    nodes are concatenated as strings. If the result can be parsed with
    :func:`ast.literal_eval`, the parsed value is returned. Otherwise,
    the string is returned.

    :param values: Iterable of outputs to concatenate.
    """
    head = list(islice(values, 2))

    if not head:
        return None

    if len(head) == 1:
        raw = head[0]
        if not isinstance(raw, str):
            return raw
    else:
        raw = "".join([str(v) for v in chain(head, values)])

    try:
        return literal_eval(
            # In Python 3.10+ ast.literal_eval removes leading spaces/tabs
            # from the given string. For backwards compatibility we need to
            # parse the string ourselves without removing leading spaces/tabs.
            parse(raw, mode="eval")
        )
    except (ValueError, SyntaxError, MemoryError):
        return raw


class NativeCodeGenerator(CodeGenerator):
    """A code generator which renders Python types by not adding
    ``str()`` around output nodes.
    """

    @staticmethod
    def _default_finalize(value: t.Any) -> t.Any:
        return value

    def _output_const_repr(self, group: t.Iterable[t.Any]) -> str:
        return repr("".join([str(v) for v in group]))

    def _output_child_to_const(
        self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
    ) -> t.Any:
        const = node.as_const(frame.eval_ctx)

        if not has_safe_repr(const):
            raise nodes.Impossible()

        if isinstance(node, nodes.TemplateData):
            return const

        return finalize.const(const)  # type: ignore

    def _output_child_pre(
        self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
    ) -> None:
        if finalize.src is not None:
            self.write(finalize.src)

    def _output_child_post(
        self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
    ) -> None:
        if finalize.src is not None:
            self.write(")")


class NativeEnvironment(Environment):
    """An environment that renders templates to native Python types."""

    code_generator_class = NativeCodeGenerator


class NativeTemplate(Template):
    environment_class = NativeEnvironment

    def render(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
        """Render the template to produce a native Python type. If the
        result is a single node, its value is returned. Otherwise, the
        nodes are concatenated as strings. If the result can be parsed
        with :func:`ast.literal_eval`, the parsed value is returned.
        Otherwise, the string is returned.
        """
        ctx = self.new_context(dict(*args, **kwargs))

        try:
            return native_concat(self.root_render_func(ctx))  # type: ignore
        except Exception:
            return self.environment.handle_exception()

    async def render_async(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
        if not self.environment.is_async:
            raise RuntimeError(
                "The environment was not created with async mode enabled."
            )

        ctx = self.new_context(dict(*args, **kwargs))

        try:
            return native_concat(
                [n async for n in self.root_render_func(ctx)]  # type: ignore
            )
        except Exception:
            return self.environment.handle_exception()


NativeEnvironment.template_class = NativeTemplate

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
June 25 2025 08:31:36
root / root
0755
__pycache__
--
May 15 2025 08:30:38
root / root
0755
__init__.py
2.153 KB
April 17 2025 13:10:59
root / root
0644
_identifier.py
1.733 KB
April 17 2025 13:10:59
root / root
0644
async_utils.py
1.901 KB
April 17 2025 13:10:59
root / root
0644
bccache.py
12.373 KB
April 17 2025 13:10:59
root / root
0644
compiler.py
70.517 KB
April 17 2025 13:10:59
root / root
0644
constants.py
1.399 KB
April 17 2025 13:10:59
root / root
0644
debug.py
8.295 KB
April 17 2025 13:10:59
root / root
0644
defaults.py
1.237 KB
April 17 2025 13:10:59
root / root
0644
environment.py
59.554 KB
April 17 2025 13:10:59
root / root
0644
exceptions.py
4.952 KB
April 17 2025 13:10:59
root / root
0644
ext.py
31.369 KB
April 17 2025 13:10:59
root / root
0644
filters.py
51.376 KB
April 17 2025 13:10:59
root / root
0644
idtracking.py
10.47 KB
April 17 2025 13:10:59
root / root
0644
lexer.py
29.229 KB
April 17 2025 13:10:59
root / root
0644
loaders.py
22.221 KB
April 17 2025 13:10:59
root / root
0644
meta.py
4.293 KB
April 17 2025 13:10:59
root / root
0644
nativetypes.py
3.876 KB
April 17 2025 13:10:59
root / root
0644
nodes.py
33.74 KB
April 17 2025 13:10:59
root / root
0644
optimizer.py
1.611 KB
April 17 2025 13:10:59
root / root
0644
parser.py
38.835 KB
April 17 2025 13:10:59
root / root
0644
py.typed
0 KB
April 17 2025 13:10:59
root / root
0644
runtime.py
34.232 KB
April 17 2025 13:10:59
root / root
0644
sandbox.py
14.258 KB
April 17 2025 13:10:59
root / root
0644
tests.py
5.767 KB
April 17 2025 13:10:59
root / root
0644
utils.py
26.339 KB
April 17 2025 13:10:59
root / root
0644
visitor.py
3.488 KB
April 17 2025 13:10:59
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF