Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +4 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/__init__.py +4 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/__main__.py +12 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/__pycache__/__init__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/__pycache__/__main__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/__pycache__/core.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/cacert.pem +0 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/core.py +114 -0
- deepseekvl2/lib/python3.10/site-packages/certifi/py.typed +0 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/__init__.py +38 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/_identifier.py +6 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/bccache.py +408 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/compiler.py +1998 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/constants.py +20 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/debug.py +191 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/defaults.py +48 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/exceptions.py +166 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/ext.py +870 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/idtracking.py +318 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/lexer.py +868 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/meta.py +112 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/nativetypes.py +130 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/optimizer.py +48 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/parser.py +1049 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/py.typed +0 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/tests.py +256 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/utils.py +766 -0
- deepseekvl2/lib/python3.10/site-packages/jinja2/visitor.py +92 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/__pycache__/__init__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/__pycache__/_pickle.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/_bounded_integers.cpython-310-x86_64-linux-gnu.so +3 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/_generator.cpython-310-x86_64-linux-gnu.so +3 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so +3 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/lib/libnpyrandom.a +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/mtrand.cpython-310-x86_64-linux-gnu.so +3 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_direct.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_extending.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937_regressions.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_random.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_randomstate.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_randomstate_regression.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_regression.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_seed_sequence.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_smoke.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/__init__.py +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/__pycache__/__init__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/mt19937-testset-1.csv +1001 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/mt19937-testset-2.csv +1001 -0
.gitattributes
CHANGED
|
@@ -711,3 +711,7 @@ deepseekvl2/lib/python3.10/site-packages/numpy/lib/__pycache__/function_base.cpy
|
|
| 711 |
deepseekvl2/lib/python3.10/site-packages/numpy/random/_pcg64.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 712 |
deepseekvl2/lib/python3.10/site-packages/numpy/random/_common.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 713 |
infer_4_33_0/lib/python3.10/site-packages/google/protobuf/__pycache__/descriptor_pb2.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
deepseekvl2/lib/python3.10/site-packages/numpy/random/_pcg64.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 712 |
deepseekvl2/lib/python3.10/site-packages/numpy/random/_common.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 713 |
infer_4_33_0/lib/python3.10/site-packages/google/protobuf/__pycache__/descriptor_pb2.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 714 |
+
deepseekvl2/lib/python3.10/site-packages/numpy/random/_bounded_integers.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 715 |
+
deepseekvl2/lib/python3.10/site-packages/numpy/random/_generator.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 716 |
+
deepseekvl2/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 717 |
+
deepseekvl2/lib/python3.10/site-packages/numpy/random/mtrand.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
deepseekvl2/lib/python3.10/site-packages/certifi/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .core import contents, where
|
| 2 |
+
|
| 3 |
+
__all__ = ["contents", "where"]
|
| 4 |
+
__version__ = "2025.01.31"
|
deepseekvl2/lib/python3.10/site-packages/certifi/__main__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
|
| 3 |
+
from certifi import contents, where
|
| 4 |
+
|
| 5 |
+
parser = argparse.ArgumentParser()
|
| 6 |
+
parser.add_argument("-c", "--contents", action="store_true")
|
| 7 |
+
args = parser.parse_args()
|
| 8 |
+
|
| 9 |
+
if args.contents:
|
| 10 |
+
print(contents())
|
| 11 |
+
else:
|
| 12 |
+
print(where())
|
deepseekvl2/lib/python3.10/site-packages/certifi/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (277 Bytes). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/certifi/__pycache__/__main__.cpython-310.pyc
ADDED
|
Binary file (415 Bytes). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/certifi/__pycache__/core.cpython-310.pyc
ADDED
|
Binary file (2.11 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/certifi/cacert.pem
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
deepseekvl2/lib/python3.10/site-packages/certifi/core.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
certifi.py
|
| 3 |
+
~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
This module returns the installation location of cacert.pem or its contents.
|
| 6 |
+
"""
|
| 7 |
+
import sys
|
| 8 |
+
import atexit
|
| 9 |
+
|
| 10 |
+
def exit_cacert_ctx() -> None:
|
| 11 |
+
_CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
if sys.version_info >= (3, 11):
|
| 15 |
+
|
| 16 |
+
from importlib.resources import as_file, files
|
| 17 |
+
|
| 18 |
+
_CACERT_CTX = None
|
| 19 |
+
_CACERT_PATH = None
|
| 20 |
+
|
| 21 |
+
def where() -> str:
|
| 22 |
+
# This is slightly terrible, but we want to delay extracting the file
|
| 23 |
+
# in cases where we're inside of a zipimport situation until someone
|
| 24 |
+
# actually calls where(), but we don't want to re-extract the file
|
| 25 |
+
# on every call of where(), so we'll do it once then store it in a
|
| 26 |
+
# global variable.
|
| 27 |
+
global _CACERT_CTX
|
| 28 |
+
global _CACERT_PATH
|
| 29 |
+
if _CACERT_PATH is None:
|
| 30 |
+
# This is slightly janky, the importlib.resources API wants you to
|
| 31 |
+
# manage the cleanup of this file, so it doesn't actually return a
|
| 32 |
+
# path, it returns a context manager that will give you the path
|
| 33 |
+
# when you enter it and will do any cleanup when you leave it. In
|
| 34 |
+
# the common case of not needing a temporary file, it will just
|
| 35 |
+
# return the file system location and the __exit__() is a no-op.
|
| 36 |
+
#
|
| 37 |
+
# We also have to hold onto the actual context manager, because
|
| 38 |
+
# it will do the cleanup whenever it gets garbage collected, so
|
| 39 |
+
# we will also store that at the global level as well.
|
| 40 |
+
_CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem"))
|
| 41 |
+
_CACERT_PATH = str(_CACERT_CTX.__enter__())
|
| 42 |
+
atexit.register(exit_cacert_ctx)
|
| 43 |
+
|
| 44 |
+
return _CACERT_PATH
|
| 45 |
+
|
| 46 |
+
def contents() -> str:
|
| 47 |
+
return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii")
|
| 48 |
+
|
| 49 |
+
elif sys.version_info >= (3, 7):
|
| 50 |
+
|
| 51 |
+
from importlib.resources import path as get_path, read_text
|
| 52 |
+
|
| 53 |
+
_CACERT_CTX = None
|
| 54 |
+
_CACERT_PATH = None
|
| 55 |
+
|
| 56 |
+
def where() -> str:
|
| 57 |
+
# This is slightly terrible, but we want to delay extracting the
|
| 58 |
+
# file in cases where we're inside of a zipimport situation until
|
| 59 |
+
# someone actually calls where(), but we don't want to re-extract
|
| 60 |
+
# the file on every call of where(), so we'll do it once then store
|
| 61 |
+
# it in a global variable.
|
| 62 |
+
global _CACERT_CTX
|
| 63 |
+
global _CACERT_PATH
|
| 64 |
+
if _CACERT_PATH is None:
|
| 65 |
+
# This is slightly janky, the importlib.resources API wants you
|
| 66 |
+
# to manage the cleanup of this file, so it doesn't actually
|
| 67 |
+
# return a path, it returns a context manager that will give
|
| 68 |
+
# you the path when you enter it and will do any cleanup when
|
| 69 |
+
# you leave it. In the common case of not needing a temporary
|
| 70 |
+
# file, it will just return the file system location and the
|
| 71 |
+
# __exit__() is a no-op.
|
| 72 |
+
#
|
| 73 |
+
# We also have to hold onto the actual context manager, because
|
| 74 |
+
# it will do the cleanup whenever it gets garbage collected, so
|
| 75 |
+
# we will also store that at the global level as well.
|
| 76 |
+
_CACERT_CTX = get_path("certifi", "cacert.pem")
|
| 77 |
+
_CACERT_PATH = str(_CACERT_CTX.__enter__())
|
| 78 |
+
atexit.register(exit_cacert_ctx)
|
| 79 |
+
|
| 80 |
+
return _CACERT_PATH
|
| 81 |
+
|
| 82 |
+
def contents() -> str:
|
| 83 |
+
return read_text("certifi", "cacert.pem", encoding="ascii")
|
| 84 |
+
|
| 85 |
+
else:
|
| 86 |
+
import os
|
| 87 |
+
import types
|
| 88 |
+
from typing import Union
|
| 89 |
+
|
| 90 |
+
Package = Union[types.ModuleType, str]
|
| 91 |
+
Resource = Union[str, "os.PathLike"]
|
| 92 |
+
|
| 93 |
+
# This fallback will work for Python versions prior to 3.7 that lack the
|
| 94 |
+
# importlib.resources module but relies on the existing `where` function
|
| 95 |
+
# so won't address issues with environments like PyOxidizer that don't set
|
| 96 |
+
# __file__ on modules.
|
| 97 |
+
def read_text(
|
| 98 |
+
package: Package,
|
| 99 |
+
resource: Resource,
|
| 100 |
+
encoding: str = 'utf-8',
|
| 101 |
+
errors: str = 'strict'
|
| 102 |
+
) -> str:
|
| 103 |
+
with open(where(), encoding=encoding) as data:
|
| 104 |
+
return data.read()
|
| 105 |
+
|
| 106 |
+
# If we don't have importlib.resources, then we will just do the old logic
|
| 107 |
+
# of assuming we're on the filesystem and munge the path directly.
|
| 108 |
+
def where() -> str:
|
| 109 |
+
f = os.path.dirname(__file__)
|
| 110 |
+
|
| 111 |
+
return os.path.join(f, "cacert.pem")
|
| 112 |
+
|
| 113 |
+
def contents() -> str:
|
| 114 |
+
return read_text("certifi", "cacert.pem", encoding="ascii")
|
deepseekvl2/lib/python3.10/site-packages/certifi/py.typed
ADDED
|
File without changes
|
deepseekvl2/lib/python3.10/site-packages/jinja2/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Jinja is a template engine written in pure Python. It provides a
|
| 2 |
+
non-XML syntax that supports inline expressions and an optional
|
| 3 |
+
sandboxed environment.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .bccache import BytecodeCache as BytecodeCache
|
| 7 |
+
from .bccache import FileSystemBytecodeCache as FileSystemBytecodeCache
|
| 8 |
+
from .bccache import MemcachedBytecodeCache as MemcachedBytecodeCache
|
| 9 |
+
from .environment import Environment as Environment
|
| 10 |
+
from .environment import Template as Template
|
| 11 |
+
from .exceptions import TemplateAssertionError as TemplateAssertionError
|
| 12 |
+
from .exceptions import TemplateError as TemplateError
|
| 13 |
+
from .exceptions import TemplateNotFound as TemplateNotFound
|
| 14 |
+
from .exceptions import TemplateRuntimeError as TemplateRuntimeError
|
| 15 |
+
from .exceptions import TemplatesNotFound as TemplatesNotFound
|
| 16 |
+
from .exceptions import TemplateSyntaxError as TemplateSyntaxError
|
| 17 |
+
from .exceptions import UndefinedError as UndefinedError
|
| 18 |
+
from .loaders import BaseLoader as BaseLoader
|
| 19 |
+
from .loaders import ChoiceLoader as ChoiceLoader
|
| 20 |
+
from .loaders import DictLoader as DictLoader
|
| 21 |
+
from .loaders import FileSystemLoader as FileSystemLoader
|
| 22 |
+
from .loaders import FunctionLoader as FunctionLoader
|
| 23 |
+
from .loaders import ModuleLoader as ModuleLoader
|
| 24 |
+
from .loaders import PackageLoader as PackageLoader
|
| 25 |
+
from .loaders import PrefixLoader as PrefixLoader
|
| 26 |
+
from .runtime import ChainableUndefined as ChainableUndefined
|
| 27 |
+
from .runtime import DebugUndefined as DebugUndefined
|
| 28 |
+
from .runtime import make_logging_undefined as make_logging_undefined
|
| 29 |
+
from .runtime import StrictUndefined as StrictUndefined
|
| 30 |
+
from .runtime import Undefined as Undefined
|
| 31 |
+
from .utils import clear_caches as clear_caches
|
| 32 |
+
from .utils import is_undefined as is_undefined
|
| 33 |
+
from .utils import pass_context as pass_context
|
| 34 |
+
from .utils import pass_environment as pass_environment
|
| 35 |
+
from .utils import pass_eval_context as pass_eval_context
|
| 36 |
+
from .utils import select_autoescape as select_autoescape
|
| 37 |
+
|
| 38 |
+
__version__ = "3.1.5"
|
deepseekvl2/lib/python3.10/site-packages/jinja2/_identifier.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
# generated by scripts/generate_identifier_pattern.py
|
| 4 |
+
pattern = re.compile(
|
| 5 |
+
r"[\w·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-ٰٟۖ-ۜ۟-۪ۤۧۨ-ܑۭܰ-݊ަ-ް߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛࣓-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣঁ-ঃ়া-ৄেৈো-্ৗৢৣ৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑੰੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣஂா-ூெ-ைொ-்ௗఀ-ఄా-ౄె-ైొ-్ౕౖౢౣಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣංඃ්ා-ුූෘ-ෟෲෳัิ-ฺ็-๎ັິ-ູົຼ່-ໍ༹༘༙༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏႚ-ႝ፝-፟ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝᠋-᠍ᢅᢆᢩᤠ-ᤫᤰ-᤻ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼᪰-᪽ᬀ-ᬄ᬴-᭄᭫-᭳ᮀ-ᮂᮡ-ᮭ᯦-᯳ᰤ-᰷᳐-᳔᳒-᳨᳭ᳲ-᳴᳷-᳹᷀-᷹᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰℘℮⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣠-꣱ꣿꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀ꧥꨩ-ꨶꩃꩌꩍꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭ﬞ︀-️︠-︯︳︴﹍-﹏_𐇽𐋠𐍶-𐍺𐨁-𐨃𐨅𐨆𐨌-𐨏𐨸-𐨿𐨺𐫦𐫥𐴤-𐽆𐴧-𐽐𑀀-𑀂𑀸-𑁆𑁿-𑂂𑂰-𑂺𑄀-𑄂𑄧-𑄴𑅅𑅆𑅳𑆀-𑆂𑆳-𑇀𑇉-𑇌𑈬-𑈷𑈾𑋟-𑋪𑌀-𑌃𑌻𑌼𑌾-𑍄𑍇𑍈𑍋-𑍍𑍗𑍢𑍣𑍦-𑍬𑍰-𑍴𑐵-𑑆𑑞𑒰-𑓃𑖯-𑖵𑖸-𑗀𑗜𑗝𑘰-𑙀𑚫-𑚷𑜝-𑜫𑠬-𑠺𑨁-𑨊𑨳-𑨹𑨻-𑨾𑩇𑩑-𑩛𑪊-𑪙𑰯-𑰶𑰸-𑰿𑲒-𑲧𑲩-𑲶𑴱-𑴶𑴺𑴼𑴽𑴿-𑵅𑵇𑶊-𑶎𑶐𑶑𑶓-𑶗𑻳-𑻶𖫰-𖫴𖬰-𖬶𖽑-𖽾𖾏-𖾒𛲝𛲞𝅥-𝅩𝅭-𝅲𝅻-𝆂𝆅-𝆋𝆪-𝆭𝉂-𝉄𝨀-𝨶𝨻-𝩬𝩵𝪄𝪛-𝪟𝪡-𝪯𞀀-𞀆𞀈-𞀘𞀛-𞀡𞀣𞀤𞀦-𞣐𞀪-𞣖𞥄-𞥊󠄀-󠇯]+" # noqa: B950
|
| 6 |
+
)
|
deepseekvl2/lib/python3.10/site-packages/jinja2/bccache.py
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The optional bytecode cache system. This is useful if you have very
|
| 2 |
+
complex template situations and the compilation of all those templates
|
| 3 |
+
slows down your application too much.
|
| 4 |
+
|
| 5 |
+
Situations where this is useful are often forking web applications that
|
| 6 |
+
are initialized on the first request.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import errno
|
| 10 |
+
import fnmatch
|
| 11 |
+
import marshal
|
| 12 |
+
import os
|
| 13 |
+
import pickle
|
| 14 |
+
import stat
|
| 15 |
+
import sys
|
| 16 |
+
import tempfile
|
| 17 |
+
import typing as t
|
| 18 |
+
from hashlib import sha1
|
| 19 |
+
from io import BytesIO
|
| 20 |
+
from types import CodeType
|
| 21 |
+
|
| 22 |
+
if t.TYPE_CHECKING:
|
| 23 |
+
import typing_extensions as te
|
| 24 |
+
|
| 25 |
+
from .environment import Environment
|
| 26 |
+
|
| 27 |
+
class _MemcachedClient(te.Protocol):
|
| 28 |
+
def get(self, key: str) -> bytes: ...
|
| 29 |
+
|
| 30 |
+
def set(
|
| 31 |
+
self, key: str, value: bytes, timeout: t.Optional[int] = None
|
| 32 |
+
) -> None: ...
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
bc_version = 5
|
| 36 |
+
# Magic bytes to identify Jinja bytecode cache files. Contains the
|
| 37 |
+
# Python major and minor version to avoid loading incompatible bytecode
|
| 38 |
+
# if a project upgrades its Python version.
|
| 39 |
+
bc_magic = (
|
| 40 |
+
b"j2"
|
| 41 |
+
+ pickle.dumps(bc_version, 2)
|
| 42 |
+
+ pickle.dumps((sys.version_info[0] << 24) | sys.version_info[1], 2)
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Bucket:
|
| 47 |
+
"""Buckets are used to store the bytecode for one template. It's created
|
| 48 |
+
and initialized by the bytecode cache and passed to the loading functions.
|
| 49 |
+
|
| 50 |
+
The buckets get an internal checksum from the cache assigned and use this
|
| 51 |
+
to automatically reject outdated cache material. Individual bytecode
|
| 52 |
+
cache subclasses don't have to care about cache invalidation.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def __init__(self, environment: "Environment", key: str, checksum: str) -> None:
|
| 56 |
+
self.environment = environment
|
| 57 |
+
self.key = key
|
| 58 |
+
self.checksum = checksum
|
| 59 |
+
self.reset()
|
| 60 |
+
|
| 61 |
+
def reset(self) -> None:
|
| 62 |
+
"""Resets the bucket (unloads the bytecode)."""
|
| 63 |
+
self.code: t.Optional[CodeType] = None
|
| 64 |
+
|
| 65 |
+
def load_bytecode(self, f: t.BinaryIO) -> None:
|
| 66 |
+
"""Loads bytecode from a file or file like object."""
|
| 67 |
+
# make sure the magic header is correct
|
| 68 |
+
magic = f.read(len(bc_magic))
|
| 69 |
+
if magic != bc_magic:
|
| 70 |
+
self.reset()
|
| 71 |
+
return
|
| 72 |
+
# the source code of the file changed, we need to reload
|
| 73 |
+
checksum = pickle.load(f)
|
| 74 |
+
if self.checksum != checksum:
|
| 75 |
+
self.reset()
|
| 76 |
+
return
|
| 77 |
+
# if marshal_load fails then we need to reload
|
| 78 |
+
try:
|
| 79 |
+
self.code = marshal.load(f)
|
| 80 |
+
except (EOFError, ValueError, TypeError):
|
| 81 |
+
self.reset()
|
| 82 |
+
return
|
| 83 |
+
|
| 84 |
+
def write_bytecode(self, f: t.IO[bytes]) -> None:
|
| 85 |
+
"""Dump the bytecode into the file or file like object passed."""
|
| 86 |
+
if self.code is None:
|
| 87 |
+
raise TypeError("can't write empty bucket")
|
| 88 |
+
f.write(bc_magic)
|
| 89 |
+
pickle.dump(self.checksum, f, 2)
|
| 90 |
+
marshal.dump(self.code, f)
|
| 91 |
+
|
| 92 |
+
def bytecode_from_string(self, string: bytes) -> None:
|
| 93 |
+
"""Load bytecode from bytes."""
|
| 94 |
+
self.load_bytecode(BytesIO(string))
|
| 95 |
+
|
| 96 |
+
def bytecode_to_string(self) -> bytes:
|
| 97 |
+
"""Return the bytecode as bytes."""
|
| 98 |
+
out = BytesIO()
|
| 99 |
+
self.write_bytecode(out)
|
| 100 |
+
return out.getvalue()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class BytecodeCache:
|
| 104 |
+
"""To implement your own bytecode cache you have to subclass this class
|
| 105 |
+
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
|
| 106 |
+
these methods are passed a :class:`~jinja2.bccache.Bucket`.
|
| 107 |
+
|
| 108 |
+
A very basic bytecode cache that saves the bytecode on the file system::
|
| 109 |
+
|
| 110 |
+
from os import path
|
| 111 |
+
|
| 112 |
+
class MyCache(BytecodeCache):
|
| 113 |
+
|
| 114 |
+
def __init__(self, directory):
|
| 115 |
+
self.directory = directory
|
| 116 |
+
|
| 117 |
+
def load_bytecode(self, bucket):
|
| 118 |
+
filename = path.join(self.directory, bucket.key)
|
| 119 |
+
if path.exists(filename):
|
| 120 |
+
with open(filename, 'rb') as f:
|
| 121 |
+
bucket.load_bytecode(f)
|
| 122 |
+
|
| 123 |
+
def dump_bytecode(self, bucket):
|
| 124 |
+
filename = path.join(self.directory, bucket.key)
|
| 125 |
+
with open(filename, 'wb') as f:
|
| 126 |
+
bucket.write_bytecode(f)
|
| 127 |
+
|
| 128 |
+
A more advanced version of a filesystem based bytecode cache is part of
|
| 129 |
+
Jinja.
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
def load_bytecode(self, bucket: Bucket) -> None:
|
| 133 |
+
"""Subclasses have to override this method to load bytecode into a
|
| 134 |
+
bucket. If they are not able to find code in the cache for the
|
| 135 |
+
bucket, it must not do anything.
|
| 136 |
+
"""
|
| 137 |
+
raise NotImplementedError()
|
| 138 |
+
|
| 139 |
+
def dump_bytecode(self, bucket: Bucket) -> None:
|
| 140 |
+
"""Subclasses have to override this method to write the bytecode
|
| 141 |
+
from a bucket back to the cache. If it unable to do so it must not
|
| 142 |
+
fail silently but raise an exception.
|
| 143 |
+
"""
|
| 144 |
+
raise NotImplementedError()
|
| 145 |
+
|
| 146 |
+
def clear(self) -> None:
|
| 147 |
+
"""Clears the cache. This method is not used by Jinja but should be
|
| 148 |
+
implemented to allow applications to clear the bytecode cache used
|
| 149 |
+
by a particular environment.
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
def get_cache_key(
|
| 153 |
+
self, name: str, filename: t.Optional[t.Union[str]] = None
|
| 154 |
+
) -> str:
|
| 155 |
+
"""Returns the unique hash key for this template name."""
|
| 156 |
+
hash = sha1(name.encode("utf-8"))
|
| 157 |
+
|
| 158 |
+
if filename is not None:
|
| 159 |
+
hash.update(f"|{filename}".encode())
|
| 160 |
+
|
| 161 |
+
return hash.hexdigest()
|
| 162 |
+
|
| 163 |
+
def get_source_checksum(self, source: str) -> str:
|
| 164 |
+
"""Returns a checksum for the source."""
|
| 165 |
+
return sha1(source.encode("utf-8")).hexdigest()
|
| 166 |
+
|
| 167 |
+
def get_bucket(
|
| 168 |
+
self,
|
| 169 |
+
environment: "Environment",
|
| 170 |
+
name: str,
|
| 171 |
+
filename: t.Optional[str],
|
| 172 |
+
source: str,
|
| 173 |
+
) -> Bucket:
|
| 174 |
+
"""Return a cache bucket for the given template. All arguments are
|
| 175 |
+
mandatory but filename may be `None`.
|
| 176 |
+
"""
|
| 177 |
+
key = self.get_cache_key(name, filename)
|
| 178 |
+
checksum = self.get_source_checksum(source)
|
| 179 |
+
bucket = Bucket(environment, key, checksum)
|
| 180 |
+
self.load_bytecode(bucket)
|
| 181 |
+
return bucket
|
| 182 |
+
|
| 183 |
+
def set_bucket(self, bucket: Bucket) -> None:
|
| 184 |
+
"""Put the bucket into the cache."""
|
| 185 |
+
self.dump_bytecode(bucket)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class FileSystemBytecodeCache(BytecodeCache):
|
| 189 |
+
"""A bytecode cache that stores bytecode on the filesystem. It accepts
|
| 190 |
+
two arguments: The directory where the cache items are stored and a
|
| 191 |
+
pattern string that is used to build the filename.
|
| 192 |
+
|
| 193 |
+
If no directory is specified a default cache directory is selected. On
|
| 194 |
+
Windows the user's temp directory is used, on UNIX systems a directory
|
| 195 |
+
is created for the user in the system temp directory.
|
| 196 |
+
|
| 197 |
+
The pattern can be used to have multiple separate caches operate on the
|
| 198 |
+
same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``
|
| 199 |
+
is replaced with the cache key.
|
| 200 |
+
|
| 201 |
+
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
|
| 202 |
+
|
| 203 |
+
This bytecode cache supports clearing of the cache using the clear method.
|
| 204 |
+
"""
|
| 205 |
+
|
| 206 |
+
def __init__(
|
| 207 |
+
self, directory: t.Optional[str] = None, pattern: str = "__jinja2_%s.cache"
|
| 208 |
+
) -> None:
|
| 209 |
+
if directory is None:
|
| 210 |
+
directory = self._get_default_cache_dir()
|
| 211 |
+
self.directory = directory
|
| 212 |
+
self.pattern = pattern
|
| 213 |
+
|
| 214 |
+
def _get_default_cache_dir(self) -> str:
|
| 215 |
+
def _unsafe_dir() -> "te.NoReturn":
|
| 216 |
+
raise RuntimeError(
|
| 217 |
+
"Cannot determine safe temp directory. You "
|
| 218 |
+
"need to explicitly provide one."
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
tmpdir = tempfile.gettempdir()
|
| 222 |
+
|
| 223 |
+
# On windows the temporary directory is used specific unless
|
| 224 |
+
# explicitly forced otherwise. We can just use that.
|
| 225 |
+
if os.name == "nt":
|
| 226 |
+
return tmpdir
|
| 227 |
+
if not hasattr(os, "getuid"):
|
| 228 |
+
_unsafe_dir()
|
| 229 |
+
|
| 230 |
+
dirname = f"_jinja2-cache-{os.getuid()}"
|
| 231 |
+
actual_dir = os.path.join(tmpdir, dirname)
|
| 232 |
+
|
| 233 |
+
try:
|
| 234 |
+
os.mkdir(actual_dir, stat.S_IRWXU)
|
| 235 |
+
except OSError as e:
|
| 236 |
+
if e.errno != errno.EEXIST:
|
| 237 |
+
raise
|
| 238 |
+
try:
|
| 239 |
+
os.chmod(actual_dir, stat.S_IRWXU)
|
| 240 |
+
actual_dir_stat = os.lstat(actual_dir)
|
| 241 |
+
if (
|
| 242 |
+
actual_dir_stat.st_uid != os.getuid()
|
| 243 |
+
or not stat.S_ISDIR(actual_dir_stat.st_mode)
|
| 244 |
+
or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU
|
| 245 |
+
):
|
| 246 |
+
_unsafe_dir()
|
| 247 |
+
except OSError as e:
|
| 248 |
+
if e.errno != errno.EEXIST:
|
| 249 |
+
raise
|
| 250 |
+
|
| 251 |
+
actual_dir_stat = os.lstat(actual_dir)
|
| 252 |
+
if (
|
| 253 |
+
actual_dir_stat.st_uid != os.getuid()
|
| 254 |
+
or not stat.S_ISDIR(actual_dir_stat.st_mode)
|
| 255 |
+
or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU
|
| 256 |
+
):
|
| 257 |
+
_unsafe_dir()
|
| 258 |
+
|
| 259 |
+
return actual_dir
|
| 260 |
+
|
| 261 |
+
def _get_cache_filename(self, bucket: Bucket) -> str:
|
| 262 |
+
return os.path.join(self.directory, self.pattern % (bucket.key,))
|
| 263 |
+
|
| 264 |
+
def load_bytecode(self, bucket: Bucket) -> None:
|
| 265 |
+
filename = self._get_cache_filename(bucket)
|
| 266 |
+
|
| 267 |
+
# Don't test for existence before opening the file, since the
|
| 268 |
+
# file could disappear after the test before the open.
|
| 269 |
+
try:
|
| 270 |
+
f = open(filename, "rb")
|
| 271 |
+
except (FileNotFoundError, IsADirectoryError, PermissionError):
|
| 272 |
+
# PermissionError can occur on Windows when an operation is
|
| 273 |
+
# in progress, such as calling clear().
|
| 274 |
+
return
|
| 275 |
+
|
| 276 |
+
with f:
|
| 277 |
+
bucket.load_bytecode(f)
|
| 278 |
+
|
| 279 |
+
def dump_bytecode(self, bucket: Bucket) -> None:
|
| 280 |
+
# Write to a temporary file, then rename to the real name after
|
| 281 |
+
# writing. This avoids another process reading the file before
|
| 282 |
+
# it is fully written.
|
| 283 |
+
name = self._get_cache_filename(bucket)
|
| 284 |
+
f = tempfile.NamedTemporaryFile(
|
| 285 |
+
mode="wb",
|
| 286 |
+
dir=os.path.dirname(name),
|
| 287 |
+
prefix=os.path.basename(name),
|
| 288 |
+
suffix=".tmp",
|
| 289 |
+
delete=False,
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
def remove_silent() -> None:
|
| 293 |
+
try:
|
| 294 |
+
os.remove(f.name)
|
| 295 |
+
except OSError:
|
| 296 |
+
# Another process may have called clear(). On Windows,
|
| 297 |
+
# another program may be holding the file open.
|
| 298 |
+
pass
|
| 299 |
+
|
| 300 |
+
try:
|
| 301 |
+
with f:
|
| 302 |
+
bucket.write_bytecode(f)
|
| 303 |
+
except BaseException:
|
| 304 |
+
remove_silent()
|
| 305 |
+
raise
|
| 306 |
+
|
| 307 |
+
try:
|
| 308 |
+
os.replace(f.name, name)
|
| 309 |
+
except OSError:
|
| 310 |
+
# Another process may have called clear(). On Windows,
|
| 311 |
+
# another program may be holding the file open.
|
| 312 |
+
remove_silent()
|
| 313 |
+
except BaseException:
|
| 314 |
+
remove_silent()
|
| 315 |
+
raise
|
| 316 |
+
|
| 317 |
+
def clear(self) -> None:
|
| 318 |
+
# imported lazily here because google app-engine doesn't support
|
| 319 |
+
# write access on the file system and the function does not exist
|
| 320 |
+
# normally.
|
| 321 |
+
from os import remove
|
| 322 |
+
|
| 323 |
+
files = fnmatch.filter(os.listdir(self.directory), self.pattern % ("*",))
|
| 324 |
+
for filename in files:
|
| 325 |
+
try:
|
| 326 |
+
remove(os.path.join(self.directory, filename))
|
| 327 |
+
except OSError:
|
| 328 |
+
pass
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class MemcachedBytecodeCache(BytecodeCache):
|
| 332 |
+
"""This class implements a bytecode cache that uses a memcache cache for
|
| 333 |
+
storing the information. It does not enforce a specific memcache library
|
| 334 |
+
(tummy's memcache or cmemcache) but will accept any class that provides
|
| 335 |
+
the minimal interface required.
|
| 336 |
+
|
| 337 |
+
Libraries compatible with this class:
|
| 338 |
+
|
| 339 |
+
- `cachelib <https://github.com/pallets/cachelib>`_
|
| 340 |
+
- `python-memcached <https://pypi.org/project/python-memcached/>`_
|
| 341 |
+
|
| 342 |
+
(Unfortunately the django cache interface is not compatible because it
|
| 343 |
+
does not support storing binary data, only text. You can however pass
|
| 344 |
+
the underlying cache client to the bytecode cache which is available
|
| 345 |
+
as `django.core.cache.cache._client`.)
|
| 346 |
+
|
| 347 |
+
The minimal interface for the client passed to the constructor is this:
|
| 348 |
+
|
| 349 |
+
.. class:: MinimalClientInterface
|
| 350 |
+
|
| 351 |
+
.. method:: set(key, value[, timeout])
|
| 352 |
+
|
| 353 |
+
Stores the bytecode in the cache. `value` is a string and
|
| 354 |
+
`timeout` the timeout of the key. If timeout is not provided
|
| 355 |
+
a default timeout or no timeout should be assumed, if it's
|
| 356 |
+
provided it's an integer with the number of seconds the cache
|
| 357 |
+
item should exist.
|
| 358 |
+
|
| 359 |
+
.. method:: get(key)
|
| 360 |
+
|
| 361 |
+
Returns the value for the cache key. If the item does not
|
| 362 |
+
exist in the cache the return value must be `None`.
|
| 363 |
+
|
| 364 |
+
The other arguments to the constructor are the prefix for all keys that
|
| 365 |
+
is added before the actual cache key and the timeout for the bytecode in
|
| 366 |
+
the cache system. We recommend a high (or no) timeout.
|
| 367 |
+
|
| 368 |
+
This bytecode cache does not support clearing of used items in the cache.
|
| 369 |
+
The clear method is a no-operation function.
|
| 370 |
+
|
| 371 |
+
.. versionadded:: 2.7
|
| 372 |
+
Added support for ignoring memcache errors through the
|
| 373 |
+
`ignore_memcache_errors` parameter.
|
| 374 |
+
"""
|
| 375 |
+
|
| 376 |
+
def __init__(
|
| 377 |
+
self,
|
| 378 |
+
client: "_MemcachedClient",
|
| 379 |
+
prefix: str = "jinja2/bytecode/",
|
| 380 |
+
timeout: t.Optional[int] = None,
|
| 381 |
+
ignore_memcache_errors: bool = True,
|
| 382 |
+
):
|
| 383 |
+
self.client = client
|
| 384 |
+
self.prefix = prefix
|
| 385 |
+
self.timeout = timeout
|
| 386 |
+
self.ignore_memcache_errors = ignore_memcache_errors
|
| 387 |
+
|
| 388 |
+
def load_bytecode(self, bucket: Bucket) -> None:
|
| 389 |
+
try:
|
| 390 |
+
code = self.client.get(self.prefix + bucket.key)
|
| 391 |
+
except Exception:
|
| 392 |
+
if not self.ignore_memcache_errors:
|
| 393 |
+
raise
|
| 394 |
+
else:
|
| 395 |
+
bucket.bytecode_from_string(code)
|
| 396 |
+
|
| 397 |
+
def dump_bytecode(self, bucket: Bucket) -> None:
|
| 398 |
+
key = self.prefix + bucket.key
|
| 399 |
+
value = bucket.bytecode_to_string()
|
| 400 |
+
|
| 401 |
+
try:
|
| 402 |
+
if self.timeout is not None:
|
| 403 |
+
self.client.set(key, value, self.timeout)
|
| 404 |
+
else:
|
| 405 |
+
self.client.set(key, value)
|
| 406 |
+
except Exception:
|
| 407 |
+
if not self.ignore_memcache_errors:
|
| 408 |
+
raise
|
deepseekvl2/lib/python3.10/site-packages/jinja2/compiler.py
ADDED
|
@@ -0,0 +1,1998 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Compiles nodes from the parser into Python code."""
|
| 2 |
+
|
| 3 |
+
import typing as t
|
| 4 |
+
from contextlib import contextmanager
|
| 5 |
+
from functools import update_wrapper
|
| 6 |
+
from io import StringIO
|
| 7 |
+
from itertools import chain
|
| 8 |
+
from keyword import iskeyword as is_python_keyword
|
| 9 |
+
|
| 10 |
+
from markupsafe import escape
|
| 11 |
+
from markupsafe import Markup
|
| 12 |
+
|
| 13 |
+
from . import nodes
|
| 14 |
+
from .exceptions import TemplateAssertionError
|
| 15 |
+
from .idtracking import Symbols
|
| 16 |
+
from .idtracking import VAR_LOAD_ALIAS
|
| 17 |
+
from .idtracking import VAR_LOAD_PARAMETER
|
| 18 |
+
from .idtracking import VAR_LOAD_RESOLVE
|
| 19 |
+
from .idtracking import VAR_LOAD_UNDEFINED
|
| 20 |
+
from .nodes import EvalContext
|
| 21 |
+
from .optimizer import Optimizer
|
| 22 |
+
from .utils import _PassArg
|
| 23 |
+
from .utils import concat
|
| 24 |
+
from .visitor import NodeVisitor
|
| 25 |
+
|
| 26 |
+
if t.TYPE_CHECKING:
|
| 27 |
+
import typing_extensions as te
|
| 28 |
+
|
| 29 |
+
from .environment import Environment
|
| 30 |
+
|
| 31 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 32 |
+
|
| 33 |
+
operators = {
|
| 34 |
+
"eq": "==",
|
| 35 |
+
"ne": "!=",
|
| 36 |
+
"gt": ">",
|
| 37 |
+
"gteq": ">=",
|
| 38 |
+
"lt": "<",
|
| 39 |
+
"lteq": "<=",
|
| 40 |
+
"in": "in",
|
| 41 |
+
"notin": "not in",
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def optimizeconst(f: F) -> F:
|
| 46 |
+
def new_func(
|
| 47 |
+
self: "CodeGenerator", node: nodes.Expr, frame: "Frame", **kwargs: t.Any
|
| 48 |
+
) -> t.Any:
|
| 49 |
+
# Only optimize if the frame is not volatile
|
| 50 |
+
if self.optimizer is not None and not frame.eval_ctx.volatile:
|
| 51 |
+
new_node = self.optimizer.visit(node, frame.eval_ctx)
|
| 52 |
+
|
| 53 |
+
if new_node != node:
|
| 54 |
+
return self.visit(new_node, frame)
|
| 55 |
+
|
| 56 |
+
return f(self, node, frame, **kwargs)
|
| 57 |
+
|
| 58 |
+
return update_wrapper(new_func, f) # type: ignore[return-value]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _make_binop(op: str) -> t.Callable[["CodeGenerator", nodes.BinExpr, "Frame"], None]:
|
| 62 |
+
@optimizeconst
|
| 63 |
+
def visitor(self: "CodeGenerator", node: nodes.BinExpr, frame: Frame) -> None:
|
| 64 |
+
if (
|
| 65 |
+
self.environment.sandboxed and op in self.environment.intercepted_binops # type: ignore
|
| 66 |
+
):
|
| 67 |
+
self.write(f"environment.call_binop(context, {op!r}, ")
|
| 68 |
+
self.visit(node.left, frame)
|
| 69 |
+
self.write(", ")
|
| 70 |
+
self.visit(node.right, frame)
|
| 71 |
+
else:
|
| 72 |
+
self.write("(")
|
| 73 |
+
self.visit(node.left, frame)
|
| 74 |
+
self.write(f" {op} ")
|
| 75 |
+
self.visit(node.right, frame)
|
| 76 |
+
|
| 77 |
+
self.write(")")
|
| 78 |
+
|
| 79 |
+
return visitor
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _make_unop(
|
| 83 |
+
op: str,
|
| 84 |
+
) -> t.Callable[["CodeGenerator", nodes.UnaryExpr, "Frame"], None]:
|
| 85 |
+
@optimizeconst
|
| 86 |
+
def visitor(self: "CodeGenerator", node: nodes.UnaryExpr, frame: Frame) -> None:
|
| 87 |
+
if (
|
| 88 |
+
self.environment.sandboxed and op in self.environment.intercepted_unops # type: ignore
|
| 89 |
+
):
|
| 90 |
+
self.write(f"environment.call_unop(context, {op!r}, ")
|
| 91 |
+
self.visit(node.node, frame)
|
| 92 |
+
else:
|
| 93 |
+
self.write("(" + op)
|
| 94 |
+
self.visit(node.node, frame)
|
| 95 |
+
|
| 96 |
+
self.write(")")
|
| 97 |
+
|
| 98 |
+
return visitor
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def generate(
|
| 102 |
+
node: nodes.Template,
|
| 103 |
+
environment: "Environment",
|
| 104 |
+
name: t.Optional[str],
|
| 105 |
+
filename: t.Optional[str],
|
| 106 |
+
stream: t.Optional[t.TextIO] = None,
|
| 107 |
+
defer_init: bool = False,
|
| 108 |
+
optimized: bool = True,
|
| 109 |
+
) -> t.Optional[str]:
|
| 110 |
+
"""Generate the python source for a node tree."""
|
| 111 |
+
if not isinstance(node, nodes.Template):
|
| 112 |
+
raise TypeError("Can't compile non template nodes")
|
| 113 |
+
|
| 114 |
+
generator = environment.code_generator_class(
|
| 115 |
+
environment, name, filename, stream, defer_init, optimized
|
| 116 |
+
)
|
| 117 |
+
generator.visit(node)
|
| 118 |
+
|
| 119 |
+
if stream is None:
|
| 120 |
+
return generator.stream.getvalue() # type: ignore
|
| 121 |
+
|
| 122 |
+
return None
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def has_safe_repr(value: t.Any) -> bool:
|
| 126 |
+
"""Does the node have a safe representation?"""
|
| 127 |
+
if value is None or value is NotImplemented or value is Ellipsis:
|
| 128 |
+
return True
|
| 129 |
+
|
| 130 |
+
if type(value) in {bool, int, float, complex, range, str, Markup}:
|
| 131 |
+
return True
|
| 132 |
+
|
| 133 |
+
if type(value) in {tuple, list, set, frozenset}:
|
| 134 |
+
return all(has_safe_repr(v) for v in value)
|
| 135 |
+
|
| 136 |
+
if type(value) is dict: # noqa E721
|
| 137 |
+
return all(has_safe_repr(k) and has_safe_repr(v) for k, v in value.items())
|
| 138 |
+
|
| 139 |
+
return False
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def find_undeclared(
|
| 143 |
+
nodes: t.Iterable[nodes.Node], names: t.Iterable[str]
|
| 144 |
+
) -> t.Set[str]:
|
| 145 |
+
"""Check if the names passed are accessed undeclared. The return value
|
| 146 |
+
is a set of all the undeclared names from the sequence of names found.
|
| 147 |
+
"""
|
| 148 |
+
visitor = UndeclaredNameVisitor(names)
|
| 149 |
+
try:
|
| 150 |
+
for node in nodes:
|
| 151 |
+
visitor.visit(node)
|
| 152 |
+
except VisitorExit:
|
| 153 |
+
pass
|
| 154 |
+
return visitor.undeclared
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
class MacroRef:
|
| 158 |
+
def __init__(self, node: t.Union[nodes.Macro, nodes.CallBlock]) -> None:
|
| 159 |
+
self.node = node
|
| 160 |
+
self.accesses_caller = False
|
| 161 |
+
self.accesses_kwargs = False
|
| 162 |
+
self.accesses_varargs = False
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class Frame:
|
| 166 |
+
"""Holds compile time information for us."""
|
| 167 |
+
|
| 168 |
+
def __init__(
|
| 169 |
+
self,
|
| 170 |
+
eval_ctx: EvalContext,
|
| 171 |
+
parent: t.Optional["Frame"] = None,
|
| 172 |
+
level: t.Optional[int] = None,
|
| 173 |
+
) -> None:
|
| 174 |
+
self.eval_ctx = eval_ctx
|
| 175 |
+
|
| 176 |
+
# the parent of this frame
|
| 177 |
+
self.parent = parent
|
| 178 |
+
|
| 179 |
+
if parent is None:
|
| 180 |
+
self.symbols = Symbols(level=level)
|
| 181 |
+
|
| 182 |
+
# in some dynamic inheritance situations the compiler needs to add
|
| 183 |
+
# write tests around output statements.
|
| 184 |
+
self.require_output_check = False
|
| 185 |
+
|
| 186 |
+
# inside some tags we are using a buffer rather than yield statements.
|
| 187 |
+
# this for example affects {% filter %} or {% macro %}. If a frame
|
| 188 |
+
# is buffered this variable points to the name of the list used as
|
| 189 |
+
# buffer.
|
| 190 |
+
self.buffer: t.Optional[str] = None
|
| 191 |
+
|
| 192 |
+
# the name of the block we're in, otherwise None.
|
| 193 |
+
self.block: t.Optional[str] = None
|
| 194 |
+
|
| 195 |
+
else:
|
| 196 |
+
self.symbols = Symbols(parent.symbols, level=level)
|
| 197 |
+
self.require_output_check = parent.require_output_check
|
| 198 |
+
self.buffer = parent.buffer
|
| 199 |
+
self.block = parent.block
|
| 200 |
+
|
| 201 |
+
# a toplevel frame is the root + soft frames such as if conditions.
|
| 202 |
+
self.toplevel = False
|
| 203 |
+
|
| 204 |
+
# the root frame is basically just the outermost frame, so no if
|
| 205 |
+
# conditions. This information is used to optimize inheritance
|
| 206 |
+
# situations.
|
| 207 |
+
self.rootlevel = False
|
| 208 |
+
|
| 209 |
+
# variables set inside of loops and blocks should not affect outer frames,
|
| 210 |
+
# but they still needs to be kept track of as part of the active context.
|
| 211 |
+
self.loop_frame = False
|
| 212 |
+
self.block_frame = False
|
| 213 |
+
|
| 214 |
+
# track whether the frame is being used in an if-statement or conditional
|
| 215 |
+
# expression as it determines which errors should be raised during runtime
|
| 216 |
+
# or compile time.
|
| 217 |
+
self.soft_frame = False
|
| 218 |
+
|
| 219 |
+
def copy(self) -> "te.Self":
|
| 220 |
+
"""Create a copy of the current one."""
|
| 221 |
+
rv = object.__new__(self.__class__)
|
| 222 |
+
rv.__dict__.update(self.__dict__)
|
| 223 |
+
rv.symbols = self.symbols.copy()
|
| 224 |
+
return rv
|
| 225 |
+
|
| 226 |
+
def inner(self, isolated: bool = False) -> "Frame":
|
| 227 |
+
"""Return an inner frame."""
|
| 228 |
+
if isolated:
|
| 229 |
+
return Frame(self.eval_ctx, level=self.symbols.level + 1)
|
| 230 |
+
return Frame(self.eval_ctx, self)
|
| 231 |
+
|
| 232 |
+
def soft(self) -> "te.Self":
|
| 233 |
+
"""Return a soft frame. A soft frame may not be modified as
|
| 234 |
+
standalone thing as it shares the resources with the frame it
|
| 235 |
+
was created of, but it's not a rootlevel frame any longer.
|
| 236 |
+
|
| 237 |
+
This is only used to implement if-statements and conditional
|
| 238 |
+
expressions.
|
| 239 |
+
"""
|
| 240 |
+
rv = self.copy()
|
| 241 |
+
rv.rootlevel = False
|
| 242 |
+
rv.soft_frame = True
|
| 243 |
+
return rv
|
| 244 |
+
|
| 245 |
+
__copy__ = copy
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class VisitorExit(RuntimeError):
|
| 249 |
+
"""Exception used by the `UndeclaredNameVisitor` to signal a stop."""
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class DependencyFinderVisitor(NodeVisitor):
|
| 253 |
+
"""A visitor that collects filter and test calls."""
|
| 254 |
+
|
| 255 |
+
def __init__(self) -> None:
|
| 256 |
+
self.filters: t.Set[str] = set()
|
| 257 |
+
self.tests: t.Set[str] = set()
|
| 258 |
+
|
| 259 |
+
def visit_Filter(self, node: nodes.Filter) -> None:
|
| 260 |
+
self.generic_visit(node)
|
| 261 |
+
self.filters.add(node.name)
|
| 262 |
+
|
| 263 |
+
def visit_Test(self, node: nodes.Test) -> None:
|
| 264 |
+
self.generic_visit(node)
|
| 265 |
+
self.tests.add(node.name)
|
| 266 |
+
|
| 267 |
+
def visit_Block(self, node: nodes.Block) -> None:
|
| 268 |
+
"""Stop visiting at blocks."""
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
class UndeclaredNameVisitor(NodeVisitor):
|
| 272 |
+
"""A visitor that checks if a name is accessed without being
|
| 273 |
+
declared. This is different from the frame visitor as it will
|
| 274 |
+
not stop at closure frames.
|
| 275 |
+
"""
|
| 276 |
+
|
| 277 |
+
def __init__(self, names: t.Iterable[str]) -> None:
|
| 278 |
+
self.names = set(names)
|
| 279 |
+
self.undeclared: t.Set[str] = set()
|
| 280 |
+
|
| 281 |
+
def visit_Name(self, node: nodes.Name) -> None:
|
| 282 |
+
if node.ctx == "load" and node.name in self.names:
|
| 283 |
+
self.undeclared.add(node.name)
|
| 284 |
+
if self.undeclared == self.names:
|
| 285 |
+
raise VisitorExit()
|
| 286 |
+
else:
|
| 287 |
+
self.names.discard(node.name)
|
| 288 |
+
|
| 289 |
+
def visit_Block(self, node: nodes.Block) -> None:
|
| 290 |
+
"""Stop visiting a blocks."""
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
class CompilerExit(Exception):
|
| 294 |
+
"""Raised if the compiler encountered a situation where it just
|
| 295 |
+
doesn't make sense to further process the code. Any block that
|
| 296 |
+
raises such an exception is not further processed.
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class CodeGenerator(NodeVisitor):
|
| 301 |
+
def __init__(
|
| 302 |
+
self,
|
| 303 |
+
environment: "Environment",
|
| 304 |
+
name: t.Optional[str],
|
| 305 |
+
filename: t.Optional[str],
|
| 306 |
+
stream: t.Optional[t.TextIO] = None,
|
| 307 |
+
defer_init: bool = False,
|
| 308 |
+
optimized: bool = True,
|
| 309 |
+
) -> None:
|
| 310 |
+
if stream is None:
|
| 311 |
+
stream = StringIO()
|
| 312 |
+
self.environment = environment
|
| 313 |
+
self.name = name
|
| 314 |
+
self.filename = filename
|
| 315 |
+
self.stream = stream
|
| 316 |
+
self.created_block_context = False
|
| 317 |
+
self.defer_init = defer_init
|
| 318 |
+
self.optimizer: t.Optional[Optimizer] = None
|
| 319 |
+
|
| 320 |
+
if optimized:
|
| 321 |
+
self.optimizer = Optimizer(environment)
|
| 322 |
+
|
| 323 |
+
# aliases for imports
|
| 324 |
+
self.import_aliases: t.Dict[str, str] = {}
|
| 325 |
+
|
| 326 |
+
# a registry for all blocks. Because blocks are moved out
|
| 327 |
+
# into the global python scope they are registered here
|
| 328 |
+
self.blocks: t.Dict[str, nodes.Block] = {}
|
| 329 |
+
|
| 330 |
+
# the number of extends statements so far
|
| 331 |
+
self.extends_so_far = 0
|
| 332 |
+
|
| 333 |
+
# some templates have a rootlevel extends. In this case we
|
| 334 |
+
# can safely assume that we're a child template and do some
|
| 335 |
+
# more optimizations.
|
| 336 |
+
self.has_known_extends = False
|
| 337 |
+
|
| 338 |
+
# the current line number
|
| 339 |
+
self.code_lineno = 1
|
| 340 |
+
|
| 341 |
+
# registry of all filters and tests (global, not block local)
|
| 342 |
+
self.tests: t.Dict[str, str] = {}
|
| 343 |
+
self.filters: t.Dict[str, str] = {}
|
| 344 |
+
|
| 345 |
+
# the debug information
|
| 346 |
+
self.debug_info: t.List[t.Tuple[int, int]] = []
|
| 347 |
+
self._write_debug_info: t.Optional[int] = None
|
| 348 |
+
|
| 349 |
+
# the number of new lines before the next write()
|
| 350 |
+
self._new_lines = 0
|
| 351 |
+
|
| 352 |
+
# the line number of the last written statement
|
| 353 |
+
self._last_line = 0
|
| 354 |
+
|
| 355 |
+
# true if nothing was written so far.
|
| 356 |
+
self._first_write = True
|
| 357 |
+
|
| 358 |
+
# used by the `temporary_identifier` method to get new
|
| 359 |
+
# unique, temporary identifier
|
| 360 |
+
self._last_identifier = 0
|
| 361 |
+
|
| 362 |
+
# the current indentation
|
| 363 |
+
self._indentation = 0
|
| 364 |
+
|
| 365 |
+
# Tracks toplevel assignments
|
| 366 |
+
self._assign_stack: t.List[t.Set[str]] = []
|
| 367 |
+
|
| 368 |
+
# Tracks parameter definition blocks
|
| 369 |
+
self._param_def_block: t.List[t.Set[str]] = []
|
| 370 |
+
|
| 371 |
+
# Tracks the current context.
|
| 372 |
+
self._context_reference_stack = ["context"]
|
| 373 |
+
|
| 374 |
+
@property
|
| 375 |
+
def optimized(self) -> bool:
|
| 376 |
+
return self.optimizer is not None
|
| 377 |
+
|
| 378 |
+
# -- Various compilation helpers
|
| 379 |
+
|
| 380 |
+
def fail(self, msg: str, lineno: int) -> "te.NoReturn":
|
| 381 |
+
"""Fail with a :exc:`TemplateAssertionError`."""
|
| 382 |
+
raise TemplateAssertionError(msg, lineno, self.name, self.filename)
|
| 383 |
+
|
| 384 |
+
def temporary_identifier(self) -> str:
|
| 385 |
+
"""Get a new unique identifier."""
|
| 386 |
+
self._last_identifier += 1
|
| 387 |
+
return f"t_{self._last_identifier}"
|
| 388 |
+
|
| 389 |
+
def buffer(self, frame: Frame) -> None:
|
| 390 |
+
"""Enable buffering for the frame from that point onwards."""
|
| 391 |
+
frame.buffer = self.temporary_identifier()
|
| 392 |
+
self.writeline(f"{frame.buffer} = []")
|
| 393 |
+
|
| 394 |
+
def return_buffer_contents(
|
| 395 |
+
self, frame: Frame, force_unescaped: bool = False
|
| 396 |
+
) -> None:
|
| 397 |
+
"""Return the buffer contents of the frame."""
|
| 398 |
+
if not force_unescaped:
|
| 399 |
+
if frame.eval_ctx.volatile:
|
| 400 |
+
self.writeline("if context.eval_ctx.autoescape:")
|
| 401 |
+
self.indent()
|
| 402 |
+
self.writeline(f"return Markup(concat({frame.buffer}))")
|
| 403 |
+
self.outdent()
|
| 404 |
+
self.writeline("else:")
|
| 405 |
+
self.indent()
|
| 406 |
+
self.writeline(f"return concat({frame.buffer})")
|
| 407 |
+
self.outdent()
|
| 408 |
+
return
|
| 409 |
+
elif frame.eval_ctx.autoescape:
|
| 410 |
+
self.writeline(f"return Markup(concat({frame.buffer}))")
|
| 411 |
+
return
|
| 412 |
+
self.writeline(f"return concat({frame.buffer})")
|
| 413 |
+
|
| 414 |
+
def indent(self) -> None:
|
| 415 |
+
"""Indent by one."""
|
| 416 |
+
self._indentation += 1
|
| 417 |
+
|
| 418 |
+
def outdent(self, step: int = 1) -> None:
|
| 419 |
+
"""Outdent by step."""
|
| 420 |
+
self._indentation -= step
|
| 421 |
+
|
| 422 |
+
def start_write(self, frame: Frame, node: t.Optional[nodes.Node] = None) -> None:
|
| 423 |
+
"""Yield or write into the frame buffer."""
|
| 424 |
+
if frame.buffer is None:
|
| 425 |
+
self.writeline("yield ", node)
|
| 426 |
+
else:
|
| 427 |
+
self.writeline(f"{frame.buffer}.append(", node)
|
| 428 |
+
|
| 429 |
+
def end_write(self, frame: Frame) -> None:
|
| 430 |
+
"""End the writing process started by `start_write`."""
|
| 431 |
+
if frame.buffer is not None:
|
| 432 |
+
self.write(")")
|
| 433 |
+
|
| 434 |
+
def simple_write(
|
| 435 |
+
self, s: str, frame: Frame, node: t.Optional[nodes.Node] = None
|
| 436 |
+
) -> None:
|
| 437 |
+
"""Simple shortcut for start_write + write + end_write."""
|
| 438 |
+
self.start_write(frame, node)
|
| 439 |
+
self.write(s)
|
| 440 |
+
self.end_write(frame)
|
| 441 |
+
|
| 442 |
+
def blockvisit(self, nodes: t.Iterable[nodes.Node], frame: Frame) -> None:
|
| 443 |
+
"""Visit a list of nodes as block in a frame. If the current frame
|
| 444 |
+
is no buffer a dummy ``if 0: yield None`` is written automatically.
|
| 445 |
+
"""
|
| 446 |
+
try:
|
| 447 |
+
self.writeline("pass")
|
| 448 |
+
for node in nodes:
|
| 449 |
+
self.visit(node, frame)
|
| 450 |
+
except CompilerExit:
|
| 451 |
+
pass
|
| 452 |
+
|
| 453 |
+
def write(self, x: str) -> None:
|
| 454 |
+
"""Write a string into the output stream."""
|
| 455 |
+
if self._new_lines:
|
| 456 |
+
if not self._first_write:
|
| 457 |
+
self.stream.write("\n" * self._new_lines)
|
| 458 |
+
self.code_lineno += self._new_lines
|
| 459 |
+
if self._write_debug_info is not None:
|
| 460 |
+
self.debug_info.append((self._write_debug_info, self.code_lineno))
|
| 461 |
+
self._write_debug_info = None
|
| 462 |
+
self._first_write = False
|
| 463 |
+
self.stream.write(" " * self._indentation)
|
| 464 |
+
self._new_lines = 0
|
| 465 |
+
self.stream.write(x)
|
| 466 |
+
|
| 467 |
+
def writeline(
|
| 468 |
+
self, x: str, node: t.Optional[nodes.Node] = None, extra: int = 0
|
| 469 |
+
) -> None:
|
| 470 |
+
"""Combination of newline and write."""
|
| 471 |
+
self.newline(node, extra)
|
| 472 |
+
self.write(x)
|
| 473 |
+
|
| 474 |
+
def newline(self, node: t.Optional[nodes.Node] = None, extra: int = 0) -> None:
|
| 475 |
+
"""Add one or more newlines before the next write."""
|
| 476 |
+
self._new_lines = max(self._new_lines, 1 + extra)
|
| 477 |
+
if node is not None and node.lineno != self._last_line:
|
| 478 |
+
self._write_debug_info = node.lineno
|
| 479 |
+
self._last_line = node.lineno
|
| 480 |
+
|
| 481 |
+
def signature(
|
| 482 |
+
self,
|
| 483 |
+
node: t.Union[nodes.Call, nodes.Filter, nodes.Test],
|
| 484 |
+
frame: Frame,
|
| 485 |
+
extra_kwargs: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 486 |
+
) -> None:
|
| 487 |
+
"""Writes a function call to the stream for the current node.
|
| 488 |
+
A leading comma is added automatically. The extra keyword
|
| 489 |
+
arguments may not include python keywords otherwise a syntax
|
| 490 |
+
error could occur. The extra keyword arguments should be given
|
| 491 |
+
as python dict.
|
| 492 |
+
"""
|
| 493 |
+
# if any of the given keyword arguments is a python keyword
|
| 494 |
+
# we have to make sure that no invalid call is created.
|
| 495 |
+
kwarg_workaround = any(
|
| 496 |
+
is_python_keyword(t.cast(str, k))
|
| 497 |
+
for k in chain((x.key for x in node.kwargs), extra_kwargs or ())
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
for arg in node.args:
|
| 501 |
+
self.write(", ")
|
| 502 |
+
self.visit(arg, frame)
|
| 503 |
+
|
| 504 |
+
if not kwarg_workaround:
|
| 505 |
+
for kwarg in node.kwargs:
|
| 506 |
+
self.write(", ")
|
| 507 |
+
self.visit(kwarg, frame)
|
| 508 |
+
if extra_kwargs is not None:
|
| 509 |
+
for key, value in extra_kwargs.items():
|
| 510 |
+
self.write(f", {key}={value}")
|
| 511 |
+
if node.dyn_args:
|
| 512 |
+
self.write(", *")
|
| 513 |
+
self.visit(node.dyn_args, frame)
|
| 514 |
+
|
| 515 |
+
if kwarg_workaround:
|
| 516 |
+
if node.dyn_kwargs is not None:
|
| 517 |
+
self.write(", **dict({")
|
| 518 |
+
else:
|
| 519 |
+
self.write(", **{")
|
| 520 |
+
for kwarg in node.kwargs:
|
| 521 |
+
self.write(f"{kwarg.key!r}: ")
|
| 522 |
+
self.visit(kwarg.value, frame)
|
| 523 |
+
self.write(", ")
|
| 524 |
+
if extra_kwargs is not None:
|
| 525 |
+
for key, value in extra_kwargs.items():
|
| 526 |
+
self.write(f"{key!r}: {value}, ")
|
| 527 |
+
if node.dyn_kwargs is not None:
|
| 528 |
+
self.write("}, **")
|
| 529 |
+
self.visit(node.dyn_kwargs, frame)
|
| 530 |
+
self.write(")")
|
| 531 |
+
else:
|
| 532 |
+
self.write("}")
|
| 533 |
+
|
| 534 |
+
elif node.dyn_kwargs is not None:
|
| 535 |
+
self.write(", **")
|
| 536 |
+
self.visit(node.dyn_kwargs, frame)
|
| 537 |
+
|
| 538 |
+
def pull_dependencies(self, nodes: t.Iterable[nodes.Node]) -> None:
|
| 539 |
+
"""Find all filter and test names used in the template and
|
| 540 |
+
assign them to variables in the compiled namespace. Checking
|
| 541 |
+
that the names are registered with the environment is done when
|
| 542 |
+
compiling the Filter and Test nodes. If the node is in an If or
|
| 543 |
+
CondExpr node, the check is done at runtime instead.
|
| 544 |
+
|
| 545 |
+
.. versionchanged:: 3.0
|
| 546 |
+
Filters and tests in If and CondExpr nodes are checked at
|
| 547 |
+
runtime instead of compile time.
|
| 548 |
+
"""
|
| 549 |
+
visitor = DependencyFinderVisitor()
|
| 550 |
+
|
| 551 |
+
for node in nodes:
|
| 552 |
+
visitor.visit(node)
|
| 553 |
+
|
| 554 |
+
for id_map, names, dependency in (
|
| 555 |
+
(self.filters, visitor.filters, "filters"),
|
| 556 |
+
(
|
| 557 |
+
self.tests,
|
| 558 |
+
visitor.tests,
|
| 559 |
+
"tests",
|
| 560 |
+
),
|
| 561 |
+
):
|
| 562 |
+
for name in sorted(names):
|
| 563 |
+
if name not in id_map:
|
| 564 |
+
id_map[name] = self.temporary_identifier()
|
| 565 |
+
|
| 566 |
+
# add check during runtime that dependencies used inside of executed
|
| 567 |
+
# blocks are defined, as this step may be skipped during compile time
|
| 568 |
+
self.writeline("try:")
|
| 569 |
+
self.indent()
|
| 570 |
+
self.writeline(f"{id_map[name]} = environment.{dependency}[{name!r}]")
|
| 571 |
+
self.outdent()
|
| 572 |
+
self.writeline("except KeyError:")
|
| 573 |
+
self.indent()
|
| 574 |
+
self.writeline("@internalcode")
|
| 575 |
+
self.writeline(f"def {id_map[name]}(*unused):")
|
| 576 |
+
self.indent()
|
| 577 |
+
self.writeline(
|
| 578 |
+
f'raise TemplateRuntimeError("No {dependency[:-1]}'
|
| 579 |
+
f' named {name!r} found.")'
|
| 580 |
+
)
|
| 581 |
+
self.outdent()
|
| 582 |
+
self.outdent()
|
| 583 |
+
|
| 584 |
+
def enter_frame(self, frame: Frame) -> None:
|
| 585 |
+
undefs = []
|
| 586 |
+
for target, (action, param) in frame.symbols.loads.items():
|
| 587 |
+
if action == VAR_LOAD_PARAMETER:
|
| 588 |
+
pass
|
| 589 |
+
elif action == VAR_LOAD_RESOLVE:
|
| 590 |
+
self.writeline(f"{target} = {self.get_resolve_func()}({param!r})")
|
| 591 |
+
elif action == VAR_LOAD_ALIAS:
|
| 592 |
+
self.writeline(f"{target} = {param}")
|
| 593 |
+
elif action == VAR_LOAD_UNDEFINED:
|
| 594 |
+
undefs.append(target)
|
| 595 |
+
else:
|
| 596 |
+
raise NotImplementedError("unknown load instruction")
|
| 597 |
+
if undefs:
|
| 598 |
+
self.writeline(f"{' = '.join(undefs)} = missing")
|
| 599 |
+
|
| 600 |
+
def leave_frame(self, frame: Frame, with_python_scope: bool = False) -> None:
|
| 601 |
+
if not with_python_scope:
|
| 602 |
+
undefs = []
|
| 603 |
+
for target in frame.symbols.loads:
|
| 604 |
+
undefs.append(target)
|
| 605 |
+
if undefs:
|
| 606 |
+
self.writeline(f"{' = '.join(undefs)} = missing")
|
| 607 |
+
|
| 608 |
+
def choose_async(self, async_value: str = "async ", sync_value: str = "") -> str:
|
| 609 |
+
return async_value if self.environment.is_async else sync_value
|
| 610 |
+
|
| 611 |
+
def func(self, name: str) -> str:
|
| 612 |
+
return f"{self.choose_async()}def {name}"
|
| 613 |
+
|
| 614 |
+
def macro_body(
|
| 615 |
+
self, node: t.Union[nodes.Macro, nodes.CallBlock], frame: Frame
|
| 616 |
+
) -> t.Tuple[Frame, MacroRef]:
|
| 617 |
+
"""Dump the function def of a macro or call block."""
|
| 618 |
+
frame = frame.inner()
|
| 619 |
+
frame.symbols.analyze_node(node)
|
| 620 |
+
macro_ref = MacroRef(node)
|
| 621 |
+
|
| 622 |
+
explicit_caller = None
|
| 623 |
+
skip_special_params = set()
|
| 624 |
+
args = []
|
| 625 |
+
|
| 626 |
+
for idx, arg in enumerate(node.args):
|
| 627 |
+
if arg.name == "caller":
|
| 628 |
+
explicit_caller = idx
|
| 629 |
+
if arg.name in ("kwargs", "varargs"):
|
| 630 |
+
skip_special_params.add(arg.name)
|
| 631 |
+
args.append(frame.symbols.ref(arg.name))
|
| 632 |
+
|
| 633 |
+
undeclared = find_undeclared(node.body, ("caller", "kwargs", "varargs"))
|
| 634 |
+
|
| 635 |
+
if "caller" in undeclared:
|
| 636 |
+
# In older Jinja versions there was a bug that allowed caller
|
| 637 |
+
# to retain the special behavior even if it was mentioned in
|
| 638 |
+
# the argument list. However thankfully this was only really
|
| 639 |
+
# working if it was the last argument. So we are explicitly
|
| 640 |
+
# checking this now and error out if it is anywhere else in
|
| 641 |
+
# the argument list.
|
| 642 |
+
if explicit_caller is not None:
|
| 643 |
+
try:
|
| 644 |
+
node.defaults[explicit_caller - len(node.args)]
|
| 645 |
+
except IndexError:
|
| 646 |
+
self.fail(
|
| 647 |
+
"When defining macros or call blocks the "
|
| 648 |
+
'special "caller" argument must be omitted '
|
| 649 |
+
"or be given a default.",
|
| 650 |
+
node.lineno,
|
| 651 |
+
)
|
| 652 |
+
else:
|
| 653 |
+
args.append(frame.symbols.declare_parameter("caller"))
|
| 654 |
+
macro_ref.accesses_caller = True
|
| 655 |
+
if "kwargs" in undeclared and "kwargs" not in skip_special_params:
|
| 656 |
+
args.append(frame.symbols.declare_parameter("kwargs"))
|
| 657 |
+
macro_ref.accesses_kwargs = True
|
| 658 |
+
if "varargs" in undeclared and "varargs" not in skip_special_params:
|
| 659 |
+
args.append(frame.symbols.declare_parameter("varargs"))
|
| 660 |
+
macro_ref.accesses_varargs = True
|
| 661 |
+
|
| 662 |
+
# macros are delayed, they never require output checks
|
| 663 |
+
frame.require_output_check = False
|
| 664 |
+
frame.symbols.analyze_node(node)
|
| 665 |
+
self.writeline(f"{self.func('macro')}({', '.join(args)}):", node)
|
| 666 |
+
self.indent()
|
| 667 |
+
|
| 668 |
+
self.buffer(frame)
|
| 669 |
+
self.enter_frame(frame)
|
| 670 |
+
|
| 671 |
+
self.push_parameter_definitions(frame)
|
| 672 |
+
for idx, arg in enumerate(node.args):
|
| 673 |
+
ref = frame.symbols.ref(arg.name)
|
| 674 |
+
self.writeline(f"if {ref} is missing:")
|
| 675 |
+
self.indent()
|
| 676 |
+
try:
|
| 677 |
+
default = node.defaults[idx - len(node.args)]
|
| 678 |
+
except IndexError:
|
| 679 |
+
self.writeline(
|
| 680 |
+
f'{ref} = undefined("parameter {arg.name!r} was not provided",'
|
| 681 |
+
f" name={arg.name!r})"
|
| 682 |
+
)
|
| 683 |
+
else:
|
| 684 |
+
self.writeline(f"{ref} = ")
|
| 685 |
+
self.visit(default, frame)
|
| 686 |
+
self.mark_parameter_stored(ref)
|
| 687 |
+
self.outdent()
|
| 688 |
+
self.pop_parameter_definitions()
|
| 689 |
+
|
| 690 |
+
self.blockvisit(node.body, frame)
|
| 691 |
+
self.return_buffer_contents(frame, force_unescaped=True)
|
| 692 |
+
self.leave_frame(frame, with_python_scope=True)
|
| 693 |
+
self.outdent()
|
| 694 |
+
|
| 695 |
+
return frame, macro_ref
|
| 696 |
+
|
| 697 |
+
def macro_def(self, macro_ref: MacroRef, frame: Frame) -> None:
|
| 698 |
+
"""Dump the macro definition for the def created by macro_body."""
|
| 699 |
+
arg_tuple = ", ".join(repr(x.name) for x in macro_ref.node.args)
|
| 700 |
+
name = getattr(macro_ref.node, "name", None)
|
| 701 |
+
if len(macro_ref.node.args) == 1:
|
| 702 |
+
arg_tuple += ","
|
| 703 |
+
self.write(
|
| 704 |
+
f"Macro(environment, macro, {name!r}, ({arg_tuple}),"
|
| 705 |
+
f" {macro_ref.accesses_kwargs!r}, {macro_ref.accesses_varargs!r},"
|
| 706 |
+
f" {macro_ref.accesses_caller!r}, context.eval_ctx.autoescape)"
|
| 707 |
+
)
|
| 708 |
+
|
| 709 |
+
def position(self, node: nodes.Node) -> str:
|
| 710 |
+
"""Return a human readable position for the node."""
|
| 711 |
+
rv = f"line {node.lineno}"
|
| 712 |
+
if self.name is not None:
|
| 713 |
+
rv = f"{rv} in {self.name!r}"
|
| 714 |
+
return rv
|
| 715 |
+
|
| 716 |
+
def dump_local_context(self, frame: Frame) -> str:
|
| 717 |
+
items_kv = ", ".join(
|
| 718 |
+
f"{name!r}: {target}"
|
| 719 |
+
for name, target in frame.symbols.dump_stores().items()
|
| 720 |
+
)
|
| 721 |
+
return f"{{{items_kv}}}"
|
| 722 |
+
|
| 723 |
+
def write_commons(self) -> None:
|
| 724 |
+
"""Writes a common preamble that is used by root and block functions.
|
| 725 |
+
Primarily this sets up common local helpers and enforces a generator
|
| 726 |
+
through a dead branch.
|
| 727 |
+
"""
|
| 728 |
+
self.writeline("resolve = context.resolve_or_missing")
|
| 729 |
+
self.writeline("undefined = environment.undefined")
|
| 730 |
+
self.writeline("concat = environment.concat")
|
| 731 |
+
# always use the standard Undefined class for the implicit else of
|
| 732 |
+
# conditional expressions
|
| 733 |
+
self.writeline("cond_expr_undefined = Undefined")
|
| 734 |
+
self.writeline("if 0: yield None")
|
| 735 |
+
|
| 736 |
+
def push_parameter_definitions(self, frame: Frame) -> None:
|
| 737 |
+
"""Pushes all parameter targets from the given frame into a local
|
| 738 |
+
stack that permits tracking of yet to be assigned parameters. In
|
| 739 |
+
particular this enables the optimization from `visit_Name` to skip
|
| 740 |
+
undefined expressions for parameters in macros as macros can reference
|
| 741 |
+
otherwise unbound parameters.
|
| 742 |
+
"""
|
| 743 |
+
self._param_def_block.append(frame.symbols.dump_param_targets())
|
| 744 |
+
|
| 745 |
+
def pop_parameter_definitions(self) -> None:
|
| 746 |
+
"""Pops the current parameter definitions set."""
|
| 747 |
+
self._param_def_block.pop()
|
| 748 |
+
|
| 749 |
+
def mark_parameter_stored(self, target: str) -> None:
|
| 750 |
+
"""Marks a parameter in the current parameter definitions as stored.
|
| 751 |
+
This will skip the enforced undefined checks.
|
| 752 |
+
"""
|
| 753 |
+
if self._param_def_block:
|
| 754 |
+
self._param_def_block[-1].discard(target)
|
| 755 |
+
|
| 756 |
+
def push_context_reference(self, target: str) -> None:
|
| 757 |
+
self._context_reference_stack.append(target)
|
| 758 |
+
|
| 759 |
+
def pop_context_reference(self) -> None:
|
| 760 |
+
self._context_reference_stack.pop()
|
| 761 |
+
|
| 762 |
+
def get_context_ref(self) -> str:
|
| 763 |
+
return self._context_reference_stack[-1]
|
| 764 |
+
|
| 765 |
+
def get_resolve_func(self) -> str:
|
| 766 |
+
target = self._context_reference_stack[-1]
|
| 767 |
+
if target == "context":
|
| 768 |
+
return "resolve"
|
| 769 |
+
return f"{target}.resolve"
|
| 770 |
+
|
| 771 |
+
def derive_context(self, frame: Frame) -> str:
|
| 772 |
+
return f"{self.get_context_ref()}.derived({self.dump_local_context(frame)})"
|
| 773 |
+
|
| 774 |
+
def parameter_is_undeclared(self, target: str) -> bool:
|
| 775 |
+
"""Checks if a given target is an undeclared parameter."""
|
| 776 |
+
if not self._param_def_block:
|
| 777 |
+
return False
|
| 778 |
+
return target in self._param_def_block[-1]
|
| 779 |
+
|
| 780 |
+
def push_assign_tracking(self) -> None:
|
| 781 |
+
"""Pushes a new layer for assignment tracking."""
|
| 782 |
+
self._assign_stack.append(set())
|
| 783 |
+
|
| 784 |
+
def pop_assign_tracking(self, frame: Frame) -> None:
|
| 785 |
+
"""Pops the topmost level for assignment tracking and updates the
|
| 786 |
+
context variables if necessary.
|
| 787 |
+
"""
|
| 788 |
+
vars = self._assign_stack.pop()
|
| 789 |
+
if (
|
| 790 |
+
not frame.block_frame
|
| 791 |
+
and not frame.loop_frame
|
| 792 |
+
and not frame.toplevel
|
| 793 |
+
or not vars
|
| 794 |
+
):
|
| 795 |
+
return
|
| 796 |
+
public_names = [x for x in vars if x[:1] != "_"]
|
| 797 |
+
if len(vars) == 1:
|
| 798 |
+
name = next(iter(vars))
|
| 799 |
+
ref = frame.symbols.ref(name)
|
| 800 |
+
if frame.loop_frame:
|
| 801 |
+
self.writeline(f"_loop_vars[{name!r}] = {ref}")
|
| 802 |
+
return
|
| 803 |
+
if frame.block_frame:
|
| 804 |
+
self.writeline(f"_block_vars[{name!r}] = {ref}")
|
| 805 |
+
return
|
| 806 |
+
self.writeline(f"context.vars[{name!r}] = {ref}")
|
| 807 |
+
else:
|
| 808 |
+
if frame.loop_frame:
|
| 809 |
+
self.writeline("_loop_vars.update({")
|
| 810 |
+
elif frame.block_frame:
|
| 811 |
+
self.writeline("_block_vars.update({")
|
| 812 |
+
else:
|
| 813 |
+
self.writeline("context.vars.update({")
|
| 814 |
+
for idx, name in enumerate(sorted(vars)):
|
| 815 |
+
if idx:
|
| 816 |
+
self.write(", ")
|
| 817 |
+
ref = frame.symbols.ref(name)
|
| 818 |
+
self.write(f"{name!r}: {ref}")
|
| 819 |
+
self.write("})")
|
| 820 |
+
if not frame.block_frame and not frame.loop_frame and public_names:
|
| 821 |
+
if len(public_names) == 1:
|
| 822 |
+
self.writeline(f"context.exported_vars.add({public_names[0]!r})")
|
| 823 |
+
else:
|
| 824 |
+
names_str = ", ".join(map(repr, sorted(public_names)))
|
| 825 |
+
self.writeline(f"context.exported_vars.update(({names_str}))")
|
| 826 |
+
|
| 827 |
+
# -- Statement Visitors
|
| 828 |
+
|
| 829 |
+
def visit_Template(
|
| 830 |
+
self, node: nodes.Template, frame: t.Optional[Frame] = None
|
| 831 |
+
) -> None:
|
| 832 |
+
assert frame is None, "no root frame allowed"
|
| 833 |
+
eval_ctx = EvalContext(self.environment, self.name)
|
| 834 |
+
|
| 835 |
+
from .runtime import async_exported
|
| 836 |
+
from .runtime import exported
|
| 837 |
+
|
| 838 |
+
if self.environment.is_async:
|
| 839 |
+
exported_names = sorted(exported + async_exported)
|
| 840 |
+
else:
|
| 841 |
+
exported_names = sorted(exported)
|
| 842 |
+
|
| 843 |
+
self.writeline("from jinja2.runtime import " + ", ".join(exported_names))
|
| 844 |
+
|
| 845 |
+
# if we want a deferred initialization we cannot move the
|
| 846 |
+
# environment into a local name
|
| 847 |
+
envenv = "" if self.defer_init else ", environment=environment"
|
| 848 |
+
|
| 849 |
+
# do we have an extends tag at all? If not, we can save some
|
| 850 |
+
# overhead by just not processing any inheritance code.
|
| 851 |
+
have_extends = node.find(nodes.Extends) is not None
|
| 852 |
+
|
| 853 |
+
# find all blocks
|
| 854 |
+
for block in node.find_all(nodes.Block):
|
| 855 |
+
if block.name in self.blocks:
|
| 856 |
+
self.fail(f"block {block.name!r} defined twice", block.lineno)
|
| 857 |
+
self.blocks[block.name] = block
|
| 858 |
+
|
| 859 |
+
# find all imports and import them
|
| 860 |
+
for import_ in node.find_all(nodes.ImportedName):
|
| 861 |
+
if import_.importname not in self.import_aliases:
|
| 862 |
+
imp = import_.importname
|
| 863 |
+
self.import_aliases[imp] = alias = self.temporary_identifier()
|
| 864 |
+
if "." in imp:
|
| 865 |
+
module, obj = imp.rsplit(".", 1)
|
| 866 |
+
self.writeline(f"from {module} import {obj} as {alias}")
|
| 867 |
+
else:
|
| 868 |
+
self.writeline(f"import {imp} as {alias}")
|
| 869 |
+
|
| 870 |
+
# add the load name
|
| 871 |
+
self.writeline(f"name = {self.name!r}")
|
| 872 |
+
|
| 873 |
+
# generate the root render function.
|
| 874 |
+
self.writeline(
|
| 875 |
+
f"{self.func('root')}(context, missing=missing{envenv}):", extra=1
|
| 876 |
+
)
|
| 877 |
+
self.indent()
|
| 878 |
+
self.write_commons()
|
| 879 |
+
|
| 880 |
+
# process the root
|
| 881 |
+
frame = Frame(eval_ctx)
|
| 882 |
+
if "self" in find_undeclared(node.body, ("self",)):
|
| 883 |
+
ref = frame.symbols.declare_parameter("self")
|
| 884 |
+
self.writeline(f"{ref} = TemplateReference(context)")
|
| 885 |
+
frame.symbols.analyze_node(node)
|
| 886 |
+
frame.toplevel = frame.rootlevel = True
|
| 887 |
+
frame.require_output_check = have_extends and not self.has_known_extends
|
| 888 |
+
if have_extends:
|
| 889 |
+
self.writeline("parent_template = None")
|
| 890 |
+
self.enter_frame(frame)
|
| 891 |
+
self.pull_dependencies(node.body)
|
| 892 |
+
self.blockvisit(node.body, frame)
|
| 893 |
+
self.leave_frame(frame, with_python_scope=True)
|
| 894 |
+
self.outdent()
|
| 895 |
+
|
| 896 |
+
# make sure that the parent root is called.
|
| 897 |
+
if have_extends:
|
| 898 |
+
if not self.has_known_extends:
|
| 899 |
+
self.indent()
|
| 900 |
+
self.writeline("if parent_template is not None:")
|
| 901 |
+
self.indent()
|
| 902 |
+
if not self.environment.is_async:
|
| 903 |
+
self.writeline("yield from parent_template.root_render_func(context)")
|
| 904 |
+
else:
|
| 905 |
+
self.writeline("agen = parent_template.root_render_func(context)")
|
| 906 |
+
self.writeline("try:")
|
| 907 |
+
self.indent()
|
| 908 |
+
self.writeline("async for event in agen:")
|
| 909 |
+
self.indent()
|
| 910 |
+
self.writeline("yield event")
|
| 911 |
+
self.outdent()
|
| 912 |
+
self.outdent()
|
| 913 |
+
self.writeline("finally: await agen.aclose()")
|
| 914 |
+
self.outdent(1 + (not self.has_known_extends))
|
| 915 |
+
|
| 916 |
+
# at this point we now have the blocks collected and can visit them too.
|
| 917 |
+
for name, block in self.blocks.items():
|
| 918 |
+
self.writeline(
|
| 919 |
+
f"{self.func('block_' + name)}(context, missing=missing{envenv}):",
|
| 920 |
+
block,
|
| 921 |
+
1,
|
| 922 |
+
)
|
| 923 |
+
self.indent()
|
| 924 |
+
self.write_commons()
|
| 925 |
+
# It's important that we do not make this frame a child of the
|
| 926 |
+
# toplevel template. This would cause a variety of
|
| 927 |
+
# interesting issues with identifier tracking.
|
| 928 |
+
block_frame = Frame(eval_ctx)
|
| 929 |
+
block_frame.block_frame = True
|
| 930 |
+
undeclared = find_undeclared(block.body, ("self", "super"))
|
| 931 |
+
if "self" in undeclared:
|
| 932 |
+
ref = block_frame.symbols.declare_parameter("self")
|
| 933 |
+
self.writeline(f"{ref} = TemplateReference(context)")
|
| 934 |
+
if "super" in undeclared:
|
| 935 |
+
ref = block_frame.symbols.declare_parameter("super")
|
| 936 |
+
self.writeline(f"{ref} = context.super({name!r}, block_{name})")
|
| 937 |
+
block_frame.symbols.analyze_node(block)
|
| 938 |
+
block_frame.block = name
|
| 939 |
+
self.writeline("_block_vars = {}")
|
| 940 |
+
self.enter_frame(block_frame)
|
| 941 |
+
self.pull_dependencies(block.body)
|
| 942 |
+
self.blockvisit(block.body, block_frame)
|
| 943 |
+
self.leave_frame(block_frame, with_python_scope=True)
|
| 944 |
+
self.outdent()
|
| 945 |
+
|
| 946 |
+
blocks_kv_str = ", ".join(f"{x!r}: block_{x}" for x in self.blocks)
|
| 947 |
+
self.writeline(f"blocks = {{{blocks_kv_str}}}", extra=1)
|
| 948 |
+
debug_kv_str = "&".join(f"{k}={v}" for k, v in self.debug_info)
|
| 949 |
+
self.writeline(f"debug_info = {debug_kv_str!r}")
|
| 950 |
+
|
| 951 |
+
def visit_Block(self, node: nodes.Block, frame: Frame) -> None:
|
| 952 |
+
"""Call a block and register it for the template."""
|
| 953 |
+
level = 0
|
| 954 |
+
if frame.toplevel:
|
| 955 |
+
# if we know that we are a child template, there is no need to
|
| 956 |
+
# check if we are one
|
| 957 |
+
if self.has_known_extends:
|
| 958 |
+
return
|
| 959 |
+
if self.extends_so_far > 0:
|
| 960 |
+
self.writeline("if parent_template is None:")
|
| 961 |
+
self.indent()
|
| 962 |
+
level += 1
|
| 963 |
+
|
| 964 |
+
if node.scoped:
|
| 965 |
+
context = self.derive_context(frame)
|
| 966 |
+
else:
|
| 967 |
+
context = self.get_context_ref()
|
| 968 |
+
|
| 969 |
+
if node.required:
|
| 970 |
+
self.writeline(f"if len(context.blocks[{node.name!r}]) <= 1:", node)
|
| 971 |
+
self.indent()
|
| 972 |
+
self.writeline(
|
| 973 |
+
f'raise TemplateRuntimeError("Required block {node.name!r} not found")',
|
| 974 |
+
node,
|
| 975 |
+
)
|
| 976 |
+
self.outdent()
|
| 977 |
+
|
| 978 |
+
if not self.environment.is_async and frame.buffer is None:
|
| 979 |
+
self.writeline(
|
| 980 |
+
f"yield from context.blocks[{node.name!r}][0]({context})", node
|
| 981 |
+
)
|
| 982 |
+
else:
|
| 983 |
+
self.writeline(f"gen = context.blocks[{node.name!r}][0]({context})")
|
| 984 |
+
self.writeline("try:")
|
| 985 |
+
self.indent()
|
| 986 |
+
self.writeline(
|
| 987 |
+
f"{self.choose_async()}for event in gen:",
|
| 988 |
+
node,
|
| 989 |
+
)
|
| 990 |
+
self.indent()
|
| 991 |
+
self.simple_write("event", frame)
|
| 992 |
+
self.outdent()
|
| 993 |
+
self.outdent()
|
| 994 |
+
self.writeline(
|
| 995 |
+
f"finally: {self.choose_async('await gen.aclose()', 'gen.close()')}"
|
| 996 |
+
)
|
| 997 |
+
|
| 998 |
+
self.outdent(level)
|
| 999 |
+
|
| 1000 |
+
def visit_Extends(self, node: nodes.Extends, frame: Frame) -> None:
|
| 1001 |
+
"""Calls the extender."""
|
| 1002 |
+
if not frame.toplevel:
|
| 1003 |
+
self.fail("cannot use extend from a non top-level scope", node.lineno)
|
| 1004 |
+
|
| 1005 |
+
# if the number of extends statements in general is zero so
|
| 1006 |
+
# far, we don't have to add a check if something extended
|
| 1007 |
+
# the template before this one.
|
| 1008 |
+
if self.extends_so_far > 0:
|
| 1009 |
+
# if we have a known extends we just add a template runtime
|
| 1010 |
+
# error into the generated code. We could catch that at compile
|
| 1011 |
+
# time too, but i welcome it not to confuse users by throwing the
|
| 1012 |
+
# same error at different times just "because we can".
|
| 1013 |
+
if not self.has_known_extends:
|
| 1014 |
+
self.writeline("if parent_template is not None:")
|
| 1015 |
+
self.indent()
|
| 1016 |
+
self.writeline('raise TemplateRuntimeError("extended multiple times")')
|
| 1017 |
+
|
| 1018 |
+
# if we have a known extends already we don't need that code here
|
| 1019 |
+
# as we know that the template execution will end here.
|
| 1020 |
+
if self.has_known_extends:
|
| 1021 |
+
raise CompilerExit()
|
| 1022 |
+
else:
|
| 1023 |
+
self.outdent()
|
| 1024 |
+
|
| 1025 |
+
self.writeline("parent_template = environment.get_template(", node)
|
| 1026 |
+
self.visit(node.template, frame)
|
| 1027 |
+
self.write(f", {self.name!r})")
|
| 1028 |
+
self.writeline("for name, parent_block in parent_template.blocks.items():")
|
| 1029 |
+
self.indent()
|
| 1030 |
+
self.writeline("context.blocks.setdefault(name, []).append(parent_block)")
|
| 1031 |
+
self.outdent()
|
| 1032 |
+
|
| 1033 |
+
# if this extends statement was in the root level we can take
|
| 1034 |
+
# advantage of that information and simplify the generated code
|
| 1035 |
+
# in the top level from this point onwards
|
| 1036 |
+
if frame.rootlevel:
|
| 1037 |
+
self.has_known_extends = True
|
| 1038 |
+
|
| 1039 |
+
# and now we have one more
|
| 1040 |
+
self.extends_so_far += 1
|
| 1041 |
+
|
| 1042 |
+
def visit_Include(self, node: nodes.Include, frame: Frame) -> None:
|
| 1043 |
+
"""Handles includes."""
|
| 1044 |
+
if node.ignore_missing:
|
| 1045 |
+
self.writeline("try:")
|
| 1046 |
+
self.indent()
|
| 1047 |
+
|
| 1048 |
+
func_name = "get_or_select_template"
|
| 1049 |
+
if isinstance(node.template, nodes.Const):
|
| 1050 |
+
if isinstance(node.template.value, str):
|
| 1051 |
+
func_name = "get_template"
|
| 1052 |
+
elif isinstance(node.template.value, (tuple, list)):
|
| 1053 |
+
func_name = "select_template"
|
| 1054 |
+
elif isinstance(node.template, (nodes.Tuple, nodes.List)):
|
| 1055 |
+
func_name = "select_template"
|
| 1056 |
+
|
| 1057 |
+
self.writeline(f"template = environment.{func_name}(", node)
|
| 1058 |
+
self.visit(node.template, frame)
|
| 1059 |
+
self.write(f", {self.name!r})")
|
| 1060 |
+
if node.ignore_missing:
|
| 1061 |
+
self.outdent()
|
| 1062 |
+
self.writeline("except TemplateNotFound:")
|
| 1063 |
+
self.indent()
|
| 1064 |
+
self.writeline("pass")
|
| 1065 |
+
self.outdent()
|
| 1066 |
+
self.writeline("else:")
|
| 1067 |
+
self.indent()
|
| 1068 |
+
|
| 1069 |
+
def loop_body() -> None:
|
| 1070 |
+
self.indent()
|
| 1071 |
+
self.simple_write("event", frame)
|
| 1072 |
+
self.outdent()
|
| 1073 |
+
|
| 1074 |
+
if node.with_context:
|
| 1075 |
+
self.writeline(
|
| 1076 |
+
f"gen = template.root_render_func("
|
| 1077 |
+
"template.new_context(context.get_all(), True,"
|
| 1078 |
+
f" {self.dump_local_context(frame)}))"
|
| 1079 |
+
)
|
| 1080 |
+
self.writeline("try:")
|
| 1081 |
+
self.indent()
|
| 1082 |
+
self.writeline(f"{self.choose_async()}for event in gen:")
|
| 1083 |
+
loop_body()
|
| 1084 |
+
self.outdent()
|
| 1085 |
+
self.writeline(
|
| 1086 |
+
f"finally: {self.choose_async('await gen.aclose()', 'gen.close()')}"
|
| 1087 |
+
)
|
| 1088 |
+
elif self.environment.is_async:
|
| 1089 |
+
self.writeline(
|
| 1090 |
+
"for event in (await template._get_default_module_async())"
|
| 1091 |
+
"._body_stream:"
|
| 1092 |
+
)
|
| 1093 |
+
loop_body()
|
| 1094 |
+
else:
|
| 1095 |
+
self.writeline("yield from template._get_default_module()._body_stream")
|
| 1096 |
+
|
| 1097 |
+
if node.ignore_missing:
|
| 1098 |
+
self.outdent()
|
| 1099 |
+
|
| 1100 |
+
def _import_common(
|
| 1101 |
+
self, node: t.Union[nodes.Import, nodes.FromImport], frame: Frame
|
| 1102 |
+
) -> None:
|
| 1103 |
+
self.write(f"{self.choose_async('await ')}environment.get_template(")
|
| 1104 |
+
self.visit(node.template, frame)
|
| 1105 |
+
self.write(f", {self.name!r}).")
|
| 1106 |
+
|
| 1107 |
+
if node.with_context:
|
| 1108 |
+
f_name = f"make_module{self.choose_async('_async')}"
|
| 1109 |
+
self.write(
|
| 1110 |
+
f"{f_name}(context.get_all(), True, {self.dump_local_context(frame)})"
|
| 1111 |
+
)
|
| 1112 |
+
else:
|
| 1113 |
+
self.write(f"_get_default_module{self.choose_async('_async')}(context)")
|
| 1114 |
+
|
| 1115 |
+
def visit_Import(self, node: nodes.Import, frame: Frame) -> None:
|
| 1116 |
+
"""Visit regular imports."""
|
| 1117 |
+
self.writeline(f"{frame.symbols.ref(node.target)} = ", node)
|
| 1118 |
+
if frame.toplevel:
|
| 1119 |
+
self.write(f"context.vars[{node.target!r}] = ")
|
| 1120 |
+
|
| 1121 |
+
self._import_common(node, frame)
|
| 1122 |
+
|
| 1123 |
+
if frame.toplevel and not node.target.startswith("_"):
|
| 1124 |
+
self.writeline(f"context.exported_vars.discard({node.target!r})")
|
| 1125 |
+
|
| 1126 |
+
def visit_FromImport(self, node: nodes.FromImport, frame: Frame) -> None:
|
| 1127 |
+
"""Visit named imports."""
|
| 1128 |
+
self.newline(node)
|
| 1129 |
+
self.write("included_template = ")
|
| 1130 |
+
self._import_common(node, frame)
|
| 1131 |
+
var_names = []
|
| 1132 |
+
discarded_names = []
|
| 1133 |
+
for name in node.names:
|
| 1134 |
+
if isinstance(name, tuple):
|
| 1135 |
+
name, alias = name
|
| 1136 |
+
else:
|
| 1137 |
+
alias = name
|
| 1138 |
+
self.writeline(
|
| 1139 |
+
f"{frame.symbols.ref(alias)} ="
|
| 1140 |
+
f" getattr(included_template, {name!r}, missing)"
|
| 1141 |
+
)
|
| 1142 |
+
self.writeline(f"if {frame.symbols.ref(alias)} is missing:")
|
| 1143 |
+
self.indent()
|
| 1144 |
+
# The position will contain the template name, and will be formatted
|
| 1145 |
+
# into a string that will be compiled into an f-string. Curly braces
|
| 1146 |
+
# in the name must be replaced with escapes so that they will not be
|
| 1147 |
+
# executed as part of the f-string.
|
| 1148 |
+
position = self.position(node).replace("{", "{{").replace("}", "}}")
|
| 1149 |
+
message = (
|
| 1150 |
+
"the template {included_template.__name__!r}"
|
| 1151 |
+
f" (imported on {position})"
|
| 1152 |
+
f" does not export the requested name {name!r}"
|
| 1153 |
+
)
|
| 1154 |
+
self.writeline(
|
| 1155 |
+
f"{frame.symbols.ref(alias)} = undefined(f{message!r}, name={name!r})"
|
| 1156 |
+
)
|
| 1157 |
+
self.outdent()
|
| 1158 |
+
if frame.toplevel:
|
| 1159 |
+
var_names.append(alias)
|
| 1160 |
+
if not alias.startswith("_"):
|
| 1161 |
+
discarded_names.append(alias)
|
| 1162 |
+
|
| 1163 |
+
if var_names:
|
| 1164 |
+
if len(var_names) == 1:
|
| 1165 |
+
name = var_names[0]
|
| 1166 |
+
self.writeline(f"context.vars[{name!r}] = {frame.symbols.ref(name)}")
|
| 1167 |
+
else:
|
| 1168 |
+
names_kv = ", ".join(
|
| 1169 |
+
f"{name!r}: {frame.symbols.ref(name)}" for name in var_names
|
| 1170 |
+
)
|
| 1171 |
+
self.writeline(f"context.vars.update({{{names_kv}}})")
|
| 1172 |
+
if discarded_names:
|
| 1173 |
+
if len(discarded_names) == 1:
|
| 1174 |
+
self.writeline(f"context.exported_vars.discard({discarded_names[0]!r})")
|
| 1175 |
+
else:
|
| 1176 |
+
names_str = ", ".join(map(repr, discarded_names))
|
| 1177 |
+
self.writeline(
|
| 1178 |
+
f"context.exported_vars.difference_update(({names_str}))"
|
| 1179 |
+
)
|
| 1180 |
+
|
| 1181 |
+
def visit_For(self, node: nodes.For, frame: Frame) -> None:
|
| 1182 |
+
loop_frame = frame.inner()
|
| 1183 |
+
loop_frame.loop_frame = True
|
| 1184 |
+
test_frame = frame.inner()
|
| 1185 |
+
else_frame = frame.inner()
|
| 1186 |
+
|
| 1187 |
+
# try to figure out if we have an extended loop. An extended loop
|
| 1188 |
+
# is necessary if the loop is in recursive mode if the special loop
|
| 1189 |
+
# variable is accessed in the body if the body is a scoped block.
|
| 1190 |
+
extended_loop = (
|
| 1191 |
+
node.recursive
|
| 1192 |
+
or "loop"
|
| 1193 |
+
in find_undeclared(node.iter_child_nodes(only=("body",)), ("loop",))
|
| 1194 |
+
or any(block.scoped for block in node.find_all(nodes.Block))
|
| 1195 |
+
)
|
| 1196 |
+
|
| 1197 |
+
loop_ref = None
|
| 1198 |
+
if extended_loop:
|
| 1199 |
+
loop_ref = loop_frame.symbols.declare_parameter("loop")
|
| 1200 |
+
|
| 1201 |
+
loop_frame.symbols.analyze_node(node, for_branch="body")
|
| 1202 |
+
if node.else_:
|
| 1203 |
+
else_frame.symbols.analyze_node(node, for_branch="else")
|
| 1204 |
+
|
| 1205 |
+
if node.test:
|
| 1206 |
+
loop_filter_func = self.temporary_identifier()
|
| 1207 |
+
test_frame.symbols.analyze_node(node, for_branch="test")
|
| 1208 |
+
self.writeline(f"{self.func(loop_filter_func)}(fiter):", node.test)
|
| 1209 |
+
self.indent()
|
| 1210 |
+
self.enter_frame(test_frame)
|
| 1211 |
+
self.writeline(self.choose_async("async for ", "for "))
|
| 1212 |
+
self.visit(node.target, loop_frame)
|
| 1213 |
+
self.write(" in ")
|
| 1214 |
+
self.write(self.choose_async("auto_aiter(fiter)", "fiter"))
|
| 1215 |
+
self.write(":")
|
| 1216 |
+
self.indent()
|
| 1217 |
+
self.writeline("if ", node.test)
|
| 1218 |
+
self.visit(node.test, test_frame)
|
| 1219 |
+
self.write(":")
|
| 1220 |
+
self.indent()
|
| 1221 |
+
self.writeline("yield ")
|
| 1222 |
+
self.visit(node.target, loop_frame)
|
| 1223 |
+
self.outdent(3)
|
| 1224 |
+
self.leave_frame(test_frame, with_python_scope=True)
|
| 1225 |
+
|
| 1226 |
+
# if we don't have an recursive loop we have to find the shadowed
|
| 1227 |
+
# variables at that point. Because loops can be nested but the loop
|
| 1228 |
+
# variable is a special one we have to enforce aliasing for it.
|
| 1229 |
+
if node.recursive:
|
| 1230 |
+
self.writeline(
|
| 1231 |
+
f"{self.func('loop')}(reciter, loop_render_func, depth=0):", node
|
| 1232 |
+
)
|
| 1233 |
+
self.indent()
|
| 1234 |
+
self.buffer(loop_frame)
|
| 1235 |
+
|
| 1236 |
+
# Use the same buffer for the else frame
|
| 1237 |
+
else_frame.buffer = loop_frame.buffer
|
| 1238 |
+
|
| 1239 |
+
# make sure the loop variable is a special one and raise a template
|
| 1240 |
+
# assertion error if a loop tries to write to loop
|
| 1241 |
+
if extended_loop:
|
| 1242 |
+
self.writeline(f"{loop_ref} = missing")
|
| 1243 |
+
|
| 1244 |
+
for name in node.find_all(nodes.Name):
|
| 1245 |
+
if name.ctx == "store" and name.name == "loop":
|
| 1246 |
+
self.fail(
|
| 1247 |
+
"Can't assign to special loop variable in for-loop target",
|
| 1248 |
+
name.lineno,
|
| 1249 |
+
)
|
| 1250 |
+
|
| 1251 |
+
if node.else_:
|
| 1252 |
+
iteration_indicator = self.temporary_identifier()
|
| 1253 |
+
self.writeline(f"{iteration_indicator} = 1")
|
| 1254 |
+
|
| 1255 |
+
self.writeline(self.choose_async("async for ", "for "), node)
|
| 1256 |
+
self.visit(node.target, loop_frame)
|
| 1257 |
+
if extended_loop:
|
| 1258 |
+
self.write(f", {loop_ref} in {self.choose_async('Async')}LoopContext(")
|
| 1259 |
+
else:
|
| 1260 |
+
self.write(" in ")
|
| 1261 |
+
|
| 1262 |
+
if node.test:
|
| 1263 |
+
self.write(f"{loop_filter_func}(")
|
| 1264 |
+
if node.recursive:
|
| 1265 |
+
self.write("reciter")
|
| 1266 |
+
else:
|
| 1267 |
+
if self.environment.is_async and not extended_loop:
|
| 1268 |
+
self.write("auto_aiter(")
|
| 1269 |
+
self.visit(node.iter, frame)
|
| 1270 |
+
if self.environment.is_async and not extended_loop:
|
| 1271 |
+
self.write(")")
|
| 1272 |
+
if node.test:
|
| 1273 |
+
self.write(")")
|
| 1274 |
+
|
| 1275 |
+
if node.recursive:
|
| 1276 |
+
self.write(", undefined, loop_render_func, depth):")
|
| 1277 |
+
else:
|
| 1278 |
+
self.write(", undefined):" if extended_loop else ":")
|
| 1279 |
+
|
| 1280 |
+
self.indent()
|
| 1281 |
+
self.enter_frame(loop_frame)
|
| 1282 |
+
|
| 1283 |
+
self.writeline("_loop_vars = {}")
|
| 1284 |
+
self.blockvisit(node.body, loop_frame)
|
| 1285 |
+
if node.else_:
|
| 1286 |
+
self.writeline(f"{iteration_indicator} = 0")
|
| 1287 |
+
self.outdent()
|
| 1288 |
+
self.leave_frame(
|
| 1289 |
+
loop_frame, with_python_scope=node.recursive and not node.else_
|
| 1290 |
+
)
|
| 1291 |
+
|
| 1292 |
+
if node.else_:
|
| 1293 |
+
self.writeline(f"if {iteration_indicator}:")
|
| 1294 |
+
self.indent()
|
| 1295 |
+
self.enter_frame(else_frame)
|
| 1296 |
+
self.blockvisit(node.else_, else_frame)
|
| 1297 |
+
self.leave_frame(else_frame)
|
| 1298 |
+
self.outdent()
|
| 1299 |
+
|
| 1300 |
+
# if the node was recursive we have to return the buffer contents
|
| 1301 |
+
# and start the iteration code
|
| 1302 |
+
if node.recursive:
|
| 1303 |
+
self.return_buffer_contents(loop_frame)
|
| 1304 |
+
self.outdent()
|
| 1305 |
+
self.start_write(frame, node)
|
| 1306 |
+
self.write(f"{self.choose_async('await ')}loop(")
|
| 1307 |
+
if self.environment.is_async:
|
| 1308 |
+
self.write("auto_aiter(")
|
| 1309 |
+
self.visit(node.iter, frame)
|
| 1310 |
+
if self.environment.is_async:
|
| 1311 |
+
self.write(")")
|
| 1312 |
+
self.write(", loop)")
|
| 1313 |
+
self.end_write(frame)
|
| 1314 |
+
|
| 1315 |
+
# at the end of the iteration, clear any assignments made in the
|
| 1316 |
+
# loop from the top level
|
| 1317 |
+
if self._assign_stack:
|
| 1318 |
+
self._assign_stack[-1].difference_update(loop_frame.symbols.stores)
|
| 1319 |
+
|
| 1320 |
+
def visit_If(self, node: nodes.If, frame: Frame) -> None:
|
| 1321 |
+
if_frame = frame.soft()
|
| 1322 |
+
self.writeline("if ", node)
|
| 1323 |
+
self.visit(node.test, if_frame)
|
| 1324 |
+
self.write(":")
|
| 1325 |
+
self.indent()
|
| 1326 |
+
self.blockvisit(node.body, if_frame)
|
| 1327 |
+
self.outdent()
|
| 1328 |
+
for elif_ in node.elif_:
|
| 1329 |
+
self.writeline("elif ", elif_)
|
| 1330 |
+
self.visit(elif_.test, if_frame)
|
| 1331 |
+
self.write(":")
|
| 1332 |
+
self.indent()
|
| 1333 |
+
self.blockvisit(elif_.body, if_frame)
|
| 1334 |
+
self.outdent()
|
| 1335 |
+
if node.else_:
|
| 1336 |
+
self.writeline("else:")
|
| 1337 |
+
self.indent()
|
| 1338 |
+
self.blockvisit(node.else_, if_frame)
|
| 1339 |
+
self.outdent()
|
| 1340 |
+
|
| 1341 |
+
def visit_Macro(self, node: nodes.Macro, frame: Frame) -> None:
|
| 1342 |
+
macro_frame, macro_ref = self.macro_body(node, frame)
|
| 1343 |
+
self.newline()
|
| 1344 |
+
if frame.toplevel:
|
| 1345 |
+
if not node.name.startswith("_"):
|
| 1346 |
+
self.write(f"context.exported_vars.add({node.name!r})")
|
| 1347 |
+
self.writeline(f"context.vars[{node.name!r}] = ")
|
| 1348 |
+
self.write(f"{frame.symbols.ref(node.name)} = ")
|
| 1349 |
+
self.macro_def(macro_ref, macro_frame)
|
| 1350 |
+
|
| 1351 |
+
def visit_CallBlock(self, node: nodes.CallBlock, frame: Frame) -> None:
|
| 1352 |
+
call_frame, macro_ref = self.macro_body(node, frame)
|
| 1353 |
+
self.writeline("caller = ")
|
| 1354 |
+
self.macro_def(macro_ref, call_frame)
|
| 1355 |
+
self.start_write(frame, node)
|
| 1356 |
+
self.visit_Call(node.call, frame, forward_caller=True)
|
| 1357 |
+
self.end_write(frame)
|
| 1358 |
+
|
| 1359 |
+
def visit_FilterBlock(self, node: nodes.FilterBlock, frame: Frame) -> None:
|
| 1360 |
+
filter_frame = frame.inner()
|
| 1361 |
+
filter_frame.symbols.analyze_node(node)
|
| 1362 |
+
self.enter_frame(filter_frame)
|
| 1363 |
+
self.buffer(filter_frame)
|
| 1364 |
+
self.blockvisit(node.body, filter_frame)
|
| 1365 |
+
self.start_write(frame, node)
|
| 1366 |
+
self.visit_Filter(node.filter, filter_frame)
|
| 1367 |
+
self.end_write(frame)
|
| 1368 |
+
self.leave_frame(filter_frame)
|
| 1369 |
+
|
| 1370 |
+
def visit_With(self, node: nodes.With, frame: Frame) -> None:
|
| 1371 |
+
with_frame = frame.inner()
|
| 1372 |
+
with_frame.symbols.analyze_node(node)
|
| 1373 |
+
self.enter_frame(with_frame)
|
| 1374 |
+
for target, expr in zip(node.targets, node.values):
|
| 1375 |
+
self.newline()
|
| 1376 |
+
self.visit(target, with_frame)
|
| 1377 |
+
self.write(" = ")
|
| 1378 |
+
self.visit(expr, frame)
|
| 1379 |
+
self.blockvisit(node.body, with_frame)
|
| 1380 |
+
self.leave_frame(with_frame)
|
| 1381 |
+
|
| 1382 |
+
def visit_ExprStmt(self, node: nodes.ExprStmt, frame: Frame) -> None:
|
| 1383 |
+
self.newline(node)
|
| 1384 |
+
self.visit(node.node, frame)
|
| 1385 |
+
|
| 1386 |
+
class _FinalizeInfo(t.NamedTuple):
|
| 1387 |
+
const: t.Optional[t.Callable[..., str]]
|
| 1388 |
+
src: t.Optional[str]
|
| 1389 |
+
|
| 1390 |
+
@staticmethod
|
| 1391 |
+
def _default_finalize(value: t.Any) -> t.Any:
|
| 1392 |
+
"""The default finalize function if the environment isn't
|
| 1393 |
+
configured with one. Or, if the environment has one, this is
|
| 1394 |
+
called on that function's output for constants.
|
| 1395 |
+
"""
|
| 1396 |
+
return str(value)
|
| 1397 |
+
|
| 1398 |
+
_finalize: t.Optional[_FinalizeInfo] = None
|
| 1399 |
+
|
| 1400 |
+
def _make_finalize(self) -> _FinalizeInfo:
|
| 1401 |
+
"""Build the finalize function to be used on constants and at
|
| 1402 |
+
runtime. Cached so it's only created once for all output nodes.
|
| 1403 |
+
|
| 1404 |
+
Returns a ``namedtuple`` with the following attributes:
|
| 1405 |
+
|
| 1406 |
+
``const``
|
| 1407 |
+
A function to finalize constant data at compile time.
|
| 1408 |
+
|
| 1409 |
+
``src``
|
| 1410 |
+
Source code to output around nodes to be evaluated at
|
| 1411 |
+
runtime.
|
| 1412 |
+
"""
|
| 1413 |
+
if self._finalize is not None:
|
| 1414 |
+
return self._finalize
|
| 1415 |
+
|
| 1416 |
+
finalize: t.Optional[t.Callable[..., t.Any]]
|
| 1417 |
+
finalize = default = self._default_finalize
|
| 1418 |
+
src = None
|
| 1419 |
+
|
| 1420 |
+
if self.environment.finalize:
|
| 1421 |
+
src = "environment.finalize("
|
| 1422 |
+
env_finalize = self.environment.finalize
|
| 1423 |
+
pass_arg = {
|
| 1424 |
+
_PassArg.context: "context",
|
| 1425 |
+
_PassArg.eval_context: "context.eval_ctx",
|
| 1426 |
+
_PassArg.environment: "environment",
|
| 1427 |
+
}.get(
|
| 1428 |
+
_PassArg.from_obj(env_finalize) # type: ignore
|
| 1429 |
+
)
|
| 1430 |
+
finalize = None
|
| 1431 |
+
|
| 1432 |
+
if pass_arg is None:
|
| 1433 |
+
|
| 1434 |
+
def finalize(value: t.Any) -> t.Any: # noqa: F811
|
| 1435 |
+
return default(env_finalize(value))
|
| 1436 |
+
|
| 1437 |
+
else:
|
| 1438 |
+
src = f"{src}{pass_arg}, "
|
| 1439 |
+
|
| 1440 |
+
if pass_arg == "environment":
|
| 1441 |
+
|
| 1442 |
+
def finalize(value: t.Any) -> t.Any: # noqa: F811
|
| 1443 |
+
return default(env_finalize(self.environment, value))
|
| 1444 |
+
|
| 1445 |
+
self._finalize = self._FinalizeInfo(finalize, src)
|
| 1446 |
+
return self._finalize
|
| 1447 |
+
|
| 1448 |
+
def _output_const_repr(self, group: t.Iterable[t.Any]) -> str:
|
| 1449 |
+
"""Given a group of constant values converted from ``Output``
|
| 1450 |
+
child nodes, produce a string to write to the template module
|
| 1451 |
+
source.
|
| 1452 |
+
"""
|
| 1453 |
+
return repr(concat(group))
|
| 1454 |
+
|
| 1455 |
+
def _output_child_to_const(
|
| 1456 |
+
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
|
| 1457 |
+
) -> str:
|
| 1458 |
+
"""Try to optimize a child of an ``Output`` node by trying to
|
| 1459 |
+
convert it to constant, finalized data at compile time.
|
| 1460 |
+
|
| 1461 |
+
If :exc:`Impossible` is raised, the node is not constant and
|
| 1462 |
+
will be evaluated at runtime. Any other exception will also be
|
| 1463 |
+
evaluated at runtime for easier debugging.
|
| 1464 |
+
"""
|
| 1465 |
+
const = node.as_const(frame.eval_ctx)
|
| 1466 |
+
|
| 1467 |
+
if frame.eval_ctx.autoescape:
|
| 1468 |
+
const = escape(const)
|
| 1469 |
+
|
| 1470 |
+
# Template data doesn't go through finalize.
|
| 1471 |
+
if isinstance(node, nodes.TemplateData):
|
| 1472 |
+
return str(const)
|
| 1473 |
+
|
| 1474 |
+
return finalize.const(const) # type: ignore
|
| 1475 |
+
|
| 1476 |
+
def _output_child_pre(
|
| 1477 |
+
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
|
| 1478 |
+
) -> None:
|
| 1479 |
+
"""Output extra source code before visiting a child of an
|
| 1480 |
+
``Output`` node.
|
| 1481 |
+
"""
|
| 1482 |
+
if frame.eval_ctx.volatile:
|
| 1483 |
+
self.write("(escape if context.eval_ctx.autoescape else str)(")
|
| 1484 |
+
elif frame.eval_ctx.autoescape:
|
| 1485 |
+
self.write("escape(")
|
| 1486 |
+
else:
|
| 1487 |
+
self.write("str(")
|
| 1488 |
+
|
| 1489 |
+
if finalize.src is not None:
|
| 1490 |
+
self.write(finalize.src)
|
| 1491 |
+
|
| 1492 |
+
def _output_child_post(
|
| 1493 |
+
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
|
| 1494 |
+
) -> None:
|
| 1495 |
+
"""Output extra source code after visiting a child of an
|
| 1496 |
+
``Output`` node.
|
| 1497 |
+
"""
|
| 1498 |
+
self.write(")")
|
| 1499 |
+
|
| 1500 |
+
if finalize.src is not None:
|
| 1501 |
+
self.write(")")
|
| 1502 |
+
|
| 1503 |
+
def visit_Output(self, node: nodes.Output, frame: Frame) -> None:
|
| 1504 |
+
# If an extends is active, don't render outside a block.
|
| 1505 |
+
if frame.require_output_check:
|
| 1506 |
+
# A top-level extends is known to exist at compile time.
|
| 1507 |
+
if self.has_known_extends:
|
| 1508 |
+
return
|
| 1509 |
+
|
| 1510 |
+
self.writeline("if parent_template is None:")
|
| 1511 |
+
self.indent()
|
| 1512 |
+
|
| 1513 |
+
finalize = self._make_finalize()
|
| 1514 |
+
body: t.List[t.Union[t.List[t.Any], nodes.Expr]] = []
|
| 1515 |
+
|
| 1516 |
+
# Evaluate constants at compile time if possible. Each item in
|
| 1517 |
+
# body will be either a list of static data or a node to be
|
| 1518 |
+
# evaluated at runtime.
|
| 1519 |
+
for child in node.nodes:
|
| 1520 |
+
try:
|
| 1521 |
+
if not (
|
| 1522 |
+
# If the finalize function requires runtime context,
|
| 1523 |
+
# constants can't be evaluated at compile time.
|
| 1524 |
+
finalize.const
|
| 1525 |
+
# Unless it's basic template data that won't be
|
| 1526 |
+
# finalized anyway.
|
| 1527 |
+
or isinstance(child, nodes.TemplateData)
|
| 1528 |
+
):
|
| 1529 |
+
raise nodes.Impossible()
|
| 1530 |
+
|
| 1531 |
+
const = self._output_child_to_const(child, frame, finalize)
|
| 1532 |
+
except (nodes.Impossible, Exception):
|
| 1533 |
+
# The node was not constant and needs to be evaluated at
|
| 1534 |
+
# runtime. Or another error was raised, which is easier
|
| 1535 |
+
# to debug at runtime.
|
| 1536 |
+
body.append(child)
|
| 1537 |
+
continue
|
| 1538 |
+
|
| 1539 |
+
if body and isinstance(body[-1], list):
|
| 1540 |
+
body[-1].append(const)
|
| 1541 |
+
else:
|
| 1542 |
+
body.append([const])
|
| 1543 |
+
|
| 1544 |
+
if frame.buffer is not None:
|
| 1545 |
+
if len(body) == 1:
|
| 1546 |
+
self.writeline(f"{frame.buffer}.append(")
|
| 1547 |
+
else:
|
| 1548 |
+
self.writeline(f"{frame.buffer}.extend((")
|
| 1549 |
+
|
| 1550 |
+
self.indent()
|
| 1551 |
+
|
| 1552 |
+
for item in body:
|
| 1553 |
+
if isinstance(item, list):
|
| 1554 |
+
# A group of constant data to join and output.
|
| 1555 |
+
val = self._output_const_repr(item)
|
| 1556 |
+
|
| 1557 |
+
if frame.buffer is None:
|
| 1558 |
+
self.writeline("yield " + val)
|
| 1559 |
+
else:
|
| 1560 |
+
self.writeline(val + ",")
|
| 1561 |
+
else:
|
| 1562 |
+
if frame.buffer is None:
|
| 1563 |
+
self.writeline("yield ", item)
|
| 1564 |
+
else:
|
| 1565 |
+
self.newline(item)
|
| 1566 |
+
|
| 1567 |
+
# A node to be evaluated at runtime.
|
| 1568 |
+
self._output_child_pre(item, frame, finalize)
|
| 1569 |
+
self.visit(item, frame)
|
| 1570 |
+
self._output_child_post(item, frame, finalize)
|
| 1571 |
+
|
| 1572 |
+
if frame.buffer is not None:
|
| 1573 |
+
self.write(",")
|
| 1574 |
+
|
| 1575 |
+
if frame.buffer is not None:
|
| 1576 |
+
self.outdent()
|
| 1577 |
+
self.writeline(")" if len(body) == 1 else "))")
|
| 1578 |
+
|
| 1579 |
+
if frame.require_output_check:
|
| 1580 |
+
self.outdent()
|
| 1581 |
+
|
| 1582 |
+
def visit_Assign(self, node: nodes.Assign, frame: Frame) -> None:
|
| 1583 |
+
self.push_assign_tracking()
|
| 1584 |
+
|
| 1585 |
+
# ``a.b`` is allowed for assignment, and is parsed as an NSRef. However,
|
| 1586 |
+
# it is only valid if it references a Namespace object. Emit a check for
|
| 1587 |
+
# that for each ref here, before assignment code is emitted. This can't
|
| 1588 |
+
# be done in visit_NSRef as the ref could be in the middle of a tuple.
|
| 1589 |
+
seen_refs: t.Set[str] = set()
|
| 1590 |
+
|
| 1591 |
+
for nsref in node.find_all(nodes.NSRef):
|
| 1592 |
+
if nsref.name in seen_refs:
|
| 1593 |
+
# Only emit the check for each reference once, in case the same
|
| 1594 |
+
# ref is used multiple times in a tuple, `ns.a, ns.b = c, d`.
|
| 1595 |
+
continue
|
| 1596 |
+
|
| 1597 |
+
seen_refs.add(nsref.name)
|
| 1598 |
+
ref = frame.symbols.ref(nsref.name)
|
| 1599 |
+
self.writeline(f"if not isinstance({ref}, Namespace):")
|
| 1600 |
+
self.indent()
|
| 1601 |
+
self.writeline(
|
| 1602 |
+
"raise TemplateRuntimeError"
|
| 1603 |
+
'("cannot assign attribute on non-namespace object")'
|
| 1604 |
+
)
|
| 1605 |
+
self.outdent()
|
| 1606 |
+
|
| 1607 |
+
self.newline(node)
|
| 1608 |
+
self.visit(node.target, frame)
|
| 1609 |
+
self.write(" = ")
|
| 1610 |
+
self.visit(node.node, frame)
|
| 1611 |
+
self.pop_assign_tracking(frame)
|
| 1612 |
+
|
| 1613 |
+
def visit_AssignBlock(self, node: nodes.AssignBlock, frame: Frame) -> None:
|
| 1614 |
+
self.push_assign_tracking()
|
| 1615 |
+
block_frame = frame.inner()
|
| 1616 |
+
# This is a special case. Since a set block always captures we
|
| 1617 |
+
# will disable output checks. This way one can use set blocks
|
| 1618 |
+
# toplevel even in extended templates.
|
| 1619 |
+
block_frame.require_output_check = False
|
| 1620 |
+
block_frame.symbols.analyze_node(node)
|
| 1621 |
+
self.enter_frame(block_frame)
|
| 1622 |
+
self.buffer(block_frame)
|
| 1623 |
+
self.blockvisit(node.body, block_frame)
|
| 1624 |
+
self.newline(node)
|
| 1625 |
+
self.visit(node.target, frame)
|
| 1626 |
+
self.write(" = (Markup if context.eval_ctx.autoescape else identity)(")
|
| 1627 |
+
if node.filter is not None:
|
| 1628 |
+
self.visit_Filter(node.filter, block_frame)
|
| 1629 |
+
else:
|
| 1630 |
+
self.write(f"concat({block_frame.buffer})")
|
| 1631 |
+
self.write(")")
|
| 1632 |
+
self.pop_assign_tracking(frame)
|
| 1633 |
+
self.leave_frame(block_frame)
|
| 1634 |
+
|
| 1635 |
+
# -- Expression Visitors
|
| 1636 |
+
|
| 1637 |
+
def visit_Name(self, node: nodes.Name, frame: Frame) -> None:
|
| 1638 |
+
if node.ctx == "store" and (
|
| 1639 |
+
frame.toplevel or frame.loop_frame or frame.block_frame
|
| 1640 |
+
):
|
| 1641 |
+
if self._assign_stack:
|
| 1642 |
+
self._assign_stack[-1].add(node.name)
|
| 1643 |
+
ref = frame.symbols.ref(node.name)
|
| 1644 |
+
|
| 1645 |
+
# If we are looking up a variable we might have to deal with the
|
| 1646 |
+
# case where it's undefined. We can skip that case if the load
|
| 1647 |
+
# instruction indicates a parameter which are always defined.
|
| 1648 |
+
if node.ctx == "load":
|
| 1649 |
+
load = frame.symbols.find_load(ref)
|
| 1650 |
+
if not (
|
| 1651 |
+
load is not None
|
| 1652 |
+
and load[0] == VAR_LOAD_PARAMETER
|
| 1653 |
+
and not self.parameter_is_undeclared(ref)
|
| 1654 |
+
):
|
| 1655 |
+
self.write(
|
| 1656 |
+
f"(undefined(name={node.name!r}) if {ref} is missing else {ref})"
|
| 1657 |
+
)
|
| 1658 |
+
return
|
| 1659 |
+
|
| 1660 |
+
self.write(ref)
|
| 1661 |
+
|
| 1662 |
+
def visit_NSRef(self, node: nodes.NSRef, frame: Frame) -> None:
|
| 1663 |
+
# NSRef is a dotted assignment target a.b=c, but uses a[b]=c internally.
|
| 1664 |
+
# visit_Assign emits code to validate that each ref is to a Namespace
|
| 1665 |
+
# object only. That can't be emitted here as the ref could be in the
|
| 1666 |
+
# middle of a tuple assignment.
|
| 1667 |
+
ref = frame.symbols.ref(node.name)
|
| 1668 |
+
self.writeline(f"{ref}[{node.attr!r}]")
|
| 1669 |
+
|
| 1670 |
+
def visit_Const(self, node: nodes.Const, frame: Frame) -> None:
|
| 1671 |
+
val = node.as_const(frame.eval_ctx)
|
| 1672 |
+
if isinstance(val, float):
|
| 1673 |
+
self.write(str(val))
|
| 1674 |
+
else:
|
| 1675 |
+
self.write(repr(val))
|
| 1676 |
+
|
| 1677 |
+
def visit_TemplateData(self, node: nodes.TemplateData, frame: Frame) -> None:
|
| 1678 |
+
try:
|
| 1679 |
+
self.write(repr(node.as_const(frame.eval_ctx)))
|
| 1680 |
+
except nodes.Impossible:
|
| 1681 |
+
self.write(
|
| 1682 |
+
f"(Markup if context.eval_ctx.autoescape else identity)({node.data!r})"
|
| 1683 |
+
)
|
| 1684 |
+
|
| 1685 |
+
def visit_Tuple(self, node: nodes.Tuple, frame: Frame) -> None:
|
| 1686 |
+
self.write("(")
|
| 1687 |
+
idx = -1
|
| 1688 |
+
for idx, item in enumerate(node.items):
|
| 1689 |
+
if idx:
|
| 1690 |
+
self.write(", ")
|
| 1691 |
+
self.visit(item, frame)
|
| 1692 |
+
self.write(",)" if idx == 0 else ")")
|
| 1693 |
+
|
| 1694 |
+
def visit_List(self, node: nodes.List, frame: Frame) -> None:
|
| 1695 |
+
self.write("[")
|
| 1696 |
+
for idx, item in enumerate(node.items):
|
| 1697 |
+
if idx:
|
| 1698 |
+
self.write(", ")
|
| 1699 |
+
self.visit(item, frame)
|
| 1700 |
+
self.write("]")
|
| 1701 |
+
|
| 1702 |
+
def visit_Dict(self, node: nodes.Dict, frame: Frame) -> None:
|
| 1703 |
+
self.write("{")
|
| 1704 |
+
for idx, item in enumerate(node.items):
|
| 1705 |
+
if idx:
|
| 1706 |
+
self.write(", ")
|
| 1707 |
+
self.visit(item.key, frame)
|
| 1708 |
+
self.write(": ")
|
| 1709 |
+
self.visit(item.value, frame)
|
| 1710 |
+
self.write("}")
|
| 1711 |
+
|
| 1712 |
+
visit_Add = _make_binop("+")
|
| 1713 |
+
visit_Sub = _make_binop("-")
|
| 1714 |
+
visit_Mul = _make_binop("*")
|
| 1715 |
+
visit_Div = _make_binop("/")
|
| 1716 |
+
visit_FloorDiv = _make_binop("//")
|
| 1717 |
+
visit_Pow = _make_binop("**")
|
| 1718 |
+
visit_Mod = _make_binop("%")
|
| 1719 |
+
visit_And = _make_binop("and")
|
| 1720 |
+
visit_Or = _make_binop("or")
|
| 1721 |
+
visit_Pos = _make_unop("+")
|
| 1722 |
+
visit_Neg = _make_unop("-")
|
| 1723 |
+
visit_Not = _make_unop("not ")
|
| 1724 |
+
|
| 1725 |
+
@optimizeconst
|
| 1726 |
+
def visit_Concat(self, node: nodes.Concat, frame: Frame) -> None:
|
| 1727 |
+
if frame.eval_ctx.volatile:
|
| 1728 |
+
func_name = "(markup_join if context.eval_ctx.volatile else str_join)"
|
| 1729 |
+
elif frame.eval_ctx.autoescape:
|
| 1730 |
+
func_name = "markup_join"
|
| 1731 |
+
else:
|
| 1732 |
+
func_name = "str_join"
|
| 1733 |
+
self.write(f"{func_name}((")
|
| 1734 |
+
for arg in node.nodes:
|
| 1735 |
+
self.visit(arg, frame)
|
| 1736 |
+
self.write(", ")
|
| 1737 |
+
self.write("))")
|
| 1738 |
+
|
| 1739 |
+
@optimizeconst
|
| 1740 |
+
def visit_Compare(self, node: nodes.Compare, frame: Frame) -> None:
|
| 1741 |
+
self.write("(")
|
| 1742 |
+
self.visit(node.expr, frame)
|
| 1743 |
+
for op in node.ops:
|
| 1744 |
+
self.visit(op, frame)
|
| 1745 |
+
self.write(")")
|
| 1746 |
+
|
| 1747 |
+
def visit_Operand(self, node: nodes.Operand, frame: Frame) -> None:
|
| 1748 |
+
self.write(f" {operators[node.op]} ")
|
| 1749 |
+
self.visit(node.expr, frame)
|
| 1750 |
+
|
| 1751 |
+
@optimizeconst
|
| 1752 |
+
def visit_Getattr(self, node: nodes.Getattr, frame: Frame) -> None:
|
| 1753 |
+
if self.environment.is_async:
|
| 1754 |
+
self.write("(await auto_await(")
|
| 1755 |
+
|
| 1756 |
+
self.write("environment.getattr(")
|
| 1757 |
+
self.visit(node.node, frame)
|
| 1758 |
+
self.write(f", {node.attr!r})")
|
| 1759 |
+
|
| 1760 |
+
if self.environment.is_async:
|
| 1761 |
+
self.write("))")
|
| 1762 |
+
|
| 1763 |
+
@optimizeconst
|
| 1764 |
+
def visit_Getitem(self, node: nodes.Getitem, frame: Frame) -> None:
|
| 1765 |
+
# slices bypass the environment getitem method.
|
| 1766 |
+
if isinstance(node.arg, nodes.Slice):
|
| 1767 |
+
self.visit(node.node, frame)
|
| 1768 |
+
self.write("[")
|
| 1769 |
+
self.visit(node.arg, frame)
|
| 1770 |
+
self.write("]")
|
| 1771 |
+
else:
|
| 1772 |
+
if self.environment.is_async:
|
| 1773 |
+
self.write("(await auto_await(")
|
| 1774 |
+
|
| 1775 |
+
self.write("environment.getitem(")
|
| 1776 |
+
self.visit(node.node, frame)
|
| 1777 |
+
self.write(", ")
|
| 1778 |
+
self.visit(node.arg, frame)
|
| 1779 |
+
self.write(")")
|
| 1780 |
+
|
| 1781 |
+
if self.environment.is_async:
|
| 1782 |
+
self.write("))")
|
| 1783 |
+
|
| 1784 |
+
def visit_Slice(self, node: nodes.Slice, frame: Frame) -> None:
|
| 1785 |
+
if node.start is not None:
|
| 1786 |
+
self.visit(node.start, frame)
|
| 1787 |
+
self.write(":")
|
| 1788 |
+
if node.stop is not None:
|
| 1789 |
+
self.visit(node.stop, frame)
|
| 1790 |
+
if node.step is not None:
|
| 1791 |
+
self.write(":")
|
| 1792 |
+
self.visit(node.step, frame)
|
| 1793 |
+
|
| 1794 |
+
@contextmanager
|
| 1795 |
+
def _filter_test_common(
|
| 1796 |
+
self, node: t.Union[nodes.Filter, nodes.Test], frame: Frame, is_filter: bool
|
| 1797 |
+
) -> t.Iterator[None]:
|
| 1798 |
+
if self.environment.is_async:
|
| 1799 |
+
self.write("(await auto_await(")
|
| 1800 |
+
|
| 1801 |
+
if is_filter:
|
| 1802 |
+
self.write(f"{self.filters[node.name]}(")
|
| 1803 |
+
func = self.environment.filters.get(node.name)
|
| 1804 |
+
else:
|
| 1805 |
+
self.write(f"{self.tests[node.name]}(")
|
| 1806 |
+
func = self.environment.tests.get(node.name)
|
| 1807 |
+
|
| 1808 |
+
# When inside an If or CondExpr frame, allow the filter to be
|
| 1809 |
+
# undefined at compile time and only raise an error if it's
|
| 1810 |
+
# actually called at runtime. See pull_dependencies.
|
| 1811 |
+
if func is None and not frame.soft_frame:
|
| 1812 |
+
type_name = "filter" if is_filter else "test"
|
| 1813 |
+
self.fail(f"No {type_name} named {node.name!r}.", node.lineno)
|
| 1814 |
+
|
| 1815 |
+
pass_arg = {
|
| 1816 |
+
_PassArg.context: "context",
|
| 1817 |
+
_PassArg.eval_context: "context.eval_ctx",
|
| 1818 |
+
_PassArg.environment: "environment",
|
| 1819 |
+
}.get(
|
| 1820 |
+
_PassArg.from_obj(func) # type: ignore
|
| 1821 |
+
)
|
| 1822 |
+
|
| 1823 |
+
if pass_arg is not None:
|
| 1824 |
+
self.write(f"{pass_arg}, ")
|
| 1825 |
+
|
| 1826 |
+
# Back to the visitor function to handle visiting the target of
|
| 1827 |
+
# the filter or test.
|
| 1828 |
+
yield
|
| 1829 |
+
|
| 1830 |
+
self.signature(node, frame)
|
| 1831 |
+
self.write(")")
|
| 1832 |
+
|
| 1833 |
+
if self.environment.is_async:
|
| 1834 |
+
self.write("))")
|
| 1835 |
+
|
| 1836 |
+
@optimizeconst
|
| 1837 |
+
def visit_Filter(self, node: nodes.Filter, frame: Frame) -> None:
|
| 1838 |
+
with self._filter_test_common(node, frame, True):
|
| 1839 |
+
# if the filter node is None we are inside a filter block
|
| 1840 |
+
# and want to write to the current buffer
|
| 1841 |
+
if node.node is not None:
|
| 1842 |
+
self.visit(node.node, frame)
|
| 1843 |
+
elif frame.eval_ctx.volatile:
|
| 1844 |
+
self.write(
|
| 1845 |
+
f"(Markup(concat({frame.buffer}))"
|
| 1846 |
+
f" if context.eval_ctx.autoescape else concat({frame.buffer}))"
|
| 1847 |
+
)
|
| 1848 |
+
elif frame.eval_ctx.autoescape:
|
| 1849 |
+
self.write(f"Markup(concat({frame.buffer}))")
|
| 1850 |
+
else:
|
| 1851 |
+
self.write(f"concat({frame.buffer})")
|
| 1852 |
+
|
| 1853 |
+
@optimizeconst
|
| 1854 |
+
def visit_Test(self, node: nodes.Test, frame: Frame) -> None:
|
| 1855 |
+
with self._filter_test_common(node, frame, False):
|
| 1856 |
+
self.visit(node.node, frame)
|
| 1857 |
+
|
| 1858 |
+
@optimizeconst
|
| 1859 |
+
def visit_CondExpr(self, node: nodes.CondExpr, frame: Frame) -> None:
|
| 1860 |
+
frame = frame.soft()
|
| 1861 |
+
|
| 1862 |
+
def write_expr2() -> None:
|
| 1863 |
+
if node.expr2 is not None:
|
| 1864 |
+
self.visit(node.expr2, frame)
|
| 1865 |
+
return
|
| 1866 |
+
|
| 1867 |
+
self.write(
|
| 1868 |
+
f'cond_expr_undefined("the inline if-expression on'
|
| 1869 |
+
f" {self.position(node)} evaluated to false and no else"
|
| 1870 |
+
f' section was defined.")'
|
| 1871 |
+
)
|
| 1872 |
+
|
| 1873 |
+
self.write("(")
|
| 1874 |
+
self.visit(node.expr1, frame)
|
| 1875 |
+
self.write(" if ")
|
| 1876 |
+
self.visit(node.test, frame)
|
| 1877 |
+
self.write(" else ")
|
| 1878 |
+
write_expr2()
|
| 1879 |
+
self.write(")")
|
| 1880 |
+
|
| 1881 |
+
@optimizeconst
|
| 1882 |
+
def visit_Call(
|
| 1883 |
+
self, node: nodes.Call, frame: Frame, forward_caller: bool = False
|
| 1884 |
+
) -> None:
|
| 1885 |
+
if self.environment.is_async:
|
| 1886 |
+
self.write("(await auto_await(")
|
| 1887 |
+
if self.environment.sandboxed:
|
| 1888 |
+
self.write("environment.call(context, ")
|
| 1889 |
+
else:
|
| 1890 |
+
self.write("context.call(")
|
| 1891 |
+
self.visit(node.node, frame)
|
| 1892 |
+
extra_kwargs = {"caller": "caller"} if forward_caller else None
|
| 1893 |
+
loop_kwargs = {"_loop_vars": "_loop_vars"} if frame.loop_frame else {}
|
| 1894 |
+
block_kwargs = {"_block_vars": "_block_vars"} if frame.block_frame else {}
|
| 1895 |
+
if extra_kwargs:
|
| 1896 |
+
extra_kwargs.update(loop_kwargs, **block_kwargs)
|
| 1897 |
+
elif loop_kwargs or block_kwargs:
|
| 1898 |
+
extra_kwargs = dict(loop_kwargs, **block_kwargs)
|
| 1899 |
+
self.signature(node, frame, extra_kwargs)
|
| 1900 |
+
self.write(")")
|
| 1901 |
+
if self.environment.is_async:
|
| 1902 |
+
self.write("))")
|
| 1903 |
+
|
| 1904 |
+
def visit_Keyword(self, node: nodes.Keyword, frame: Frame) -> None:
|
| 1905 |
+
self.write(node.key + "=")
|
| 1906 |
+
self.visit(node.value, frame)
|
| 1907 |
+
|
| 1908 |
+
# -- Unused nodes for extensions
|
| 1909 |
+
|
| 1910 |
+
def visit_MarkSafe(self, node: nodes.MarkSafe, frame: Frame) -> None:
|
| 1911 |
+
self.write("Markup(")
|
| 1912 |
+
self.visit(node.expr, frame)
|
| 1913 |
+
self.write(")")
|
| 1914 |
+
|
| 1915 |
+
def visit_MarkSafeIfAutoescape(
|
| 1916 |
+
self, node: nodes.MarkSafeIfAutoescape, frame: Frame
|
| 1917 |
+
) -> None:
|
| 1918 |
+
self.write("(Markup if context.eval_ctx.autoescape else identity)(")
|
| 1919 |
+
self.visit(node.expr, frame)
|
| 1920 |
+
self.write(")")
|
| 1921 |
+
|
| 1922 |
+
def visit_EnvironmentAttribute(
|
| 1923 |
+
self, node: nodes.EnvironmentAttribute, frame: Frame
|
| 1924 |
+
) -> None:
|
| 1925 |
+
self.write("environment." + node.name)
|
| 1926 |
+
|
| 1927 |
+
def visit_ExtensionAttribute(
|
| 1928 |
+
self, node: nodes.ExtensionAttribute, frame: Frame
|
| 1929 |
+
) -> None:
|
| 1930 |
+
self.write(f"environment.extensions[{node.identifier!r}].{node.name}")
|
| 1931 |
+
|
| 1932 |
+
def visit_ImportedName(self, node: nodes.ImportedName, frame: Frame) -> None:
|
| 1933 |
+
self.write(self.import_aliases[node.importname])
|
| 1934 |
+
|
| 1935 |
+
def visit_InternalName(self, node: nodes.InternalName, frame: Frame) -> None:
|
| 1936 |
+
self.write(node.name)
|
| 1937 |
+
|
| 1938 |
+
def visit_ContextReference(
|
| 1939 |
+
self, node: nodes.ContextReference, frame: Frame
|
| 1940 |
+
) -> None:
|
| 1941 |
+
self.write("context")
|
| 1942 |
+
|
| 1943 |
+
def visit_DerivedContextReference(
|
| 1944 |
+
self, node: nodes.DerivedContextReference, frame: Frame
|
| 1945 |
+
) -> None:
|
| 1946 |
+
self.write(self.derive_context(frame))
|
| 1947 |
+
|
| 1948 |
+
def visit_Continue(self, node: nodes.Continue, frame: Frame) -> None:
|
| 1949 |
+
self.writeline("continue", node)
|
| 1950 |
+
|
| 1951 |
+
def visit_Break(self, node: nodes.Break, frame: Frame) -> None:
|
| 1952 |
+
self.writeline("break", node)
|
| 1953 |
+
|
| 1954 |
+
def visit_Scope(self, node: nodes.Scope, frame: Frame) -> None:
|
| 1955 |
+
scope_frame = frame.inner()
|
| 1956 |
+
scope_frame.symbols.analyze_node(node)
|
| 1957 |
+
self.enter_frame(scope_frame)
|
| 1958 |
+
self.blockvisit(node.body, scope_frame)
|
| 1959 |
+
self.leave_frame(scope_frame)
|
| 1960 |
+
|
| 1961 |
+
def visit_OverlayScope(self, node: nodes.OverlayScope, frame: Frame) -> None:
|
| 1962 |
+
ctx = self.temporary_identifier()
|
| 1963 |
+
self.writeline(f"{ctx} = {self.derive_context(frame)}")
|
| 1964 |
+
self.writeline(f"{ctx}.vars = ")
|
| 1965 |
+
self.visit(node.context, frame)
|
| 1966 |
+
self.push_context_reference(ctx)
|
| 1967 |
+
|
| 1968 |
+
scope_frame = frame.inner(isolated=True)
|
| 1969 |
+
scope_frame.symbols.analyze_node(node)
|
| 1970 |
+
self.enter_frame(scope_frame)
|
| 1971 |
+
self.blockvisit(node.body, scope_frame)
|
| 1972 |
+
self.leave_frame(scope_frame)
|
| 1973 |
+
self.pop_context_reference()
|
| 1974 |
+
|
| 1975 |
+
def visit_EvalContextModifier(
|
| 1976 |
+
self, node: nodes.EvalContextModifier, frame: Frame
|
| 1977 |
+
) -> None:
|
| 1978 |
+
for keyword in node.options:
|
| 1979 |
+
self.writeline(f"context.eval_ctx.{keyword.key} = ")
|
| 1980 |
+
self.visit(keyword.value, frame)
|
| 1981 |
+
try:
|
| 1982 |
+
val = keyword.value.as_const(frame.eval_ctx)
|
| 1983 |
+
except nodes.Impossible:
|
| 1984 |
+
frame.eval_ctx.volatile = True
|
| 1985 |
+
else:
|
| 1986 |
+
setattr(frame.eval_ctx, keyword.key, val)
|
| 1987 |
+
|
| 1988 |
+
def visit_ScopedEvalContextModifier(
|
| 1989 |
+
self, node: nodes.ScopedEvalContextModifier, frame: Frame
|
| 1990 |
+
) -> None:
|
| 1991 |
+
old_ctx_name = self.temporary_identifier()
|
| 1992 |
+
saved_ctx = frame.eval_ctx.save()
|
| 1993 |
+
self.writeline(f"{old_ctx_name} = context.eval_ctx.save()")
|
| 1994 |
+
self.visit_EvalContextModifier(node, frame)
|
| 1995 |
+
for child in node.body:
|
| 1996 |
+
self.visit(child, frame)
|
| 1997 |
+
frame.eval_ctx.revert(saved_ctx)
|
| 1998 |
+
self.writeline(f"context.eval_ctx.revert({old_ctx_name})")
|
deepseekvl2/lib/python3.10/site-packages/jinja2/constants.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#: list of lorem ipsum words used by the lipsum() helper function
|
| 2 |
+
LOREM_IPSUM_WORDS = """\
|
| 3 |
+
a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at
|
| 4 |
+
auctor augue bibendum blandit class commodo condimentum congue consectetuer
|
| 5 |
+
consequat conubia convallis cras cubilia cum curabitur curae cursus dapibus
|
| 6 |
+
diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend
|
| 7 |
+
elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames
|
| 8 |
+
faucibus felis fermentum feugiat fringilla fusce gravida habitant habitasse hac
|
| 9 |
+
hendrerit hymenaeos iaculis id imperdiet in inceptos integer interdum ipsum
|
| 10 |
+
justo lacinia lacus laoreet lectus leo libero ligula litora lobortis lorem
|
| 11 |
+
luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie
|
| 12 |
+
mollis montes morbi mus nam nascetur natoque nec neque netus nibh nisi nisl non
|
| 13 |
+
nonummy nostra nulla nullam nunc odio orci ornare parturient pede pellentesque
|
| 14 |
+
penatibus per pharetra phasellus placerat platea porta porttitor posuere
|
| 15 |
+
potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus
|
| 16 |
+
ridiculus risus rutrum sagittis sapien scelerisque sed sem semper senectus sit
|
| 17 |
+
sociis sociosqu sodales sollicitudin suscipit suspendisse taciti tellus tempor
|
| 18 |
+
tempus tincidunt torquent tortor tristique turpis ullamcorper ultrices
|
| 19 |
+
ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus
|
| 20 |
+
viverra volutpat vulputate"""
|
deepseekvl2/lib/python3.10/site-packages/jinja2/debug.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import typing as t
|
| 3 |
+
from types import CodeType
|
| 4 |
+
from types import TracebackType
|
| 5 |
+
|
| 6 |
+
from .exceptions import TemplateSyntaxError
|
| 7 |
+
from .utils import internal_code
|
| 8 |
+
from .utils import missing
|
| 9 |
+
|
| 10 |
+
if t.TYPE_CHECKING:
|
| 11 |
+
from .runtime import Context
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def rewrite_traceback_stack(source: t.Optional[str] = None) -> BaseException:
|
| 15 |
+
"""Rewrite the current exception to replace any tracebacks from
|
| 16 |
+
within compiled template code with tracebacks that look like they
|
| 17 |
+
came from the template source.
|
| 18 |
+
|
| 19 |
+
This must be called within an ``except`` block.
|
| 20 |
+
|
| 21 |
+
:param source: For ``TemplateSyntaxError``, the original source if
|
| 22 |
+
known.
|
| 23 |
+
:return: The original exception with the rewritten traceback.
|
| 24 |
+
"""
|
| 25 |
+
_, exc_value, tb = sys.exc_info()
|
| 26 |
+
exc_value = t.cast(BaseException, exc_value)
|
| 27 |
+
tb = t.cast(TracebackType, tb)
|
| 28 |
+
|
| 29 |
+
if isinstance(exc_value, TemplateSyntaxError) and not exc_value.translated:
|
| 30 |
+
exc_value.translated = True
|
| 31 |
+
exc_value.source = source
|
| 32 |
+
# Remove the old traceback, otherwise the frames from the
|
| 33 |
+
# compiler still show up.
|
| 34 |
+
exc_value.with_traceback(None)
|
| 35 |
+
# Outside of runtime, so the frame isn't executing template
|
| 36 |
+
# code, but it still needs to point at the template.
|
| 37 |
+
tb = fake_traceback(
|
| 38 |
+
exc_value, None, exc_value.filename or "<unknown>", exc_value.lineno
|
| 39 |
+
)
|
| 40 |
+
else:
|
| 41 |
+
# Skip the frame for the render function.
|
| 42 |
+
tb = tb.tb_next
|
| 43 |
+
|
| 44 |
+
stack = []
|
| 45 |
+
|
| 46 |
+
# Build the stack of traceback object, replacing any in template
|
| 47 |
+
# code with the source file and line information.
|
| 48 |
+
while tb is not None:
|
| 49 |
+
# Skip frames decorated with @internalcode. These are internal
|
| 50 |
+
# calls that aren't useful in template debugging output.
|
| 51 |
+
if tb.tb_frame.f_code in internal_code:
|
| 52 |
+
tb = tb.tb_next
|
| 53 |
+
continue
|
| 54 |
+
|
| 55 |
+
template = tb.tb_frame.f_globals.get("__jinja_template__")
|
| 56 |
+
|
| 57 |
+
if template is not None:
|
| 58 |
+
lineno = template.get_corresponding_lineno(tb.tb_lineno)
|
| 59 |
+
fake_tb = fake_traceback(exc_value, tb, template.filename, lineno)
|
| 60 |
+
stack.append(fake_tb)
|
| 61 |
+
else:
|
| 62 |
+
stack.append(tb)
|
| 63 |
+
|
| 64 |
+
tb = tb.tb_next
|
| 65 |
+
|
| 66 |
+
tb_next = None
|
| 67 |
+
|
| 68 |
+
# Assign tb_next in reverse to avoid circular references.
|
| 69 |
+
for tb in reversed(stack):
|
| 70 |
+
tb.tb_next = tb_next
|
| 71 |
+
tb_next = tb
|
| 72 |
+
|
| 73 |
+
return exc_value.with_traceback(tb_next)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def fake_traceback( # type: ignore
|
| 77 |
+
exc_value: BaseException, tb: t.Optional[TracebackType], filename: str, lineno: int
|
| 78 |
+
) -> TracebackType:
|
| 79 |
+
"""Produce a new traceback object that looks like it came from the
|
| 80 |
+
template source instead of the compiled code. The filename, line
|
| 81 |
+
number, and location name will point to the template, and the local
|
| 82 |
+
variables will be the current template context.
|
| 83 |
+
|
| 84 |
+
:param exc_value: The original exception to be re-raised to create
|
| 85 |
+
the new traceback.
|
| 86 |
+
:param tb: The original traceback to get the local variables and
|
| 87 |
+
code info from.
|
| 88 |
+
:param filename: The template filename.
|
| 89 |
+
:param lineno: The line number in the template source.
|
| 90 |
+
"""
|
| 91 |
+
if tb is not None:
|
| 92 |
+
# Replace the real locals with the context that would be
|
| 93 |
+
# available at that point in the template.
|
| 94 |
+
locals = get_template_locals(tb.tb_frame.f_locals)
|
| 95 |
+
locals.pop("__jinja_exception__", None)
|
| 96 |
+
else:
|
| 97 |
+
locals = {}
|
| 98 |
+
|
| 99 |
+
globals = {
|
| 100 |
+
"__name__": filename,
|
| 101 |
+
"__file__": filename,
|
| 102 |
+
"__jinja_exception__": exc_value,
|
| 103 |
+
}
|
| 104 |
+
# Raise an exception at the correct line number.
|
| 105 |
+
code: CodeType = compile(
|
| 106 |
+
"\n" * (lineno - 1) + "raise __jinja_exception__", filename, "exec"
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
# Build a new code object that points to the template file and
|
| 110 |
+
# replaces the location with a block name.
|
| 111 |
+
location = "template"
|
| 112 |
+
|
| 113 |
+
if tb is not None:
|
| 114 |
+
function = tb.tb_frame.f_code.co_name
|
| 115 |
+
|
| 116 |
+
if function == "root":
|
| 117 |
+
location = "top-level template code"
|
| 118 |
+
elif function.startswith("block_"):
|
| 119 |
+
location = f"block {function[6:]!r}"
|
| 120 |
+
|
| 121 |
+
if sys.version_info >= (3, 8):
|
| 122 |
+
code = code.replace(co_name=location)
|
| 123 |
+
else:
|
| 124 |
+
code = CodeType(
|
| 125 |
+
code.co_argcount,
|
| 126 |
+
code.co_kwonlyargcount,
|
| 127 |
+
code.co_nlocals,
|
| 128 |
+
code.co_stacksize,
|
| 129 |
+
code.co_flags,
|
| 130 |
+
code.co_code,
|
| 131 |
+
code.co_consts,
|
| 132 |
+
code.co_names,
|
| 133 |
+
code.co_varnames,
|
| 134 |
+
code.co_filename,
|
| 135 |
+
location,
|
| 136 |
+
code.co_firstlineno,
|
| 137 |
+
code.co_lnotab,
|
| 138 |
+
code.co_freevars,
|
| 139 |
+
code.co_cellvars,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# Execute the new code, which is guaranteed to raise, and return
|
| 143 |
+
# the new traceback without this frame.
|
| 144 |
+
try:
|
| 145 |
+
exec(code, globals, locals)
|
| 146 |
+
except BaseException:
|
| 147 |
+
return sys.exc_info()[2].tb_next # type: ignore
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def get_template_locals(real_locals: t.Mapping[str, t.Any]) -> t.Dict[str, t.Any]:
|
| 151 |
+
"""Based on the runtime locals, get the context that would be
|
| 152 |
+
available at that point in the template.
|
| 153 |
+
"""
|
| 154 |
+
# Start with the current template context.
|
| 155 |
+
ctx: t.Optional[Context] = real_locals.get("context")
|
| 156 |
+
|
| 157 |
+
if ctx is not None:
|
| 158 |
+
data: t.Dict[str, t.Any] = ctx.get_all().copy()
|
| 159 |
+
else:
|
| 160 |
+
data = {}
|
| 161 |
+
|
| 162 |
+
# Might be in a derived context that only sets local variables
|
| 163 |
+
# rather than pushing a context. Local variables follow the scheme
|
| 164 |
+
# l_depth_name. Find the highest-depth local that has a value for
|
| 165 |
+
# each name.
|
| 166 |
+
local_overrides: t.Dict[str, t.Tuple[int, t.Any]] = {}
|
| 167 |
+
|
| 168 |
+
for name, value in real_locals.items():
|
| 169 |
+
if not name.startswith("l_") or value is missing:
|
| 170 |
+
# Not a template variable, or no longer relevant.
|
| 171 |
+
continue
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
_, depth_str, name = name.split("_", 2)
|
| 175 |
+
depth = int(depth_str)
|
| 176 |
+
except ValueError:
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
cur_depth = local_overrides.get(name, (-1,))[0]
|
| 180 |
+
|
| 181 |
+
if cur_depth < depth:
|
| 182 |
+
local_overrides[name] = (depth, value)
|
| 183 |
+
|
| 184 |
+
# Modify the context with any derived context.
|
| 185 |
+
for name, (_, value) in local_overrides.items():
|
| 186 |
+
if value is missing:
|
| 187 |
+
data.pop(name, None)
|
| 188 |
+
else:
|
| 189 |
+
data[name] = value
|
| 190 |
+
|
| 191 |
+
return data
|
deepseekvl2/lib/python3.10/site-packages/jinja2/defaults.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
|
| 3 |
+
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
|
| 4 |
+
from .tests import TESTS as DEFAULT_TESTS # noqa: F401
|
| 5 |
+
from .utils import Cycler
|
| 6 |
+
from .utils import generate_lorem_ipsum
|
| 7 |
+
from .utils import Joiner
|
| 8 |
+
from .utils import Namespace
|
| 9 |
+
|
| 10 |
+
if t.TYPE_CHECKING:
|
| 11 |
+
import typing_extensions as te
|
| 12 |
+
|
| 13 |
+
# defaults for the parser / lexer
|
| 14 |
+
BLOCK_START_STRING = "{%"
|
| 15 |
+
BLOCK_END_STRING = "%}"
|
| 16 |
+
VARIABLE_START_STRING = "{{"
|
| 17 |
+
VARIABLE_END_STRING = "}}"
|
| 18 |
+
COMMENT_START_STRING = "{#"
|
| 19 |
+
COMMENT_END_STRING = "#}"
|
| 20 |
+
LINE_STATEMENT_PREFIX: t.Optional[str] = None
|
| 21 |
+
LINE_COMMENT_PREFIX: t.Optional[str] = None
|
| 22 |
+
TRIM_BLOCKS = False
|
| 23 |
+
LSTRIP_BLOCKS = False
|
| 24 |
+
NEWLINE_SEQUENCE: "te.Literal['\\n', '\\r\\n', '\\r']" = "\n"
|
| 25 |
+
KEEP_TRAILING_NEWLINE = False
|
| 26 |
+
|
| 27 |
+
# default filters, tests and namespace
|
| 28 |
+
|
| 29 |
+
DEFAULT_NAMESPACE = {
|
| 30 |
+
"range": range,
|
| 31 |
+
"dict": dict,
|
| 32 |
+
"lipsum": generate_lorem_ipsum,
|
| 33 |
+
"cycler": Cycler,
|
| 34 |
+
"joiner": Joiner,
|
| 35 |
+
"namespace": Namespace,
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# default policies
|
| 39 |
+
DEFAULT_POLICIES: t.Dict[str, t.Any] = {
|
| 40 |
+
"compiler.ascii_str": True,
|
| 41 |
+
"urlize.rel": "noopener",
|
| 42 |
+
"urlize.target": None,
|
| 43 |
+
"urlize.extra_schemes": None,
|
| 44 |
+
"truncate.leeway": 5,
|
| 45 |
+
"json.dumps_function": None,
|
| 46 |
+
"json.dumps_kwargs": {"sort_keys": True},
|
| 47 |
+
"ext.i18n.trimmed": False,
|
| 48 |
+
}
|
deepseekvl2/lib/python3.10/site-packages/jinja2/exceptions.py
ADDED
|
@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
+
import typing as t
|
| 2 |
+
|
| 3 |
+
if t.TYPE_CHECKING:
|
| 4 |
+
from .runtime import Undefined
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TemplateError(Exception):
|
| 8 |
+
"""Baseclass for all template errors."""
|
| 9 |
+
|
| 10 |
+
def __init__(self, message: t.Optional[str] = None) -> None:
|
| 11 |
+
super().__init__(message)
|
| 12 |
+
|
| 13 |
+
@property
|
| 14 |
+
def message(self) -> t.Optional[str]:
|
| 15 |
+
return self.args[0] if self.args else None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class TemplateNotFound(IOError, LookupError, TemplateError):
|
| 19 |
+
"""Raised if a template does not exist.
|
| 20 |
+
|
| 21 |
+
.. versionchanged:: 2.11
|
| 22 |
+
If the given name is :class:`Undefined` and no message was
|
| 23 |
+
provided, an :exc:`UndefinedError` is raised.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
# Silence the Python warning about message being deprecated since
|
| 27 |
+
# it's not valid here.
|
| 28 |
+
message: t.Optional[str] = None
|
| 29 |
+
|
| 30 |
+
def __init__(
|
| 31 |
+
self,
|
| 32 |
+
name: t.Optional[t.Union[str, "Undefined"]],
|
| 33 |
+
message: t.Optional[str] = None,
|
| 34 |
+
) -> None:
|
| 35 |
+
IOError.__init__(self, name)
|
| 36 |
+
|
| 37 |
+
if message is None:
|
| 38 |
+
from .runtime import Undefined
|
| 39 |
+
|
| 40 |
+
if isinstance(name, Undefined):
|
| 41 |
+
name._fail_with_undefined_error()
|
| 42 |
+
|
| 43 |
+
message = name
|
| 44 |
+
|
| 45 |
+
self.message = message
|
| 46 |
+
self.name = name
|
| 47 |
+
self.templates = [name]
|
| 48 |
+
|
| 49 |
+
def __str__(self) -> str:
|
| 50 |
+
return str(self.message)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class TemplatesNotFound(TemplateNotFound):
|
| 54 |
+
"""Like :class:`TemplateNotFound` but raised if multiple templates
|
| 55 |
+
are selected. This is a subclass of :class:`TemplateNotFound`
|
| 56 |
+
exception, so just catching the base exception will catch both.
|
| 57 |
+
|
| 58 |
+
.. versionchanged:: 2.11
|
| 59 |
+
If a name in the list of names is :class:`Undefined`, a message
|
| 60 |
+
about it being undefined is shown rather than the empty string.
|
| 61 |
+
|
| 62 |
+
.. versionadded:: 2.2
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
def __init__(
|
| 66 |
+
self,
|
| 67 |
+
names: t.Sequence[t.Union[str, "Undefined"]] = (),
|
| 68 |
+
message: t.Optional[str] = None,
|
| 69 |
+
) -> None:
|
| 70 |
+
if message is None:
|
| 71 |
+
from .runtime import Undefined
|
| 72 |
+
|
| 73 |
+
parts = []
|
| 74 |
+
|
| 75 |
+
for name in names:
|
| 76 |
+
if isinstance(name, Undefined):
|
| 77 |
+
parts.append(name._undefined_message)
|
| 78 |
+
else:
|
| 79 |
+
parts.append(name)
|
| 80 |
+
|
| 81 |
+
parts_str = ", ".join(map(str, parts))
|
| 82 |
+
message = f"none of the templates given were found: {parts_str}"
|
| 83 |
+
|
| 84 |
+
super().__init__(names[-1] if names else None, message)
|
| 85 |
+
self.templates = list(names)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class TemplateSyntaxError(TemplateError):
|
| 89 |
+
"""Raised to tell the user that there is a problem with the template."""
|
| 90 |
+
|
| 91 |
+
def __init__(
|
| 92 |
+
self,
|
| 93 |
+
message: str,
|
| 94 |
+
lineno: int,
|
| 95 |
+
name: t.Optional[str] = None,
|
| 96 |
+
filename: t.Optional[str] = None,
|
| 97 |
+
) -> None:
|
| 98 |
+
super().__init__(message)
|
| 99 |
+
self.lineno = lineno
|
| 100 |
+
self.name = name
|
| 101 |
+
self.filename = filename
|
| 102 |
+
self.source: t.Optional[str] = None
|
| 103 |
+
|
| 104 |
+
# this is set to True if the debug.translate_syntax_error
|
| 105 |
+
# function translated the syntax error into a new traceback
|
| 106 |
+
self.translated = False
|
| 107 |
+
|
| 108 |
+
def __str__(self) -> str:
|
| 109 |
+
# for translated errors we only return the message
|
| 110 |
+
if self.translated:
|
| 111 |
+
return t.cast(str, self.message)
|
| 112 |
+
|
| 113 |
+
# otherwise attach some stuff
|
| 114 |
+
location = f"line {self.lineno}"
|
| 115 |
+
name = self.filename or self.name
|
| 116 |
+
if name:
|
| 117 |
+
location = f'File "{name}", {location}'
|
| 118 |
+
lines = [t.cast(str, self.message), " " + location]
|
| 119 |
+
|
| 120 |
+
# if the source is set, add the line to the output
|
| 121 |
+
if self.source is not None:
|
| 122 |
+
try:
|
| 123 |
+
line = self.source.splitlines()[self.lineno - 1]
|
| 124 |
+
except IndexError:
|
| 125 |
+
pass
|
| 126 |
+
else:
|
| 127 |
+
lines.append(" " + line.strip())
|
| 128 |
+
|
| 129 |
+
return "\n".join(lines)
|
| 130 |
+
|
| 131 |
+
def __reduce__(self): # type: ignore
|
| 132 |
+
# https://bugs.python.org/issue1692335 Exceptions that take
|
| 133 |
+
# multiple required arguments have problems with pickling.
|
| 134 |
+
# Without this, raises TypeError: __init__() missing 1 required
|
| 135 |
+
# positional argument: 'lineno'
|
| 136 |
+
return self.__class__, (self.message, self.lineno, self.name, self.filename)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class TemplateAssertionError(TemplateSyntaxError):
|
| 140 |
+
"""Like a template syntax error, but covers cases where something in the
|
| 141 |
+
template caused an error at compile time that wasn't necessarily caused
|
| 142 |
+
by a syntax error. However it's a direct subclass of
|
| 143 |
+
:exc:`TemplateSyntaxError` and has the same attributes.
|
| 144 |
+
"""
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class TemplateRuntimeError(TemplateError):
|
| 148 |
+
"""A generic runtime error in the template engine. Under some situations
|
| 149 |
+
Jinja may raise this exception.
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
class UndefinedError(TemplateRuntimeError):
|
| 154 |
+
"""Raised if a template tries to operate on :class:`Undefined`."""
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
class SecurityError(TemplateRuntimeError):
|
| 158 |
+
"""Raised if a template tries to do something insecure if the
|
| 159 |
+
sandbox is enabled.
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
class FilterArgumentError(TemplateRuntimeError):
|
| 164 |
+
"""This error is raised if a filter was called with inappropriate
|
| 165 |
+
arguments
|
| 166 |
+
"""
|
deepseekvl2/lib/python3.10/site-packages/jinja2/ext.py
ADDED
|
@@ -0,0 +1,870 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extension API for adding custom tags and behavior."""
|
| 2 |
+
|
| 3 |
+
import pprint
|
| 4 |
+
import re
|
| 5 |
+
import typing as t
|
| 6 |
+
|
| 7 |
+
from markupsafe import Markup
|
| 8 |
+
|
| 9 |
+
from . import defaults
|
| 10 |
+
from . import nodes
|
| 11 |
+
from .environment import Environment
|
| 12 |
+
from .exceptions import TemplateAssertionError
|
| 13 |
+
from .exceptions import TemplateSyntaxError
|
| 14 |
+
from .runtime import concat # type: ignore
|
| 15 |
+
from .runtime import Context
|
| 16 |
+
from .runtime import Undefined
|
| 17 |
+
from .utils import import_string
|
| 18 |
+
from .utils import pass_context
|
| 19 |
+
|
| 20 |
+
if t.TYPE_CHECKING:
|
| 21 |
+
import typing_extensions as te
|
| 22 |
+
|
| 23 |
+
from .lexer import Token
|
| 24 |
+
from .lexer import TokenStream
|
| 25 |
+
from .parser import Parser
|
| 26 |
+
|
| 27 |
+
class _TranslationsBasic(te.Protocol):
|
| 28 |
+
def gettext(self, message: str) -> str: ...
|
| 29 |
+
|
| 30 |
+
def ngettext(self, singular: str, plural: str, n: int) -> str:
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
class _TranslationsContext(_TranslationsBasic):
|
| 34 |
+
def pgettext(self, context: str, message: str) -> str: ...
|
| 35 |
+
|
| 36 |
+
def npgettext(
|
| 37 |
+
self, context: str, singular: str, plural: str, n: int
|
| 38 |
+
) -> str: ...
|
| 39 |
+
|
| 40 |
+
_SupportedTranslations = t.Union[_TranslationsBasic, _TranslationsContext]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# I18N functions available in Jinja templates. If the I18N library
|
| 44 |
+
# provides ugettext, it will be assigned to gettext.
|
| 45 |
+
GETTEXT_FUNCTIONS: t.Tuple[str, ...] = (
|
| 46 |
+
"_",
|
| 47 |
+
"gettext",
|
| 48 |
+
"ngettext",
|
| 49 |
+
"pgettext",
|
| 50 |
+
"npgettext",
|
| 51 |
+
)
|
| 52 |
+
_ws_re = re.compile(r"\s*\n\s*")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class Extension:
|
| 56 |
+
"""Extensions can be used to add extra functionality to the Jinja template
|
| 57 |
+
system at the parser level. Custom extensions are bound to an environment
|
| 58 |
+
but may not store environment specific data on `self`. The reason for
|
| 59 |
+
this is that an extension can be bound to another environment (for
|
| 60 |
+
overlays) by creating a copy and reassigning the `environment` attribute.
|
| 61 |
+
|
| 62 |
+
As extensions are created by the environment they cannot accept any
|
| 63 |
+
arguments for configuration. One may want to work around that by using
|
| 64 |
+
a factory function, but that is not possible as extensions are identified
|
| 65 |
+
by their import name. The correct way to configure the extension is
|
| 66 |
+
storing the configuration values on the environment. Because this way the
|
| 67 |
+
environment ends up acting as central configuration storage the
|
| 68 |
+
attributes may clash which is why extensions have to ensure that the names
|
| 69 |
+
they choose for configuration are not too generic. ``prefix`` for example
|
| 70 |
+
is a terrible name, ``fragment_cache_prefix`` on the other hand is a good
|
| 71 |
+
name as includes the name of the extension (fragment cache).
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
identifier: t.ClassVar[str]
|
| 75 |
+
|
| 76 |
+
def __init_subclass__(cls) -> None:
|
| 77 |
+
cls.identifier = f"{cls.__module__}.{cls.__name__}"
|
| 78 |
+
|
| 79 |
+
#: if this extension parses this is the list of tags it's listening to.
|
| 80 |
+
tags: t.Set[str] = set()
|
| 81 |
+
|
| 82 |
+
#: the priority of that extension. This is especially useful for
|
| 83 |
+
#: extensions that preprocess values. A lower value means higher
|
| 84 |
+
#: priority.
|
| 85 |
+
#:
|
| 86 |
+
#: .. versionadded:: 2.4
|
| 87 |
+
priority = 100
|
| 88 |
+
|
| 89 |
+
def __init__(self, environment: Environment) -> None:
|
| 90 |
+
self.environment = environment
|
| 91 |
+
|
| 92 |
+
def bind(self, environment: Environment) -> "te.Self":
|
| 93 |
+
"""Create a copy of this extension bound to another environment."""
|
| 94 |
+
rv = object.__new__(self.__class__)
|
| 95 |
+
rv.__dict__.update(self.__dict__)
|
| 96 |
+
rv.environment = environment
|
| 97 |
+
return rv
|
| 98 |
+
|
| 99 |
+
def preprocess(
|
| 100 |
+
self, source: str, name: t.Optional[str], filename: t.Optional[str] = None
|
| 101 |
+
) -> str:
|
| 102 |
+
"""This method is called before the actual lexing and can be used to
|
| 103 |
+
preprocess the source. The `filename` is optional. The return value
|
| 104 |
+
must be the preprocessed source.
|
| 105 |
+
"""
|
| 106 |
+
return source
|
| 107 |
+
|
| 108 |
+
def filter_stream(
|
| 109 |
+
self, stream: "TokenStream"
|
| 110 |
+
) -> t.Union["TokenStream", t.Iterable["Token"]]:
|
| 111 |
+
"""It's passed a :class:`~jinja2.lexer.TokenStream` that can be used
|
| 112 |
+
to filter tokens returned. This method has to return an iterable of
|
| 113 |
+
:class:`~jinja2.lexer.Token`\\s, but it doesn't have to return a
|
| 114 |
+
:class:`~jinja2.lexer.TokenStream`.
|
| 115 |
+
"""
|
| 116 |
+
return stream
|
| 117 |
+
|
| 118 |
+
def parse(self, parser: "Parser") -> t.Union[nodes.Node, t.List[nodes.Node]]:
|
| 119 |
+
"""If any of the :attr:`tags` matched this method is called with the
|
| 120 |
+
parser as first argument. The token the parser stream is pointing at
|
| 121 |
+
is the name token that matched. This method has to return one or a
|
| 122 |
+
list of multiple nodes.
|
| 123 |
+
"""
|
| 124 |
+
raise NotImplementedError()
|
| 125 |
+
|
| 126 |
+
def attr(
|
| 127 |
+
self, name: str, lineno: t.Optional[int] = None
|
| 128 |
+
) -> nodes.ExtensionAttribute:
|
| 129 |
+
"""Return an attribute node for the current extension. This is useful
|
| 130 |
+
to pass constants on extensions to generated template code.
|
| 131 |
+
|
| 132 |
+
::
|
| 133 |
+
|
| 134 |
+
self.attr('_my_attribute', lineno=lineno)
|
| 135 |
+
"""
|
| 136 |
+
return nodes.ExtensionAttribute(self.identifier, name, lineno=lineno)
|
| 137 |
+
|
| 138 |
+
def call_method(
|
| 139 |
+
self,
|
| 140 |
+
name: str,
|
| 141 |
+
args: t.Optional[t.List[nodes.Expr]] = None,
|
| 142 |
+
kwargs: t.Optional[t.List[nodes.Keyword]] = None,
|
| 143 |
+
dyn_args: t.Optional[nodes.Expr] = None,
|
| 144 |
+
dyn_kwargs: t.Optional[nodes.Expr] = None,
|
| 145 |
+
lineno: t.Optional[int] = None,
|
| 146 |
+
) -> nodes.Call:
|
| 147 |
+
"""Call a method of the extension. This is a shortcut for
|
| 148 |
+
:meth:`attr` + :class:`jinja2.nodes.Call`.
|
| 149 |
+
"""
|
| 150 |
+
if args is None:
|
| 151 |
+
args = []
|
| 152 |
+
if kwargs is None:
|
| 153 |
+
kwargs = []
|
| 154 |
+
return nodes.Call(
|
| 155 |
+
self.attr(name, lineno=lineno),
|
| 156 |
+
args,
|
| 157 |
+
kwargs,
|
| 158 |
+
dyn_args,
|
| 159 |
+
dyn_kwargs,
|
| 160 |
+
lineno=lineno,
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@pass_context
|
| 165 |
+
def _gettext_alias(
|
| 166 |
+
__context: Context, *args: t.Any, **kwargs: t.Any
|
| 167 |
+
) -> t.Union[t.Any, Undefined]:
|
| 168 |
+
return __context.call(__context.resolve("gettext"), *args, **kwargs)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _make_new_gettext(func: t.Callable[[str], str]) -> t.Callable[..., str]:
|
| 172 |
+
@pass_context
|
| 173 |
+
def gettext(__context: Context, __string: str, **variables: t.Any) -> str:
|
| 174 |
+
rv = __context.call(func, __string)
|
| 175 |
+
if __context.eval_ctx.autoescape:
|
| 176 |
+
rv = Markup(rv)
|
| 177 |
+
# Always treat as a format string, even if there are no
|
| 178 |
+
# variables. This makes translation strings more consistent
|
| 179 |
+
# and predictable. This requires escaping
|
| 180 |
+
return rv % variables # type: ignore
|
| 181 |
+
|
| 182 |
+
return gettext
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def _make_new_ngettext(func: t.Callable[[str, str, int], str]) -> t.Callable[..., str]:
|
| 186 |
+
@pass_context
|
| 187 |
+
def ngettext(
|
| 188 |
+
__context: Context,
|
| 189 |
+
__singular: str,
|
| 190 |
+
__plural: str,
|
| 191 |
+
__num: int,
|
| 192 |
+
**variables: t.Any,
|
| 193 |
+
) -> str:
|
| 194 |
+
variables.setdefault("num", __num)
|
| 195 |
+
rv = __context.call(func, __singular, __plural, __num)
|
| 196 |
+
if __context.eval_ctx.autoescape:
|
| 197 |
+
rv = Markup(rv)
|
| 198 |
+
# Always treat as a format string, see gettext comment above.
|
| 199 |
+
return rv % variables # type: ignore
|
| 200 |
+
|
| 201 |
+
return ngettext
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _make_new_pgettext(func: t.Callable[[str, str], str]) -> t.Callable[..., str]:
|
| 205 |
+
@pass_context
|
| 206 |
+
def pgettext(
|
| 207 |
+
__context: Context, __string_ctx: str, __string: str, **variables: t.Any
|
| 208 |
+
) -> str:
|
| 209 |
+
variables.setdefault("context", __string_ctx)
|
| 210 |
+
rv = __context.call(func, __string_ctx, __string)
|
| 211 |
+
|
| 212 |
+
if __context.eval_ctx.autoescape:
|
| 213 |
+
rv = Markup(rv)
|
| 214 |
+
|
| 215 |
+
# Always treat as a format string, see gettext comment above.
|
| 216 |
+
return rv % variables # type: ignore
|
| 217 |
+
|
| 218 |
+
return pgettext
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def _make_new_npgettext(
|
| 222 |
+
func: t.Callable[[str, str, str, int], str],
|
| 223 |
+
) -> t.Callable[..., str]:
|
| 224 |
+
@pass_context
|
| 225 |
+
def npgettext(
|
| 226 |
+
__context: Context,
|
| 227 |
+
__string_ctx: str,
|
| 228 |
+
__singular: str,
|
| 229 |
+
__plural: str,
|
| 230 |
+
__num: int,
|
| 231 |
+
**variables: t.Any,
|
| 232 |
+
) -> str:
|
| 233 |
+
variables.setdefault("context", __string_ctx)
|
| 234 |
+
variables.setdefault("num", __num)
|
| 235 |
+
rv = __context.call(func, __string_ctx, __singular, __plural, __num)
|
| 236 |
+
|
| 237 |
+
if __context.eval_ctx.autoescape:
|
| 238 |
+
rv = Markup(rv)
|
| 239 |
+
|
| 240 |
+
# Always treat as a format string, see gettext comment above.
|
| 241 |
+
return rv % variables # type: ignore
|
| 242 |
+
|
| 243 |
+
return npgettext
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class InternationalizationExtension(Extension):
|
| 247 |
+
"""This extension adds gettext support to Jinja."""
|
| 248 |
+
|
| 249 |
+
tags = {"trans"}
|
| 250 |
+
|
| 251 |
+
# TODO: the i18n extension is currently reevaluating values in a few
|
| 252 |
+
# situations. Take this example:
|
| 253 |
+
# {% trans count=something() %}{{ count }} foo{% pluralize
|
| 254 |
+
# %}{{ count }} fooss{% endtrans %}
|
| 255 |
+
# something is called twice here. One time for the gettext value and
|
| 256 |
+
# the other time for the n-parameter of the ngettext function.
|
| 257 |
+
|
| 258 |
+
def __init__(self, environment: Environment) -> None:
|
| 259 |
+
super().__init__(environment)
|
| 260 |
+
environment.globals["_"] = _gettext_alias
|
| 261 |
+
environment.extend(
|
| 262 |
+
install_gettext_translations=self._install,
|
| 263 |
+
install_null_translations=self._install_null,
|
| 264 |
+
install_gettext_callables=self._install_callables,
|
| 265 |
+
uninstall_gettext_translations=self._uninstall,
|
| 266 |
+
extract_translations=self._extract,
|
| 267 |
+
newstyle_gettext=False,
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
def _install(
|
| 271 |
+
self, translations: "_SupportedTranslations", newstyle: t.Optional[bool] = None
|
| 272 |
+
) -> None:
|
| 273 |
+
# ugettext and ungettext are preferred in case the I18N library
|
| 274 |
+
# is providing compatibility with older Python versions.
|
| 275 |
+
gettext = getattr(translations, "ugettext", None)
|
| 276 |
+
if gettext is None:
|
| 277 |
+
gettext = translations.gettext
|
| 278 |
+
ngettext = getattr(translations, "ungettext", None)
|
| 279 |
+
if ngettext is None:
|
| 280 |
+
ngettext = translations.ngettext
|
| 281 |
+
|
| 282 |
+
pgettext = getattr(translations, "pgettext", None)
|
| 283 |
+
npgettext = getattr(translations, "npgettext", None)
|
| 284 |
+
self._install_callables(
|
| 285 |
+
gettext, ngettext, newstyle=newstyle, pgettext=pgettext, npgettext=npgettext
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
def _install_null(self, newstyle: t.Optional[bool] = None) -> None:
|
| 289 |
+
import gettext
|
| 290 |
+
|
| 291 |
+
translations = gettext.NullTranslations()
|
| 292 |
+
|
| 293 |
+
if hasattr(translations, "pgettext"):
|
| 294 |
+
# Python < 3.8
|
| 295 |
+
pgettext = translations.pgettext
|
| 296 |
+
else:
|
| 297 |
+
|
| 298 |
+
def pgettext(c: str, s: str) -> str: # type: ignore[misc]
|
| 299 |
+
return s
|
| 300 |
+
|
| 301 |
+
if hasattr(translations, "npgettext"):
|
| 302 |
+
npgettext = translations.npgettext
|
| 303 |
+
else:
|
| 304 |
+
|
| 305 |
+
def npgettext(c: str, s: str, p: str, n: int) -> str: # type: ignore[misc]
|
| 306 |
+
return s if n == 1 else p
|
| 307 |
+
|
| 308 |
+
self._install_callables(
|
| 309 |
+
gettext=translations.gettext,
|
| 310 |
+
ngettext=translations.ngettext,
|
| 311 |
+
newstyle=newstyle,
|
| 312 |
+
pgettext=pgettext,
|
| 313 |
+
npgettext=npgettext,
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
def _install_callables(
|
| 317 |
+
self,
|
| 318 |
+
gettext: t.Callable[[str], str],
|
| 319 |
+
ngettext: t.Callable[[str, str, int], str],
|
| 320 |
+
newstyle: t.Optional[bool] = None,
|
| 321 |
+
pgettext: t.Optional[t.Callable[[str, str], str]] = None,
|
| 322 |
+
npgettext: t.Optional[t.Callable[[str, str, str, int], str]] = None,
|
| 323 |
+
) -> None:
|
| 324 |
+
if newstyle is not None:
|
| 325 |
+
self.environment.newstyle_gettext = newstyle # type: ignore
|
| 326 |
+
if self.environment.newstyle_gettext: # type: ignore
|
| 327 |
+
gettext = _make_new_gettext(gettext)
|
| 328 |
+
ngettext = _make_new_ngettext(ngettext)
|
| 329 |
+
|
| 330 |
+
if pgettext is not None:
|
| 331 |
+
pgettext = _make_new_pgettext(pgettext)
|
| 332 |
+
|
| 333 |
+
if npgettext is not None:
|
| 334 |
+
npgettext = _make_new_npgettext(npgettext)
|
| 335 |
+
|
| 336 |
+
self.environment.globals.update(
|
| 337 |
+
gettext=gettext, ngettext=ngettext, pgettext=pgettext, npgettext=npgettext
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
def _uninstall(self, translations: "_SupportedTranslations") -> None:
|
| 341 |
+
for key in ("gettext", "ngettext", "pgettext", "npgettext"):
|
| 342 |
+
self.environment.globals.pop(key, None)
|
| 343 |
+
|
| 344 |
+
def _extract(
|
| 345 |
+
self,
|
| 346 |
+
source: t.Union[str, nodes.Template],
|
| 347 |
+
gettext_functions: t.Sequence[str] = GETTEXT_FUNCTIONS,
|
| 348 |
+
) -> t.Iterator[
|
| 349 |
+
t.Tuple[int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]]]
|
| 350 |
+
]:
|
| 351 |
+
if isinstance(source, str):
|
| 352 |
+
source = self.environment.parse(source)
|
| 353 |
+
return extract_from_ast(source, gettext_functions)
|
| 354 |
+
|
| 355 |
+
def parse(self, parser: "Parser") -> t.Union[nodes.Node, t.List[nodes.Node]]:
|
| 356 |
+
"""Parse a translatable tag."""
|
| 357 |
+
lineno = next(parser.stream).lineno
|
| 358 |
+
|
| 359 |
+
context = None
|
| 360 |
+
context_token = parser.stream.next_if("string")
|
| 361 |
+
|
| 362 |
+
if context_token is not None:
|
| 363 |
+
context = context_token.value
|
| 364 |
+
|
| 365 |
+
# find all the variables referenced. Additionally a variable can be
|
| 366 |
+
# defined in the body of the trans block too, but this is checked at
|
| 367 |
+
# a later state.
|
| 368 |
+
plural_expr: t.Optional[nodes.Expr] = None
|
| 369 |
+
plural_expr_assignment: t.Optional[nodes.Assign] = None
|
| 370 |
+
num_called_num = False
|
| 371 |
+
variables: t.Dict[str, nodes.Expr] = {}
|
| 372 |
+
trimmed = None
|
| 373 |
+
while parser.stream.current.type != "block_end":
|
| 374 |
+
if variables:
|
| 375 |
+
parser.stream.expect("comma")
|
| 376 |
+
|
| 377 |
+
# skip colon for python compatibility
|
| 378 |
+
if parser.stream.skip_if("colon"):
|
| 379 |
+
break
|
| 380 |
+
|
| 381 |
+
token = parser.stream.expect("name")
|
| 382 |
+
if token.value in variables:
|
| 383 |
+
parser.fail(
|
| 384 |
+
f"translatable variable {token.value!r} defined twice.",
|
| 385 |
+
token.lineno,
|
| 386 |
+
exc=TemplateAssertionError,
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
# expressions
|
| 390 |
+
if parser.stream.current.type == "assign":
|
| 391 |
+
next(parser.stream)
|
| 392 |
+
variables[token.value] = var = parser.parse_expression()
|
| 393 |
+
elif trimmed is None and token.value in ("trimmed", "notrimmed"):
|
| 394 |
+
trimmed = token.value == "trimmed"
|
| 395 |
+
continue
|
| 396 |
+
else:
|
| 397 |
+
variables[token.value] = var = nodes.Name(token.value, "load")
|
| 398 |
+
|
| 399 |
+
if plural_expr is None:
|
| 400 |
+
if isinstance(var, nodes.Call):
|
| 401 |
+
plural_expr = nodes.Name("_trans", "load")
|
| 402 |
+
variables[token.value] = plural_expr
|
| 403 |
+
plural_expr_assignment = nodes.Assign(
|
| 404 |
+
nodes.Name("_trans", "store"), var
|
| 405 |
+
)
|
| 406 |
+
else:
|
| 407 |
+
plural_expr = var
|
| 408 |
+
num_called_num = token.value == "num"
|
| 409 |
+
|
| 410 |
+
parser.stream.expect("block_end")
|
| 411 |
+
|
| 412 |
+
plural = None
|
| 413 |
+
have_plural = False
|
| 414 |
+
referenced = set()
|
| 415 |
+
|
| 416 |
+
# now parse until endtrans or pluralize
|
| 417 |
+
singular_names, singular = self._parse_block(parser, True)
|
| 418 |
+
if singular_names:
|
| 419 |
+
referenced.update(singular_names)
|
| 420 |
+
if plural_expr is None:
|
| 421 |
+
plural_expr = nodes.Name(singular_names[0], "load")
|
| 422 |
+
num_called_num = singular_names[0] == "num"
|
| 423 |
+
|
| 424 |
+
# if we have a pluralize block, we parse that too
|
| 425 |
+
if parser.stream.current.test("name:pluralize"):
|
| 426 |
+
have_plural = True
|
| 427 |
+
next(parser.stream)
|
| 428 |
+
if parser.stream.current.type != "block_end":
|
| 429 |
+
token = parser.stream.expect("name")
|
| 430 |
+
if token.value not in variables:
|
| 431 |
+
parser.fail(
|
| 432 |
+
f"unknown variable {token.value!r} for pluralization",
|
| 433 |
+
token.lineno,
|
| 434 |
+
exc=TemplateAssertionError,
|
| 435 |
+
)
|
| 436 |
+
plural_expr = variables[token.value]
|
| 437 |
+
num_called_num = token.value == "num"
|
| 438 |
+
parser.stream.expect("block_end")
|
| 439 |
+
plural_names, plural = self._parse_block(parser, False)
|
| 440 |
+
next(parser.stream)
|
| 441 |
+
referenced.update(plural_names)
|
| 442 |
+
else:
|
| 443 |
+
next(parser.stream)
|
| 444 |
+
|
| 445 |
+
# register free names as simple name expressions
|
| 446 |
+
for name in referenced:
|
| 447 |
+
if name not in variables:
|
| 448 |
+
variables[name] = nodes.Name(name, "load")
|
| 449 |
+
|
| 450 |
+
if not have_plural:
|
| 451 |
+
plural_expr = None
|
| 452 |
+
elif plural_expr is None:
|
| 453 |
+
parser.fail("pluralize without variables", lineno)
|
| 454 |
+
|
| 455 |
+
if trimmed is None:
|
| 456 |
+
trimmed = self.environment.policies["ext.i18n.trimmed"]
|
| 457 |
+
if trimmed:
|
| 458 |
+
singular = self._trim_whitespace(singular)
|
| 459 |
+
if plural:
|
| 460 |
+
plural = self._trim_whitespace(plural)
|
| 461 |
+
|
| 462 |
+
node = self._make_node(
|
| 463 |
+
singular,
|
| 464 |
+
plural,
|
| 465 |
+
context,
|
| 466 |
+
variables,
|
| 467 |
+
plural_expr,
|
| 468 |
+
bool(referenced),
|
| 469 |
+
num_called_num and have_plural,
|
| 470 |
+
)
|
| 471 |
+
node.set_lineno(lineno)
|
| 472 |
+
if plural_expr_assignment is not None:
|
| 473 |
+
return [plural_expr_assignment, node]
|
| 474 |
+
else:
|
| 475 |
+
return node
|
| 476 |
+
|
| 477 |
+
def _trim_whitespace(self, string: str, _ws_re: t.Pattern[str] = _ws_re) -> str:
|
| 478 |
+
return _ws_re.sub(" ", string.strip())
|
| 479 |
+
|
| 480 |
+
def _parse_block(
|
| 481 |
+
self, parser: "Parser", allow_pluralize: bool
|
| 482 |
+
) -> t.Tuple[t.List[str], str]:
|
| 483 |
+
"""Parse until the next block tag with a given name."""
|
| 484 |
+
referenced = []
|
| 485 |
+
buf = []
|
| 486 |
+
|
| 487 |
+
while True:
|
| 488 |
+
if parser.stream.current.type == "data":
|
| 489 |
+
buf.append(parser.stream.current.value.replace("%", "%%"))
|
| 490 |
+
next(parser.stream)
|
| 491 |
+
elif parser.stream.current.type == "variable_begin":
|
| 492 |
+
next(parser.stream)
|
| 493 |
+
name = parser.stream.expect("name").value
|
| 494 |
+
referenced.append(name)
|
| 495 |
+
buf.append(f"%({name})s")
|
| 496 |
+
parser.stream.expect("variable_end")
|
| 497 |
+
elif parser.stream.current.type == "block_begin":
|
| 498 |
+
next(parser.stream)
|
| 499 |
+
block_name = (
|
| 500 |
+
parser.stream.current.value
|
| 501 |
+
if parser.stream.current.type == "name"
|
| 502 |
+
else None
|
| 503 |
+
)
|
| 504 |
+
if block_name == "endtrans":
|
| 505 |
+
break
|
| 506 |
+
elif block_name == "pluralize":
|
| 507 |
+
if allow_pluralize:
|
| 508 |
+
break
|
| 509 |
+
parser.fail(
|
| 510 |
+
"a translatable section can have only one pluralize section"
|
| 511 |
+
)
|
| 512 |
+
elif block_name == "trans":
|
| 513 |
+
parser.fail(
|
| 514 |
+
"trans blocks can't be nested; did you mean `endtrans`?"
|
| 515 |
+
)
|
| 516 |
+
parser.fail(
|
| 517 |
+
f"control structures in translatable sections are not allowed; "
|
| 518 |
+
f"saw `{block_name}`"
|
| 519 |
+
)
|
| 520 |
+
elif parser.stream.eos:
|
| 521 |
+
parser.fail("unclosed translation block")
|
| 522 |
+
else:
|
| 523 |
+
raise RuntimeError("internal parser error")
|
| 524 |
+
|
| 525 |
+
return referenced, concat(buf)
|
| 526 |
+
|
| 527 |
+
def _make_node(
|
| 528 |
+
self,
|
| 529 |
+
singular: str,
|
| 530 |
+
plural: t.Optional[str],
|
| 531 |
+
context: t.Optional[str],
|
| 532 |
+
variables: t.Dict[str, nodes.Expr],
|
| 533 |
+
plural_expr: t.Optional[nodes.Expr],
|
| 534 |
+
vars_referenced: bool,
|
| 535 |
+
num_called_num: bool,
|
| 536 |
+
) -> nodes.Output:
|
| 537 |
+
"""Generates a useful node from the data provided."""
|
| 538 |
+
newstyle = self.environment.newstyle_gettext # type: ignore
|
| 539 |
+
node: nodes.Expr
|
| 540 |
+
|
| 541 |
+
# no variables referenced? no need to escape for old style
|
| 542 |
+
# gettext invocations only if there are vars.
|
| 543 |
+
if not vars_referenced and not newstyle:
|
| 544 |
+
singular = singular.replace("%%", "%")
|
| 545 |
+
if plural:
|
| 546 |
+
plural = plural.replace("%%", "%")
|
| 547 |
+
|
| 548 |
+
func_name = "gettext"
|
| 549 |
+
func_args: t.List[nodes.Expr] = [nodes.Const(singular)]
|
| 550 |
+
|
| 551 |
+
if context is not None:
|
| 552 |
+
func_args.insert(0, nodes.Const(context))
|
| 553 |
+
func_name = f"p{func_name}"
|
| 554 |
+
|
| 555 |
+
if plural_expr is not None:
|
| 556 |
+
func_name = f"n{func_name}"
|
| 557 |
+
func_args.extend((nodes.Const(plural), plural_expr))
|
| 558 |
+
|
| 559 |
+
node = nodes.Call(nodes.Name(func_name, "load"), func_args, [], None, None)
|
| 560 |
+
|
| 561 |
+
# in case newstyle gettext is used, the method is powerful
|
| 562 |
+
# enough to handle the variable expansion and autoescape
|
| 563 |
+
# handling itself
|
| 564 |
+
if newstyle:
|
| 565 |
+
for key, value in variables.items():
|
| 566 |
+
# the function adds that later anyways in case num was
|
| 567 |
+
# called num, so just skip it.
|
| 568 |
+
if num_called_num and key == "num":
|
| 569 |
+
continue
|
| 570 |
+
node.kwargs.append(nodes.Keyword(key, value))
|
| 571 |
+
|
| 572 |
+
# otherwise do that here
|
| 573 |
+
else:
|
| 574 |
+
# mark the return value as safe if we are in an
|
| 575 |
+
# environment with autoescaping turned on
|
| 576 |
+
node = nodes.MarkSafeIfAutoescape(node)
|
| 577 |
+
if variables:
|
| 578 |
+
node = nodes.Mod(
|
| 579 |
+
node,
|
| 580 |
+
nodes.Dict(
|
| 581 |
+
[
|
| 582 |
+
nodes.Pair(nodes.Const(key), value)
|
| 583 |
+
for key, value in variables.items()
|
| 584 |
+
]
|
| 585 |
+
),
|
| 586 |
+
)
|
| 587 |
+
return nodes.Output([node])
|
| 588 |
+
|
| 589 |
+
|
| 590 |
+
class ExprStmtExtension(Extension):
|
| 591 |
+
"""Adds a `do` tag to Jinja that works like the print statement just
|
| 592 |
+
that it doesn't print the return value.
|
| 593 |
+
"""
|
| 594 |
+
|
| 595 |
+
tags = {"do"}
|
| 596 |
+
|
| 597 |
+
def parse(self, parser: "Parser") -> nodes.ExprStmt:
|
| 598 |
+
node = nodes.ExprStmt(lineno=next(parser.stream).lineno)
|
| 599 |
+
node.node = parser.parse_tuple()
|
| 600 |
+
return node
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
class LoopControlExtension(Extension):
|
| 604 |
+
"""Adds break and continue to the template engine."""
|
| 605 |
+
|
| 606 |
+
tags = {"break", "continue"}
|
| 607 |
+
|
| 608 |
+
def parse(self, parser: "Parser") -> t.Union[nodes.Break, nodes.Continue]:
|
| 609 |
+
token = next(parser.stream)
|
| 610 |
+
if token.value == "break":
|
| 611 |
+
return nodes.Break(lineno=token.lineno)
|
| 612 |
+
return nodes.Continue(lineno=token.lineno)
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
class DebugExtension(Extension):
|
| 616 |
+
"""A ``{% debug %}`` tag that dumps the available variables,
|
| 617 |
+
filters, and tests.
|
| 618 |
+
|
| 619 |
+
.. code-block:: html+jinja
|
| 620 |
+
|
| 621 |
+
<pre>{% debug %}</pre>
|
| 622 |
+
|
| 623 |
+
.. code-block:: text
|
| 624 |
+
|
| 625 |
+
{'context': {'cycler': <class 'jinja2.utils.Cycler'>,
|
| 626 |
+
...,
|
| 627 |
+
'namespace': <class 'jinja2.utils.Namespace'>},
|
| 628 |
+
'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
|
| 629 |
+
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
|
| 630 |
+
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
|
| 631 |
+
..., 'odd', 'sameas', 'sequence', 'string', 'undefined', 'upper']}
|
| 632 |
+
|
| 633 |
+
.. versionadded:: 2.11.0
|
| 634 |
+
"""
|
| 635 |
+
|
| 636 |
+
tags = {"debug"}
|
| 637 |
+
|
| 638 |
+
def parse(self, parser: "Parser") -> nodes.Output:
|
| 639 |
+
lineno = parser.stream.expect("name:debug").lineno
|
| 640 |
+
context = nodes.ContextReference()
|
| 641 |
+
result = self.call_method("_render", [context], lineno=lineno)
|
| 642 |
+
return nodes.Output([result], lineno=lineno)
|
| 643 |
+
|
| 644 |
+
def _render(self, context: Context) -> str:
|
| 645 |
+
result = {
|
| 646 |
+
"context": context.get_all(),
|
| 647 |
+
"filters": sorted(self.environment.filters.keys()),
|
| 648 |
+
"tests": sorted(self.environment.tests.keys()),
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
# Set the depth since the intent is to show the top few names.
|
| 652 |
+
return pprint.pformat(result, depth=3, compact=True)
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
def extract_from_ast(
|
| 656 |
+
ast: nodes.Template,
|
| 657 |
+
gettext_functions: t.Sequence[str] = GETTEXT_FUNCTIONS,
|
| 658 |
+
babel_style: bool = True,
|
| 659 |
+
) -> t.Iterator[
|
| 660 |
+
t.Tuple[int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]]]
|
| 661 |
+
]:
|
| 662 |
+
"""Extract localizable strings from the given template node. Per
|
| 663 |
+
default this function returns matches in babel style that means non string
|
| 664 |
+
parameters as well as keyword arguments are returned as `None`. This
|
| 665 |
+
allows Babel to figure out what you really meant if you are using
|
| 666 |
+
gettext functions that allow keyword arguments for placeholder expansion.
|
| 667 |
+
If you don't want that behavior set the `babel_style` parameter to `False`
|
| 668 |
+
which causes only strings to be returned and parameters are always stored
|
| 669 |
+
in tuples. As a consequence invalid gettext calls (calls without a single
|
| 670 |
+
string parameter or string parameters after non-string parameters) are
|
| 671 |
+
skipped.
|
| 672 |
+
|
| 673 |
+
This example explains the behavior:
|
| 674 |
+
|
| 675 |
+
>>> from jinja2 import Environment
|
| 676 |
+
>>> env = Environment()
|
| 677 |
+
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
|
| 678 |
+
>>> list(extract_from_ast(node))
|
| 679 |
+
[(1, '_', 'foo'), (1, '_', ()), (1, 'ngettext', ('foo', 'bar', None))]
|
| 680 |
+
>>> list(extract_from_ast(node, babel_style=False))
|
| 681 |
+
[(1, '_', ('foo',)), (1, 'ngettext', ('foo', 'bar'))]
|
| 682 |
+
|
| 683 |
+
For every string found this function yields a ``(lineno, function,
|
| 684 |
+
message)`` tuple, where:
|
| 685 |
+
|
| 686 |
+
* ``lineno`` is the number of the line on which the string was found,
|
| 687 |
+
* ``function`` is the name of the ``gettext`` function used (if the
|
| 688 |
+
string was extracted from embedded Python code), and
|
| 689 |
+
* ``message`` is the string, or a tuple of strings for functions
|
| 690 |
+
with multiple string arguments.
|
| 691 |
+
|
| 692 |
+
This extraction function operates on the AST and is because of that unable
|
| 693 |
+
to extract any comments. For comment support you have to use the babel
|
| 694 |
+
extraction interface or extract comments yourself.
|
| 695 |
+
"""
|
| 696 |
+
out: t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]]
|
| 697 |
+
|
| 698 |
+
for node in ast.find_all(nodes.Call):
|
| 699 |
+
if (
|
| 700 |
+
not isinstance(node.node, nodes.Name)
|
| 701 |
+
or node.node.name not in gettext_functions
|
| 702 |
+
):
|
| 703 |
+
continue
|
| 704 |
+
|
| 705 |
+
strings: t.List[t.Optional[str]] = []
|
| 706 |
+
|
| 707 |
+
for arg in node.args:
|
| 708 |
+
if isinstance(arg, nodes.Const) and isinstance(arg.value, str):
|
| 709 |
+
strings.append(arg.value)
|
| 710 |
+
else:
|
| 711 |
+
strings.append(None)
|
| 712 |
+
|
| 713 |
+
for _ in node.kwargs:
|
| 714 |
+
strings.append(None)
|
| 715 |
+
if node.dyn_args is not None:
|
| 716 |
+
strings.append(None)
|
| 717 |
+
if node.dyn_kwargs is not None:
|
| 718 |
+
strings.append(None)
|
| 719 |
+
|
| 720 |
+
if not babel_style:
|
| 721 |
+
out = tuple(x for x in strings if x is not None)
|
| 722 |
+
|
| 723 |
+
if not out:
|
| 724 |
+
continue
|
| 725 |
+
else:
|
| 726 |
+
if len(strings) == 1:
|
| 727 |
+
out = strings[0]
|
| 728 |
+
else:
|
| 729 |
+
out = tuple(strings)
|
| 730 |
+
|
| 731 |
+
yield node.lineno, node.node.name, out
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
class _CommentFinder:
|
| 735 |
+
"""Helper class to find comments in a token stream. Can only
|
| 736 |
+
find comments for gettext calls forwards. Once the comment
|
| 737 |
+
from line 4 is found, a comment for line 1 will not return a
|
| 738 |
+
usable value.
|
| 739 |
+
"""
|
| 740 |
+
|
| 741 |
+
def __init__(
|
| 742 |
+
self, tokens: t.Sequence[t.Tuple[int, str, str]], comment_tags: t.Sequence[str]
|
| 743 |
+
) -> None:
|
| 744 |
+
self.tokens = tokens
|
| 745 |
+
self.comment_tags = comment_tags
|
| 746 |
+
self.offset = 0
|
| 747 |
+
self.last_lineno = 0
|
| 748 |
+
|
| 749 |
+
def find_backwards(self, offset: int) -> t.List[str]:
|
| 750 |
+
try:
|
| 751 |
+
for _, token_type, token_value in reversed(
|
| 752 |
+
self.tokens[self.offset : offset]
|
| 753 |
+
):
|
| 754 |
+
if token_type in ("comment", "linecomment"):
|
| 755 |
+
try:
|
| 756 |
+
prefix, comment = token_value.split(None, 1)
|
| 757 |
+
except ValueError:
|
| 758 |
+
continue
|
| 759 |
+
if prefix in self.comment_tags:
|
| 760 |
+
return [comment.rstrip()]
|
| 761 |
+
return []
|
| 762 |
+
finally:
|
| 763 |
+
self.offset = offset
|
| 764 |
+
|
| 765 |
+
def find_comments(self, lineno: int) -> t.List[str]:
|
| 766 |
+
if not self.comment_tags or self.last_lineno > lineno:
|
| 767 |
+
return []
|
| 768 |
+
for idx, (token_lineno, _, _) in enumerate(self.tokens[self.offset :]):
|
| 769 |
+
if token_lineno > lineno:
|
| 770 |
+
return self.find_backwards(self.offset + idx)
|
| 771 |
+
return self.find_backwards(len(self.tokens))
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
def babel_extract(
|
| 775 |
+
fileobj: t.BinaryIO,
|
| 776 |
+
keywords: t.Sequence[str],
|
| 777 |
+
comment_tags: t.Sequence[str],
|
| 778 |
+
options: t.Dict[str, t.Any],
|
| 779 |
+
) -> t.Iterator[
|
| 780 |
+
t.Tuple[
|
| 781 |
+
int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]], t.List[str]
|
| 782 |
+
]
|
| 783 |
+
]:
|
| 784 |
+
"""Babel extraction method for Jinja templates.
|
| 785 |
+
|
| 786 |
+
.. versionchanged:: 2.3
|
| 787 |
+
Basic support for translation comments was added. If `comment_tags`
|
| 788 |
+
is now set to a list of keywords for extraction, the extractor will
|
| 789 |
+
try to find the best preceding comment that begins with one of the
|
| 790 |
+
keywords. For best results, make sure to not have more than one
|
| 791 |
+
gettext call in one line of code and the matching comment in the
|
| 792 |
+
same line or the line before.
|
| 793 |
+
|
| 794 |
+
.. versionchanged:: 2.5.1
|
| 795 |
+
The `newstyle_gettext` flag can be set to `True` to enable newstyle
|
| 796 |
+
gettext calls.
|
| 797 |
+
|
| 798 |
+
.. versionchanged:: 2.7
|
| 799 |
+
A `silent` option can now be provided. If set to `False` template
|
| 800 |
+
syntax errors are propagated instead of being ignored.
|
| 801 |
+
|
| 802 |
+
:param fileobj: the file-like object the messages should be extracted from
|
| 803 |
+
:param keywords: a list of keywords (i.e. function names) that should be
|
| 804 |
+
recognized as translation functions
|
| 805 |
+
:param comment_tags: a list of translator tags to search for and include
|
| 806 |
+
in the results.
|
| 807 |
+
:param options: a dictionary of additional options (optional)
|
| 808 |
+
:return: an iterator over ``(lineno, funcname, message, comments)`` tuples.
|
| 809 |
+
(comments will be empty currently)
|
| 810 |
+
"""
|
| 811 |
+
extensions: t.Dict[t.Type[Extension], None] = {}
|
| 812 |
+
|
| 813 |
+
for extension_name in options.get("extensions", "").split(","):
|
| 814 |
+
extension_name = extension_name.strip()
|
| 815 |
+
|
| 816 |
+
if not extension_name:
|
| 817 |
+
continue
|
| 818 |
+
|
| 819 |
+
extensions[import_string(extension_name)] = None
|
| 820 |
+
|
| 821 |
+
if InternationalizationExtension not in extensions:
|
| 822 |
+
extensions[InternationalizationExtension] = None
|
| 823 |
+
|
| 824 |
+
def getbool(options: t.Mapping[str, str], key: str, default: bool = False) -> bool:
|
| 825 |
+
return options.get(key, str(default)).lower() in {"1", "on", "yes", "true"}
|
| 826 |
+
|
| 827 |
+
silent = getbool(options, "silent", True)
|
| 828 |
+
environment = Environment(
|
| 829 |
+
options.get("block_start_string", defaults.BLOCK_START_STRING),
|
| 830 |
+
options.get("block_end_string", defaults.BLOCK_END_STRING),
|
| 831 |
+
options.get("variable_start_string", defaults.VARIABLE_START_STRING),
|
| 832 |
+
options.get("variable_end_string", defaults.VARIABLE_END_STRING),
|
| 833 |
+
options.get("comment_start_string", defaults.COMMENT_START_STRING),
|
| 834 |
+
options.get("comment_end_string", defaults.COMMENT_END_STRING),
|
| 835 |
+
options.get("line_statement_prefix") or defaults.LINE_STATEMENT_PREFIX,
|
| 836 |
+
options.get("line_comment_prefix") or defaults.LINE_COMMENT_PREFIX,
|
| 837 |
+
getbool(options, "trim_blocks", defaults.TRIM_BLOCKS),
|
| 838 |
+
getbool(options, "lstrip_blocks", defaults.LSTRIP_BLOCKS),
|
| 839 |
+
defaults.NEWLINE_SEQUENCE,
|
| 840 |
+
getbool(options, "keep_trailing_newline", defaults.KEEP_TRAILING_NEWLINE),
|
| 841 |
+
tuple(extensions),
|
| 842 |
+
cache_size=0,
|
| 843 |
+
auto_reload=False,
|
| 844 |
+
)
|
| 845 |
+
|
| 846 |
+
if getbool(options, "trimmed"):
|
| 847 |
+
environment.policies["ext.i18n.trimmed"] = True
|
| 848 |
+
if getbool(options, "newstyle_gettext"):
|
| 849 |
+
environment.newstyle_gettext = True # type: ignore
|
| 850 |
+
|
| 851 |
+
source = fileobj.read().decode(options.get("encoding", "utf-8"))
|
| 852 |
+
try:
|
| 853 |
+
node = environment.parse(source)
|
| 854 |
+
tokens = list(environment.lex(environment.preprocess(source)))
|
| 855 |
+
except TemplateSyntaxError:
|
| 856 |
+
if not silent:
|
| 857 |
+
raise
|
| 858 |
+
# skip templates with syntax errors
|
| 859 |
+
return
|
| 860 |
+
|
| 861 |
+
finder = _CommentFinder(tokens, comment_tags)
|
| 862 |
+
for lineno, func, message in extract_from_ast(node, keywords):
|
| 863 |
+
yield lineno, func, message, finder.find_comments(lineno)
|
| 864 |
+
|
| 865 |
+
|
| 866 |
+
#: nicer import names
|
| 867 |
+
i18n = InternationalizationExtension
|
| 868 |
+
do = ExprStmtExtension
|
| 869 |
+
loopcontrols = LoopControlExtension
|
| 870 |
+
debug = DebugExtension
|
deepseekvl2/lib/python3.10/site-packages/jinja2/idtracking.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
|
| 3 |
+
from . import nodes
|
| 4 |
+
from .visitor import NodeVisitor
|
| 5 |
+
|
| 6 |
+
if t.TYPE_CHECKING:
|
| 7 |
+
import typing_extensions as te
|
| 8 |
+
|
| 9 |
+
VAR_LOAD_PARAMETER = "param"
|
| 10 |
+
VAR_LOAD_RESOLVE = "resolve"
|
| 11 |
+
VAR_LOAD_ALIAS = "alias"
|
| 12 |
+
VAR_LOAD_UNDEFINED = "undefined"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def find_symbols(
|
| 16 |
+
nodes: t.Iterable[nodes.Node], parent_symbols: t.Optional["Symbols"] = None
|
| 17 |
+
) -> "Symbols":
|
| 18 |
+
sym = Symbols(parent=parent_symbols)
|
| 19 |
+
visitor = FrameSymbolVisitor(sym)
|
| 20 |
+
for node in nodes:
|
| 21 |
+
visitor.visit(node)
|
| 22 |
+
return sym
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def symbols_for_node(
|
| 26 |
+
node: nodes.Node, parent_symbols: t.Optional["Symbols"] = None
|
| 27 |
+
) -> "Symbols":
|
| 28 |
+
sym = Symbols(parent=parent_symbols)
|
| 29 |
+
sym.analyze_node(node)
|
| 30 |
+
return sym
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Symbols:
|
| 34 |
+
def __init__(
|
| 35 |
+
self, parent: t.Optional["Symbols"] = None, level: t.Optional[int] = None
|
| 36 |
+
) -> None:
|
| 37 |
+
if level is None:
|
| 38 |
+
if parent is None:
|
| 39 |
+
level = 0
|
| 40 |
+
else:
|
| 41 |
+
level = parent.level + 1
|
| 42 |
+
|
| 43 |
+
self.level: int = level
|
| 44 |
+
self.parent = parent
|
| 45 |
+
self.refs: t.Dict[str, str] = {}
|
| 46 |
+
self.loads: t.Dict[str, t.Any] = {}
|
| 47 |
+
self.stores: t.Set[str] = set()
|
| 48 |
+
|
| 49 |
+
def analyze_node(self, node: nodes.Node, **kwargs: t.Any) -> None:
|
| 50 |
+
visitor = RootVisitor(self)
|
| 51 |
+
visitor.visit(node, **kwargs)
|
| 52 |
+
|
| 53 |
+
def _define_ref(
|
| 54 |
+
self, name: str, load: t.Optional[t.Tuple[str, t.Optional[str]]] = None
|
| 55 |
+
) -> str:
|
| 56 |
+
ident = f"l_{self.level}_{name}"
|
| 57 |
+
self.refs[name] = ident
|
| 58 |
+
if load is not None:
|
| 59 |
+
self.loads[ident] = load
|
| 60 |
+
return ident
|
| 61 |
+
|
| 62 |
+
def find_load(self, target: str) -> t.Optional[t.Any]:
|
| 63 |
+
if target in self.loads:
|
| 64 |
+
return self.loads[target]
|
| 65 |
+
|
| 66 |
+
if self.parent is not None:
|
| 67 |
+
return self.parent.find_load(target)
|
| 68 |
+
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
def find_ref(self, name: str) -> t.Optional[str]:
|
| 72 |
+
if name in self.refs:
|
| 73 |
+
return self.refs[name]
|
| 74 |
+
|
| 75 |
+
if self.parent is not None:
|
| 76 |
+
return self.parent.find_ref(name)
|
| 77 |
+
|
| 78 |
+
return None
|
| 79 |
+
|
| 80 |
+
def ref(self, name: str) -> str:
|
| 81 |
+
rv = self.find_ref(name)
|
| 82 |
+
if rv is None:
|
| 83 |
+
raise AssertionError(
|
| 84 |
+
"Tried to resolve a name to a reference that was"
|
| 85 |
+
f" unknown to the frame ({name!r})"
|
| 86 |
+
)
|
| 87 |
+
return rv
|
| 88 |
+
|
| 89 |
+
def copy(self) -> "te.Self":
|
| 90 |
+
rv = object.__new__(self.__class__)
|
| 91 |
+
rv.__dict__.update(self.__dict__)
|
| 92 |
+
rv.refs = self.refs.copy()
|
| 93 |
+
rv.loads = self.loads.copy()
|
| 94 |
+
rv.stores = self.stores.copy()
|
| 95 |
+
return rv
|
| 96 |
+
|
| 97 |
+
def store(self, name: str) -> None:
|
| 98 |
+
self.stores.add(name)
|
| 99 |
+
|
| 100 |
+
# If we have not see the name referenced yet, we need to figure
|
| 101 |
+
# out what to set it to.
|
| 102 |
+
if name not in self.refs:
|
| 103 |
+
# If there is a parent scope we check if the name has a
|
| 104 |
+
# reference there. If it does it means we might have to alias
|
| 105 |
+
# to a variable there.
|
| 106 |
+
if self.parent is not None:
|
| 107 |
+
outer_ref = self.parent.find_ref(name)
|
| 108 |
+
if outer_ref is not None:
|
| 109 |
+
self._define_ref(name, load=(VAR_LOAD_ALIAS, outer_ref))
|
| 110 |
+
return
|
| 111 |
+
|
| 112 |
+
# Otherwise we can just set it to undefined.
|
| 113 |
+
self._define_ref(name, load=(VAR_LOAD_UNDEFINED, None))
|
| 114 |
+
|
| 115 |
+
def declare_parameter(self, name: str) -> str:
|
| 116 |
+
self.stores.add(name)
|
| 117 |
+
return self._define_ref(name, load=(VAR_LOAD_PARAMETER, None))
|
| 118 |
+
|
| 119 |
+
def load(self, name: str) -> None:
|
| 120 |
+
if self.find_ref(name) is None:
|
| 121 |
+
self._define_ref(name, load=(VAR_LOAD_RESOLVE, name))
|
| 122 |
+
|
| 123 |
+
def branch_update(self, branch_symbols: t.Sequence["Symbols"]) -> None:
|
| 124 |
+
stores: t.Set[str] = set()
|
| 125 |
+
|
| 126 |
+
for branch in branch_symbols:
|
| 127 |
+
stores.update(branch.stores)
|
| 128 |
+
|
| 129 |
+
stores.difference_update(self.stores)
|
| 130 |
+
|
| 131 |
+
for sym in branch_symbols:
|
| 132 |
+
self.refs.update(sym.refs)
|
| 133 |
+
self.loads.update(sym.loads)
|
| 134 |
+
self.stores.update(sym.stores)
|
| 135 |
+
|
| 136 |
+
for name in stores:
|
| 137 |
+
target = self.find_ref(name)
|
| 138 |
+
assert target is not None, "should not happen"
|
| 139 |
+
|
| 140 |
+
if self.parent is not None:
|
| 141 |
+
outer_target = self.parent.find_ref(name)
|
| 142 |
+
if outer_target is not None:
|
| 143 |
+
self.loads[target] = (VAR_LOAD_ALIAS, outer_target)
|
| 144 |
+
continue
|
| 145 |
+
self.loads[target] = (VAR_LOAD_RESOLVE, name)
|
| 146 |
+
|
| 147 |
+
def dump_stores(self) -> t.Dict[str, str]:
|
| 148 |
+
rv: t.Dict[str, str] = {}
|
| 149 |
+
node: t.Optional[Symbols] = self
|
| 150 |
+
|
| 151 |
+
while node is not None:
|
| 152 |
+
for name in sorted(node.stores):
|
| 153 |
+
if name not in rv:
|
| 154 |
+
rv[name] = self.find_ref(name) # type: ignore
|
| 155 |
+
|
| 156 |
+
node = node.parent
|
| 157 |
+
|
| 158 |
+
return rv
|
| 159 |
+
|
| 160 |
+
def dump_param_targets(self) -> t.Set[str]:
|
| 161 |
+
rv = set()
|
| 162 |
+
node: t.Optional[Symbols] = self
|
| 163 |
+
|
| 164 |
+
while node is not None:
|
| 165 |
+
for target, (instr, _) in self.loads.items():
|
| 166 |
+
if instr == VAR_LOAD_PARAMETER:
|
| 167 |
+
rv.add(target)
|
| 168 |
+
|
| 169 |
+
node = node.parent
|
| 170 |
+
|
| 171 |
+
return rv
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
class RootVisitor(NodeVisitor):
|
| 175 |
+
def __init__(self, symbols: "Symbols") -> None:
|
| 176 |
+
self.sym_visitor = FrameSymbolVisitor(symbols)
|
| 177 |
+
|
| 178 |
+
def _simple_visit(self, node: nodes.Node, **kwargs: t.Any) -> None:
|
| 179 |
+
for child in node.iter_child_nodes():
|
| 180 |
+
self.sym_visitor.visit(child)
|
| 181 |
+
|
| 182 |
+
visit_Template = _simple_visit
|
| 183 |
+
visit_Block = _simple_visit
|
| 184 |
+
visit_Macro = _simple_visit
|
| 185 |
+
visit_FilterBlock = _simple_visit
|
| 186 |
+
visit_Scope = _simple_visit
|
| 187 |
+
visit_If = _simple_visit
|
| 188 |
+
visit_ScopedEvalContextModifier = _simple_visit
|
| 189 |
+
|
| 190 |
+
def visit_AssignBlock(self, node: nodes.AssignBlock, **kwargs: t.Any) -> None:
|
| 191 |
+
for child in node.body:
|
| 192 |
+
self.sym_visitor.visit(child)
|
| 193 |
+
|
| 194 |
+
def visit_CallBlock(self, node: nodes.CallBlock, **kwargs: t.Any) -> None:
|
| 195 |
+
for child in node.iter_child_nodes(exclude=("call",)):
|
| 196 |
+
self.sym_visitor.visit(child)
|
| 197 |
+
|
| 198 |
+
def visit_OverlayScope(self, node: nodes.OverlayScope, **kwargs: t.Any) -> None:
|
| 199 |
+
for child in node.body:
|
| 200 |
+
self.sym_visitor.visit(child)
|
| 201 |
+
|
| 202 |
+
def visit_For(
|
| 203 |
+
self, node: nodes.For, for_branch: str = "body", **kwargs: t.Any
|
| 204 |
+
) -> None:
|
| 205 |
+
if for_branch == "body":
|
| 206 |
+
self.sym_visitor.visit(node.target, store_as_param=True)
|
| 207 |
+
branch = node.body
|
| 208 |
+
elif for_branch == "else":
|
| 209 |
+
branch = node.else_
|
| 210 |
+
elif for_branch == "test":
|
| 211 |
+
self.sym_visitor.visit(node.target, store_as_param=True)
|
| 212 |
+
if node.test is not None:
|
| 213 |
+
self.sym_visitor.visit(node.test)
|
| 214 |
+
return
|
| 215 |
+
else:
|
| 216 |
+
raise RuntimeError("Unknown for branch")
|
| 217 |
+
|
| 218 |
+
if branch:
|
| 219 |
+
for item in branch:
|
| 220 |
+
self.sym_visitor.visit(item)
|
| 221 |
+
|
| 222 |
+
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None:
|
| 223 |
+
for target in node.targets:
|
| 224 |
+
self.sym_visitor.visit(target)
|
| 225 |
+
for child in node.body:
|
| 226 |
+
self.sym_visitor.visit(child)
|
| 227 |
+
|
| 228 |
+
def generic_visit(self, node: nodes.Node, *args: t.Any, **kwargs: t.Any) -> None:
|
| 229 |
+
raise NotImplementedError(f"Cannot find symbols for {type(node).__name__!r}")
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class FrameSymbolVisitor(NodeVisitor):
|
| 233 |
+
"""A visitor for `Frame.inspect`."""
|
| 234 |
+
|
| 235 |
+
def __init__(self, symbols: "Symbols") -> None:
|
| 236 |
+
self.symbols = symbols
|
| 237 |
+
|
| 238 |
+
def visit_Name(
|
| 239 |
+
self, node: nodes.Name, store_as_param: bool = False, **kwargs: t.Any
|
| 240 |
+
) -> None:
|
| 241 |
+
"""All assignments to names go through this function."""
|
| 242 |
+
if store_as_param or node.ctx == "param":
|
| 243 |
+
self.symbols.declare_parameter(node.name)
|
| 244 |
+
elif node.ctx == "store":
|
| 245 |
+
self.symbols.store(node.name)
|
| 246 |
+
elif node.ctx == "load":
|
| 247 |
+
self.symbols.load(node.name)
|
| 248 |
+
|
| 249 |
+
def visit_NSRef(self, node: nodes.NSRef, **kwargs: t.Any) -> None:
|
| 250 |
+
self.symbols.load(node.name)
|
| 251 |
+
|
| 252 |
+
def visit_If(self, node: nodes.If, **kwargs: t.Any) -> None:
|
| 253 |
+
self.visit(node.test, **kwargs)
|
| 254 |
+
original_symbols = self.symbols
|
| 255 |
+
|
| 256 |
+
def inner_visit(nodes: t.Iterable[nodes.Node]) -> "Symbols":
|
| 257 |
+
self.symbols = rv = original_symbols.copy()
|
| 258 |
+
|
| 259 |
+
for subnode in nodes:
|
| 260 |
+
self.visit(subnode, **kwargs)
|
| 261 |
+
|
| 262 |
+
self.symbols = original_symbols
|
| 263 |
+
return rv
|
| 264 |
+
|
| 265 |
+
body_symbols = inner_visit(node.body)
|
| 266 |
+
elif_symbols = inner_visit(node.elif_)
|
| 267 |
+
else_symbols = inner_visit(node.else_ or ())
|
| 268 |
+
self.symbols.branch_update([body_symbols, elif_symbols, else_symbols])
|
| 269 |
+
|
| 270 |
+
def visit_Macro(self, node: nodes.Macro, **kwargs: t.Any) -> None:
|
| 271 |
+
self.symbols.store(node.name)
|
| 272 |
+
|
| 273 |
+
def visit_Import(self, node: nodes.Import, **kwargs: t.Any) -> None:
|
| 274 |
+
self.generic_visit(node, **kwargs)
|
| 275 |
+
self.symbols.store(node.target)
|
| 276 |
+
|
| 277 |
+
def visit_FromImport(self, node: nodes.FromImport, **kwargs: t.Any) -> None:
|
| 278 |
+
self.generic_visit(node, **kwargs)
|
| 279 |
+
|
| 280 |
+
for name in node.names:
|
| 281 |
+
if isinstance(name, tuple):
|
| 282 |
+
self.symbols.store(name[1])
|
| 283 |
+
else:
|
| 284 |
+
self.symbols.store(name)
|
| 285 |
+
|
| 286 |
+
def visit_Assign(self, node: nodes.Assign, **kwargs: t.Any) -> None:
|
| 287 |
+
"""Visit assignments in the correct order."""
|
| 288 |
+
self.visit(node.node, **kwargs)
|
| 289 |
+
self.visit(node.target, **kwargs)
|
| 290 |
+
|
| 291 |
+
def visit_For(self, node: nodes.For, **kwargs: t.Any) -> None:
|
| 292 |
+
"""Visiting stops at for blocks. However the block sequence
|
| 293 |
+
is visited as part of the outer scope.
|
| 294 |
+
"""
|
| 295 |
+
self.visit(node.iter, **kwargs)
|
| 296 |
+
|
| 297 |
+
def visit_CallBlock(self, node: nodes.CallBlock, **kwargs: t.Any) -> None:
|
| 298 |
+
self.visit(node.call, **kwargs)
|
| 299 |
+
|
| 300 |
+
def visit_FilterBlock(self, node: nodes.FilterBlock, **kwargs: t.Any) -> None:
|
| 301 |
+
self.visit(node.filter, **kwargs)
|
| 302 |
+
|
| 303 |
+
def visit_With(self, node: nodes.With, **kwargs: t.Any) -> None:
|
| 304 |
+
for target in node.values:
|
| 305 |
+
self.visit(target)
|
| 306 |
+
|
| 307 |
+
def visit_AssignBlock(self, node: nodes.AssignBlock, **kwargs: t.Any) -> None:
|
| 308 |
+
"""Stop visiting at block assigns."""
|
| 309 |
+
self.visit(node.target, **kwargs)
|
| 310 |
+
|
| 311 |
+
def visit_Scope(self, node: nodes.Scope, **kwargs: t.Any) -> None:
|
| 312 |
+
"""Stop visiting at scopes."""
|
| 313 |
+
|
| 314 |
+
def visit_Block(self, node: nodes.Block, **kwargs: t.Any) -> None:
|
| 315 |
+
"""Stop visiting at blocks."""
|
| 316 |
+
|
| 317 |
+
def visit_OverlayScope(self, node: nodes.OverlayScope, **kwargs: t.Any) -> None:
|
| 318 |
+
"""Do not visit into overlay scopes."""
|
deepseekvl2/lib/python3.10/site-packages/jinja2/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Implements a Jinja / Python combination lexer. The ``Lexer`` class
|
| 2 |
+
is used to do some preprocessing. It filters out invalid operators like
|
| 3 |
+
the bitshift operators we don't allow in templates. It separates
|
| 4 |
+
template code and python code in expressions.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import re
|
| 8 |
+
import typing as t
|
| 9 |
+
from ast import literal_eval
|
| 10 |
+
from collections import deque
|
| 11 |
+
from sys import intern
|
| 12 |
+
|
| 13 |
+
from ._identifier import pattern as name_re
|
| 14 |
+
from .exceptions import TemplateSyntaxError
|
| 15 |
+
from .utils import LRUCache
|
| 16 |
+
|
| 17 |
+
if t.TYPE_CHECKING:
|
| 18 |
+
import typing_extensions as te
|
| 19 |
+
|
| 20 |
+
from .environment import Environment
|
| 21 |
+
|
| 22 |
+
# cache for the lexers. Exists in order to be able to have multiple
|
| 23 |
+
# environments with the same lexer
|
| 24 |
+
_lexer_cache: t.MutableMapping[t.Tuple, "Lexer"] = LRUCache(50) # type: ignore
|
| 25 |
+
|
| 26 |
+
# static regular expressions
|
| 27 |
+
whitespace_re = re.compile(r"\s+")
|
| 28 |
+
newline_re = re.compile(r"(\r\n|\r|\n)")
|
| 29 |
+
string_re = re.compile(
|
| 30 |
+
r"('([^'\\]*(?:\\.[^'\\]*)*)'" r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S
|
| 31 |
+
)
|
| 32 |
+
integer_re = re.compile(
|
| 33 |
+
r"""
|
| 34 |
+
(
|
| 35 |
+
0b(_?[0-1])+ # binary
|
| 36 |
+
|
|
| 37 |
+
0o(_?[0-7])+ # octal
|
| 38 |
+
|
|
| 39 |
+
0x(_?[\da-f])+ # hex
|
| 40 |
+
|
|
| 41 |
+
[1-9](_?\d)* # decimal
|
| 42 |
+
|
|
| 43 |
+
0(_?0)* # decimal zero
|
| 44 |
+
)
|
| 45 |
+
""",
|
| 46 |
+
re.IGNORECASE | re.VERBOSE,
|
| 47 |
+
)
|
| 48 |
+
float_re = re.compile(
|
| 49 |
+
r"""
|
| 50 |
+
(?<!\.) # doesn't start with a .
|
| 51 |
+
(\d+_)*\d+ # digits, possibly _ separated
|
| 52 |
+
(
|
| 53 |
+
(\.(\d+_)*\d+)? # optional fractional part
|
| 54 |
+
e[+\-]?(\d+_)*\d+ # exponent part
|
| 55 |
+
|
|
| 56 |
+
\.(\d+_)*\d+ # required fractional part
|
| 57 |
+
)
|
| 58 |
+
""",
|
| 59 |
+
re.IGNORECASE | re.VERBOSE,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# internal the tokens and keep references to them
|
| 63 |
+
TOKEN_ADD = intern("add")
|
| 64 |
+
TOKEN_ASSIGN = intern("assign")
|
| 65 |
+
TOKEN_COLON = intern("colon")
|
| 66 |
+
TOKEN_COMMA = intern("comma")
|
| 67 |
+
TOKEN_DIV = intern("div")
|
| 68 |
+
TOKEN_DOT = intern("dot")
|
| 69 |
+
TOKEN_EQ = intern("eq")
|
| 70 |
+
TOKEN_FLOORDIV = intern("floordiv")
|
| 71 |
+
TOKEN_GT = intern("gt")
|
| 72 |
+
TOKEN_GTEQ = intern("gteq")
|
| 73 |
+
TOKEN_LBRACE = intern("lbrace")
|
| 74 |
+
TOKEN_LBRACKET = intern("lbracket")
|
| 75 |
+
TOKEN_LPAREN = intern("lparen")
|
| 76 |
+
TOKEN_LT = intern("lt")
|
| 77 |
+
TOKEN_LTEQ = intern("lteq")
|
| 78 |
+
TOKEN_MOD = intern("mod")
|
| 79 |
+
TOKEN_MUL = intern("mul")
|
| 80 |
+
TOKEN_NE = intern("ne")
|
| 81 |
+
TOKEN_PIPE = intern("pipe")
|
| 82 |
+
TOKEN_POW = intern("pow")
|
| 83 |
+
TOKEN_RBRACE = intern("rbrace")
|
| 84 |
+
TOKEN_RBRACKET = intern("rbracket")
|
| 85 |
+
TOKEN_RPAREN = intern("rparen")
|
| 86 |
+
TOKEN_SEMICOLON = intern("semicolon")
|
| 87 |
+
TOKEN_SUB = intern("sub")
|
| 88 |
+
TOKEN_TILDE = intern("tilde")
|
| 89 |
+
TOKEN_WHITESPACE = intern("whitespace")
|
| 90 |
+
TOKEN_FLOAT = intern("float")
|
| 91 |
+
TOKEN_INTEGER = intern("integer")
|
| 92 |
+
TOKEN_NAME = intern("name")
|
| 93 |
+
TOKEN_STRING = intern("string")
|
| 94 |
+
TOKEN_OPERATOR = intern("operator")
|
| 95 |
+
TOKEN_BLOCK_BEGIN = intern("block_begin")
|
| 96 |
+
TOKEN_BLOCK_END = intern("block_end")
|
| 97 |
+
TOKEN_VARIABLE_BEGIN = intern("variable_begin")
|
| 98 |
+
TOKEN_VARIABLE_END = intern("variable_end")
|
| 99 |
+
TOKEN_RAW_BEGIN = intern("raw_begin")
|
| 100 |
+
TOKEN_RAW_END = intern("raw_end")
|
| 101 |
+
TOKEN_COMMENT_BEGIN = intern("comment_begin")
|
| 102 |
+
TOKEN_COMMENT_END = intern("comment_end")
|
| 103 |
+
TOKEN_COMMENT = intern("comment")
|
| 104 |
+
TOKEN_LINESTATEMENT_BEGIN = intern("linestatement_begin")
|
| 105 |
+
TOKEN_LINESTATEMENT_END = intern("linestatement_end")
|
| 106 |
+
TOKEN_LINECOMMENT_BEGIN = intern("linecomment_begin")
|
| 107 |
+
TOKEN_LINECOMMENT_END = intern("linecomment_end")
|
| 108 |
+
TOKEN_LINECOMMENT = intern("linecomment")
|
| 109 |
+
TOKEN_DATA = intern("data")
|
| 110 |
+
TOKEN_INITIAL = intern("initial")
|
| 111 |
+
TOKEN_EOF = intern("eof")
|
| 112 |
+
|
| 113 |
+
# bind operators to token types
|
| 114 |
+
operators = {
|
| 115 |
+
"+": TOKEN_ADD,
|
| 116 |
+
"-": TOKEN_SUB,
|
| 117 |
+
"/": TOKEN_DIV,
|
| 118 |
+
"//": TOKEN_FLOORDIV,
|
| 119 |
+
"*": TOKEN_MUL,
|
| 120 |
+
"%": TOKEN_MOD,
|
| 121 |
+
"**": TOKEN_POW,
|
| 122 |
+
"~": TOKEN_TILDE,
|
| 123 |
+
"[": TOKEN_LBRACKET,
|
| 124 |
+
"]": TOKEN_RBRACKET,
|
| 125 |
+
"(": TOKEN_LPAREN,
|
| 126 |
+
")": TOKEN_RPAREN,
|
| 127 |
+
"{": TOKEN_LBRACE,
|
| 128 |
+
"}": TOKEN_RBRACE,
|
| 129 |
+
"==": TOKEN_EQ,
|
| 130 |
+
"!=": TOKEN_NE,
|
| 131 |
+
">": TOKEN_GT,
|
| 132 |
+
">=": TOKEN_GTEQ,
|
| 133 |
+
"<": TOKEN_LT,
|
| 134 |
+
"<=": TOKEN_LTEQ,
|
| 135 |
+
"=": TOKEN_ASSIGN,
|
| 136 |
+
".": TOKEN_DOT,
|
| 137 |
+
":": TOKEN_COLON,
|
| 138 |
+
"|": TOKEN_PIPE,
|
| 139 |
+
",": TOKEN_COMMA,
|
| 140 |
+
";": TOKEN_SEMICOLON,
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
reverse_operators = {v: k for k, v in operators.items()}
|
| 144 |
+
assert len(operators) == len(reverse_operators), "operators dropped"
|
| 145 |
+
operator_re = re.compile(
|
| 146 |
+
f"({'|'.join(re.escape(x) for x in sorted(operators, key=lambda x: -len(x)))})"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
ignored_tokens = frozenset(
|
| 150 |
+
[
|
| 151 |
+
TOKEN_COMMENT_BEGIN,
|
| 152 |
+
TOKEN_COMMENT,
|
| 153 |
+
TOKEN_COMMENT_END,
|
| 154 |
+
TOKEN_WHITESPACE,
|
| 155 |
+
TOKEN_LINECOMMENT_BEGIN,
|
| 156 |
+
TOKEN_LINECOMMENT_END,
|
| 157 |
+
TOKEN_LINECOMMENT,
|
| 158 |
+
]
|
| 159 |
+
)
|
| 160 |
+
ignore_if_empty = frozenset(
|
| 161 |
+
[TOKEN_WHITESPACE, TOKEN_DATA, TOKEN_COMMENT, TOKEN_LINECOMMENT]
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def _describe_token_type(token_type: str) -> str:
|
| 166 |
+
if token_type in reverse_operators:
|
| 167 |
+
return reverse_operators[token_type]
|
| 168 |
+
|
| 169 |
+
return {
|
| 170 |
+
TOKEN_COMMENT_BEGIN: "begin of comment",
|
| 171 |
+
TOKEN_COMMENT_END: "end of comment",
|
| 172 |
+
TOKEN_COMMENT: "comment",
|
| 173 |
+
TOKEN_LINECOMMENT: "comment",
|
| 174 |
+
TOKEN_BLOCK_BEGIN: "begin of statement block",
|
| 175 |
+
TOKEN_BLOCK_END: "end of statement block",
|
| 176 |
+
TOKEN_VARIABLE_BEGIN: "begin of print statement",
|
| 177 |
+
TOKEN_VARIABLE_END: "end of print statement",
|
| 178 |
+
TOKEN_LINESTATEMENT_BEGIN: "begin of line statement",
|
| 179 |
+
TOKEN_LINESTATEMENT_END: "end of line statement",
|
| 180 |
+
TOKEN_DATA: "template data / text",
|
| 181 |
+
TOKEN_EOF: "end of template",
|
| 182 |
+
}.get(token_type, token_type)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def describe_token(token: "Token") -> str:
|
| 186 |
+
"""Returns a description of the token."""
|
| 187 |
+
if token.type == TOKEN_NAME:
|
| 188 |
+
return token.value
|
| 189 |
+
|
| 190 |
+
return _describe_token_type(token.type)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def describe_token_expr(expr: str) -> str:
|
| 194 |
+
"""Like `describe_token` but for token expressions."""
|
| 195 |
+
if ":" in expr:
|
| 196 |
+
type, value = expr.split(":", 1)
|
| 197 |
+
|
| 198 |
+
if type == TOKEN_NAME:
|
| 199 |
+
return value
|
| 200 |
+
else:
|
| 201 |
+
type = expr
|
| 202 |
+
|
| 203 |
+
return _describe_token_type(type)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def count_newlines(value: str) -> int:
|
| 207 |
+
"""Count the number of newline characters in the string. This is
|
| 208 |
+
useful for extensions that filter a stream.
|
| 209 |
+
"""
|
| 210 |
+
return len(newline_re.findall(value))
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def compile_rules(environment: "Environment") -> t.List[t.Tuple[str, str]]:
|
| 214 |
+
"""Compiles all the rules from the environment into a list of rules."""
|
| 215 |
+
e = re.escape
|
| 216 |
+
rules = [
|
| 217 |
+
(
|
| 218 |
+
len(environment.comment_start_string),
|
| 219 |
+
TOKEN_COMMENT_BEGIN,
|
| 220 |
+
e(environment.comment_start_string),
|
| 221 |
+
),
|
| 222 |
+
(
|
| 223 |
+
len(environment.block_start_string),
|
| 224 |
+
TOKEN_BLOCK_BEGIN,
|
| 225 |
+
e(environment.block_start_string),
|
| 226 |
+
),
|
| 227 |
+
(
|
| 228 |
+
len(environment.variable_start_string),
|
| 229 |
+
TOKEN_VARIABLE_BEGIN,
|
| 230 |
+
e(environment.variable_start_string),
|
| 231 |
+
),
|
| 232 |
+
]
|
| 233 |
+
|
| 234 |
+
if environment.line_statement_prefix is not None:
|
| 235 |
+
rules.append(
|
| 236 |
+
(
|
| 237 |
+
len(environment.line_statement_prefix),
|
| 238 |
+
TOKEN_LINESTATEMENT_BEGIN,
|
| 239 |
+
r"^[ \t\v]*" + e(environment.line_statement_prefix),
|
| 240 |
+
)
|
| 241 |
+
)
|
| 242 |
+
if environment.line_comment_prefix is not None:
|
| 243 |
+
rules.append(
|
| 244 |
+
(
|
| 245 |
+
len(environment.line_comment_prefix),
|
| 246 |
+
TOKEN_LINECOMMENT_BEGIN,
|
| 247 |
+
r"(?:^|(?<=\S))[^\S\r\n]*" + e(environment.line_comment_prefix),
|
| 248 |
+
)
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
return [x[1:] for x in sorted(rules, reverse=True)]
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
class Failure:
|
| 255 |
+
"""Class that raises a `TemplateSyntaxError` if called.
|
| 256 |
+
Used by the `Lexer` to specify known errors.
|
| 257 |
+
"""
|
| 258 |
+
|
| 259 |
+
def __init__(
|
| 260 |
+
self, message: str, cls: t.Type[TemplateSyntaxError] = TemplateSyntaxError
|
| 261 |
+
) -> None:
|
| 262 |
+
self.message = message
|
| 263 |
+
self.error_class = cls
|
| 264 |
+
|
| 265 |
+
def __call__(self, lineno: int, filename: t.Optional[str]) -> "te.NoReturn":
|
| 266 |
+
raise self.error_class(self.message, lineno, filename)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class Token(t.NamedTuple):
|
| 270 |
+
lineno: int
|
| 271 |
+
type: str
|
| 272 |
+
value: str
|
| 273 |
+
|
| 274 |
+
def __str__(self) -> str:
|
| 275 |
+
return describe_token(self)
|
| 276 |
+
|
| 277 |
+
def test(self, expr: str) -> bool:
|
| 278 |
+
"""Test a token against a token expression. This can either be a
|
| 279 |
+
token type or ``'token_type:token_value'``. This can only test
|
| 280 |
+
against string values and types.
|
| 281 |
+
"""
|
| 282 |
+
# here we do a regular string equality check as test_any is usually
|
| 283 |
+
# passed an iterable of not interned strings.
|
| 284 |
+
if self.type == expr:
|
| 285 |
+
return True
|
| 286 |
+
|
| 287 |
+
if ":" in expr:
|
| 288 |
+
return expr.split(":", 1) == [self.type, self.value]
|
| 289 |
+
|
| 290 |
+
return False
|
| 291 |
+
|
| 292 |
+
def test_any(self, *iterable: str) -> bool:
|
| 293 |
+
"""Test against multiple token expressions."""
|
| 294 |
+
return any(self.test(expr) for expr in iterable)
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class TokenStreamIterator:
|
| 298 |
+
"""The iterator for tokenstreams. Iterate over the stream
|
| 299 |
+
until the eof token is reached.
|
| 300 |
+
"""
|
| 301 |
+
|
| 302 |
+
def __init__(self, stream: "TokenStream") -> None:
|
| 303 |
+
self.stream = stream
|
| 304 |
+
|
| 305 |
+
def __iter__(self) -> "TokenStreamIterator":
|
| 306 |
+
return self
|
| 307 |
+
|
| 308 |
+
def __next__(self) -> Token:
|
| 309 |
+
token = self.stream.current
|
| 310 |
+
|
| 311 |
+
if token.type is TOKEN_EOF:
|
| 312 |
+
self.stream.close()
|
| 313 |
+
raise StopIteration
|
| 314 |
+
|
| 315 |
+
next(self.stream)
|
| 316 |
+
return token
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class TokenStream:
|
| 320 |
+
"""A token stream is an iterable that yields :class:`Token`\\s. The
|
| 321 |
+
parser however does not iterate over it but calls :meth:`next` to go
|
| 322 |
+
one token ahead. The current active token is stored as :attr:`current`.
|
| 323 |
+
"""
|
| 324 |
+
|
| 325 |
+
def __init__(
|
| 326 |
+
self,
|
| 327 |
+
generator: t.Iterable[Token],
|
| 328 |
+
name: t.Optional[str],
|
| 329 |
+
filename: t.Optional[str],
|
| 330 |
+
):
|
| 331 |
+
self._iter = iter(generator)
|
| 332 |
+
self._pushed: te.Deque[Token] = deque()
|
| 333 |
+
self.name = name
|
| 334 |
+
self.filename = filename
|
| 335 |
+
self.closed = False
|
| 336 |
+
self.current = Token(1, TOKEN_INITIAL, "")
|
| 337 |
+
next(self)
|
| 338 |
+
|
| 339 |
+
def __iter__(self) -> TokenStreamIterator:
|
| 340 |
+
return TokenStreamIterator(self)
|
| 341 |
+
|
| 342 |
+
def __bool__(self) -> bool:
|
| 343 |
+
return bool(self._pushed) or self.current.type is not TOKEN_EOF
|
| 344 |
+
|
| 345 |
+
@property
|
| 346 |
+
def eos(self) -> bool:
|
| 347 |
+
"""Are we at the end of the stream?"""
|
| 348 |
+
return not self
|
| 349 |
+
|
| 350 |
+
def push(self, token: Token) -> None:
|
| 351 |
+
"""Push a token back to the stream."""
|
| 352 |
+
self._pushed.append(token)
|
| 353 |
+
|
| 354 |
+
def look(self) -> Token:
|
| 355 |
+
"""Look at the next token."""
|
| 356 |
+
old_token = next(self)
|
| 357 |
+
result = self.current
|
| 358 |
+
self.push(result)
|
| 359 |
+
self.current = old_token
|
| 360 |
+
return result
|
| 361 |
+
|
| 362 |
+
def skip(self, n: int = 1) -> None:
|
| 363 |
+
"""Got n tokens ahead."""
|
| 364 |
+
for _ in range(n):
|
| 365 |
+
next(self)
|
| 366 |
+
|
| 367 |
+
def next_if(self, expr: str) -> t.Optional[Token]:
|
| 368 |
+
"""Perform the token test and return the token if it matched.
|
| 369 |
+
Otherwise the return value is `None`.
|
| 370 |
+
"""
|
| 371 |
+
if self.current.test(expr):
|
| 372 |
+
return next(self)
|
| 373 |
+
|
| 374 |
+
return None
|
| 375 |
+
|
| 376 |
+
def skip_if(self, expr: str) -> bool:
|
| 377 |
+
"""Like :meth:`next_if` but only returns `True` or `False`."""
|
| 378 |
+
return self.next_if(expr) is not None
|
| 379 |
+
|
| 380 |
+
def __next__(self) -> Token:
|
| 381 |
+
"""Go one token ahead and return the old one.
|
| 382 |
+
|
| 383 |
+
Use the built-in :func:`next` instead of calling this directly.
|
| 384 |
+
"""
|
| 385 |
+
rv = self.current
|
| 386 |
+
|
| 387 |
+
if self._pushed:
|
| 388 |
+
self.current = self._pushed.popleft()
|
| 389 |
+
elif self.current.type is not TOKEN_EOF:
|
| 390 |
+
try:
|
| 391 |
+
self.current = next(self._iter)
|
| 392 |
+
except StopIteration:
|
| 393 |
+
self.close()
|
| 394 |
+
|
| 395 |
+
return rv
|
| 396 |
+
|
| 397 |
+
def close(self) -> None:
|
| 398 |
+
"""Close the stream."""
|
| 399 |
+
self.current = Token(self.current.lineno, TOKEN_EOF, "")
|
| 400 |
+
self._iter = iter(())
|
| 401 |
+
self.closed = True
|
| 402 |
+
|
| 403 |
+
def expect(self, expr: str) -> Token:
|
| 404 |
+
"""Expect a given token type and return it. This accepts the same
|
| 405 |
+
argument as :meth:`jinja2.lexer.Token.test`.
|
| 406 |
+
"""
|
| 407 |
+
if not self.current.test(expr):
|
| 408 |
+
expr = describe_token_expr(expr)
|
| 409 |
+
|
| 410 |
+
if self.current.type is TOKEN_EOF:
|
| 411 |
+
raise TemplateSyntaxError(
|
| 412 |
+
f"unexpected end of template, expected {expr!r}.",
|
| 413 |
+
self.current.lineno,
|
| 414 |
+
self.name,
|
| 415 |
+
self.filename,
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
raise TemplateSyntaxError(
|
| 419 |
+
f"expected token {expr!r}, got {describe_token(self.current)!r}",
|
| 420 |
+
self.current.lineno,
|
| 421 |
+
self.name,
|
| 422 |
+
self.filename,
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
return next(self)
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
def get_lexer(environment: "Environment") -> "Lexer":
|
| 429 |
+
"""Return a lexer which is probably cached."""
|
| 430 |
+
key = (
|
| 431 |
+
environment.block_start_string,
|
| 432 |
+
environment.block_end_string,
|
| 433 |
+
environment.variable_start_string,
|
| 434 |
+
environment.variable_end_string,
|
| 435 |
+
environment.comment_start_string,
|
| 436 |
+
environment.comment_end_string,
|
| 437 |
+
environment.line_statement_prefix,
|
| 438 |
+
environment.line_comment_prefix,
|
| 439 |
+
environment.trim_blocks,
|
| 440 |
+
environment.lstrip_blocks,
|
| 441 |
+
environment.newline_sequence,
|
| 442 |
+
environment.keep_trailing_newline,
|
| 443 |
+
)
|
| 444 |
+
lexer = _lexer_cache.get(key)
|
| 445 |
+
|
| 446 |
+
if lexer is None:
|
| 447 |
+
_lexer_cache[key] = lexer = Lexer(environment)
|
| 448 |
+
|
| 449 |
+
return lexer
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
class OptionalLStrip(tuple): # type: ignore[type-arg]
|
| 453 |
+
"""A special tuple for marking a point in the state that can have
|
| 454 |
+
lstrip applied.
|
| 455 |
+
"""
|
| 456 |
+
|
| 457 |
+
__slots__ = ()
|
| 458 |
+
|
| 459 |
+
# Even though it looks like a no-op, creating instances fails
|
| 460 |
+
# without this.
|
| 461 |
+
def __new__(cls, *members, **kwargs): # type: ignore
|
| 462 |
+
return super().__new__(cls, members)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
class _Rule(t.NamedTuple):
|
| 466 |
+
pattern: t.Pattern[str]
|
| 467 |
+
tokens: t.Union[str, t.Tuple[str, ...], t.Tuple[Failure]]
|
| 468 |
+
command: t.Optional[str]
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
class Lexer:
|
| 472 |
+
"""Class that implements a lexer for a given environment. Automatically
|
| 473 |
+
created by the environment class, usually you don't have to do that.
|
| 474 |
+
|
| 475 |
+
Note that the lexer is not automatically bound to an environment.
|
| 476 |
+
Multiple environments can share the same lexer.
|
| 477 |
+
"""
|
| 478 |
+
|
| 479 |
+
def __init__(self, environment: "Environment") -> None:
|
| 480 |
+
# shortcuts
|
| 481 |
+
e = re.escape
|
| 482 |
+
|
| 483 |
+
def c(x: str) -> t.Pattern[str]:
|
| 484 |
+
return re.compile(x, re.M | re.S)
|
| 485 |
+
|
| 486 |
+
# lexing rules for tags
|
| 487 |
+
tag_rules: t.List[_Rule] = [
|
| 488 |
+
_Rule(whitespace_re, TOKEN_WHITESPACE, None),
|
| 489 |
+
_Rule(float_re, TOKEN_FLOAT, None),
|
| 490 |
+
_Rule(integer_re, TOKEN_INTEGER, None),
|
| 491 |
+
_Rule(name_re, TOKEN_NAME, None),
|
| 492 |
+
_Rule(string_re, TOKEN_STRING, None),
|
| 493 |
+
_Rule(operator_re, TOKEN_OPERATOR, None),
|
| 494 |
+
]
|
| 495 |
+
|
| 496 |
+
# assemble the root lexing rule. because "|" is ungreedy
|
| 497 |
+
# we have to sort by length so that the lexer continues working
|
| 498 |
+
# as expected when we have parsing rules like <% for block and
|
| 499 |
+
# <%= for variables. (if someone wants asp like syntax)
|
| 500 |
+
# variables are just part of the rules if variable processing
|
| 501 |
+
# is required.
|
| 502 |
+
root_tag_rules = compile_rules(environment)
|
| 503 |
+
|
| 504 |
+
block_start_re = e(environment.block_start_string)
|
| 505 |
+
block_end_re = e(environment.block_end_string)
|
| 506 |
+
comment_end_re = e(environment.comment_end_string)
|
| 507 |
+
variable_end_re = e(environment.variable_end_string)
|
| 508 |
+
|
| 509 |
+
# block suffix if trimming is enabled
|
| 510 |
+
block_suffix_re = "\\n?" if environment.trim_blocks else ""
|
| 511 |
+
|
| 512 |
+
self.lstrip_blocks = environment.lstrip_blocks
|
| 513 |
+
|
| 514 |
+
self.newline_sequence = environment.newline_sequence
|
| 515 |
+
self.keep_trailing_newline = environment.keep_trailing_newline
|
| 516 |
+
|
| 517 |
+
root_raw_re = (
|
| 518 |
+
rf"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*"
|
| 519 |
+
rf"(?:\-{block_end_re}\s*|{block_end_re}))"
|
| 520 |
+
)
|
| 521 |
+
root_parts_re = "|".join(
|
| 522 |
+
[root_raw_re] + [rf"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules]
|
| 523 |
+
)
|
| 524 |
+
|
| 525 |
+
# global lexing rules
|
| 526 |
+
self.rules: t.Dict[str, t.List[_Rule]] = {
|
| 527 |
+
"root": [
|
| 528 |
+
# directives
|
| 529 |
+
_Rule(
|
| 530 |
+
c(rf"(.*?)(?:{root_parts_re})"),
|
| 531 |
+
OptionalLStrip(TOKEN_DATA, "#bygroup"), # type: ignore
|
| 532 |
+
"#bygroup",
|
| 533 |
+
),
|
| 534 |
+
# data
|
| 535 |
+
_Rule(c(".+"), TOKEN_DATA, None),
|
| 536 |
+
],
|
| 537 |
+
# comments
|
| 538 |
+
TOKEN_COMMENT_BEGIN: [
|
| 539 |
+
_Rule(
|
| 540 |
+
c(
|
| 541 |
+
rf"(.*?)((?:\+{comment_end_re}|\-{comment_end_re}\s*"
|
| 542 |
+
rf"|{comment_end_re}{block_suffix_re}))"
|
| 543 |
+
),
|
| 544 |
+
(TOKEN_COMMENT, TOKEN_COMMENT_END),
|
| 545 |
+
"#pop",
|
| 546 |
+
),
|
| 547 |
+
_Rule(c(r"(.)"), (Failure("Missing end of comment tag"),), None),
|
| 548 |
+
],
|
| 549 |
+
# blocks
|
| 550 |
+
TOKEN_BLOCK_BEGIN: [
|
| 551 |
+
_Rule(
|
| 552 |
+
c(
|
| 553 |
+
rf"(?:\+{block_end_re}|\-{block_end_re}\s*"
|
| 554 |
+
rf"|{block_end_re}{block_suffix_re})"
|
| 555 |
+
),
|
| 556 |
+
TOKEN_BLOCK_END,
|
| 557 |
+
"#pop",
|
| 558 |
+
),
|
| 559 |
+
]
|
| 560 |
+
+ tag_rules,
|
| 561 |
+
# variables
|
| 562 |
+
TOKEN_VARIABLE_BEGIN: [
|
| 563 |
+
_Rule(
|
| 564 |
+
c(rf"\-{variable_end_re}\s*|{variable_end_re}"),
|
| 565 |
+
TOKEN_VARIABLE_END,
|
| 566 |
+
"#pop",
|
| 567 |
+
)
|
| 568 |
+
]
|
| 569 |
+
+ tag_rules,
|
| 570 |
+
# raw block
|
| 571 |
+
TOKEN_RAW_BEGIN: [
|
| 572 |
+
_Rule(
|
| 573 |
+
c(
|
| 574 |
+
rf"(.*?)((?:{block_start_re}(\-|\+|))\s*endraw\s*"
|
| 575 |
+
rf"(?:\+{block_end_re}|\-{block_end_re}\s*"
|
| 576 |
+
rf"|{block_end_re}{block_suffix_re}))"
|
| 577 |
+
),
|
| 578 |
+
OptionalLStrip(TOKEN_DATA, TOKEN_RAW_END), # type: ignore
|
| 579 |
+
"#pop",
|
| 580 |
+
),
|
| 581 |
+
_Rule(c(r"(.)"), (Failure("Missing end of raw directive"),), None),
|
| 582 |
+
],
|
| 583 |
+
# line statements
|
| 584 |
+
TOKEN_LINESTATEMENT_BEGIN: [
|
| 585 |
+
_Rule(c(r"\s*(\n|$)"), TOKEN_LINESTATEMENT_END, "#pop")
|
| 586 |
+
]
|
| 587 |
+
+ tag_rules,
|
| 588 |
+
# line comments
|
| 589 |
+
TOKEN_LINECOMMENT_BEGIN: [
|
| 590 |
+
_Rule(
|
| 591 |
+
c(r"(.*?)()(?=\n|$)"),
|
| 592 |
+
(TOKEN_LINECOMMENT, TOKEN_LINECOMMENT_END),
|
| 593 |
+
"#pop",
|
| 594 |
+
)
|
| 595 |
+
],
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
def _normalize_newlines(self, value: str) -> str:
|
| 599 |
+
"""Replace all newlines with the configured sequence in strings
|
| 600 |
+
and template data.
|
| 601 |
+
"""
|
| 602 |
+
return newline_re.sub(self.newline_sequence, value)
|
| 603 |
+
|
| 604 |
+
def tokenize(
|
| 605 |
+
self,
|
| 606 |
+
source: str,
|
| 607 |
+
name: t.Optional[str] = None,
|
| 608 |
+
filename: t.Optional[str] = None,
|
| 609 |
+
state: t.Optional[str] = None,
|
| 610 |
+
) -> TokenStream:
|
| 611 |
+
"""Calls tokeniter + tokenize and wraps it in a token stream."""
|
| 612 |
+
stream = self.tokeniter(source, name, filename, state)
|
| 613 |
+
return TokenStream(self.wrap(stream, name, filename), name, filename)
|
| 614 |
+
|
| 615 |
+
def wrap(
|
| 616 |
+
self,
|
| 617 |
+
stream: t.Iterable[t.Tuple[int, str, str]],
|
| 618 |
+
name: t.Optional[str] = None,
|
| 619 |
+
filename: t.Optional[str] = None,
|
| 620 |
+
) -> t.Iterator[Token]:
|
| 621 |
+
"""This is called with the stream as returned by `tokenize` and wraps
|
| 622 |
+
every token in a :class:`Token` and converts the value.
|
| 623 |
+
"""
|
| 624 |
+
for lineno, token, value_str in stream:
|
| 625 |
+
if token in ignored_tokens:
|
| 626 |
+
continue
|
| 627 |
+
|
| 628 |
+
value: t.Any = value_str
|
| 629 |
+
|
| 630 |
+
if token == TOKEN_LINESTATEMENT_BEGIN:
|
| 631 |
+
token = TOKEN_BLOCK_BEGIN
|
| 632 |
+
elif token == TOKEN_LINESTATEMENT_END:
|
| 633 |
+
token = TOKEN_BLOCK_END
|
| 634 |
+
# we are not interested in those tokens in the parser
|
| 635 |
+
elif token in (TOKEN_RAW_BEGIN, TOKEN_RAW_END):
|
| 636 |
+
continue
|
| 637 |
+
elif token == TOKEN_DATA:
|
| 638 |
+
value = self._normalize_newlines(value_str)
|
| 639 |
+
elif token == "keyword":
|
| 640 |
+
token = value_str
|
| 641 |
+
elif token == TOKEN_NAME:
|
| 642 |
+
value = value_str
|
| 643 |
+
|
| 644 |
+
if not value.isidentifier():
|
| 645 |
+
raise TemplateSyntaxError(
|
| 646 |
+
"Invalid character in identifier", lineno, name, filename
|
| 647 |
+
)
|
| 648 |
+
elif token == TOKEN_STRING:
|
| 649 |
+
# try to unescape string
|
| 650 |
+
try:
|
| 651 |
+
value = (
|
| 652 |
+
self._normalize_newlines(value_str[1:-1])
|
| 653 |
+
.encode("ascii", "backslashreplace")
|
| 654 |
+
.decode("unicode-escape")
|
| 655 |
+
)
|
| 656 |
+
except Exception as e:
|
| 657 |
+
msg = str(e).split(":")[-1].strip()
|
| 658 |
+
raise TemplateSyntaxError(msg, lineno, name, filename) from e
|
| 659 |
+
elif token == TOKEN_INTEGER:
|
| 660 |
+
value = int(value_str.replace("_", ""), 0)
|
| 661 |
+
elif token == TOKEN_FLOAT:
|
| 662 |
+
# remove all "_" first to support more Python versions
|
| 663 |
+
value = literal_eval(value_str.replace("_", ""))
|
| 664 |
+
elif token == TOKEN_OPERATOR:
|
| 665 |
+
token = operators[value_str]
|
| 666 |
+
|
| 667 |
+
yield Token(lineno, token, value)
|
| 668 |
+
|
| 669 |
+
def tokeniter(
|
| 670 |
+
self,
|
| 671 |
+
source: str,
|
| 672 |
+
name: t.Optional[str],
|
| 673 |
+
filename: t.Optional[str] = None,
|
| 674 |
+
state: t.Optional[str] = None,
|
| 675 |
+
) -> t.Iterator[t.Tuple[int, str, str]]:
|
| 676 |
+
"""This method tokenizes the text and returns the tokens in a
|
| 677 |
+
generator. Use this method if you just want to tokenize a template.
|
| 678 |
+
|
| 679 |
+
.. versionchanged:: 3.0
|
| 680 |
+
Only ``\\n``, ``\\r\\n`` and ``\\r`` are treated as line
|
| 681 |
+
breaks.
|
| 682 |
+
"""
|
| 683 |
+
lines = newline_re.split(source)[::2]
|
| 684 |
+
|
| 685 |
+
if not self.keep_trailing_newline and lines[-1] == "":
|
| 686 |
+
del lines[-1]
|
| 687 |
+
|
| 688 |
+
source = "\n".join(lines)
|
| 689 |
+
pos = 0
|
| 690 |
+
lineno = 1
|
| 691 |
+
stack = ["root"]
|
| 692 |
+
|
| 693 |
+
if state is not None and state != "root":
|
| 694 |
+
assert state in ("variable", "block"), "invalid state"
|
| 695 |
+
stack.append(state + "_begin")
|
| 696 |
+
|
| 697 |
+
statetokens = self.rules[stack[-1]]
|
| 698 |
+
source_length = len(source)
|
| 699 |
+
balancing_stack: t.List[str] = []
|
| 700 |
+
newlines_stripped = 0
|
| 701 |
+
line_starting = True
|
| 702 |
+
|
| 703 |
+
while True:
|
| 704 |
+
# tokenizer loop
|
| 705 |
+
for regex, tokens, new_state in statetokens:
|
| 706 |
+
m = regex.match(source, pos)
|
| 707 |
+
|
| 708 |
+
# if no match we try again with the next rule
|
| 709 |
+
if m is None:
|
| 710 |
+
continue
|
| 711 |
+
|
| 712 |
+
# we only match blocks and variables if braces / parentheses
|
| 713 |
+
# are balanced. continue parsing with the lower rule which
|
| 714 |
+
# is the operator rule. do this only if the end tags look
|
| 715 |
+
# like operators
|
| 716 |
+
if balancing_stack and tokens in (
|
| 717 |
+
TOKEN_VARIABLE_END,
|
| 718 |
+
TOKEN_BLOCK_END,
|
| 719 |
+
TOKEN_LINESTATEMENT_END,
|
| 720 |
+
):
|
| 721 |
+
continue
|
| 722 |
+
|
| 723 |
+
# tuples support more options
|
| 724 |
+
if isinstance(tokens, tuple):
|
| 725 |
+
groups: t.Sequence[str] = m.groups()
|
| 726 |
+
|
| 727 |
+
if isinstance(tokens, OptionalLStrip):
|
| 728 |
+
# Rule supports lstrip. Match will look like
|
| 729 |
+
# text, block type, whitespace control, type, control, ...
|
| 730 |
+
text = groups[0]
|
| 731 |
+
# Skipping the text and first type, every other group is the
|
| 732 |
+
# whitespace control for each type. One of the groups will be
|
| 733 |
+
# -, +, or empty string instead of None.
|
| 734 |
+
strip_sign = next(g for g in groups[2::2] if g is not None)
|
| 735 |
+
|
| 736 |
+
if strip_sign == "-":
|
| 737 |
+
# Strip all whitespace between the text and the tag.
|
| 738 |
+
stripped = text.rstrip()
|
| 739 |
+
newlines_stripped = text[len(stripped) :].count("\n")
|
| 740 |
+
groups = [stripped, *groups[1:]]
|
| 741 |
+
elif (
|
| 742 |
+
# Not marked for preserving whitespace.
|
| 743 |
+
strip_sign != "+"
|
| 744 |
+
# lstrip is enabled.
|
| 745 |
+
and self.lstrip_blocks
|
| 746 |
+
# Not a variable expression.
|
| 747 |
+
and not m.groupdict().get(TOKEN_VARIABLE_BEGIN)
|
| 748 |
+
):
|
| 749 |
+
# The start of text between the last newline and the tag.
|
| 750 |
+
l_pos = text.rfind("\n") + 1
|
| 751 |
+
|
| 752 |
+
if l_pos > 0 or line_starting:
|
| 753 |
+
# If there's only whitespace between the newline and the
|
| 754 |
+
# tag, strip it.
|
| 755 |
+
if whitespace_re.fullmatch(text, l_pos):
|
| 756 |
+
groups = [text[:l_pos], *groups[1:]]
|
| 757 |
+
|
| 758 |
+
for idx, token in enumerate(tokens):
|
| 759 |
+
# failure group
|
| 760 |
+
if isinstance(token, Failure):
|
| 761 |
+
raise token(lineno, filename)
|
| 762 |
+
# bygroup is a bit more complex, in that case we
|
| 763 |
+
# yield for the current token the first named
|
| 764 |
+
# group that matched
|
| 765 |
+
elif token == "#bygroup":
|
| 766 |
+
for key, value in m.groupdict().items():
|
| 767 |
+
if value is not None:
|
| 768 |
+
yield lineno, key, value
|
| 769 |
+
lineno += value.count("\n")
|
| 770 |
+
break
|
| 771 |
+
else:
|
| 772 |
+
raise RuntimeError(
|
| 773 |
+
f"{regex!r} wanted to resolve the token dynamically"
|
| 774 |
+
" but no group matched"
|
| 775 |
+
)
|
| 776 |
+
# normal group
|
| 777 |
+
else:
|
| 778 |
+
data = groups[idx]
|
| 779 |
+
|
| 780 |
+
if data or token not in ignore_if_empty:
|
| 781 |
+
yield lineno, token, data # type: ignore[misc]
|
| 782 |
+
|
| 783 |
+
lineno += data.count("\n") + newlines_stripped
|
| 784 |
+
newlines_stripped = 0
|
| 785 |
+
|
| 786 |
+
# strings as token just are yielded as it.
|
| 787 |
+
else:
|
| 788 |
+
data = m.group()
|
| 789 |
+
|
| 790 |
+
# update brace/parentheses balance
|
| 791 |
+
if tokens == TOKEN_OPERATOR:
|
| 792 |
+
if data == "{":
|
| 793 |
+
balancing_stack.append("}")
|
| 794 |
+
elif data == "(":
|
| 795 |
+
balancing_stack.append(")")
|
| 796 |
+
elif data == "[":
|
| 797 |
+
balancing_stack.append("]")
|
| 798 |
+
elif data in ("}", ")", "]"):
|
| 799 |
+
if not balancing_stack:
|
| 800 |
+
raise TemplateSyntaxError(
|
| 801 |
+
f"unexpected '{data}'", lineno, name, filename
|
| 802 |
+
)
|
| 803 |
+
|
| 804 |
+
expected_op = balancing_stack.pop()
|
| 805 |
+
|
| 806 |
+
if expected_op != data:
|
| 807 |
+
raise TemplateSyntaxError(
|
| 808 |
+
f"unexpected '{data}', expected '{expected_op}'",
|
| 809 |
+
lineno,
|
| 810 |
+
name,
|
| 811 |
+
filename,
|
| 812 |
+
)
|
| 813 |
+
|
| 814 |
+
# yield items
|
| 815 |
+
if data or tokens not in ignore_if_empty:
|
| 816 |
+
yield lineno, tokens, data
|
| 817 |
+
|
| 818 |
+
lineno += data.count("\n")
|
| 819 |
+
|
| 820 |
+
line_starting = m.group()[-1:] == "\n"
|
| 821 |
+
# fetch new position into new variable so that we can check
|
| 822 |
+
# if there is a internal parsing error which would result
|
| 823 |
+
# in an infinite loop
|
| 824 |
+
pos2 = m.end()
|
| 825 |
+
|
| 826 |
+
# handle state changes
|
| 827 |
+
if new_state is not None:
|
| 828 |
+
# remove the uppermost state
|
| 829 |
+
if new_state == "#pop":
|
| 830 |
+
stack.pop()
|
| 831 |
+
# resolve the new state by group checking
|
| 832 |
+
elif new_state == "#bygroup":
|
| 833 |
+
for key, value in m.groupdict().items():
|
| 834 |
+
if value is not None:
|
| 835 |
+
stack.append(key)
|
| 836 |
+
break
|
| 837 |
+
else:
|
| 838 |
+
raise RuntimeError(
|
| 839 |
+
f"{regex!r} wanted to resolve the new state dynamically"
|
| 840 |
+
f" but no group matched"
|
| 841 |
+
)
|
| 842 |
+
# direct state name given
|
| 843 |
+
else:
|
| 844 |
+
stack.append(new_state)
|
| 845 |
+
|
| 846 |
+
statetokens = self.rules[stack[-1]]
|
| 847 |
+
# we are still at the same position and no stack change.
|
| 848 |
+
# this means a loop without break condition, avoid that and
|
| 849 |
+
# raise error
|
| 850 |
+
elif pos2 == pos:
|
| 851 |
+
raise RuntimeError(
|
| 852 |
+
f"{regex!r} yielded empty string without stack change"
|
| 853 |
+
)
|
| 854 |
+
|
| 855 |
+
# publish new function and start again
|
| 856 |
+
pos = pos2
|
| 857 |
+
break
|
| 858 |
+
# if loop terminated without break we haven't found a single match
|
| 859 |
+
# either we are at the end of the file or we have a problem
|
| 860 |
+
else:
|
| 861 |
+
# end of text
|
| 862 |
+
if pos >= source_length:
|
| 863 |
+
return
|
| 864 |
+
|
| 865 |
+
# something went wrong
|
| 866 |
+
raise TemplateSyntaxError(
|
| 867 |
+
f"unexpected char {source[pos]!r} at {pos}", lineno, name, filename
|
| 868 |
+
)
|
deepseekvl2/lib/python3.10/site-packages/jinja2/meta.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions that expose information about templates that might be
|
| 2 |
+
interesting for introspection.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import typing as t
|
| 6 |
+
|
| 7 |
+
from . import nodes
|
| 8 |
+
from .compiler import CodeGenerator
|
| 9 |
+
from .compiler import Frame
|
| 10 |
+
|
| 11 |
+
if t.TYPE_CHECKING:
|
| 12 |
+
from .environment import Environment
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TrackingCodeGenerator(CodeGenerator):
|
| 16 |
+
"""We abuse the code generator for introspection."""
|
| 17 |
+
|
| 18 |
+
def __init__(self, environment: "Environment") -> None:
|
| 19 |
+
super().__init__(environment, "<introspection>", "<introspection>")
|
| 20 |
+
self.undeclared_identifiers: t.Set[str] = set()
|
| 21 |
+
|
| 22 |
+
def write(self, x: str) -> None:
|
| 23 |
+
"""Don't write."""
|
| 24 |
+
|
| 25 |
+
def enter_frame(self, frame: Frame) -> None:
|
| 26 |
+
"""Remember all undeclared identifiers."""
|
| 27 |
+
super().enter_frame(frame)
|
| 28 |
+
|
| 29 |
+
for _, (action, param) in frame.symbols.loads.items():
|
| 30 |
+
if action == "resolve" and param not in self.environment.globals:
|
| 31 |
+
self.undeclared_identifiers.add(param)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def find_undeclared_variables(ast: nodes.Template) -> t.Set[str]:
|
| 35 |
+
"""Returns a set of all variables in the AST that will be looked up from
|
| 36 |
+
the context at runtime. Because at compile time it's not known which
|
| 37 |
+
variables will be used depending on the path the execution takes at
|
| 38 |
+
runtime, all variables are returned.
|
| 39 |
+
|
| 40 |
+
>>> from jinja2 import Environment, meta
|
| 41 |
+
>>> env = Environment()
|
| 42 |
+
>>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
|
| 43 |
+
>>> meta.find_undeclared_variables(ast) == {'bar'}
|
| 44 |
+
True
|
| 45 |
+
|
| 46 |
+
.. admonition:: Implementation
|
| 47 |
+
|
| 48 |
+
Internally the code generator is used for finding undeclared variables.
|
| 49 |
+
This is good to know because the code generator might raise a
|
| 50 |
+
:exc:`TemplateAssertionError` during compilation and as a matter of
|
| 51 |
+
fact this function can currently raise that exception as well.
|
| 52 |
+
"""
|
| 53 |
+
codegen = TrackingCodeGenerator(ast.environment) # type: ignore
|
| 54 |
+
codegen.visit(ast)
|
| 55 |
+
return codegen.undeclared_identifiers
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
_ref_types = (nodes.Extends, nodes.FromImport, nodes.Import, nodes.Include)
|
| 59 |
+
_RefType = t.Union[nodes.Extends, nodes.FromImport, nodes.Import, nodes.Include]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def find_referenced_templates(ast: nodes.Template) -> t.Iterator[t.Optional[str]]:
|
| 63 |
+
"""Finds all the referenced templates from the AST. This will return an
|
| 64 |
+
iterator over all the hardcoded template extensions, inclusions and
|
| 65 |
+
imports. If dynamic inheritance or inclusion is used, `None` will be
|
| 66 |
+
yielded.
|
| 67 |
+
|
| 68 |
+
>>> from jinja2 import Environment, meta
|
| 69 |
+
>>> env = Environment()
|
| 70 |
+
>>> ast = env.parse('{% extends "layout.html" %}{% include helper %}')
|
| 71 |
+
>>> list(meta.find_referenced_templates(ast))
|
| 72 |
+
['layout.html', None]
|
| 73 |
+
|
| 74 |
+
This function is useful for dependency tracking. For example if you want
|
| 75 |
+
to rebuild parts of the website after a layout template has changed.
|
| 76 |
+
"""
|
| 77 |
+
template_name: t.Any
|
| 78 |
+
|
| 79 |
+
for node in ast.find_all(_ref_types):
|
| 80 |
+
template: nodes.Expr = node.template # type: ignore
|
| 81 |
+
|
| 82 |
+
if not isinstance(template, nodes.Const):
|
| 83 |
+
# a tuple with some non consts in there
|
| 84 |
+
if isinstance(template, (nodes.Tuple, nodes.List)):
|
| 85 |
+
for template_name in template.items:
|
| 86 |
+
# something const, only yield the strings and ignore
|
| 87 |
+
# non-string consts that really just make no sense
|
| 88 |
+
if isinstance(template_name, nodes.Const):
|
| 89 |
+
if isinstance(template_name.value, str):
|
| 90 |
+
yield template_name.value
|
| 91 |
+
# something dynamic in there
|
| 92 |
+
else:
|
| 93 |
+
yield None
|
| 94 |
+
# something dynamic we don't know about here
|
| 95 |
+
else:
|
| 96 |
+
yield None
|
| 97 |
+
continue
|
| 98 |
+
# constant is a basestring, direct template name
|
| 99 |
+
if isinstance(template.value, str):
|
| 100 |
+
yield template.value
|
| 101 |
+
# a tuple or list (latter *should* not happen) made of consts,
|
| 102 |
+
# yield the consts that are strings. We could warn here for
|
| 103 |
+
# non string values
|
| 104 |
+
elif isinstance(node, nodes.Include) and isinstance(
|
| 105 |
+
template.value, (tuple, list)
|
| 106 |
+
):
|
| 107 |
+
for template_name in template.value:
|
| 108 |
+
if isinstance(template_name, str):
|
| 109 |
+
yield template_name
|
| 110 |
+
# something else we don't care about, we could warn here
|
| 111 |
+
else:
|
| 112 |
+
yield None
|
deepseekvl2/lib/python3.10/site-packages/jinja2/nativetypes.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
from ast import literal_eval
|
| 3 |
+
from ast import parse
|
| 4 |
+
from itertools import chain
|
| 5 |
+
from itertools import islice
|
| 6 |
+
from types import GeneratorType
|
| 7 |
+
|
| 8 |
+
from . import nodes
|
| 9 |
+
from .compiler import CodeGenerator
|
| 10 |
+
from .compiler import Frame
|
| 11 |
+
from .compiler import has_safe_repr
|
| 12 |
+
from .environment import Environment
|
| 13 |
+
from .environment import Template
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def native_concat(values: t.Iterable[t.Any]) -> t.Optional[t.Any]:
|
| 17 |
+
"""Return a native Python type from the list of compiled nodes. If
|
| 18 |
+
the result is a single node, its value is returned. Otherwise, the
|
| 19 |
+
nodes are concatenated as strings. If the result can be parsed with
|
| 20 |
+
:func:`ast.literal_eval`, the parsed value is returned. Otherwise,
|
| 21 |
+
the string is returned.
|
| 22 |
+
|
| 23 |
+
:param values: Iterable of outputs to concatenate.
|
| 24 |
+
"""
|
| 25 |
+
head = list(islice(values, 2))
|
| 26 |
+
|
| 27 |
+
if not head:
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
if len(head) == 1:
|
| 31 |
+
raw = head[0]
|
| 32 |
+
if not isinstance(raw, str):
|
| 33 |
+
return raw
|
| 34 |
+
else:
|
| 35 |
+
if isinstance(values, GeneratorType):
|
| 36 |
+
values = chain(head, values)
|
| 37 |
+
raw = "".join([str(v) for v in values])
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
return literal_eval(
|
| 41 |
+
# In Python 3.10+ ast.literal_eval removes leading spaces/tabs
|
| 42 |
+
# from the given string. For backwards compatibility we need to
|
| 43 |
+
# parse the string ourselves without removing leading spaces/tabs.
|
| 44 |
+
parse(raw, mode="eval")
|
| 45 |
+
)
|
| 46 |
+
except (ValueError, SyntaxError, MemoryError):
|
| 47 |
+
return raw
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class NativeCodeGenerator(CodeGenerator):
|
| 51 |
+
"""A code generator which renders Python types by not adding
|
| 52 |
+
``str()`` around output nodes.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
@staticmethod
|
| 56 |
+
def _default_finalize(value: t.Any) -> t.Any:
|
| 57 |
+
return value
|
| 58 |
+
|
| 59 |
+
def _output_const_repr(self, group: t.Iterable[t.Any]) -> str:
|
| 60 |
+
return repr("".join([str(v) for v in group]))
|
| 61 |
+
|
| 62 |
+
def _output_child_to_const(
|
| 63 |
+
self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
|
| 64 |
+
) -> t.Any:
|
| 65 |
+
const = node.as_const(frame.eval_ctx)
|
| 66 |
+
|
| 67 |
+
if not has_safe_repr(const):
|
| 68 |
+
raise nodes.Impossible()
|
| 69 |
+
|
| 70 |
+
if isinstance(node, nodes.TemplateData):
|
| 71 |
+
return const
|
| 72 |
+
|
| 73 |
+
return finalize.const(const) # type: ignore
|
| 74 |
+
|
| 75 |
+
def _output_child_pre(
|
| 76 |
+
self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
|
| 77 |
+
) -> None:
|
| 78 |
+
if finalize.src is not None:
|
| 79 |
+
self.write(finalize.src)
|
| 80 |
+
|
| 81 |
+
def _output_child_post(
|
| 82 |
+
self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
|
| 83 |
+
) -> None:
|
| 84 |
+
if finalize.src is not None:
|
| 85 |
+
self.write(")")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class NativeEnvironment(Environment):
|
| 89 |
+
"""An environment that renders templates to native Python types."""
|
| 90 |
+
|
| 91 |
+
code_generator_class = NativeCodeGenerator
|
| 92 |
+
concat = staticmethod(native_concat) # type: ignore
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class NativeTemplate(Template):
|
| 96 |
+
environment_class = NativeEnvironment
|
| 97 |
+
|
| 98 |
+
def render(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
| 99 |
+
"""Render the template to produce a native Python type. If the
|
| 100 |
+
result is a single node, its value is returned. Otherwise, the
|
| 101 |
+
nodes are concatenated as strings. If the result can be parsed
|
| 102 |
+
with :func:`ast.literal_eval`, the parsed value is returned.
|
| 103 |
+
Otherwise, the string is returned.
|
| 104 |
+
"""
|
| 105 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
return self.environment_class.concat( # type: ignore
|
| 109 |
+
self.root_render_func(ctx)
|
| 110 |
+
)
|
| 111 |
+
except Exception:
|
| 112 |
+
return self.environment.handle_exception()
|
| 113 |
+
|
| 114 |
+
async def render_async(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
| 115 |
+
if not self.environment.is_async:
|
| 116 |
+
raise RuntimeError(
|
| 117 |
+
"The environment was not created with async mode enabled."
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
return self.environment_class.concat( # type: ignore
|
| 124 |
+
[n async for n in self.root_render_func(ctx)] # type: ignore
|
| 125 |
+
)
|
| 126 |
+
except Exception:
|
| 127 |
+
return self.environment.handle_exception()
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
NativeEnvironment.template_class = NativeTemplate
|
deepseekvl2/lib/python3.10/site-packages/jinja2/optimizer.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The optimizer tries to constant fold expressions and modify the AST
|
| 2 |
+
in place so that it should be faster to evaluate.
|
| 3 |
+
|
| 4 |
+
Because the AST does not contain all the scoping information and the
|
| 5 |
+
compiler has to find that out, we cannot do all the optimizations we
|
| 6 |
+
want. For example, loop unrolling doesn't work because unrolled loops
|
| 7 |
+
would have a different scope. The solution would be a second syntax tree
|
| 8 |
+
that stored the scoping rules.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import typing as t
|
| 12 |
+
|
| 13 |
+
from . import nodes
|
| 14 |
+
from .visitor import NodeTransformer
|
| 15 |
+
|
| 16 |
+
if t.TYPE_CHECKING:
|
| 17 |
+
from .environment import Environment
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def optimize(node: nodes.Node, environment: "Environment") -> nodes.Node:
|
| 21 |
+
"""The context hint can be used to perform an static optimization
|
| 22 |
+
based on the context given."""
|
| 23 |
+
optimizer = Optimizer(environment)
|
| 24 |
+
return t.cast(nodes.Node, optimizer.visit(node))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Optimizer(NodeTransformer):
|
| 28 |
+
def __init__(self, environment: "t.Optional[Environment]") -> None:
|
| 29 |
+
self.environment = environment
|
| 30 |
+
|
| 31 |
+
def generic_visit(
|
| 32 |
+
self, node: nodes.Node, *args: t.Any, **kwargs: t.Any
|
| 33 |
+
) -> nodes.Node:
|
| 34 |
+
node = super().generic_visit(node, *args, **kwargs)
|
| 35 |
+
|
| 36 |
+
# Do constant folding. Some other nodes besides Expr have
|
| 37 |
+
# as_const, but folding them causes errors later on.
|
| 38 |
+
if isinstance(node, nodes.Expr):
|
| 39 |
+
try:
|
| 40 |
+
return nodes.Const.from_untrusted(
|
| 41 |
+
node.as_const(args[0] if args else None),
|
| 42 |
+
lineno=node.lineno,
|
| 43 |
+
environment=self.environment,
|
| 44 |
+
)
|
| 45 |
+
except nodes.Impossible:
|
| 46 |
+
pass
|
| 47 |
+
|
| 48 |
+
return node
|
deepseekvl2/lib/python3.10/site-packages/jinja2/parser.py
ADDED
|
@@ -0,0 +1,1049 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse tokens from the lexer into nodes for the compiler."""
|
| 2 |
+
|
| 3 |
+
import typing
|
| 4 |
+
import typing as t
|
| 5 |
+
|
| 6 |
+
from . import nodes
|
| 7 |
+
from .exceptions import TemplateAssertionError
|
| 8 |
+
from .exceptions import TemplateSyntaxError
|
| 9 |
+
from .lexer import describe_token
|
| 10 |
+
from .lexer import describe_token_expr
|
| 11 |
+
|
| 12 |
+
if t.TYPE_CHECKING:
|
| 13 |
+
import typing_extensions as te
|
| 14 |
+
|
| 15 |
+
from .environment import Environment
|
| 16 |
+
|
| 17 |
+
_ImportInclude = t.TypeVar("_ImportInclude", nodes.Import, nodes.Include)
|
| 18 |
+
_MacroCall = t.TypeVar("_MacroCall", nodes.Macro, nodes.CallBlock)
|
| 19 |
+
|
| 20 |
+
_statement_keywords = frozenset(
|
| 21 |
+
[
|
| 22 |
+
"for",
|
| 23 |
+
"if",
|
| 24 |
+
"block",
|
| 25 |
+
"extends",
|
| 26 |
+
"print",
|
| 27 |
+
"macro",
|
| 28 |
+
"include",
|
| 29 |
+
"from",
|
| 30 |
+
"import",
|
| 31 |
+
"set",
|
| 32 |
+
"with",
|
| 33 |
+
"autoescape",
|
| 34 |
+
]
|
| 35 |
+
)
|
| 36 |
+
_compare_operators = frozenset(["eq", "ne", "lt", "lteq", "gt", "gteq"])
|
| 37 |
+
|
| 38 |
+
_math_nodes: t.Dict[str, t.Type[nodes.Expr]] = {
|
| 39 |
+
"add": nodes.Add,
|
| 40 |
+
"sub": nodes.Sub,
|
| 41 |
+
"mul": nodes.Mul,
|
| 42 |
+
"div": nodes.Div,
|
| 43 |
+
"floordiv": nodes.FloorDiv,
|
| 44 |
+
"mod": nodes.Mod,
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class Parser:
|
| 49 |
+
"""This is the central parsing class Jinja uses. It's passed to
|
| 50 |
+
extensions and can be used to parse expressions or statements.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def __init__(
|
| 54 |
+
self,
|
| 55 |
+
environment: "Environment",
|
| 56 |
+
source: str,
|
| 57 |
+
name: t.Optional[str] = None,
|
| 58 |
+
filename: t.Optional[str] = None,
|
| 59 |
+
state: t.Optional[str] = None,
|
| 60 |
+
) -> None:
|
| 61 |
+
self.environment = environment
|
| 62 |
+
self.stream = environment._tokenize(source, name, filename, state)
|
| 63 |
+
self.name = name
|
| 64 |
+
self.filename = filename
|
| 65 |
+
self.closed = False
|
| 66 |
+
self.extensions: t.Dict[
|
| 67 |
+
str, t.Callable[[Parser], t.Union[nodes.Node, t.List[nodes.Node]]]
|
| 68 |
+
] = {}
|
| 69 |
+
for extension in environment.iter_extensions():
|
| 70 |
+
for tag in extension.tags:
|
| 71 |
+
self.extensions[tag] = extension.parse
|
| 72 |
+
self._last_identifier = 0
|
| 73 |
+
self._tag_stack: t.List[str] = []
|
| 74 |
+
self._end_token_stack: t.List[t.Tuple[str, ...]] = []
|
| 75 |
+
|
| 76 |
+
def fail(
|
| 77 |
+
self,
|
| 78 |
+
msg: str,
|
| 79 |
+
lineno: t.Optional[int] = None,
|
| 80 |
+
exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError,
|
| 81 |
+
) -> "te.NoReturn":
|
| 82 |
+
"""Convenience method that raises `exc` with the message, passed
|
| 83 |
+
line number or last line number as well as the current name and
|
| 84 |
+
filename.
|
| 85 |
+
"""
|
| 86 |
+
if lineno is None:
|
| 87 |
+
lineno = self.stream.current.lineno
|
| 88 |
+
raise exc(msg, lineno, self.name, self.filename)
|
| 89 |
+
|
| 90 |
+
def _fail_ut_eof(
|
| 91 |
+
self,
|
| 92 |
+
name: t.Optional[str],
|
| 93 |
+
end_token_stack: t.List[t.Tuple[str, ...]],
|
| 94 |
+
lineno: t.Optional[int],
|
| 95 |
+
) -> "te.NoReturn":
|
| 96 |
+
expected: t.Set[str] = set()
|
| 97 |
+
for exprs in end_token_stack:
|
| 98 |
+
expected.update(map(describe_token_expr, exprs))
|
| 99 |
+
if end_token_stack:
|
| 100 |
+
currently_looking: t.Optional[str] = " or ".join(
|
| 101 |
+
map(repr, map(describe_token_expr, end_token_stack[-1]))
|
| 102 |
+
)
|
| 103 |
+
else:
|
| 104 |
+
currently_looking = None
|
| 105 |
+
|
| 106 |
+
if name is None:
|
| 107 |
+
message = ["Unexpected end of template."]
|
| 108 |
+
else:
|
| 109 |
+
message = [f"Encountered unknown tag {name!r}."]
|
| 110 |
+
|
| 111 |
+
if currently_looking:
|
| 112 |
+
if name is not None and name in expected:
|
| 113 |
+
message.append(
|
| 114 |
+
"You probably made a nesting mistake. Jinja is expecting this tag,"
|
| 115 |
+
f" but currently looking for {currently_looking}."
|
| 116 |
+
)
|
| 117 |
+
else:
|
| 118 |
+
message.append(
|
| 119 |
+
f"Jinja was looking for the following tags: {currently_looking}."
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
if self._tag_stack:
|
| 123 |
+
message.append(
|
| 124 |
+
"The innermost block that needs to be closed is"
|
| 125 |
+
f" {self._tag_stack[-1]!r}."
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
self.fail(" ".join(message), lineno)
|
| 129 |
+
|
| 130 |
+
def fail_unknown_tag(
|
| 131 |
+
self, name: str, lineno: t.Optional[int] = None
|
| 132 |
+
) -> "te.NoReturn":
|
| 133 |
+
"""Called if the parser encounters an unknown tag. Tries to fail
|
| 134 |
+
with a human readable error message that could help to identify
|
| 135 |
+
the problem.
|
| 136 |
+
"""
|
| 137 |
+
self._fail_ut_eof(name, self._end_token_stack, lineno)
|
| 138 |
+
|
| 139 |
+
def fail_eof(
|
| 140 |
+
self,
|
| 141 |
+
end_tokens: t.Optional[t.Tuple[str, ...]] = None,
|
| 142 |
+
lineno: t.Optional[int] = None,
|
| 143 |
+
) -> "te.NoReturn":
|
| 144 |
+
"""Like fail_unknown_tag but for end of template situations."""
|
| 145 |
+
stack = list(self._end_token_stack)
|
| 146 |
+
if end_tokens is not None:
|
| 147 |
+
stack.append(end_tokens)
|
| 148 |
+
self._fail_ut_eof(None, stack, lineno)
|
| 149 |
+
|
| 150 |
+
def is_tuple_end(
|
| 151 |
+
self, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None
|
| 152 |
+
) -> bool:
|
| 153 |
+
"""Are we at the end of a tuple?"""
|
| 154 |
+
if self.stream.current.type in ("variable_end", "block_end", "rparen"):
|
| 155 |
+
return True
|
| 156 |
+
elif extra_end_rules is not None:
|
| 157 |
+
return self.stream.current.test_any(extra_end_rules) # type: ignore
|
| 158 |
+
return False
|
| 159 |
+
|
| 160 |
+
def free_identifier(self, lineno: t.Optional[int] = None) -> nodes.InternalName:
|
| 161 |
+
"""Return a new free identifier as :class:`~jinja2.nodes.InternalName`."""
|
| 162 |
+
self._last_identifier += 1
|
| 163 |
+
rv = object.__new__(nodes.InternalName)
|
| 164 |
+
nodes.Node.__init__(rv, f"fi{self._last_identifier}", lineno=lineno)
|
| 165 |
+
return rv
|
| 166 |
+
|
| 167 |
+
def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]:
|
| 168 |
+
"""Parse a single statement."""
|
| 169 |
+
token = self.stream.current
|
| 170 |
+
if token.type != "name":
|
| 171 |
+
self.fail("tag name expected", token.lineno)
|
| 172 |
+
self._tag_stack.append(token.value)
|
| 173 |
+
pop_tag = True
|
| 174 |
+
try:
|
| 175 |
+
if token.value in _statement_keywords:
|
| 176 |
+
f = getattr(self, f"parse_{self.stream.current.value}")
|
| 177 |
+
return f() # type: ignore
|
| 178 |
+
if token.value == "call":
|
| 179 |
+
return self.parse_call_block()
|
| 180 |
+
if token.value == "filter":
|
| 181 |
+
return self.parse_filter_block()
|
| 182 |
+
ext = self.extensions.get(token.value)
|
| 183 |
+
if ext is not None:
|
| 184 |
+
return ext(self)
|
| 185 |
+
|
| 186 |
+
# did not work out, remove the token we pushed by accident
|
| 187 |
+
# from the stack so that the unknown tag fail function can
|
| 188 |
+
# produce a proper error message.
|
| 189 |
+
self._tag_stack.pop()
|
| 190 |
+
pop_tag = False
|
| 191 |
+
self.fail_unknown_tag(token.value, token.lineno)
|
| 192 |
+
finally:
|
| 193 |
+
if pop_tag:
|
| 194 |
+
self._tag_stack.pop()
|
| 195 |
+
|
| 196 |
+
def parse_statements(
|
| 197 |
+
self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False
|
| 198 |
+
) -> t.List[nodes.Node]:
|
| 199 |
+
"""Parse multiple statements into a list until one of the end tokens
|
| 200 |
+
is reached. This is used to parse the body of statements as it also
|
| 201 |
+
parses template data if appropriate. The parser checks first if the
|
| 202 |
+
current token is a colon and skips it if there is one. Then it checks
|
| 203 |
+
for the block end and parses until if one of the `end_tokens` is
|
| 204 |
+
reached. Per default the active token in the stream at the end of
|
| 205 |
+
the call is the matched end token. If this is not wanted `drop_needle`
|
| 206 |
+
can be set to `True` and the end token is removed.
|
| 207 |
+
"""
|
| 208 |
+
# the first token may be a colon for python compatibility
|
| 209 |
+
self.stream.skip_if("colon")
|
| 210 |
+
|
| 211 |
+
# in the future it would be possible to add whole code sections
|
| 212 |
+
# by adding some sort of end of statement token and parsing those here.
|
| 213 |
+
self.stream.expect("block_end")
|
| 214 |
+
result = self.subparse(end_tokens)
|
| 215 |
+
|
| 216 |
+
# we reached the end of the template too early, the subparser
|
| 217 |
+
# does not check for this, so we do that now
|
| 218 |
+
if self.stream.current.type == "eof":
|
| 219 |
+
self.fail_eof(end_tokens)
|
| 220 |
+
|
| 221 |
+
if drop_needle:
|
| 222 |
+
next(self.stream)
|
| 223 |
+
return result
|
| 224 |
+
|
| 225 |
+
def parse_set(self) -> t.Union[nodes.Assign, nodes.AssignBlock]:
|
| 226 |
+
"""Parse an assign statement."""
|
| 227 |
+
lineno = next(self.stream).lineno
|
| 228 |
+
target = self.parse_assign_target(with_namespace=True)
|
| 229 |
+
if self.stream.skip_if("assign"):
|
| 230 |
+
expr = self.parse_tuple()
|
| 231 |
+
return nodes.Assign(target, expr, lineno=lineno)
|
| 232 |
+
filter_node = self.parse_filter(None)
|
| 233 |
+
body = self.parse_statements(("name:endset",), drop_needle=True)
|
| 234 |
+
return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
|
| 235 |
+
|
| 236 |
+
def parse_for(self) -> nodes.For:
|
| 237 |
+
"""Parse a for loop."""
|
| 238 |
+
lineno = self.stream.expect("name:for").lineno
|
| 239 |
+
target = self.parse_assign_target(extra_end_rules=("name:in",))
|
| 240 |
+
self.stream.expect("name:in")
|
| 241 |
+
iter = self.parse_tuple(
|
| 242 |
+
with_condexpr=False, extra_end_rules=("name:recursive",)
|
| 243 |
+
)
|
| 244 |
+
test = None
|
| 245 |
+
if self.stream.skip_if("name:if"):
|
| 246 |
+
test = self.parse_expression()
|
| 247 |
+
recursive = self.stream.skip_if("name:recursive")
|
| 248 |
+
body = self.parse_statements(("name:endfor", "name:else"))
|
| 249 |
+
if next(self.stream).value == "endfor":
|
| 250 |
+
else_ = []
|
| 251 |
+
else:
|
| 252 |
+
else_ = self.parse_statements(("name:endfor",), drop_needle=True)
|
| 253 |
+
return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
|
| 254 |
+
|
| 255 |
+
def parse_if(self) -> nodes.If:
|
| 256 |
+
"""Parse an if construct."""
|
| 257 |
+
node = result = nodes.If(lineno=self.stream.expect("name:if").lineno)
|
| 258 |
+
while True:
|
| 259 |
+
node.test = self.parse_tuple(with_condexpr=False)
|
| 260 |
+
node.body = self.parse_statements(("name:elif", "name:else", "name:endif"))
|
| 261 |
+
node.elif_ = []
|
| 262 |
+
node.else_ = []
|
| 263 |
+
token = next(self.stream)
|
| 264 |
+
if token.test("name:elif"):
|
| 265 |
+
node = nodes.If(lineno=self.stream.current.lineno)
|
| 266 |
+
result.elif_.append(node)
|
| 267 |
+
continue
|
| 268 |
+
elif token.test("name:else"):
|
| 269 |
+
result.else_ = self.parse_statements(("name:endif",), drop_needle=True)
|
| 270 |
+
break
|
| 271 |
+
return result
|
| 272 |
+
|
| 273 |
+
def parse_with(self) -> nodes.With:
|
| 274 |
+
node = nodes.With(lineno=next(self.stream).lineno)
|
| 275 |
+
targets: t.List[nodes.Expr] = []
|
| 276 |
+
values: t.List[nodes.Expr] = []
|
| 277 |
+
while self.stream.current.type != "block_end":
|
| 278 |
+
if targets:
|
| 279 |
+
self.stream.expect("comma")
|
| 280 |
+
target = self.parse_assign_target()
|
| 281 |
+
target.set_ctx("param")
|
| 282 |
+
targets.append(target)
|
| 283 |
+
self.stream.expect("assign")
|
| 284 |
+
values.append(self.parse_expression())
|
| 285 |
+
node.targets = targets
|
| 286 |
+
node.values = values
|
| 287 |
+
node.body = self.parse_statements(("name:endwith",), drop_needle=True)
|
| 288 |
+
return node
|
| 289 |
+
|
| 290 |
+
def parse_autoescape(self) -> nodes.Scope:
|
| 291 |
+
node = nodes.ScopedEvalContextModifier(lineno=next(self.stream).lineno)
|
| 292 |
+
node.options = [nodes.Keyword("autoescape", self.parse_expression())]
|
| 293 |
+
node.body = self.parse_statements(("name:endautoescape",), drop_needle=True)
|
| 294 |
+
return nodes.Scope([node])
|
| 295 |
+
|
| 296 |
+
def parse_block(self) -> nodes.Block:
|
| 297 |
+
node = nodes.Block(lineno=next(self.stream).lineno)
|
| 298 |
+
node.name = self.stream.expect("name").value
|
| 299 |
+
node.scoped = self.stream.skip_if("name:scoped")
|
| 300 |
+
node.required = self.stream.skip_if("name:required")
|
| 301 |
+
|
| 302 |
+
# common problem people encounter when switching from django
|
| 303 |
+
# to jinja. we do not support hyphens in block names, so let's
|
| 304 |
+
# raise a nicer error message in that case.
|
| 305 |
+
if self.stream.current.type == "sub":
|
| 306 |
+
self.fail(
|
| 307 |
+
"Block names in Jinja have to be valid Python identifiers and may not"
|
| 308 |
+
" contain hyphens, use an underscore instead."
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
node.body = self.parse_statements(("name:endblock",), drop_needle=True)
|
| 312 |
+
|
| 313 |
+
# enforce that required blocks only contain whitespace or comments
|
| 314 |
+
# by asserting that the body, if not empty, is just TemplateData nodes
|
| 315 |
+
# with whitespace data
|
| 316 |
+
if node.required:
|
| 317 |
+
for body_node in node.body:
|
| 318 |
+
if not isinstance(body_node, nodes.Output) or any(
|
| 319 |
+
not isinstance(output_node, nodes.TemplateData)
|
| 320 |
+
or not output_node.data.isspace()
|
| 321 |
+
for output_node in body_node.nodes
|
| 322 |
+
):
|
| 323 |
+
self.fail("Required blocks can only contain comments or whitespace")
|
| 324 |
+
|
| 325 |
+
self.stream.skip_if("name:" + node.name)
|
| 326 |
+
return node
|
| 327 |
+
|
| 328 |
+
def parse_extends(self) -> nodes.Extends:
|
| 329 |
+
node = nodes.Extends(lineno=next(self.stream).lineno)
|
| 330 |
+
node.template = self.parse_expression()
|
| 331 |
+
return node
|
| 332 |
+
|
| 333 |
+
def parse_import_context(
|
| 334 |
+
self, node: _ImportInclude, default: bool
|
| 335 |
+
) -> _ImportInclude:
|
| 336 |
+
if self.stream.current.test_any(
|
| 337 |
+
"name:with", "name:without"
|
| 338 |
+
) and self.stream.look().test("name:context"):
|
| 339 |
+
node.with_context = next(self.stream).value == "with"
|
| 340 |
+
self.stream.skip()
|
| 341 |
+
else:
|
| 342 |
+
node.with_context = default
|
| 343 |
+
return node
|
| 344 |
+
|
| 345 |
+
def parse_include(self) -> nodes.Include:
|
| 346 |
+
node = nodes.Include(lineno=next(self.stream).lineno)
|
| 347 |
+
node.template = self.parse_expression()
|
| 348 |
+
if self.stream.current.test("name:ignore") and self.stream.look().test(
|
| 349 |
+
"name:missing"
|
| 350 |
+
):
|
| 351 |
+
node.ignore_missing = True
|
| 352 |
+
self.stream.skip(2)
|
| 353 |
+
else:
|
| 354 |
+
node.ignore_missing = False
|
| 355 |
+
return self.parse_import_context(node, True)
|
| 356 |
+
|
| 357 |
+
def parse_import(self) -> nodes.Import:
|
| 358 |
+
node = nodes.Import(lineno=next(self.stream).lineno)
|
| 359 |
+
node.template = self.parse_expression()
|
| 360 |
+
self.stream.expect("name:as")
|
| 361 |
+
node.target = self.parse_assign_target(name_only=True).name
|
| 362 |
+
return self.parse_import_context(node, False)
|
| 363 |
+
|
| 364 |
+
def parse_from(self) -> nodes.FromImport:
|
| 365 |
+
node = nodes.FromImport(lineno=next(self.stream).lineno)
|
| 366 |
+
node.template = self.parse_expression()
|
| 367 |
+
self.stream.expect("name:import")
|
| 368 |
+
node.names = []
|
| 369 |
+
|
| 370 |
+
def parse_context() -> bool:
|
| 371 |
+
if self.stream.current.value in {
|
| 372 |
+
"with",
|
| 373 |
+
"without",
|
| 374 |
+
} and self.stream.look().test("name:context"):
|
| 375 |
+
node.with_context = next(self.stream).value == "with"
|
| 376 |
+
self.stream.skip()
|
| 377 |
+
return True
|
| 378 |
+
return False
|
| 379 |
+
|
| 380 |
+
while True:
|
| 381 |
+
if node.names:
|
| 382 |
+
self.stream.expect("comma")
|
| 383 |
+
if self.stream.current.type == "name":
|
| 384 |
+
if parse_context():
|
| 385 |
+
break
|
| 386 |
+
target = self.parse_assign_target(name_only=True)
|
| 387 |
+
if target.name.startswith("_"):
|
| 388 |
+
self.fail(
|
| 389 |
+
"names starting with an underline can not be imported",
|
| 390 |
+
target.lineno,
|
| 391 |
+
exc=TemplateAssertionError,
|
| 392 |
+
)
|
| 393 |
+
if self.stream.skip_if("name:as"):
|
| 394 |
+
alias = self.parse_assign_target(name_only=True)
|
| 395 |
+
node.names.append((target.name, alias.name))
|
| 396 |
+
else:
|
| 397 |
+
node.names.append(target.name)
|
| 398 |
+
if parse_context() or self.stream.current.type != "comma":
|
| 399 |
+
break
|
| 400 |
+
else:
|
| 401 |
+
self.stream.expect("name")
|
| 402 |
+
if not hasattr(node, "with_context"):
|
| 403 |
+
node.with_context = False
|
| 404 |
+
return node
|
| 405 |
+
|
| 406 |
+
def parse_signature(self, node: _MacroCall) -> None:
|
| 407 |
+
args = node.args = []
|
| 408 |
+
defaults = node.defaults = []
|
| 409 |
+
self.stream.expect("lparen")
|
| 410 |
+
while self.stream.current.type != "rparen":
|
| 411 |
+
if args:
|
| 412 |
+
self.stream.expect("comma")
|
| 413 |
+
arg = self.parse_assign_target(name_only=True)
|
| 414 |
+
arg.set_ctx("param")
|
| 415 |
+
if self.stream.skip_if("assign"):
|
| 416 |
+
defaults.append(self.parse_expression())
|
| 417 |
+
elif defaults:
|
| 418 |
+
self.fail("non-default argument follows default argument")
|
| 419 |
+
args.append(arg)
|
| 420 |
+
self.stream.expect("rparen")
|
| 421 |
+
|
| 422 |
+
def parse_call_block(self) -> nodes.CallBlock:
|
| 423 |
+
node = nodes.CallBlock(lineno=next(self.stream).lineno)
|
| 424 |
+
if self.stream.current.type == "lparen":
|
| 425 |
+
self.parse_signature(node)
|
| 426 |
+
else:
|
| 427 |
+
node.args = []
|
| 428 |
+
node.defaults = []
|
| 429 |
+
|
| 430 |
+
call_node = self.parse_expression()
|
| 431 |
+
if not isinstance(call_node, nodes.Call):
|
| 432 |
+
self.fail("expected call", node.lineno)
|
| 433 |
+
node.call = call_node
|
| 434 |
+
node.body = self.parse_statements(("name:endcall",), drop_needle=True)
|
| 435 |
+
return node
|
| 436 |
+
|
| 437 |
+
def parse_filter_block(self) -> nodes.FilterBlock:
|
| 438 |
+
node = nodes.FilterBlock(lineno=next(self.stream).lineno)
|
| 439 |
+
node.filter = self.parse_filter(None, start_inline=True) # type: ignore
|
| 440 |
+
node.body = self.parse_statements(("name:endfilter",), drop_needle=True)
|
| 441 |
+
return node
|
| 442 |
+
|
| 443 |
+
def parse_macro(self) -> nodes.Macro:
|
| 444 |
+
node = nodes.Macro(lineno=next(self.stream).lineno)
|
| 445 |
+
node.name = self.parse_assign_target(name_only=True).name
|
| 446 |
+
self.parse_signature(node)
|
| 447 |
+
node.body = self.parse_statements(("name:endmacro",), drop_needle=True)
|
| 448 |
+
return node
|
| 449 |
+
|
| 450 |
+
def parse_print(self) -> nodes.Output:
|
| 451 |
+
node = nodes.Output(lineno=next(self.stream).lineno)
|
| 452 |
+
node.nodes = []
|
| 453 |
+
while self.stream.current.type != "block_end":
|
| 454 |
+
if node.nodes:
|
| 455 |
+
self.stream.expect("comma")
|
| 456 |
+
node.nodes.append(self.parse_expression())
|
| 457 |
+
return node
|
| 458 |
+
|
| 459 |
+
@typing.overload
|
| 460 |
+
def parse_assign_target(
|
| 461 |
+
self, with_tuple: bool = ..., name_only: "te.Literal[True]" = ...
|
| 462 |
+
) -> nodes.Name: ...
|
| 463 |
+
|
| 464 |
+
@typing.overload
|
| 465 |
+
def parse_assign_target(
|
| 466 |
+
self,
|
| 467 |
+
with_tuple: bool = True,
|
| 468 |
+
name_only: bool = False,
|
| 469 |
+
extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
|
| 470 |
+
with_namespace: bool = False,
|
| 471 |
+
) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]: ...
|
| 472 |
+
|
| 473 |
+
def parse_assign_target(
|
| 474 |
+
self,
|
| 475 |
+
with_tuple: bool = True,
|
| 476 |
+
name_only: bool = False,
|
| 477 |
+
extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
|
| 478 |
+
with_namespace: bool = False,
|
| 479 |
+
) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]:
|
| 480 |
+
"""Parse an assignment target. As Jinja allows assignments to
|
| 481 |
+
tuples, this function can parse all allowed assignment targets. Per
|
| 482 |
+
default assignments to tuples are parsed, that can be disable however
|
| 483 |
+
by setting `with_tuple` to `False`. If only assignments to names are
|
| 484 |
+
wanted `name_only` can be set to `True`. The `extra_end_rules`
|
| 485 |
+
parameter is forwarded to the tuple parsing function. If
|
| 486 |
+
`with_namespace` is enabled, a namespace assignment may be parsed.
|
| 487 |
+
"""
|
| 488 |
+
target: nodes.Expr
|
| 489 |
+
|
| 490 |
+
if name_only:
|
| 491 |
+
token = self.stream.expect("name")
|
| 492 |
+
target = nodes.Name(token.value, "store", lineno=token.lineno)
|
| 493 |
+
else:
|
| 494 |
+
if with_tuple:
|
| 495 |
+
target = self.parse_tuple(
|
| 496 |
+
simplified=True,
|
| 497 |
+
extra_end_rules=extra_end_rules,
|
| 498 |
+
with_namespace=with_namespace,
|
| 499 |
+
)
|
| 500 |
+
else:
|
| 501 |
+
target = self.parse_primary(with_namespace=with_namespace)
|
| 502 |
+
|
| 503 |
+
target.set_ctx("store")
|
| 504 |
+
|
| 505 |
+
if not target.can_assign():
|
| 506 |
+
self.fail(
|
| 507 |
+
f"can't assign to {type(target).__name__.lower()!r}", target.lineno
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
return target # type: ignore
|
| 511 |
+
|
| 512 |
+
def parse_expression(self, with_condexpr: bool = True) -> nodes.Expr:
|
| 513 |
+
"""Parse an expression. Per default all expressions are parsed, if
|
| 514 |
+
the optional `with_condexpr` parameter is set to `False` conditional
|
| 515 |
+
expressions are not parsed.
|
| 516 |
+
"""
|
| 517 |
+
if with_condexpr:
|
| 518 |
+
return self.parse_condexpr()
|
| 519 |
+
return self.parse_or()
|
| 520 |
+
|
| 521 |
+
def parse_condexpr(self) -> nodes.Expr:
|
| 522 |
+
lineno = self.stream.current.lineno
|
| 523 |
+
expr1 = self.parse_or()
|
| 524 |
+
expr3: t.Optional[nodes.Expr]
|
| 525 |
+
|
| 526 |
+
while self.stream.skip_if("name:if"):
|
| 527 |
+
expr2 = self.parse_or()
|
| 528 |
+
if self.stream.skip_if("name:else"):
|
| 529 |
+
expr3 = self.parse_condexpr()
|
| 530 |
+
else:
|
| 531 |
+
expr3 = None
|
| 532 |
+
expr1 = nodes.CondExpr(expr2, expr1, expr3, lineno=lineno)
|
| 533 |
+
lineno = self.stream.current.lineno
|
| 534 |
+
return expr1
|
| 535 |
+
|
| 536 |
+
def parse_or(self) -> nodes.Expr:
|
| 537 |
+
lineno = self.stream.current.lineno
|
| 538 |
+
left = self.parse_and()
|
| 539 |
+
while self.stream.skip_if("name:or"):
|
| 540 |
+
right = self.parse_and()
|
| 541 |
+
left = nodes.Or(left, right, lineno=lineno)
|
| 542 |
+
lineno = self.stream.current.lineno
|
| 543 |
+
return left
|
| 544 |
+
|
| 545 |
+
def parse_and(self) -> nodes.Expr:
|
| 546 |
+
lineno = self.stream.current.lineno
|
| 547 |
+
left = self.parse_not()
|
| 548 |
+
while self.stream.skip_if("name:and"):
|
| 549 |
+
right = self.parse_not()
|
| 550 |
+
left = nodes.And(left, right, lineno=lineno)
|
| 551 |
+
lineno = self.stream.current.lineno
|
| 552 |
+
return left
|
| 553 |
+
|
| 554 |
+
def parse_not(self) -> nodes.Expr:
|
| 555 |
+
if self.stream.current.test("name:not"):
|
| 556 |
+
lineno = next(self.stream).lineno
|
| 557 |
+
return nodes.Not(self.parse_not(), lineno=lineno)
|
| 558 |
+
return self.parse_compare()
|
| 559 |
+
|
| 560 |
+
def parse_compare(self) -> nodes.Expr:
|
| 561 |
+
lineno = self.stream.current.lineno
|
| 562 |
+
expr = self.parse_math1()
|
| 563 |
+
ops = []
|
| 564 |
+
while True:
|
| 565 |
+
token_type = self.stream.current.type
|
| 566 |
+
if token_type in _compare_operators:
|
| 567 |
+
next(self.stream)
|
| 568 |
+
ops.append(nodes.Operand(token_type, self.parse_math1()))
|
| 569 |
+
elif self.stream.skip_if("name:in"):
|
| 570 |
+
ops.append(nodes.Operand("in", self.parse_math1()))
|
| 571 |
+
elif self.stream.current.test("name:not") and self.stream.look().test(
|
| 572 |
+
"name:in"
|
| 573 |
+
):
|
| 574 |
+
self.stream.skip(2)
|
| 575 |
+
ops.append(nodes.Operand("notin", self.parse_math1()))
|
| 576 |
+
else:
|
| 577 |
+
break
|
| 578 |
+
lineno = self.stream.current.lineno
|
| 579 |
+
if not ops:
|
| 580 |
+
return expr
|
| 581 |
+
return nodes.Compare(expr, ops, lineno=lineno)
|
| 582 |
+
|
| 583 |
+
def parse_math1(self) -> nodes.Expr:
|
| 584 |
+
lineno = self.stream.current.lineno
|
| 585 |
+
left = self.parse_concat()
|
| 586 |
+
while self.stream.current.type in ("add", "sub"):
|
| 587 |
+
cls = _math_nodes[self.stream.current.type]
|
| 588 |
+
next(self.stream)
|
| 589 |
+
right = self.parse_concat()
|
| 590 |
+
left = cls(left, right, lineno=lineno)
|
| 591 |
+
lineno = self.stream.current.lineno
|
| 592 |
+
return left
|
| 593 |
+
|
| 594 |
+
def parse_concat(self) -> nodes.Expr:
|
| 595 |
+
lineno = self.stream.current.lineno
|
| 596 |
+
args = [self.parse_math2()]
|
| 597 |
+
while self.stream.current.type == "tilde":
|
| 598 |
+
next(self.stream)
|
| 599 |
+
args.append(self.parse_math2())
|
| 600 |
+
if len(args) == 1:
|
| 601 |
+
return args[0]
|
| 602 |
+
return nodes.Concat(args, lineno=lineno)
|
| 603 |
+
|
| 604 |
+
def parse_math2(self) -> nodes.Expr:
|
| 605 |
+
lineno = self.stream.current.lineno
|
| 606 |
+
left = self.parse_pow()
|
| 607 |
+
while self.stream.current.type in ("mul", "div", "floordiv", "mod"):
|
| 608 |
+
cls = _math_nodes[self.stream.current.type]
|
| 609 |
+
next(self.stream)
|
| 610 |
+
right = self.parse_pow()
|
| 611 |
+
left = cls(left, right, lineno=lineno)
|
| 612 |
+
lineno = self.stream.current.lineno
|
| 613 |
+
return left
|
| 614 |
+
|
| 615 |
+
def parse_pow(self) -> nodes.Expr:
|
| 616 |
+
lineno = self.stream.current.lineno
|
| 617 |
+
left = self.parse_unary()
|
| 618 |
+
while self.stream.current.type == "pow":
|
| 619 |
+
next(self.stream)
|
| 620 |
+
right = self.parse_unary()
|
| 621 |
+
left = nodes.Pow(left, right, lineno=lineno)
|
| 622 |
+
lineno = self.stream.current.lineno
|
| 623 |
+
return left
|
| 624 |
+
|
| 625 |
+
def parse_unary(self, with_filter: bool = True) -> nodes.Expr:
|
| 626 |
+
token_type = self.stream.current.type
|
| 627 |
+
lineno = self.stream.current.lineno
|
| 628 |
+
node: nodes.Expr
|
| 629 |
+
|
| 630 |
+
if token_type == "sub":
|
| 631 |
+
next(self.stream)
|
| 632 |
+
node = nodes.Neg(self.parse_unary(False), lineno=lineno)
|
| 633 |
+
elif token_type == "add":
|
| 634 |
+
next(self.stream)
|
| 635 |
+
node = nodes.Pos(self.parse_unary(False), lineno=lineno)
|
| 636 |
+
else:
|
| 637 |
+
node = self.parse_primary()
|
| 638 |
+
node = self.parse_postfix(node)
|
| 639 |
+
if with_filter:
|
| 640 |
+
node = self.parse_filter_expr(node)
|
| 641 |
+
return node
|
| 642 |
+
|
| 643 |
+
def parse_primary(self, with_namespace: bool = False) -> nodes.Expr:
|
| 644 |
+
"""Parse a name or literal value. If ``with_namespace`` is enabled, also
|
| 645 |
+
parse namespace attr refs, for use in assignments."""
|
| 646 |
+
token = self.stream.current
|
| 647 |
+
node: nodes.Expr
|
| 648 |
+
if token.type == "name":
|
| 649 |
+
next(self.stream)
|
| 650 |
+
if token.value in ("true", "false", "True", "False"):
|
| 651 |
+
node = nodes.Const(token.value in ("true", "True"), lineno=token.lineno)
|
| 652 |
+
elif token.value in ("none", "None"):
|
| 653 |
+
node = nodes.Const(None, lineno=token.lineno)
|
| 654 |
+
elif with_namespace and self.stream.current.type == "dot":
|
| 655 |
+
# If namespace attributes are allowed at this point, and the next
|
| 656 |
+
# token is a dot, produce a namespace reference.
|
| 657 |
+
next(self.stream)
|
| 658 |
+
attr = self.stream.expect("name")
|
| 659 |
+
node = nodes.NSRef(token.value, attr.value, lineno=token.lineno)
|
| 660 |
+
else:
|
| 661 |
+
node = nodes.Name(token.value, "load", lineno=token.lineno)
|
| 662 |
+
elif token.type == "string":
|
| 663 |
+
next(self.stream)
|
| 664 |
+
buf = [token.value]
|
| 665 |
+
lineno = token.lineno
|
| 666 |
+
while self.stream.current.type == "string":
|
| 667 |
+
buf.append(self.stream.current.value)
|
| 668 |
+
next(self.stream)
|
| 669 |
+
node = nodes.Const("".join(buf), lineno=lineno)
|
| 670 |
+
elif token.type in ("integer", "float"):
|
| 671 |
+
next(self.stream)
|
| 672 |
+
node = nodes.Const(token.value, lineno=token.lineno)
|
| 673 |
+
elif token.type == "lparen":
|
| 674 |
+
next(self.stream)
|
| 675 |
+
node = self.parse_tuple(explicit_parentheses=True)
|
| 676 |
+
self.stream.expect("rparen")
|
| 677 |
+
elif token.type == "lbracket":
|
| 678 |
+
node = self.parse_list()
|
| 679 |
+
elif token.type == "lbrace":
|
| 680 |
+
node = self.parse_dict()
|
| 681 |
+
else:
|
| 682 |
+
self.fail(f"unexpected {describe_token(token)!r}", token.lineno)
|
| 683 |
+
return node
|
| 684 |
+
|
| 685 |
+
def parse_tuple(
|
| 686 |
+
self,
|
| 687 |
+
simplified: bool = False,
|
| 688 |
+
with_condexpr: bool = True,
|
| 689 |
+
extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
|
| 690 |
+
explicit_parentheses: bool = False,
|
| 691 |
+
with_namespace: bool = False,
|
| 692 |
+
) -> t.Union[nodes.Tuple, nodes.Expr]:
|
| 693 |
+
"""Works like `parse_expression` but if multiple expressions are
|
| 694 |
+
delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
|
| 695 |
+
This method could also return a regular expression instead of a tuple
|
| 696 |
+
if no commas where found.
|
| 697 |
+
|
| 698 |
+
The default parsing mode is a full tuple. If `simplified` is `True`
|
| 699 |
+
only names and literals are parsed; ``with_namespace`` allows namespace
|
| 700 |
+
attr refs as well. The `no_condexpr` parameter is forwarded to
|
| 701 |
+
:meth:`parse_expression`.
|
| 702 |
+
|
| 703 |
+
Because tuples do not require delimiters and may end in a bogus comma
|
| 704 |
+
an extra hint is needed that marks the end of a tuple. For example
|
| 705 |
+
for loops support tuples between `for` and `in`. In that case the
|
| 706 |
+
`extra_end_rules` is set to ``['name:in']``.
|
| 707 |
+
|
| 708 |
+
`explicit_parentheses` is true if the parsing was triggered by an
|
| 709 |
+
expression in parentheses. This is used to figure out if an empty
|
| 710 |
+
tuple is a valid expression or not.
|
| 711 |
+
"""
|
| 712 |
+
lineno = self.stream.current.lineno
|
| 713 |
+
if simplified:
|
| 714 |
+
|
| 715 |
+
def parse() -> nodes.Expr:
|
| 716 |
+
return self.parse_primary(with_namespace=with_namespace)
|
| 717 |
+
|
| 718 |
+
else:
|
| 719 |
+
|
| 720 |
+
def parse() -> nodes.Expr:
|
| 721 |
+
return self.parse_expression(with_condexpr=with_condexpr)
|
| 722 |
+
|
| 723 |
+
args: t.List[nodes.Expr] = []
|
| 724 |
+
is_tuple = False
|
| 725 |
+
|
| 726 |
+
while True:
|
| 727 |
+
if args:
|
| 728 |
+
self.stream.expect("comma")
|
| 729 |
+
if self.is_tuple_end(extra_end_rules):
|
| 730 |
+
break
|
| 731 |
+
args.append(parse())
|
| 732 |
+
if self.stream.current.type == "comma":
|
| 733 |
+
is_tuple = True
|
| 734 |
+
else:
|
| 735 |
+
break
|
| 736 |
+
lineno = self.stream.current.lineno
|
| 737 |
+
|
| 738 |
+
if not is_tuple:
|
| 739 |
+
if args:
|
| 740 |
+
return args[0]
|
| 741 |
+
|
| 742 |
+
# if we don't have explicit parentheses, an empty tuple is
|
| 743 |
+
# not a valid expression. This would mean nothing (literally
|
| 744 |
+
# nothing) in the spot of an expression would be an empty
|
| 745 |
+
# tuple.
|
| 746 |
+
if not explicit_parentheses:
|
| 747 |
+
self.fail(
|
| 748 |
+
"Expected an expression,"
|
| 749 |
+
f" got {describe_token(self.stream.current)!r}"
|
| 750 |
+
)
|
| 751 |
+
|
| 752 |
+
return nodes.Tuple(args, "load", lineno=lineno)
|
| 753 |
+
|
| 754 |
+
def parse_list(self) -> nodes.List:
|
| 755 |
+
token = self.stream.expect("lbracket")
|
| 756 |
+
items: t.List[nodes.Expr] = []
|
| 757 |
+
while self.stream.current.type != "rbracket":
|
| 758 |
+
if items:
|
| 759 |
+
self.stream.expect("comma")
|
| 760 |
+
if self.stream.current.type == "rbracket":
|
| 761 |
+
break
|
| 762 |
+
items.append(self.parse_expression())
|
| 763 |
+
self.stream.expect("rbracket")
|
| 764 |
+
return nodes.List(items, lineno=token.lineno)
|
| 765 |
+
|
| 766 |
+
def parse_dict(self) -> nodes.Dict:
|
| 767 |
+
token = self.stream.expect("lbrace")
|
| 768 |
+
items: t.List[nodes.Pair] = []
|
| 769 |
+
while self.stream.current.type != "rbrace":
|
| 770 |
+
if items:
|
| 771 |
+
self.stream.expect("comma")
|
| 772 |
+
if self.stream.current.type == "rbrace":
|
| 773 |
+
break
|
| 774 |
+
key = self.parse_expression()
|
| 775 |
+
self.stream.expect("colon")
|
| 776 |
+
value = self.parse_expression()
|
| 777 |
+
items.append(nodes.Pair(key, value, lineno=key.lineno))
|
| 778 |
+
self.stream.expect("rbrace")
|
| 779 |
+
return nodes.Dict(items, lineno=token.lineno)
|
| 780 |
+
|
| 781 |
+
def parse_postfix(self, node: nodes.Expr) -> nodes.Expr:
|
| 782 |
+
while True:
|
| 783 |
+
token_type = self.stream.current.type
|
| 784 |
+
if token_type == "dot" or token_type == "lbracket":
|
| 785 |
+
node = self.parse_subscript(node)
|
| 786 |
+
# calls are valid both after postfix expressions (getattr
|
| 787 |
+
# and getitem) as well as filters and tests
|
| 788 |
+
elif token_type == "lparen":
|
| 789 |
+
node = self.parse_call(node)
|
| 790 |
+
else:
|
| 791 |
+
break
|
| 792 |
+
return node
|
| 793 |
+
|
| 794 |
+
def parse_filter_expr(self, node: nodes.Expr) -> nodes.Expr:
|
| 795 |
+
while True:
|
| 796 |
+
token_type = self.stream.current.type
|
| 797 |
+
if token_type == "pipe":
|
| 798 |
+
node = self.parse_filter(node) # type: ignore
|
| 799 |
+
elif token_type == "name" and self.stream.current.value == "is":
|
| 800 |
+
node = self.parse_test(node)
|
| 801 |
+
# calls are valid both after postfix expressions (getattr
|
| 802 |
+
# and getitem) as well as filters and tests
|
| 803 |
+
elif token_type == "lparen":
|
| 804 |
+
node = self.parse_call(node)
|
| 805 |
+
else:
|
| 806 |
+
break
|
| 807 |
+
return node
|
| 808 |
+
|
| 809 |
+
def parse_subscript(
|
| 810 |
+
self, node: nodes.Expr
|
| 811 |
+
) -> t.Union[nodes.Getattr, nodes.Getitem]:
|
| 812 |
+
token = next(self.stream)
|
| 813 |
+
arg: nodes.Expr
|
| 814 |
+
|
| 815 |
+
if token.type == "dot":
|
| 816 |
+
attr_token = self.stream.current
|
| 817 |
+
next(self.stream)
|
| 818 |
+
if attr_token.type == "name":
|
| 819 |
+
return nodes.Getattr(
|
| 820 |
+
node, attr_token.value, "load", lineno=token.lineno
|
| 821 |
+
)
|
| 822 |
+
elif attr_token.type != "integer":
|
| 823 |
+
self.fail("expected name or number", attr_token.lineno)
|
| 824 |
+
arg = nodes.Const(attr_token.value, lineno=attr_token.lineno)
|
| 825 |
+
return nodes.Getitem(node, arg, "load", lineno=token.lineno)
|
| 826 |
+
if token.type == "lbracket":
|
| 827 |
+
args: t.List[nodes.Expr] = []
|
| 828 |
+
while self.stream.current.type != "rbracket":
|
| 829 |
+
if args:
|
| 830 |
+
self.stream.expect("comma")
|
| 831 |
+
args.append(self.parse_subscribed())
|
| 832 |
+
self.stream.expect("rbracket")
|
| 833 |
+
if len(args) == 1:
|
| 834 |
+
arg = args[0]
|
| 835 |
+
else:
|
| 836 |
+
arg = nodes.Tuple(args, "load", lineno=token.lineno)
|
| 837 |
+
return nodes.Getitem(node, arg, "load", lineno=token.lineno)
|
| 838 |
+
self.fail("expected subscript expression", token.lineno)
|
| 839 |
+
|
| 840 |
+
def parse_subscribed(self) -> nodes.Expr:
|
| 841 |
+
lineno = self.stream.current.lineno
|
| 842 |
+
args: t.List[t.Optional[nodes.Expr]]
|
| 843 |
+
|
| 844 |
+
if self.stream.current.type == "colon":
|
| 845 |
+
next(self.stream)
|
| 846 |
+
args = [None]
|
| 847 |
+
else:
|
| 848 |
+
node = self.parse_expression()
|
| 849 |
+
if self.stream.current.type != "colon":
|
| 850 |
+
return node
|
| 851 |
+
next(self.stream)
|
| 852 |
+
args = [node]
|
| 853 |
+
|
| 854 |
+
if self.stream.current.type == "colon":
|
| 855 |
+
args.append(None)
|
| 856 |
+
elif self.stream.current.type not in ("rbracket", "comma"):
|
| 857 |
+
args.append(self.parse_expression())
|
| 858 |
+
else:
|
| 859 |
+
args.append(None)
|
| 860 |
+
|
| 861 |
+
if self.stream.current.type == "colon":
|
| 862 |
+
next(self.stream)
|
| 863 |
+
if self.stream.current.type not in ("rbracket", "comma"):
|
| 864 |
+
args.append(self.parse_expression())
|
| 865 |
+
else:
|
| 866 |
+
args.append(None)
|
| 867 |
+
else:
|
| 868 |
+
args.append(None)
|
| 869 |
+
|
| 870 |
+
return nodes.Slice(lineno=lineno, *args) # noqa: B026
|
| 871 |
+
|
| 872 |
+
def parse_call_args(
|
| 873 |
+
self,
|
| 874 |
+
) -> t.Tuple[
|
| 875 |
+
t.List[nodes.Expr],
|
| 876 |
+
t.List[nodes.Keyword],
|
| 877 |
+
t.Optional[nodes.Expr],
|
| 878 |
+
t.Optional[nodes.Expr],
|
| 879 |
+
]:
|
| 880 |
+
token = self.stream.expect("lparen")
|
| 881 |
+
args = []
|
| 882 |
+
kwargs = []
|
| 883 |
+
dyn_args = None
|
| 884 |
+
dyn_kwargs = None
|
| 885 |
+
require_comma = False
|
| 886 |
+
|
| 887 |
+
def ensure(expr: bool) -> None:
|
| 888 |
+
if not expr:
|
| 889 |
+
self.fail("invalid syntax for function call expression", token.lineno)
|
| 890 |
+
|
| 891 |
+
while self.stream.current.type != "rparen":
|
| 892 |
+
if require_comma:
|
| 893 |
+
self.stream.expect("comma")
|
| 894 |
+
|
| 895 |
+
# support for trailing comma
|
| 896 |
+
if self.stream.current.type == "rparen":
|
| 897 |
+
break
|
| 898 |
+
|
| 899 |
+
if self.stream.current.type == "mul":
|
| 900 |
+
ensure(dyn_args is None and dyn_kwargs is None)
|
| 901 |
+
next(self.stream)
|
| 902 |
+
dyn_args = self.parse_expression()
|
| 903 |
+
elif self.stream.current.type == "pow":
|
| 904 |
+
ensure(dyn_kwargs is None)
|
| 905 |
+
next(self.stream)
|
| 906 |
+
dyn_kwargs = self.parse_expression()
|
| 907 |
+
else:
|
| 908 |
+
if (
|
| 909 |
+
self.stream.current.type == "name"
|
| 910 |
+
and self.stream.look().type == "assign"
|
| 911 |
+
):
|
| 912 |
+
# Parsing a kwarg
|
| 913 |
+
ensure(dyn_kwargs is None)
|
| 914 |
+
key = self.stream.current.value
|
| 915 |
+
self.stream.skip(2)
|
| 916 |
+
value = self.parse_expression()
|
| 917 |
+
kwargs.append(nodes.Keyword(key, value, lineno=value.lineno))
|
| 918 |
+
else:
|
| 919 |
+
# Parsing an arg
|
| 920 |
+
ensure(dyn_args is None and dyn_kwargs is None and not kwargs)
|
| 921 |
+
args.append(self.parse_expression())
|
| 922 |
+
|
| 923 |
+
require_comma = True
|
| 924 |
+
|
| 925 |
+
self.stream.expect("rparen")
|
| 926 |
+
return args, kwargs, dyn_args, dyn_kwargs
|
| 927 |
+
|
| 928 |
+
def parse_call(self, node: nodes.Expr) -> nodes.Call:
|
| 929 |
+
# The lparen will be expected in parse_call_args, but the lineno
|
| 930 |
+
# needs to be recorded before the stream is advanced.
|
| 931 |
+
token = self.stream.current
|
| 932 |
+
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
|
| 933 |
+
return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno)
|
| 934 |
+
|
| 935 |
+
def parse_filter(
|
| 936 |
+
self, node: t.Optional[nodes.Expr], start_inline: bool = False
|
| 937 |
+
) -> t.Optional[nodes.Expr]:
|
| 938 |
+
while self.stream.current.type == "pipe" or start_inline:
|
| 939 |
+
if not start_inline:
|
| 940 |
+
next(self.stream)
|
| 941 |
+
token = self.stream.expect("name")
|
| 942 |
+
name = token.value
|
| 943 |
+
while self.stream.current.type == "dot":
|
| 944 |
+
next(self.stream)
|
| 945 |
+
name += "." + self.stream.expect("name").value
|
| 946 |
+
if self.stream.current.type == "lparen":
|
| 947 |
+
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
|
| 948 |
+
else:
|
| 949 |
+
args = []
|
| 950 |
+
kwargs = []
|
| 951 |
+
dyn_args = dyn_kwargs = None
|
| 952 |
+
node = nodes.Filter(
|
| 953 |
+
node, name, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno
|
| 954 |
+
)
|
| 955 |
+
start_inline = False
|
| 956 |
+
return node
|
| 957 |
+
|
| 958 |
+
def parse_test(self, node: nodes.Expr) -> nodes.Expr:
|
| 959 |
+
token = next(self.stream)
|
| 960 |
+
if self.stream.current.test("name:not"):
|
| 961 |
+
next(self.stream)
|
| 962 |
+
negated = True
|
| 963 |
+
else:
|
| 964 |
+
negated = False
|
| 965 |
+
name = self.stream.expect("name").value
|
| 966 |
+
while self.stream.current.type == "dot":
|
| 967 |
+
next(self.stream)
|
| 968 |
+
name += "." + self.stream.expect("name").value
|
| 969 |
+
dyn_args = dyn_kwargs = None
|
| 970 |
+
kwargs: t.List[nodes.Keyword] = []
|
| 971 |
+
if self.stream.current.type == "lparen":
|
| 972 |
+
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
|
| 973 |
+
elif self.stream.current.type in {
|
| 974 |
+
"name",
|
| 975 |
+
"string",
|
| 976 |
+
"integer",
|
| 977 |
+
"float",
|
| 978 |
+
"lparen",
|
| 979 |
+
"lbracket",
|
| 980 |
+
"lbrace",
|
| 981 |
+
} and not self.stream.current.test_any("name:else", "name:or", "name:and"):
|
| 982 |
+
if self.stream.current.test("name:is"):
|
| 983 |
+
self.fail("You cannot chain multiple tests with is")
|
| 984 |
+
arg_node = self.parse_primary()
|
| 985 |
+
arg_node = self.parse_postfix(arg_node)
|
| 986 |
+
args = [arg_node]
|
| 987 |
+
else:
|
| 988 |
+
args = []
|
| 989 |
+
node = nodes.Test(
|
| 990 |
+
node, name, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno
|
| 991 |
+
)
|
| 992 |
+
if negated:
|
| 993 |
+
node = nodes.Not(node, lineno=token.lineno)
|
| 994 |
+
return node
|
| 995 |
+
|
| 996 |
+
def subparse(
|
| 997 |
+
self, end_tokens: t.Optional[t.Tuple[str, ...]] = None
|
| 998 |
+
) -> t.List[nodes.Node]:
|
| 999 |
+
body: t.List[nodes.Node] = []
|
| 1000 |
+
data_buffer: t.List[nodes.Node] = []
|
| 1001 |
+
add_data = data_buffer.append
|
| 1002 |
+
|
| 1003 |
+
if end_tokens is not None:
|
| 1004 |
+
self._end_token_stack.append(end_tokens)
|
| 1005 |
+
|
| 1006 |
+
def flush_data() -> None:
|
| 1007 |
+
if data_buffer:
|
| 1008 |
+
lineno = data_buffer[0].lineno
|
| 1009 |
+
body.append(nodes.Output(data_buffer[:], lineno=lineno))
|
| 1010 |
+
del data_buffer[:]
|
| 1011 |
+
|
| 1012 |
+
try:
|
| 1013 |
+
while self.stream:
|
| 1014 |
+
token = self.stream.current
|
| 1015 |
+
if token.type == "data":
|
| 1016 |
+
if token.value:
|
| 1017 |
+
add_data(nodes.TemplateData(token.value, lineno=token.lineno))
|
| 1018 |
+
next(self.stream)
|
| 1019 |
+
elif token.type == "variable_begin":
|
| 1020 |
+
next(self.stream)
|
| 1021 |
+
add_data(self.parse_tuple(with_condexpr=True))
|
| 1022 |
+
self.stream.expect("variable_end")
|
| 1023 |
+
elif token.type == "block_begin":
|
| 1024 |
+
flush_data()
|
| 1025 |
+
next(self.stream)
|
| 1026 |
+
if end_tokens is not None and self.stream.current.test_any(
|
| 1027 |
+
*end_tokens
|
| 1028 |
+
):
|
| 1029 |
+
return body
|
| 1030 |
+
rv = self.parse_statement()
|
| 1031 |
+
if isinstance(rv, list):
|
| 1032 |
+
body.extend(rv)
|
| 1033 |
+
else:
|
| 1034 |
+
body.append(rv)
|
| 1035 |
+
self.stream.expect("block_end")
|
| 1036 |
+
else:
|
| 1037 |
+
raise AssertionError("internal parsing error")
|
| 1038 |
+
|
| 1039 |
+
flush_data()
|
| 1040 |
+
finally:
|
| 1041 |
+
if end_tokens is not None:
|
| 1042 |
+
self._end_token_stack.pop()
|
| 1043 |
+
return body
|
| 1044 |
+
|
| 1045 |
+
def parse(self) -> nodes.Template:
|
| 1046 |
+
"""Parse the whole template into a `Template` node."""
|
| 1047 |
+
result = nodes.Template(self.subparse(), lineno=1)
|
| 1048 |
+
result.set_environment(self.environment)
|
| 1049 |
+
return result
|
deepseekvl2/lib/python3.10/site-packages/jinja2/py.typed
ADDED
|
File without changes
|
deepseekvl2/lib/python3.10/site-packages/jinja2/tests.py
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Built-in template tests used with the ``is`` operator."""
|
| 2 |
+
|
| 3 |
+
import operator
|
| 4 |
+
import typing as t
|
| 5 |
+
from collections import abc
|
| 6 |
+
from numbers import Number
|
| 7 |
+
|
| 8 |
+
from .runtime import Undefined
|
| 9 |
+
from .utils import pass_environment
|
| 10 |
+
|
| 11 |
+
if t.TYPE_CHECKING:
|
| 12 |
+
from .environment import Environment
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_odd(value: int) -> bool:
|
| 16 |
+
"""Return true if the variable is odd."""
|
| 17 |
+
return value % 2 == 1
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_even(value: int) -> bool:
|
| 21 |
+
"""Return true if the variable is even."""
|
| 22 |
+
return value % 2 == 0
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_divisibleby(value: int, num: int) -> bool:
|
| 26 |
+
"""Check if a variable is divisible by a number."""
|
| 27 |
+
return value % num == 0
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_defined(value: t.Any) -> bool:
|
| 31 |
+
"""Return true if the variable is defined:
|
| 32 |
+
|
| 33 |
+
.. sourcecode:: jinja
|
| 34 |
+
|
| 35 |
+
{% if variable is defined %}
|
| 36 |
+
value of variable: {{ variable }}
|
| 37 |
+
{% else %}
|
| 38 |
+
variable is not defined
|
| 39 |
+
{% endif %}
|
| 40 |
+
|
| 41 |
+
See the :func:`default` filter for a simple way to set undefined
|
| 42 |
+
variables.
|
| 43 |
+
"""
|
| 44 |
+
return not isinstance(value, Undefined)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def test_undefined(value: t.Any) -> bool:
|
| 48 |
+
"""Like :func:`defined` but the other way round."""
|
| 49 |
+
return isinstance(value, Undefined)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@pass_environment
|
| 53 |
+
def test_filter(env: "Environment", value: str) -> bool:
|
| 54 |
+
"""Check if a filter exists by name. Useful if a filter may be
|
| 55 |
+
optionally available.
|
| 56 |
+
|
| 57 |
+
.. code-block:: jinja
|
| 58 |
+
|
| 59 |
+
{% if 'markdown' is filter %}
|
| 60 |
+
{{ value | markdown }}
|
| 61 |
+
{% else %}
|
| 62 |
+
{{ value }}
|
| 63 |
+
{% endif %}
|
| 64 |
+
|
| 65 |
+
.. versionadded:: 3.0
|
| 66 |
+
"""
|
| 67 |
+
return value in env.filters
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
@pass_environment
|
| 71 |
+
def test_test(env: "Environment", value: str) -> bool:
|
| 72 |
+
"""Check if a test exists by name. Useful if a test may be
|
| 73 |
+
optionally available.
|
| 74 |
+
|
| 75 |
+
.. code-block:: jinja
|
| 76 |
+
|
| 77 |
+
{% if 'loud' is test %}
|
| 78 |
+
{% if value is loud %}
|
| 79 |
+
{{ value|upper }}
|
| 80 |
+
{% else %}
|
| 81 |
+
{{ value|lower }}
|
| 82 |
+
{% endif %}
|
| 83 |
+
{% else %}
|
| 84 |
+
{{ value }}
|
| 85 |
+
{% endif %}
|
| 86 |
+
|
| 87 |
+
.. versionadded:: 3.0
|
| 88 |
+
"""
|
| 89 |
+
return value in env.tests
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def test_none(value: t.Any) -> bool:
|
| 93 |
+
"""Return true if the variable is none."""
|
| 94 |
+
return value is None
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def test_boolean(value: t.Any) -> bool:
|
| 98 |
+
"""Return true if the object is a boolean value.
|
| 99 |
+
|
| 100 |
+
.. versionadded:: 2.11
|
| 101 |
+
"""
|
| 102 |
+
return value is True or value is False
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def test_false(value: t.Any) -> bool:
|
| 106 |
+
"""Return true if the object is False.
|
| 107 |
+
|
| 108 |
+
.. versionadded:: 2.11
|
| 109 |
+
"""
|
| 110 |
+
return value is False
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_true(value: t.Any) -> bool:
|
| 114 |
+
"""Return true if the object is True.
|
| 115 |
+
|
| 116 |
+
.. versionadded:: 2.11
|
| 117 |
+
"""
|
| 118 |
+
return value is True
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# NOTE: The existing 'number' test matches booleans and floats
|
| 122 |
+
def test_integer(value: t.Any) -> bool:
|
| 123 |
+
"""Return true if the object is an integer.
|
| 124 |
+
|
| 125 |
+
.. versionadded:: 2.11
|
| 126 |
+
"""
|
| 127 |
+
return isinstance(value, int) and value is not True and value is not False
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
# NOTE: The existing 'number' test matches booleans and integers
|
| 131 |
+
def test_float(value: t.Any) -> bool:
|
| 132 |
+
"""Return true if the object is a float.
|
| 133 |
+
|
| 134 |
+
.. versionadded:: 2.11
|
| 135 |
+
"""
|
| 136 |
+
return isinstance(value, float)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def test_lower(value: str) -> bool:
|
| 140 |
+
"""Return true if the variable is lowercased."""
|
| 141 |
+
return str(value).islower()
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def test_upper(value: str) -> bool:
|
| 145 |
+
"""Return true if the variable is uppercased."""
|
| 146 |
+
return str(value).isupper()
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_string(value: t.Any) -> bool:
|
| 150 |
+
"""Return true if the object is a string."""
|
| 151 |
+
return isinstance(value, str)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def test_mapping(value: t.Any) -> bool:
|
| 155 |
+
"""Return true if the object is a mapping (dict etc.).
|
| 156 |
+
|
| 157 |
+
.. versionadded:: 2.6
|
| 158 |
+
"""
|
| 159 |
+
return isinstance(value, abc.Mapping)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def test_number(value: t.Any) -> bool:
|
| 163 |
+
"""Return true if the variable is a number."""
|
| 164 |
+
return isinstance(value, Number)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_sequence(value: t.Any) -> bool:
|
| 168 |
+
"""Return true if the variable is a sequence. Sequences are variables
|
| 169 |
+
that are iterable.
|
| 170 |
+
"""
|
| 171 |
+
try:
|
| 172 |
+
len(value)
|
| 173 |
+
value.__getitem__ # noqa B018
|
| 174 |
+
except Exception:
|
| 175 |
+
return False
|
| 176 |
+
|
| 177 |
+
return True
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def test_sameas(value: t.Any, other: t.Any) -> bool:
|
| 181 |
+
"""Check if an object points to the same memory address than another
|
| 182 |
+
object:
|
| 183 |
+
|
| 184 |
+
.. sourcecode:: jinja
|
| 185 |
+
|
| 186 |
+
{% if foo.attribute is sameas false %}
|
| 187 |
+
the foo attribute really is the `False` singleton
|
| 188 |
+
{% endif %}
|
| 189 |
+
"""
|
| 190 |
+
return value is other
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_iterable(value: t.Any) -> bool:
|
| 194 |
+
"""Check if it's possible to iterate over an object."""
|
| 195 |
+
try:
|
| 196 |
+
iter(value)
|
| 197 |
+
except TypeError:
|
| 198 |
+
return False
|
| 199 |
+
|
| 200 |
+
return True
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def test_escaped(value: t.Any) -> bool:
|
| 204 |
+
"""Check if the value is escaped."""
|
| 205 |
+
return hasattr(value, "__html__")
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_in(value: t.Any, seq: t.Container[t.Any]) -> bool:
|
| 209 |
+
"""Check if value is in seq.
|
| 210 |
+
|
| 211 |
+
.. versionadded:: 2.10
|
| 212 |
+
"""
|
| 213 |
+
return value in seq
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
TESTS = {
|
| 217 |
+
"odd": test_odd,
|
| 218 |
+
"even": test_even,
|
| 219 |
+
"divisibleby": test_divisibleby,
|
| 220 |
+
"defined": test_defined,
|
| 221 |
+
"undefined": test_undefined,
|
| 222 |
+
"filter": test_filter,
|
| 223 |
+
"test": test_test,
|
| 224 |
+
"none": test_none,
|
| 225 |
+
"boolean": test_boolean,
|
| 226 |
+
"false": test_false,
|
| 227 |
+
"true": test_true,
|
| 228 |
+
"integer": test_integer,
|
| 229 |
+
"float": test_float,
|
| 230 |
+
"lower": test_lower,
|
| 231 |
+
"upper": test_upper,
|
| 232 |
+
"string": test_string,
|
| 233 |
+
"mapping": test_mapping,
|
| 234 |
+
"number": test_number,
|
| 235 |
+
"sequence": test_sequence,
|
| 236 |
+
"iterable": test_iterable,
|
| 237 |
+
"callable": callable,
|
| 238 |
+
"sameas": test_sameas,
|
| 239 |
+
"escaped": test_escaped,
|
| 240 |
+
"in": test_in,
|
| 241 |
+
"==": operator.eq,
|
| 242 |
+
"eq": operator.eq,
|
| 243 |
+
"equalto": operator.eq,
|
| 244 |
+
"!=": operator.ne,
|
| 245 |
+
"ne": operator.ne,
|
| 246 |
+
">": operator.gt,
|
| 247 |
+
"gt": operator.gt,
|
| 248 |
+
"greaterthan": operator.gt,
|
| 249 |
+
"ge": operator.ge,
|
| 250 |
+
">=": operator.ge,
|
| 251 |
+
"<": operator.lt,
|
| 252 |
+
"lt": operator.lt,
|
| 253 |
+
"lessthan": operator.lt,
|
| 254 |
+
"<=": operator.le,
|
| 255 |
+
"le": operator.le,
|
| 256 |
+
}
|
deepseekvl2/lib/python3.10/site-packages/jinja2/utils.py
ADDED
|
@@ -0,0 +1,766 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import typing as t
|
| 6 |
+
from collections import abc
|
| 7 |
+
from collections import deque
|
| 8 |
+
from random import choice
|
| 9 |
+
from random import randrange
|
| 10 |
+
from threading import Lock
|
| 11 |
+
from types import CodeType
|
| 12 |
+
from urllib.parse import quote_from_bytes
|
| 13 |
+
|
| 14 |
+
import markupsafe
|
| 15 |
+
|
| 16 |
+
if t.TYPE_CHECKING:
|
| 17 |
+
import typing_extensions as te
|
| 18 |
+
|
| 19 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class _MissingType:
|
| 23 |
+
def __repr__(self) -> str:
|
| 24 |
+
return "missing"
|
| 25 |
+
|
| 26 |
+
def __reduce__(self) -> str:
|
| 27 |
+
return "missing"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
missing: t.Any = _MissingType()
|
| 31 |
+
"""Special singleton representing missing values for the runtime."""
|
| 32 |
+
|
| 33 |
+
internal_code: t.MutableSet[CodeType] = set()
|
| 34 |
+
|
| 35 |
+
concat = "".join
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def pass_context(f: F) -> F:
|
| 39 |
+
"""Pass the :class:`~jinja2.runtime.Context` as the first argument
|
| 40 |
+
to the decorated function when called while rendering a template.
|
| 41 |
+
|
| 42 |
+
Can be used on functions, filters, and tests.
|
| 43 |
+
|
| 44 |
+
If only ``Context.eval_context`` is needed, use
|
| 45 |
+
:func:`pass_eval_context`. If only ``Context.environment`` is
|
| 46 |
+
needed, use :func:`pass_environment`.
|
| 47 |
+
|
| 48 |
+
.. versionadded:: 3.0.0
|
| 49 |
+
Replaces ``contextfunction`` and ``contextfilter``.
|
| 50 |
+
"""
|
| 51 |
+
f.jinja_pass_arg = _PassArg.context # type: ignore
|
| 52 |
+
return f
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def pass_eval_context(f: F) -> F:
|
| 56 |
+
"""Pass the :class:`~jinja2.nodes.EvalContext` as the first argument
|
| 57 |
+
to the decorated function when called while rendering a template.
|
| 58 |
+
See :ref:`eval-context`.
|
| 59 |
+
|
| 60 |
+
Can be used on functions, filters, and tests.
|
| 61 |
+
|
| 62 |
+
If only ``EvalContext.environment`` is needed, use
|
| 63 |
+
:func:`pass_environment`.
|
| 64 |
+
|
| 65 |
+
.. versionadded:: 3.0.0
|
| 66 |
+
Replaces ``evalcontextfunction`` and ``evalcontextfilter``.
|
| 67 |
+
"""
|
| 68 |
+
f.jinja_pass_arg = _PassArg.eval_context # type: ignore
|
| 69 |
+
return f
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def pass_environment(f: F) -> F:
|
| 73 |
+
"""Pass the :class:`~jinja2.Environment` as the first argument to
|
| 74 |
+
the decorated function when called while rendering a template.
|
| 75 |
+
|
| 76 |
+
Can be used on functions, filters, and tests.
|
| 77 |
+
|
| 78 |
+
.. versionadded:: 3.0.0
|
| 79 |
+
Replaces ``environmentfunction`` and ``environmentfilter``.
|
| 80 |
+
"""
|
| 81 |
+
f.jinja_pass_arg = _PassArg.environment # type: ignore
|
| 82 |
+
return f
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class _PassArg(enum.Enum):
|
| 86 |
+
context = enum.auto()
|
| 87 |
+
eval_context = enum.auto()
|
| 88 |
+
environment = enum.auto()
|
| 89 |
+
|
| 90 |
+
@classmethod
|
| 91 |
+
def from_obj(cls, obj: F) -> t.Optional["_PassArg"]:
|
| 92 |
+
if hasattr(obj, "jinja_pass_arg"):
|
| 93 |
+
return obj.jinja_pass_arg # type: ignore
|
| 94 |
+
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def internalcode(f: F) -> F:
|
| 99 |
+
"""Marks the function as internally used"""
|
| 100 |
+
internal_code.add(f.__code__)
|
| 101 |
+
return f
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def is_undefined(obj: t.Any) -> bool:
|
| 105 |
+
"""Check if the object passed is undefined. This does nothing more than
|
| 106 |
+
performing an instance check against :class:`Undefined` but looks nicer.
|
| 107 |
+
This can be used for custom filters or tests that want to react to
|
| 108 |
+
undefined variables. For example a custom default filter can look like
|
| 109 |
+
this::
|
| 110 |
+
|
| 111 |
+
def default(var, default=''):
|
| 112 |
+
if is_undefined(var):
|
| 113 |
+
return default
|
| 114 |
+
return var
|
| 115 |
+
"""
|
| 116 |
+
from .runtime import Undefined
|
| 117 |
+
|
| 118 |
+
return isinstance(obj, Undefined)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def consume(iterable: t.Iterable[t.Any]) -> None:
|
| 122 |
+
"""Consumes an iterable without doing anything with it."""
|
| 123 |
+
for _ in iterable:
|
| 124 |
+
pass
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def clear_caches() -> None:
|
| 128 |
+
"""Jinja keeps internal caches for environments and lexers. These are
|
| 129 |
+
used so that Jinja doesn't have to recreate environments and lexers all
|
| 130 |
+
the time. Normally you don't have to care about that but if you are
|
| 131 |
+
measuring memory consumption you may want to clean the caches.
|
| 132 |
+
"""
|
| 133 |
+
from .environment import get_spontaneous_environment
|
| 134 |
+
from .lexer import _lexer_cache
|
| 135 |
+
|
| 136 |
+
get_spontaneous_environment.cache_clear()
|
| 137 |
+
_lexer_cache.clear()
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def import_string(import_name: str, silent: bool = False) -> t.Any:
|
| 141 |
+
"""Imports an object based on a string. This is useful if you want to
|
| 142 |
+
use import paths as endpoints or something similar. An import path can
|
| 143 |
+
be specified either in dotted notation (``xml.sax.saxutils.escape``)
|
| 144 |
+
or with a colon as object delimiter (``xml.sax.saxutils:escape``).
|
| 145 |
+
|
| 146 |
+
If the `silent` is True the return value will be `None` if the import
|
| 147 |
+
fails.
|
| 148 |
+
|
| 149 |
+
:return: imported object
|
| 150 |
+
"""
|
| 151 |
+
try:
|
| 152 |
+
if ":" in import_name:
|
| 153 |
+
module, obj = import_name.split(":", 1)
|
| 154 |
+
elif "." in import_name:
|
| 155 |
+
module, _, obj = import_name.rpartition(".")
|
| 156 |
+
else:
|
| 157 |
+
return __import__(import_name)
|
| 158 |
+
return getattr(__import__(module, None, None, [obj]), obj)
|
| 159 |
+
except (ImportError, AttributeError):
|
| 160 |
+
if not silent:
|
| 161 |
+
raise
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def open_if_exists(filename: str, mode: str = "rb") -> t.Optional[t.IO[t.Any]]:
|
| 165 |
+
"""Returns a file descriptor for the filename if that file exists,
|
| 166 |
+
otherwise ``None``.
|
| 167 |
+
"""
|
| 168 |
+
if not os.path.isfile(filename):
|
| 169 |
+
return None
|
| 170 |
+
|
| 171 |
+
return open(filename, mode)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def object_type_repr(obj: t.Any) -> str:
|
| 175 |
+
"""Returns the name of the object's type. For some recognized
|
| 176 |
+
singletons the name of the object is returned instead. (For
|
| 177 |
+
example for `None` and `Ellipsis`).
|
| 178 |
+
"""
|
| 179 |
+
if obj is None:
|
| 180 |
+
return "None"
|
| 181 |
+
elif obj is Ellipsis:
|
| 182 |
+
return "Ellipsis"
|
| 183 |
+
|
| 184 |
+
cls = type(obj)
|
| 185 |
+
|
| 186 |
+
if cls.__module__ == "builtins":
|
| 187 |
+
return f"{cls.__name__} object"
|
| 188 |
+
|
| 189 |
+
return f"{cls.__module__}.{cls.__name__} object"
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def pformat(obj: t.Any) -> str:
|
| 193 |
+
"""Format an object using :func:`pprint.pformat`."""
|
| 194 |
+
from pprint import pformat
|
| 195 |
+
|
| 196 |
+
return pformat(obj)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
_http_re = re.compile(
|
| 200 |
+
r"""
|
| 201 |
+
^
|
| 202 |
+
(
|
| 203 |
+
(https?://|www\.) # scheme or www
|
| 204 |
+
(([\w%-]+\.)+)? # subdomain
|
| 205 |
+
(
|
| 206 |
+
[a-z]{2,63} # basic tld
|
| 207 |
+
|
|
| 208 |
+
xn--[\w%]{2,59} # idna tld
|
| 209 |
+
)
|
| 210 |
+
|
|
| 211 |
+
([\w%-]{2,63}\.)+ # basic domain
|
| 212 |
+
(com|net|int|edu|gov|org|info|mil) # basic tld
|
| 213 |
+
|
|
| 214 |
+
(https?://) # scheme
|
| 215 |
+
(
|
| 216 |
+
(([\d]{1,3})(\.[\d]{1,3}){3}) # IPv4
|
| 217 |
+
|
|
| 218 |
+
(\[([\da-f]{0,4}:){2}([\da-f]{0,4}:?){1,6}]) # IPv6
|
| 219 |
+
)
|
| 220 |
+
)
|
| 221 |
+
(?::[\d]{1,5})? # port
|
| 222 |
+
(?:[/?#]\S*)? # path, query, and fragment
|
| 223 |
+
$
|
| 224 |
+
""",
|
| 225 |
+
re.IGNORECASE | re.VERBOSE,
|
| 226 |
+
)
|
| 227 |
+
_email_re = re.compile(r"^\S+@\w[\w.-]*\.\w+$")
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def urlize(
|
| 231 |
+
text: str,
|
| 232 |
+
trim_url_limit: t.Optional[int] = None,
|
| 233 |
+
rel: t.Optional[str] = None,
|
| 234 |
+
target: t.Optional[str] = None,
|
| 235 |
+
extra_schemes: t.Optional[t.Iterable[str]] = None,
|
| 236 |
+
) -> str:
|
| 237 |
+
"""Convert URLs in text into clickable links.
|
| 238 |
+
|
| 239 |
+
This may not recognize links in some situations. Usually, a more
|
| 240 |
+
comprehensive formatter, such as a Markdown library, is a better
|
| 241 |
+
choice.
|
| 242 |
+
|
| 243 |
+
Works on ``http://``, ``https://``, ``www.``, ``mailto:``, and email
|
| 244 |
+
addresses. Links with trailing punctuation (periods, commas, closing
|
| 245 |
+
parentheses) and leading punctuation (opening parentheses) are
|
| 246 |
+
recognized excluding the punctuation. Email addresses that include
|
| 247 |
+
header fields are not recognized (for example,
|
| 248 |
+
``mailto:address@example.com?cc=copy@example.com``).
|
| 249 |
+
|
| 250 |
+
:param text: Original text containing URLs to link.
|
| 251 |
+
:param trim_url_limit: Shorten displayed URL values to this length.
|
| 252 |
+
:param target: Add the ``target`` attribute to links.
|
| 253 |
+
:param rel: Add the ``rel`` attribute to links.
|
| 254 |
+
:param extra_schemes: Recognize URLs that start with these schemes
|
| 255 |
+
in addition to the default behavior.
|
| 256 |
+
|
| 257 |
+
.. versionchanged:: 3.0
|
| 258 |
+
The ``extra_schemes`` parameter was added.
|
| 259 |
+
|
| 260 |
+
.. versionchanged:: 3.0
|
| 261 |
+
Generate ``https://`` links for URLs without a scheme.
|
| 262 |
+
|
| 263 |
+
.. versionchanged:: 3.0
|
| 264 |
+
The parsing rules were updated. Recognize email addresses with
|
| 265 |
+
or without the ``mailto:`` scheme. Validate IP addresses. Ignore
|
| 266 |
+
parentheses and brackets in more cases.
|
| 267 |
+
"""
|
| 268 |
+
if trim_url_limit is not None:
|
| 269 |
+
|
| 270 |
+
def trim_url(x: str) -> str:
|
| 271 |
+
if len(x) > trim_url_limit:
|
| 272 |
+
return f"{x[:trim_url_limit]}..."
|
| 273 |
+
|
| 274 |
+
return x
|
| 275 |
+
|
| 276 |
+
else:
|
| 277 |
+
|
| 278 |
+
def trim_url(x: str) -> str:
|
| 279 |
+
return x
|
| 280 |
+
|
| 281 |
+
words = re.split(r"(\s+)", str(markupsafe.escape(text)))
|
| 282 |
+
rel_attr = f' rel="{markupsafe.escape(rel)}"' if rel else ""
|
| 283 |
+
target_attr = f' target="{markupsafe.escape(target)}"' if target else ""
|
| 284 |
+
|
| 285 |
+
for i, word in enumerate(words):
|
| 286 |
+
head, middle, tail = "", word, ""
|
| 287 |
+
match = re.match(r"^([(<]|<)+", middle)
|
| 288 |
+
|
| 289 |
+
if match:
|
| 290 |
+
head = match.group()
|
| 291 |
+
middle = middle[match.end() :]
|
| 292 |
+
|
| 293 |
+
# Unlike lead, which is anchored to the start of the string,
|
| 294 |
+
# need to check that the string ends with any of the characters
|
| 295 |
+
# before trying to match all of them, to avoid backtracking.
|
| 296 |
+
if middle.endswith((")", ">", ".", ",", "\n", ">")):
|
| 297 |
+
match = re.search(r"([)>.,\n]|>)+$", middle)
|
| 298 |
+
|
| 299 |
+
if match:
|
| 300 |
+
tail = match.group()
|
| 301 |
+
middle = middle[: match.start()]
|
| 302 |
+
|
| 303 |
+
# Prefer balancing parentheses in URLs instead of ignoring a
|
| 304 |
+
# trailing character.
|
| 305 |
+
for start_char, end_char in ("(", ")"), ("<", ">"), ("<", ">"):
|
| 306 |
+
start_count = middle.count(start_char)
|
| 307 |
+
|
| 308 |
+
if start_count <= middle.count(end_char):
|
| 309 |
+
# Balanced, or lighter on the left
|
| 310 |
+
continue
|
| 311 |
+
|
| 312 |
+
# Move as many as possible from the tail to balance
|
| 313 |
+
for _ in range(min(start_count, tail.count(end_char))):
|
| 314 |
+
end_index = tail.index(end_char) + len(end_char)
|
| 315 |
+
# Move anything in the tail before the end char too
|
| 316 |
+
middle += tail[:end_index]
|
| 317 |
+
tail = tail[end_index:]
|
| 318 |
+
|
| 319 |
+
if _http_re.match(middle):
|
| 320 |
+
if middle.startswith("https://") or middle.startswith("http://"):
|
| 321 |
+
middle = (
|
| 322 |
+
f'<a href="{middle}"{rel_attr}{target_attr}>{trim_url(middle)}</a>'
|
| 323 |
+
)
|
| 324 |
+
else:
|
| 325 |
+
middle = (
|
| 326 |
+
f'<a href="https://{middle}"{rel_attr}{target_attr}>'
|
| 327 |
+
f"{trim_url(middle)}</a>"
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
elif middle.startswith("mailto:") and _email_re.match(middle[7:]):
|
| 331 |
+
middle = f'<a href="{middle}">{middle[7:]}</a>'
|
| 332 |
+
|
| 333 |
+
elif (
|
| 334 |
+
"@" in middle
|
| 335 |
+
and not middle.startswith("www.")
|
| 336 |
+
# ignore values like `@a@b`
|
| 337 |
+
and not middle.startswith("@")
|
| 338 |
+
and ":" not in middle
|
| 339 |
+
and _email_re.match(middle)
|
| 340 |
+
):
|
| 341 |
+
middle = f'<a href="mailto:{middle}">{middle}</a>'
|
| 342 |
+
|
| 343 |
+
elif extra_schemes is not None:
|
| 344 |
+
for scheme in extra_schemes:
|
| 345 |
+
if middle != scheme and middle.startswith(scheme):
|
| 346 |
+
middle = f'<a href="{middle}"{rel_attr}{target_attr}>{middle}</a>'
|
| 347 |
+
|
| 348 |
+
words[i] = f"{head}{middle}{tail}"
|
| 349 |
+
|
| 350 |
+
return "".join(words)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def generate_lorem_ipsum(
|
| 354 |
+
n: int = 5, html: bool = True, min: int = 20, max: int = 100
|
| 355 |
+
) -> str:
|
| 356 |
+
"""Generate some lorem ipsum for the template."""
|
| 357 |
+
from .constants import LOREM_IPSUM_WORDS
|
| 358 |
+
|
| 359 |
+
words = LOREM_IPSUM_WORDS.split()
|
| 360 |
+
result = []
|
| 361 |
+
|
| 362 |
+
for _ in range(n):
|
| 363 |
+
next_capitalized = True
|
| 364 |
+
last_comma = last_fullstop = 0
|
| 365 |
+
word = None
|
| 366 |
+
last = None
|
| 367 |
+
p = []
|
| 368 |
+
|
| 369 |
+
# each paragraph contains out of 20 to 100 words.
|
| 370 |
+
for idx, _ in enumerate(range(randrange(min, max))):
|
| 371 |
+
while True:
|
| 372 |
+
word = choice(words)
|
| 373 |
+
if word != last:
|
| 374 |
+
last = word
|
| 375 |
+
break
|
| 376 |
+
if next_capitalized:
|
| 377 |
+
word = word.capitalize()
|
| 378 |
+
next_capitalized = False
|
| 379 |
+
# add commas
|
| 380 |
+
if idx - randrange(3, 8) > last_comma:
|
| 381 |
+
last_comma = idx
|
| 382 |
+
last_fullstop += 2
|
| 383 |
+
word += ","
|
| 384 |
+
# add end of sentences
|
| 385 |
+
if idx - randrange(10, 20) > last_fullstop:
|
| 386 |
+
last_comma = last_fullstop = idx
|
| 387 |
+
word += "."
|
| 388 |
+
next_capitalized = True
|
| 389 |
+
p.append(word)
|
| 390 |
+
|
| 391 |
+
# ensure that the paragraph ends with a dot.
|
| 392 |
+
p_str = " ".join(p)
|
| 393 |
+
|
| 394 |
+
if p_str.endswith(","):
|
| 395 |
+
p_str = p_str[:-1] + "."
|
| 396 |
+
elif not p_str.endswith("."):
|
| 397 |
+
p_str += "."
|
| 398 |
+
|
| 399 |
+
result.append(p_str)
|
| 400 |
+
|
| 401 |
+
if not html:
|
| 402 |
+
return "\n\n".join(result)
|
| 403 |
+
return markupsafe.Markup(
|
| 404 |
+
"\n".join(f"<p>{markupsafe.escape(x)}</p>" for x in result)
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def url_quote(obj: t.Any, charset: str = "utf-8", for_qs: bool = False) -> str:
|
| 409 |
+
"""Quote a string for use in a URL using the given charset.
|
| 410 |
+
|
| 411 |
+
:param obj: String or bytes to quote. Other types are converted to
|
| 412 |
+
string then encoded to bytes using the given charset.
|
| 413 |
+
:param charset: Encode text to bytes using this charset.
|
| 414 |
+
:param for_qs: Quote "/" and use "+" for spaces.
|
| 415 |
+
"""
|
| 416 |
+
if not isinstance(obj, bytes):
|
| 417 |
+
if not isinstance(obj, str):
|
| 418 |
+
obj = str(obj)
|
| 419 |
+
|
| 420 |
+
obj = obj.encode(charset)
|
| 421 |
+
|
| 422 |
+
safe = b"" if for_qs else b"/"
|
| 423 |
+
rv = quote_from_bytes(obj, safe)
|
| 424 |
+
|
| 425 |
+
if for_qs:
|
| 426 |
+
rv = rv.replace("%20", "+")
|
| 427 |
+
|
| 428 |
+
return rv
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
@abc.MutableMapping.register
|
| 432 |
+
class LRUCache:
|
| 433 |
+
"""A simple LRU Cache implementation."""
|
| 434 |
+
|
| 435 |
+
# this is fast for small capacities (something below 1000) but doesn't
|
| 436 |
+
# scale. But as long as it's only used as storage for templates this
|
| 437 |
+
# won't do any harm.
|
| 438 |
+
|
| 439 |
+
def __init__(self, capacity: int) -> None:
|
| 440 |
+
self.capacity = capacity
|
| 441 |
+
self._mapping: t.Dict[t.Any, t.Any] = {}
|
| 442 |
+
self._queue: te.Deque[t.Any] = deque()
|
| 443 |
+
self._postinit()
|
| 444 |
+
|
| 445 |
+
def _postinit(self) -> None:
|
| 446 |
+
# alias all queue methods for faster lookup
|
| 447 |
+
self._popleft = self._queue.popleft
|
| 448 |
+
self._pop = self._queue.pop
|
| 449 |
+
self._remove = self._queue.remove
|
| 450 |
+
self._wlock = Lock()
|
| 451 |
+
self._append = self._queue.append
|
| 452 |
+
|
| 453 |
+
def __getstate__(self) -> t.Mapping[str, t.Any]:
|
| 454 |
+
return {
|
| 455 |
+
"capacity": self.capacity,
|
| 456 |
+
"_mapping": self._mapping,
|
| 457 |
+
"_queue": self._queue,
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
def __setstate__(self, d: t.Mapping[str, t.Any]) -> None:
|
| 461 |
+
self.__dict__.update(d)
|
| 462 |
+
self._postinit()
|
| 463 |
+
|
| 464 |
+
def __getnewargs__(self) -> t.Tuple[t.Any, ...]:
|
| 465 |
+
return (self.capacity,)
|
| 466 |
+
|
| 467 |
+
def copy(self) -> "te.Self":
|
| 468 |
+
"""Return a shallow copy of the instance."""
|
| 469 |
+
rv = self.__class__(self.capacity)
|
| 470 |
+
rv._mapping.update(self._mapping)
|
| 471 |
+
rv._queue.extend(self._queue)
|
| 472 |
+
return rv
|
| 473 |
+
|
| 474 |
+
def get(self, key: t.Any, default: t.Any = None) -> t.Any:
|
| 475 |
+
"""Return an item from the cache dict or `default`"""
|
| 476 |
+
try:
|
| 477 |
+
return self[key]
|
| 478 |
+
except KeyError:
|
| 479 |
+
return default
|
| 480 |
+
|
| 481 |
+
def setdefault(self, key: t.Any, default: t.Any = None) -> t.Any:
|
| 482 |
+
"""Set `default` if the key is not in the cache otherwise
|
| 483 |
+
leave unchanged. Return the value of this key.
|
| 484 |
+
"""
|
| 485 |
+
try:
|
| 486 |
+
return self[key]
|
| 487 |
+
except KeyError:
|
| 488 |
+
self[key] = default
|
| 489 |
+
return default
|
| 490 |
+
|
| 491 |
+
def clear(self) -> None:
|
| 492 |
+
"""Clear the cache."""
|
| 493 |
+
with self._wlock:
|
| 494 |
+
self._mapping.clear()
|
| 495 |
+
self._queue.clear()
|
| 496 |
+
|
| 497 |
+
def __contains__(self, key: t.Any) -> bool:
|
| 498 |
+
"""Check if a key exists in this cache."""
|
| 499 |
+
return key in self._mapping
|
| 500 |
+
|
| 501 |
+
def __len__(self) -> int:
|
| 502 |
+
"""Return the current size of the cache."""
|
| 503 |
+
return len(self._mapping)
|
| 504 |
+
|
| 505 |
+
def __repr__(self) -> str:
|
| 506 |
+
return f"<{type(self).__name__} {self._mapping!r}>"
|
| 507 |
+
|
| 508 |
+
def __getitem__(self, key: t.Any) -> t.Any:
|
| 509 |
+
"""Get an item from the cache. Moves the item up so that it has the
|
| 510 |
+
highest priority then.
|
| 511 |
+
|
| 512 |
+
Raise a `KeyError` if it does not exist.
|
| 513 |
+
"""
|
| 514 |
+
with self._wlock:
|
| 515 |
+
rv = self._mapping[key]
|
| 516 |
+
|
| 517 |
+
if self._queue[-1] != key:
|
| 518 |
+
try:
|
| 519 |
+
self._remove(key)
|
| 520 |
+
except ValueError:
|
| 521 |
+
# if something removed the key from the container
|
| 522 |
+
# when we read, ignore the ValueError that we would
|
| 523 |
+
# get otherwise.
|
| 524 |
+
pass
|
| 525 |
+
|
| 526 |
+
self._append(key)
|
| 527 |
+
|
| 528 |
+
return rv
|
| 529 |
+
|
| 530 |
+
def __setitem__(self, key: t.Any, value: t.Any) -> None:
|
| 531 |
+
"""Sets the value for an item. Moves the item up so that it
|
| 532 |
+
has the highest priority then.
|
| 533 |
+
"""
|
| 534 |
+
with self._wlock:
|
| 535 |
+
if key in self._mapping:
|
| 536 |
+
self._remove(key)
|
| 537 |
+
elif len(self._mapping) == self.capacity:
|
| 538 |
+
del self._mapping[self._popleft()]
|
| 539 |
+
|
| 540 |
+
self._append(key)
|
| 541 |
+
self._mapping[key] = value
|
| 542 |
+
|
| 543 |
+
def __delitem__(self, key: t.Any) -> None:
|
| 544 |
+
"""Remove an item from the cache dict.
|
| 545 |
+
Raise a `KeyError` if it does not exist.
|
| 546 |
+
"""
|
| 547 |
+
with self._wlock:
|
| 548 |
+
del self._mapping[key]
|
| 549 |
+
|
| 550 |
+
try:
|
| 551 |
+
self._remove(key)
|
| 552 |
+
except ValueError:
|
| 553 |
+
pass
|
| 554 |
+
|
| 555 |
+
def items(self) -> t.Iterable[t.Tuple[t.Any, t.Any]]:
|
| 556 |
+
"""Return a list of items."""
|
| 557 |
+
result = [(key, self._mapping[key]) for key in list(self._queue)]
|
| 558 |
+
result.reverse()
|
| 559 |
+
return result
|
| 560 |
+
|
| 561 |
+
def values(self) -> t.Iterable[t.Any]:
|
| 562 |
+
"""Return a list of all values."""
|
| 563 |
+
return [x[1] for x in self.items()]
|
| 564 |
+
|
| 565 |
+
def keys(self) -> t.Iterable[t.Any]:
|
| 566 |
+
"""Return a list of all keys ordered by most recent usage."""
|
| 567 |
+
return list(self)
|
| 568 |
+
|
| 569 |
+
def __iter__(self) -> t.Iterator[t.Any]:
|
| 570 |
+
return reversed(tuple(self._queue))
|
| 571 |
+
|
| 572 |
+
def __reversed__(self) -> t.Iterator[t.Any]:
|
| 573 |
+
"""Iterate over the keys in the cache dict, oldest items
|
| 574 |
+
coming first.
|
| 575 |
+
"""
|
| 576 |
+
return iter(tuple(self._queue))
|
| 577 |
+
|
| 578 |
+
__copy__ = copy
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
def select_autoescape(
|
| 582 |
+
enabled_extensions: t.Collection[str] = ("html", "htm", "xml"),
|
| 583 |
+
disabled_extensions: t.Collection[str] = (),
|
| 584 |
+
default_for_string: bool = True,
|
| 585 |
+
default: bool = False,
|
| 586 |
+
) -> t.Callable[[t.Optional[str]], bool]:
|
| 587 |
+
"""Intelligently sets the initial value of autoescaping based on the
|
| 588 |
+
filename of the template. This is the recommended way to configure
|
| 589 |
+
autoescaping if you do not want to write a custom function yourself.
|
| 590 |
+
|
| 591 |
+
If you want to enable it for all templates created from strings or
|
| 592 |
+
for all templates with `.html` and `.xml` extensions::
|
| 593 |
+
|
| 594 |
+
from jinja2 import Environment, select_autoescape
|
| 595 |
+
env = Environment(autoescape=select_autoescape(
|
| 596 |
+
enabled_extensions=('html', 'xml'),
|
| 597 |
+
default_for_string=True,
|
| 598 |
+
))
|
| 599 |
+
|
| 600 |
+
Example configuration to turn it on at all times except if the template
|
| 601 |
+
ends with `.txt`::
|
| 602 |
+
|
| 603 |
+
from jinja2 import Environment, select_autoescape
|
| 604 |
+
env = Environment(autoescape=select_autoescape(
|
| 605 |
+
disabled_extensions=('txt',),
|
| 606 |
+
default_for_string=True,
|
| 607 |
+
default=True,
|
| 608 |
+
))
|
| 609 |
+
|
| 610 |
+
The `enabled_extensions` is an iterable of all the extensions that
|
| 611 |
+
autoescaping should be enabled for. Likewise `disabled_extensions` is
|
| 612 |
+
a list of all templates it should be disabled for. If a template is
|
| 613 |
+
loaded from a string then the default from `default_for_string` is used.
|
| 614 |
+
If nothing matches then the initial value of autoescaping is set to the
|
| 615 |
+
value of `default`.
|
| 616 |
+
|
| 617 |
+
For security reasons this function operates case insensitive.
|
| 618 |
+
|
| 619 |
+
.. versionadded:: 2.9
|
| 620 |
+
"""
|
| 621 |
+
enabled_patterns = tuple(f".{x.lstrip('.').lower()}" for x in enabled_extensions)
|
| 622 |
+
disabled_patterns = tuple(f".{x.lstrip('.').lower()}" for x in disabled_extensions)
|
| 623 |
+
|
| 624 |
+
def autoescape(template_name: t.Optional[str]) -> bool:
|
| 625 |
+
if template_name is None:
|
| 626 |
+
return default_for_string
|
| 627 |
+
template_name = template_name.lower()
|
| 628 |
+
if template_name.endswith(enabled_patterns):
|
| 629 |
+
return True
|
| 630 |
+
if template_name.endswith(disabled_patterns):
|
| 631 |
+
return False
|
| 632 |
+
return default
|
| 633 |
+
|
| 634 |
+
return autoescape
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def htmlsafe_json_dumps(
|
| 638 |
+
obj: t.Any, dumps: t.Optional[t.Callable[..., str]] = None, **kwargs: t.Any
|
| 639 |
+
) -> markupsafe.Markup:
|
| 640 |
+
"""Serialize an object to a string of JSON with :func:`json.dumps`,
|
| 641 |
+
then replace HTML-unsafe characters with Unicode escapes and mark
|
| 642 |
+
the result safe with :class:`~markupsafe.Markup`.
|
| 643 |
+
|
| 644 |
+
This is available in templates as the ``|tojson`` filter.
|
| 645 |
+
|
| 646 |
+
The following characters are escaped: ``<``, ``>``, ``&``, ``'``.
|
| 647 |
+
|
| 648 |
+
The returned string is safe to render in HTML documents and
|
| 649 |
+
``<script>`` tags. The exception is in HTML attributes that are
|
| 650 |
+
double quoted; either use single quotes or the ``|forceescape``
|
| 651 |
+
filter.
|
| 652 |
+
|
| 653 |
+
:param obj: The object to serialize to JSON.
|
| 654 |
+
:param dumps: The ``dumps`` function to use. Defaults to
|
| 655 |
+
``env.policies["json.dumps_function"]``, which defaults to
|
| 656 |
+
:func:`json.dumps`.
|
| 657 |
+
:param kwargs: Extra arguments to pass to ``dumps``. Merged onto
|
| 658 |
+
``env.policies["json.dumps_kwargs"]``.
|
| 659 |
+
|
| 660 |
+
.. versionchanged:: 3.0
|
| 661 |
+
The ``dumper`` parameter is renamed to ``dumps``.
|
| 662 |
+
|
| 663 |
+
.. versionadded:: 2.9
|
| 664 |
+
"""
|
| 665 |
+
if dumps is None:
|
| 666 |
+
dumps = json.dumps
|
| 667 |
+
|
| 668 |
+
return markupsafe.Markup(
|
| 669 |
+
dumps(obj, **kwargs)
|
| 670 |
+
.replace("<", "\\u003c")
|
| 671 |
+
.replace(">", "\\u003e")
|
| 672 |
+
.replace("&", "\\u0026")
|
| 673 |
+
.replace("'", "\\u0027")
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
class Cycler:
|
| 678 |
+
"""Cycle through values by yield them one at a time, then restarting
|
| 679 |
+
once the end is reached. Available as ``cycler`` in templates.
|
| 680 |
+
|
| 681 |
+
Similar to ``loop.cycle``, but can be used outside loops or across
|
| 682 |
+
multiple loops. For example, render a list of folders and files in a
|
| 683 |
+
list, alternating giving them "odd" and "even" classes.
|
| 684 |
+
|
| 685 |
+
.. code-block:: html+jinja
|
| 686 |
+
|
| 687 |
+
{% set row_class = cycler("odd", "even") %}
|
| 688 |
+
<ul class="browser">
|
| 689 |
+
{% for folder in folders %}
|
| 690 |
+
<li class="folder {{ row_class.next() }}">{{ folder }}
|
| 691 |
+
{% endfor %}
|
| 692 |
+
{% for file in files %}
|
| 693 |
+
<li class="file {{ row_class.next() }}">{{ file }}
|
| 694 |
+
{% endfor %}
|
| 695 |
+
</ul>
|
| 696 |
+
|
| 697 |
+
:param items: Each positional argument will be yielded in the order
|
| 698 |
+
given for each cycle.
|
| 699 |
+
|
| 700 |
+
.. versionadded:: 2.1
|
| 701 |
+
"""
|
| 702 |
+
|
| 703 |
+
def __init__(self, *items: t.Any) -> None:
|
| 704 |
+
if not items:
|
| 705 |
+
raise RuntimeError("at least one item has to be provided")
|
| 706 |
+
self.items = items
|
| 707 |
+
self.pos = 0
|
| 708 |
+
|
| 709 |
+
def reset(self) -> None:
|
| 710 |
+
"""Resets the current item to the first item."""
|
| 711 |
+
self.pos = 0
|
| 712 |
+
|
| 713 |
+
@property
|
| 714 |
+
def current(self) -> t.Any:
|
| 715 |
+
"""Return the current item. Equivalent to the item that will be
|
| 716 |
+
returned next time :meth:`next` is called.
|
| 717 |
+
"""
|
| 718 |
+
return self.items[self.pos]
|
| 719 |
+
|
| 720 |
+
def next(self) -> t.Any:
|
| 721 |
+
"""Return the current item, then advance :attr:`current` to the
|
| 722 |
+
next item.
|
| 723 |
+
"""
|
| 724 |
+
rv = self.current
|
| 725 |
+
self.pos = (self.pos + 1) % len(self.items)
|
| 726 |
+
return rv
|
| 727 |
+
|
| 728 |
+
__next__ = next
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
class Joiner:
|
| 732 |
+
"""A joining helper for templates."""
|
| 733 |
+
|
| 734 |
+
def __init__(self, sep: str = ", ") -> None:
|
| 735 |
+
self.sep = sep
|
| 736 |
+
self.used = False
|
| 737 |
+
|
| 738 |
+
def __call__(self) -> str:
|
| 739 |
+
if not self.used:
|
| 740 |
+
self.used = True
|
| 741 |
+
return ""
|
| 742 |
+
return self.sep
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
class Namespace:
|
| 746 |
+
"""A namespace object that can hold arbitrary attributes. It may be
|
| 747 |
+
initialized from a dictionary or with keyword arguments."""
|
| 748 |
+
|
| 749 |
+
def __init__(*args: t.Any, **kwargs: t.Any) -> None: # noqa: B902
|
| 750 |
+
self, args = args[0], args[1:]
|
| 751 |
+
self.__attrs = dict(*args, **kwargs)
|
| 752 |
+
|
| 753 |
+
def __getattribute__(self, name: str) -> t.Any:
|
| 754 |
+
# __class__ is needed for the awaitable check in async mode
|
| 755 |
+
if name in {"_Namespace__attrs", "__class__"}:
|
| 756 |
+
return object.__getattribute__(self, name)
|
| 757 |
+
try:
|
| 758 |
+
return self.__attrs[name]
|
| 759 |
+
except KeyError:
|
| 760 |
+
raise AttributeError(name) from None
|
| 761 |
+
|
| 762 |
+
def __setitem__(self, name: str, value: t.Any) -> None:
|
| 763 |
+
self.__attrs[name] = value
|
| 764 |
+
|
| 765 |
+
def __repr__(self) -> str:
|
| 766 |
+
return f"<Namespace {self.__attrs!r}>"
|
deepseekvl2/lib/python3.10/site-packages/jinja2/visitor.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""API for traversing the AST nodes. Implemented by the compiler and
|
| 2 |
+
meta introspection.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import typing as t
|
| 6 |
+
|
| 7 |
+
from .nodes import Node
|
| 8 |
+
|
| 9 |
+
if t.TYPE_CHECKING:
|
| 10 |
+
import typing_extensions as te
|
| 11 |
+
|
| 12 |
+
class VisitCallable(te.Protocol):
|
| 13 |
+
def __call__(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any: ...
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class NodeVisitor:
|
| 17 |
+
"""Walks the abstract syntax tree and call visitor functions for every
|
| 18 |
+
node found. The visitor functions may return values which will be
|
| 19 |
+
forwarded by the `visit` method.
|
| 20 |
+
|
| 21 |
+
Per default the visitor functions for the nodes are ``'visit_'`` +
|
| 22 |
+
class name of the node. So a `TryFinally` node visit function would
|
| 23 |
+
be `visit_TryFinally`. This behavior can be changed by overriding
|
| 24 |
+
the `get_visitor` function. If no visitor function exists for a node
|
| 25 |
+
(return value `None`) the `generic_visit` visitor is used instead.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def get_visitor(self, node: Node) -> "t.Optional[VisitCallable]":
|
| 29 |
+
"""Return the visitor function for this node or `None` if no visitor
|
| 30 |
+
exists for this node. In that case the generic visit function is
|
| 31 |
+
used instead.
|
| 32 |
+
"""
|
| 33 |
+
return getattr(self, f"visit_{type(node).__name__}", None)
|
| 34 |
+
|
| 35 |
+
def visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
| 36 |
+
"""Visit a node."""
|
| 37 |
+
f = self.get_visitor(node)
|
| 38 |
+
|
| 39 |
+
if f is not None:
|
| 40 |
+
return f(node, *args, **kwargs)
|
| 41 |
+
|
| 42 |
+
return self.generic_visit(node, *args, **kwargs)
|
| 43 |
+
|
| 44 |
+
def generic_visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
| 45 |
+
"""Called if no explicit visitor function exists for a node."""
|
| 46 |
+
for child_node in node.iter_child_nodes():
|
| 47 |
+
self.visit(child_node, *args, **kwargs)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class NodeTransformer(NodeVisitor):
|
| 51 |
+
"""Walks the abstract syntax tree and allows modifications of nodes.
|
| 52 |
+
|
| 53 |
+
The `NodeTransformer` will walk the AST and use the return value of the
|
| 54 |
+
visitor functions to replace or remove the old node. If the return
|
| 55 |
+
value of the visitor function is `None` the node will be removed
|
| 56 |
+
from the previous location otherwise it's replaced with the return
|
| 57 |
+
value. The return value may be the original node in which case no
|
| 58 |
+
replacement takes place.
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
def generic_visit(self, node: Node, *args: t.Any, **kwargs: t.Any) -> Node:
|
| 62 |
+
for field, old_value in node.iter_fields():
|
| 63 |
+
if isinstance(old_value, list):
|
| 64 |
+
new_values = []
|
| 65 |
+
for value in old_value:
|
| 66 |
+
if isinstance(value, Node):
|
| 67 |
+
value = self.visit(value, *args, **kwargs)
|
| 68 |
+
if value is None:
|
| 69 |
+
continue
|
| 70 |
+
elif not isinstance(value, Node):
|
| 71 |
+
new_values.extend(value)
|
| 72 |
+
continue
|
| 73 |
+
new_values.append(value)
|
| 74 |
+
old_value[:] = new_values
|
| 75 |
+
elif isinstance(old_value, Node):
|
| 76 |
+
new_node = self.visit(old_value, *args, **kwargs)
|
| 77 |
+
if new_node is None:
|
| 78 |
+
delattr(node, field)
|
| 79 |
+
else:
|
| 80 |
+
setattr(node, field, new_node)
|
| 81 |
+
return node
|
| 82 |
+
|
| 83 |
+
def visit_list(self, node: Node, *args: t.Any, **kwargs: t.Any) -> t.List[Node]:
|
| 84 |
+
"""As transformers may return lists in some places this method
|
| 85 |
+
can be used to enforce a list as return value.
|
| 86 |
+
"""
|
| 87 |
+
rv = self.visit(node, *args, **kwargs)
|
| 88 |
+
|
| 89 |
+
if not isinstance(rv, list):
|
| 90 |
+
return [rv]
|
| 91 |
+
|
| 92 |
+
return rv
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (7.42 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/__pycache__/_pickle.cpython-310.pyc
ADDED
|
Binary file (2.22 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/_bounded_integers.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc009884164d0c98b9ad76d899d8318cb2436e4caaa0034b48b6607b70efa5ad
|
| 3 |
+
size 379216
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/_generator.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:605a4ece82853cac92e920eb9a8a6da2c4ef739e6f96e3cc1bf4aed71fe14e5f
|
| 3 |
+
size 976328
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/_mt19937.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d30bd4b7d986fc29800bd588c70d3223143932ddc802bdc46d72197fbc096c11
|
| 3 |
+
size 120224
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/lib/libnpyrandom.a
ADDED
|
Binary file (71.9 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/mtrand.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b917e2f0ada2ef00b0cc509b76f14d8bce4815e3643abd58481803bbb6b585fe
|
| 3 |
+
size 783752
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (175 Bytes). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_direct.cpython-310.pyc
ADDED
|
Binary file (17.5 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_extending.cpython-310.pyc
ADDED
|
Binary file (3.13 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-310.pyc
ADDED
|
Binary file (88.9 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937_regressions.cpython-310.pyc
ADDED
|
Binary file (7.61 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_random.cpython-310.pyc
ADDED
|
Binary file (52.9 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_randomstate.cpython-310.pyc
ADDED
|
Binary file (65.6 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_randomstate_regression.cpython-310.pyc
ADDED
|
Binary file (9.3 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_regression.cpython-310.pyc
ADDED
|
Binary file (6.55 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_seed_sequence.cpython-310.pyc
ADDED
|
Binary file (2.57 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/__pycache__/test_smoke.cpython-310.pyc
ADDED
|
Binary file (25.1 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/__init__.py
ADDED
|
File without changes
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (180 Bytes). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/mt19937-testset-1.csv
ADDED
|
@@ -0,0 +1,1001 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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50239372
|
| 17 |
+
15, 0xd9d66b1d
|
| 18 |
+
16, 0xab72a161
|
| 19 |
+
17, 0xddc2e29f
|
| 20 |
+
18, 0x7ea29ab4
|
| 21 |
+
19, 0x80d141ba
|
| 22 |
+
20, 0xb1c7edf1
|
| 23 |
+
21, 0x44d29203
|
| 24 |
+
22, 0xe224d98
|
| 25 |
+
23, 0x5b3e9d26
|
| 26 |
+
24, 0x14fd567c
|
| 27 |
+
25, 0x27d98c96
|
| 28 |
+
26, 0x838779fc
|
| 29 |
+
27, 0x92a138a
|
| 30 |
+
28, 0x5d08965b
|
| 31 |
+
29, 0x531e0ad6
|
| 32 |
+
30, 0x984ee8f4
|
| 33 |
+
31, 0x1ed78539
|
| 34 |
+
32, 0x32bd6d8d
|
| 35 |
+
33, 0xc37c8516
|
| 36 |
+
34, 0x9aef5c6b
|
| 37 |
+
35, 0x3aacd139
|
| 38 |
+
36, 0xd96ed154
|
| 39 |
+
37, 0x489cd1ed
|
| 40 |
+
38, 0x2cba4b3b
|
| 41 |
+
39, 0x76c6ae72
|
| 42 |
+
40, 0x2dae02b9
|
| 43 |
+
41, 0x52ac5fd6
|
| 44 |
+
42, 0xc2b5e265
|
| 45 |
+
43, 0x630e6a28
|
| 46 |
+
44, 0x3f560d5d
|
| 47 |
+
45, 0x9315bdf3
|
| 48 |
+
46, 0xf1055aba
|
| 49 |
+
47, 0x840e42c6
|
| 50 |
+
48, 0xf2099c6b
|
| 51 |
+
49, 0x15ff7696
|
| 52 |
+
50, 0x7948d146
|
| 53 |
+
51, 0x97342961
|
| 54 |
+
52, 0x7a7a21c
|
| 55 |
+
53, 0xc66f4fb1
|
| 56 |
+
54, 0x23c4103e
|
| 57 |
+
55, 0xd7321f98
|
| 58 |
+
56, 0xeb7efb75
|
| 59 |
+
57, 0xe02490b5
|
| 60 |
+
58, 0x2aa02de
|
| 61 |
+
59, 0x8bee0bf7
|
| 62 |
+
60, 0xfc2da059
|
| 63 |
+
61, 0xae835034
|
| 64 |
+
62, 0x678f2075
|
| 65 |
+
63, 0x6d03094b
|
| 66 |
+
64, 0x56455e05
|
| 67 |
+
65, 0x18b32373
|
| 68 |
+
66, 0x8ff0356b
|
| 69 |
+
67, 0x1fe442fb
|
| 70 |
+
68, 0x3f1ab6c3
|
| 71 |
+
69, 0xb6fd21b
|
| 72 |
+
70, 0xfc310eb2
|
| 73 |
+
71, 0xb19e9a4d
|
| 74 |
+
72, 0x17ddee72
|
| 75 |
+
73, 0xfd534251
|
| 76 |
+
74, 0x9e500564
|
| 77 |
+
75, 0x9013a036
|
| 78 |
+
76, 0xcf08f118
|
| 79 |
+
77, 0x6b6d5969
|
| 80 |
+
78, 0x3ccf1977
|
| 81 |
+
79, 0x7cc11497
|
| 82 |
+
80, 0x651c6ac9
|
| 83 |
+
81, 0x4d6b104b
|
| 84 |
+
82, 0x9a28314e
|
| 85 |
+
83, 0x14c237be
|
| 86 |
+
84, 0x9cfc8d52
|
| 87 |
+
85, 0x2947fad5
|
| 88 |
+
86, 0xd71eff49
|
| 89 |
+
87, 0x5188730e
|
| 90 |
+
88, 0x4b894614
|
| 91 |
+
89, 0xf4fa2a34
|
| 92 |
+
90, 0x42f7cc69
|
| 93 |
+
91, 0x4089c9e8
|
| 94 |
+
92, 0xbf0bbfe4
|
| 95 |
+
93, 0x3cea65c
|
| 96 |
+
94, 0xc6221207
|
| 97 |
+
95, 0x1bb71a8f
|
| 98 |
+
96, 0x54843fe7
|
| 99 |
+
97, 0xbc59de4c
|
| 100 |
+
98, 0x79c6ee64
|
| 101 |
+
99, 0x14e57a26
|
| 102 |
+
100, 0x68d88fe
|
| 103 |
+
101, 0x2b86ef64
|
| 104 |
+
102, 0x8ffff3c1
|
| 105 |
+
103, 0x5bdd573f
|
| 106 |
+
104, 0x85671813
|
| 107 |
+
105, 0xefe32ca2
|
| 108 |
+
106, 0x105ded1e
|
| 109 |
+
107, 0x90ca2769
|
| 110 |
+
108, 0xb33963ac
|
| 111 |
+
109, 0x363fbbc3
|
| 112 |
+
110, 0x3b3763ae
|
| 113 |
+
111, 0x1d50ab88
|
| 114 |
+
112, 0xc9ec01eb
|
| 115 |
+
113, 0xc8bbeada
|
| 116 |
+
114, 0x5d704692
|
| 117 |
+
115, 0x5fd9e40
|
| 118 |
+
116, 0xe61c125
|
| 119 |
+
117, 0x2fe05792
|
| 120 |
+
118, 0xda8afb72
|
| 121 |
+
119, 0x4cbaa653
|
| 122 |
+
120, 0xdd2243df
|
| 123 |
+
121, 0x896fd3f5
|
| 124 |
+
122, 0x5bc23db
|
| 125 |
+
123, 0xa1c4e807
|
| 126 |
+
124, 0x57d1a24d
|
| 127 |
+
125, 0x66503ddc
|
| 128 |
+
126, 0xcf7c0838
|
| 129 |
+
127, 0x19e034fc
|
| 130 |
+
128, 0x66807450
|
| 131 |
+
129, 0xfc219b3b
|
| 132 |
+
130, 0xe8a843e7
|
| 133 |
+
131, 0x9ce61f08
|
| 134 |
+
132, 0x92b950d6
|
| 135 |
+
133, 0xce955ec4
|
| 136 |
+
134, 0xda0d1f0d
|
| 137 |
+
135, 0x960c6250
|
| 138 |
+
136, 0x39552432
|
| 139 |
+
137, 0xde845e84
|
| 140 |
+
138, 0xff3b4b11
|
| 141 |
+
139, 0x5d918e6f
|
| 142 |
+
140, 0xbb930df2
|
| 143 |
+
141, 0x7cfb0993
|
| 144 |
+
142, 0x5400e1e9
|
| 145 |
+
143, 0x3bfa0954
|
| 146 |
+
144, 0x7e2605fb
|
| 147 |
+
145, 0x11941591
|
| 148 |
+
146, 0x887e6994
|
| 149 |
+
147, 0xdc8bed45
|
| 150 |
+
148, 0x45b3fb50
|
| 151 |
+
149, 0xfbdf8358
|
| 152 |
+
150, 0x41507468
|
| 153 |
+
151, 0x34c87166
|
| 154 |
+
152, 0x17f64d77
|
| 155 |
+
153, 0x3bbaf4f8
|
| 156 |
+
154, 0x4f26f37e
|
| 157 |
+
155, 0x4a56ebf2
|
| 158 |
+
156, 0x81100f1
|
| 159 |
+
157, 0x96d94eae
|
| 160 |
+
158, 0xca88fda5
|
| 161 |
+
159, 0x2eef3a60
|
| 162 |
+
160, 0x952afbd3
|
| 163 |
+
161, 0x2bec88c7
|
| 164 |
+
162, 0x52335c4b
|
| 165 |
+
163, 0x8296db8e
|
| 166 |
+
164, 0x4da7d00a
|
| 167 |
+
165, 0xc00ac899
|
| 168 |
+
166, 0xadff8c72
|
| 169 |
+
167, 0xbecf26cf
|
| 170 |
+
168, 0x8835c83c
|
| 171 |
+
169, 0x1d13c804
|
| 172 |
+
170, 0xaa940ddc
|
| 173 |
+
171, 0x68222cfe
|
| 174 |
+
172, 0x4569c0e1
|
| 175 |
+
173, 0x29077976
|
| 176 |
+
174, 0x32d4a5af
|
| 177 |
+
175, 0xd31fcdef
|
| 178 |
+
176, 0xdc60682b
|
| 179 |
+
177, 0x7c95c368
|
| 180 |
+
178, 0x75a70213
|
| 181 |
+
179, 0x43021751
|
| 182 |
+
180, 0x5e52e0a6
|
| 183 |
+
181, 0xf7e190b5
|
| 184 |
+
182, 0xee3e4bb
|
| 185 |
+
183, 0x2fe3b150
|
| 186 |
+
184, 0xcf419c07
|
| 187 |
+
185, 0x478a4570
|
| 188 |
+
186, 0xe5c3ea50
|
| 189 |
+
187, 0x417f30a8
|
| 190 |
+
188, 0xf0cfdaa0
|
| 191 |
+
189, 0xd1f7f738
|
| 192 |
+
190, 0x2c70fc23
|
| 193 |
+
191, 0x54fc89f9
|
| 194 |
+
192, 0x444dcf01
|
| 195 |
+
193, 0xec2a002d
|
| 196 |
+
194, 0xef0c3a88
|
| 197 |
+
195, 0xde21be9
|
| 198 |
+
196, 0x88ab3296
|
| 199 |
+
197, 0x3028897c
|
| 200 |
+
198, 0x264b200b
|
| 201 |
+
199, 0xd8ae0706
|
| 202 |
+
200, 0x9eef901a
|
| 203 |
+
201, 0xbd1b96e0
|
| 204 |
+
202, 0xea71366c
|
| 205 |
+
203, 0x1465b694
|
| 206 |
+
204, 0x5a794650
|
| 207 |
+
205, 0x83df52d4
|
| 208 |
+
206, 0x8262413d
|
| 209 |
+
207, 0x5bc148c0
|
| 210 |
+
208, 0xe0ecd80c
|
| 211 |
+
209, 0x40649571
|
| 212 |
+
210, 0xb4d2ee5f
|
| 213 |
+
211, 0xedfd7d09
|
| 214 |
+
212, 0xa082e25f
|
| 215 |
+
213, 0xc62992d1
|
| 216 |
+
214, 0xbc7e65ee
|
| 217 |
+
215, 0x5499cf8a
|
| 218 |
+
216, 0xac28f775
|
| 219 |
+
217, 0x649840fb
|
| 220 |
+
218, 0xd4c54805
|
| 221 |
+
219, 0x1d166ba6
|
| 222 |
+
220, 0xbeb1171f
|
| 223 |
+
221, 0x45b66703
|
| 224 |
+
222, 0x78c03349
|
| 225 |
+
223, 0x38d2a6ff
|
| 226 |
+
224, 0x935cae8b
|
| 227 |
+
225, 0x1d07dc3f
|
| 228 |
+
226, 0x6c1ed365
|
| 229 |
+
227, 0x579fc585
|
| 230 |
+
228, 0x1320c0ec
|
| 231 |
+
229, 0x632757eb
|
| 232 |
+
230, 0xd265a397
|
| 233 |
+
231, 0x70e9b6c2
|
| 234 |
+
232, 0xc81e322c
|
| 235 |
+
233, 0xa27153cf
|
| 236 |
+
234, 0x2118ba19
|
| 237 |
+
235, 0x514ec400
|
| 238 |
+
236, 0x2bd0ecd6
|
| 239 |
+
237, 0xc3e7dae3
|
| 240 |
+
238, 0xfa39355e
|
| 241 |
+
239, 0x48f23cc1
|
| 242 |
+
240, 0xbcf75948
|
| 243 |
+
241, 0x53ccc70c
|
| 244 |
+
242, 0x75346423
|
| 245 |
+
243, 0x951181e0
|
| 246 |
+
244, 0x348e90df
|
| 247 |
+
245, 0x14365d7f
|
| 248 |
+
246, 0xfbc95d7a
|
| 249 |
+
247, 0xdc98a9e6
|
| 250 |
+
248, 0xed202df7
|
| 251 |
+
249, 0xa59ec913
|
| 252 |
+
250, 0x6b6e9ae2
|
| 253 |
+
251, 0x1697f265
|
| 254 |
+
252, 0x15d322d0
|
| 255 |
+
253, 0xa2e7ee0a
|
| 256 |
+
254, 0x88860b7e
|
| 257 |
+
255, 0x455d8b9d
|
| 258 |
+
256, 0x2f5c59cb
|
| 259 |
+
257, 0xac49c9f1
|
| 260 |
+
258, 0xa6a6a039
|
| 261 |
+
259, 0xc057f56b
|
| 262 |
+
260, 0xf1ff1208
|
| 263 |
+
261, 0x5eb8dc9d
|
| 264 |
+
262, 0xe6702509
|
| 265 |
+
263, 0xe238b0ed
|
| 266 |
+
264, 0x5ae32e3d
|
| 267 |
+
265, 0xa88ebbdf
|
| 268 |
+
266, 0xef885ae7
|
| 269 |
+
267, 0xafa6d49b
|
| 270 |
+
268, 0xc94499e0
|
| 271 |
+
269, 0x1a196325
|
| 272 |
+
270, 0x88938da3
|
| 273 |
+
271, 0x14f4345
|
| 274 |
+
272, 0xd8e33637
|
| 275 |
+
273, 0xa3551bd5
|
| 276 |
+
274, 0x73fe35c7
|
| 277 |
+
275, 0x9561e94b
|
| 278 |
+
276, 0xd673bf68
|
| 279 |
+
277, 0x16134872
|
| 280 |
+
278, 0x68c42f9f
|
| 281 |
+
279, 0xdf7574c8
|
| 282 |
+
280, 0x8809bab9
|
| 283 |
+
281, 0x1432cf69
|
| 284 |
+
282, 0xafb66bf1
|
| 285 |
+
283, 0xc184aa7b
|
| 286 |
+
284, 0xedbf2007
|
| 287 |
+
285, 0xbd420ce1
|
| 288 |
+
286, 0x761033a0
|
| 289 |
+
287, 0xff7e351f
|
| 290 |
+
288, 0xd6c3780e
|
| 291 |
+
289, 0x5844416f
|
| 292 |
+
290, 0xc6c0ee1c
|
| 293 |
+
291, 0xd2e147db
|
| 294 |
+
292, 0x92ac601a
|
| 295 |
+
293, 0x393e846b
|
| 296 |
+
294, 0x18196cca
|
| 297 |
+
295, 0x54a22be
|
| 298 |
+
296, 0x32bab1c4
|
| 299 |
+
297, 0x60365183
|
| 300 |
+
298, 0x64fa342
|
| 301 |
+
299, 0xca24a493
|
| 302 |
+
300, 0xd8cc8b83
|
| 303 |
+
301, 0x3faf102b
|
| 304 |
+
302, 0x6e09bb58
|
| 305 |
+
303, 0x812f0ea
|
| 306 |
+
304, 0x592c95d8
|
| 307 |
+
305, 0xe45ea4c5
|
| 308 |
+
306, 0x23aebf83
|
| 309 |
+
307, 0xbd9691d4
|
| 310 |
+
308, 0xf47b4baa
|
| 311 |
+
309, 0x4ac7b487
|
| 312 |
+
310, 0xcce18803
|
| 313 |
+
311, 0x3377556e
|
| 314 |
+
312, 0x3ff8e6b6
|
| 315 |
+
313, 0x99d22063
|
| 316 |
+
314, 0x23250bec
|
| 317 |
+
315, 0x4e1f9861
|
| 318 |
+
316, 0x8554249b
|
| 319 |
+
317, 0x8635c2fc
|
| 320 |
+
318, 0xe8426e8a
|
| 321 |
+
319, 0x966c29d8
|
| 322 |
+
320, 0x270b6082
|
| 323 |
+
321, 0x3180a8a1
|
| 324 |
+
322, 0xe7e1668b
|
| 325 |
+
323, 0x7f868dc
|
| 326 |
+
324, 0xcf4c17cf
|
| 327 |
+
325, 0xe31de4d1
|
| 328 |
+
326, 0xc8c8aff4
|
| 329 |
+
327, 0xae8db704
|
| 330 |
+
328, 0x3c928cc2
|
| 331 |
+
329, 0xe12cd48
|
| 332 |
+
330, 0xb33ecd04
|
| 333 |
+
331, 0xb93d7cbe
|
| 334 |
+
332, 0x49c69d6a
|
| 335 |
+
333, 0x7d3bce64
|
| 336 |
+
334, 0x86bc219
|
| 337 |
+
335, 0x8408233b
|
| 338 |
+
336, 0x44dc7479
|
| 339 |
+
337, 0xdf80d538
|
| 340 |
+
338, 0xf3db02c3
|
| 341 |
+
339, 0xbbbd31d7
|
| 342 |
+
340, 0x121281f
|
| 343 |
+
341, 0x7521e9a3
|
| 344 |
+
342, 0x8859675a
|
| 345 |
+
343, 0x75aa6502
|
| 346 |
+
344, 0x430ed15b
|
| 347 |
+
345, 0xecf0a28d
|
| 348 |
+
346, 0x659774fd
|
| 349 |
+
347, 0xd58a2311
|
| 350 |
+
348, 0x512389a9
|
| 351 |
+
349, 0xff65e1ff
|
| 352 |
+
350, 0xb6ddf222
|
| 353 |
+
351, 0xe3458895
|
| 354 |
+
352, 0x8b13cd6e
|
| 355 |
+
353, 0xd4a22870
|
| 356 |
+
354, 0xe604c50c
|
| 357 |
+
355, 0x27f54f26
|
| 358 |
+
356, 0x8f7f422f
|
| 359 |
+
357, 0x9735b4cf
|
| 360 |
+
358, 0x414072b0
|
| 361 |
+
359, 0x76a1c6d5
|
| 362 |
+
360, 0xa2208c06
|
| 363 |
+
361, 0x83cd0f61
|
| 364 |
+
362, 0x6c4f7ead
|
| 365 |
+
363, 0x6553cf76
|
| 366 |
+
364, 0xeffcf44
|
| 367 |
+
365, 0x7f434a3f
|
| 368 |
+
366, 0x9dc364bd
|
| 369 |
+
367, 0x3cdf52ed
|
| 370 |
+
368, 0xad597594
|
| 371 |
+
369, 0x9c3e211b
|
| 372 |
+
370, 0x6c04a33f
|
| 373 |
+
371, 0x885dafa6
|
| 374 |
+
372, 0xbbdaca71
|
| 375 |
+
373, 0x7ae5dd5c
|
| 376 |
+
374, 0x37675644
|
| 377 |
+
375, 0x251853c6
|
| 378 |
+
376, 0x130b086b
|
| 379 |
+
377, 0x143fa54b
|
| 380 |
+
378, 0x54cdc282
|
| 381 |
+
379, 0x9faff5b3
|
| 382 |
+
380, 0x502a5c8b
|
| 383 |
+
381, 0xd9524550
|
| 384 |
+
382, 0xae221aa6
|
| 385 |
+
383, 0x55cf759b
|
| 386 |
+
384, 0x24782da4
|
| 387 |
+
385, 0xd715d815
|
| 388 |
+
386, 0x250ea09a
|
| 389 |
+
387, 0x4e0744ac
|
| 390 |
+
388, 0x11e15814
|
| 391 |
+
389, 0xabe5f9df
|
| 392 |
+
390, 0xc8146350
|
| 393 |
+
391, 0xfba67d9b
|
| 394 |
+
392, 0x2b82e42f
|
| 395 |
+
393, 0xd4ea96fc
|
| 396 |
+
394, 0x5ffc179e
|
| 397 |
+
395, 0x1598bafe
|
| 398 |
+
396, 0x7fb6d662
|
| 399 |
+
397, 0x1a12a0db
|
| 400 |
+
398, 0x450cee4a
|
| 401 |
+
399, 0x85f8e12
|
| 402 |
+
400, 0xce71b594
|
| 403 |
+
401, 0xd4bb1d19
|
| 404 |
+
402, 0x968f379d
|
| 405 |
+
403, 0x54cc1d52
|
| 406 |
+
404, 0x467e6066
|
| 407 |
+
405, 0x7da5f9a9
|
| 408 |
+
406, 0x70977034
|
| 409 |
+
407, 0x49e65c4b
|
| 410 |
+
408, 0xd08570d1
|
| 411 |
+
409, 0x7acdf60b
|
| 412 |
+
410, 0xdffa038b
|
| 413 |
+
411, 0x9ce14e4c
|
| 414 |
+
412, 0x107cbbf8
|
| 415 |
+
413, 0xdd746ca0
|
| 416 |
+
414, 0xc6370a46
|
| 417 |
+
415, 0xe7f83312
|
| 418 |
+
416, 0x373fa9ce
|
| 419 |
+
417, 0xd822a2c6
|
| 420 |
+
418, 0x1d4efea6
|
| 421 |
+
419, 0xc53dcadb
|
| 422 |
+
420, 0x9b4e898f
|
| 423 |
+
421, 0x71daa6bf
|
| 424 |
+
422, 0x7a0bc78b
|
| 425 |
+
423, 0xd7b86f50
|
| 426 |
+
424, 0x1b8b3286
|
| 427 |
+
425, 0xcf9425dd
|
| 428 |
+
426, 0xd5263220
|
| 429 |
+
427, 0x4ea0b647
|
| 430 |
+
428, 0xc767fe64
|
| 431 |
+
429, 0xcfc5e67
|
| 432 |
+
430, 0xcc6a2942
|
| 433 |
+
431, 0xa51eff00
|
| 434 |
+
432, 0x76092e1b
|
| 435 |
+
433, 0xf606e80f
|
| 436 |
+
434, 0x824b5e20
|
| 437 |
+
435, 0xebb55e14
|
| 438 |
+
436, 0x783d96a6
|
| 439 |
+
437, 0x10696512
|
| 440 |
+
438, 0x17ee510a
|
| 441 |
+
439, 0x3ab70a1f
|
| 442 |
+
440, 0xcce6b210
|
| 443 |
+
441, 0x8f72f0fb
|
| 444 |
+
442, 0xf0610b41
|
| 445 |
+
443, 0x83d01fb5
|
| 446 |
+
444, 0x6b3de36
|
| 447 |
+
445, 0xe4c2e84f
|
| 448 |
+
446, 0x9c43bb15
|
| 449 |
+
447, 0xddf2905
|
| 450 |
+
448, 0x7dd63556
|
| 451 |
+
449, 0x3662ca09
|
| 452 |
+
450, 0xfb81f35b
|
| 453 |
+
451, 0xc2c8a72a
|
| 454 |
+
452, 0x8e93c37
|
| 455 |
+
453, 0xa93da2d4
|
| 456 |
+
454, 0xa03af8f1
|
| 457 |
+
455, 0x8d75159a
|
| 458 |
+
456, 0x15f010b0
|
| 459 |
+
457, 0xa296ab06
|
| 460 |
+
458, 0xe55962ba
|
| 461 |
+
459, 0xeae700a9
|
| 462 |
+
460, 0xe388964a
|
| 463 |
+
461, 0x917f2bec
|
| 464 |
+
462, 0x1c203fea
|
| 465 |
+
463, 0x792a01ba
|
| 466 |
+
464, 0xa93a80ac
|
| 467 |
+
465, 0x9eb8a197
|
| 468 |
+
466, 0x56c0bc73
|
| 469 |
+
467, 0xb8f05799
|
| 470 |
+
468, 0xf429a8c8
|
| 471 |
+
469, 0xb92cee42
|
| 472 |
+
470, 0xf8864ec
|
| 473 |
+
471, 0x62f2518a
|
| 474 |
+
472, 0x3a7bfa3e
|
| 475 |
+
473, 0x12e56e6d
|
| 476 |
+
474, 0xd7a18313
|
| 477 |
+
475, 0x41fa3899
|
| 478 |
+
476, 0xa09c4956
|
| 479 |
+
477, 0xebcfd94a
|
| 480 |
+
478, 0xc485f90b
|
| 481 |
+
479, 0x4391ce40
|
| 482 |
+
480, 0x742a3333
|
| 483 |
+
481, 0xc932f9e5
|
| 484 |
+
482, 0x75c6c263
|
| 485 |
+
483, 0x80937f0
|
| 486 |
+
484, 0xcf21833c
|
| 487 |
+
485, 0x16027520
|
| 488 |
+
486, 0xd42e669f
|
| 489 |
+
487, 0xb0f01fb7
|
| 490 |
+
488, 0xb35896f1
|
| 491 |
+
489, 0x763737a9
|
| 492 |
+
490, 0x1bb20209
|
| 493 |
+
491, 0x3551f189
|
| 494 |
+
492, 0x56bc2602
|
| 495 |
+
493, 0xb6eacf4
|
| 496 |
+
494, 0x42ec4d11
|
| 497 |
+
495, 0x245cc68
|
| 498 |
+
496, 0xc27ac43b
|
| 499 |
+
497, 0x9d903466
|
| 500 |
+
498, 0xce3f0c05
|
| 501 |
+
499, 0xb708c31c
|
| 502 |
+
500, 0xc0fd37eb
|
| 503 |
+
501, 0x95938b2c
|
| 504 |
+
502, 0xf20175a7
|
| 505 |
+
503, 0x4a86ee9b
|
| 506 |
+
504, 0xbe039a58
|
| 507 |
+
505, 0xd41cabe7
|
| 508 |
+
506, 0x83bc99ba
|
| 509 |
+
507, 0x761d60e1
|
| 510 |
+
508, 0x7737cc2e
|
| 511 |
+
509, 0x2b82fc4b
|
| 512 |
+
510, 0x375aa401
|
| 513 |
+
511, 0xfe9597a0
|
| 514 |
+
512, 0x5543806a
|
| 515 |
+
513, 0x44f31238
|
| 516 |
+
514, 0x7df31538
|
| 517 |
+
515, 0x74cfa770
|
| 518 |
+
516, 0x8755d881
|
| 519 |
+
517, 0x1fde665a
|
| 520 |
+
518, 0xda8bf315
|
| 521 |
+
519, 0x973d8e95
|
| 522 |
+
520, 0x72205228
|
| 523 |
+
521, 0x8fe59717
|
| 524 |
+
522, 0x7bb90b34
|
| 525 |
+
523, 0xef6ed945
|
| 526 |
+
524, 0x16fd4a38
|
| 527 |
+
525, 0x5db44de1
|
| 528 |
+
526, 0xf09f93b3
|
| 529 |
+
527, 0xe84824cc
|
| 530 |
+
528, 0x945bb50e
|
| 531 |
+
529, 0xd0be4aa5
|
| 532 |
+
530, 0x47c277c2
|
| 533 |
+
531, 0xd3800c28
|
| 534 |
+
532, 0xac1c33ec
|
| 535 |
+
533, 0xd3dacce
|
| 536 |
+
534, 0x811c8387
|
| 537 |
+
535, 0x6761b36
|
| 538 |
+
536, 0x70d3882f
|
| 539 |
+
537, 0xd6e62e3a
|
| 540 |
+
538, 0xea25daa2
|
| 541 |
+
539, 0xb07f39d1
|
| 542 |
+
540, 0x391d89d7
|
| 543 |
+
541, 0x84b6fb5e
|
| 544 |
+
542, 0x3dda3fca
|
| 545 |
+
543, 0x229e80a4
|
| 546 |
+
544, 0x3d94a4b7
|
| 547 |
+
545, 0x5d3d576a
|
| 548 |
+
546, 0xad7818a0
|
| 549 |
+
547, 0xce23b03a
|
| 550 |
+
548, 0x7aa2079c
|
| 551 |
+
549, 0x9a6be555
|
| 552 |
+
550, 0x83f3b34a
|
| 553 |
+
551, 0x1848f9d9
|
| 554 |
+
552, 0xd8fefc1c
|
| 555 |
+
553, 0x48e6ce48
|
| 556 |
+
554, 0x52e55750
|
| 557 |
+
555, 0xf41a71cf
|
| 558 |
+
556, 0xba08e259
|
| 559 |
+
557, 0xfaf06a15
|
| 560 |
+
558, 0xeaaac0fb
|
| 561 |
+
559, 0x34f90098
|
| 562 |
+
560, 0xb1dfffbb
|
| 563 |
+
561, 0x718daec2
|
| 564 |
+
562, 0xab4dda21
|
| 565 |
+
563, 0xd27cc1ee
|
| 566 |
+
564, 0x4aafbc4c
|
| 567 |
+
565, 0x356dfb4f
|
| 568 |
+
566, 0x83fcdfd6
|
| 569 |
+
567, 0x8f0bcde0
|
| 570 |
+
568, 0x4363f844
|
| 571 |
+
569, 0xadc0f4d5
|
| 572 |
+
570, 0x3bde994e
|
| 573 |
+
571, 0x3884d452
|
| 574 |
+
572, 0x21876b4a
|
| 575 |
+
573, 0x9c985398
|
| 576 |
+
574, 0xca55a226
|
| 577 |
+
575, 0x3a88c583
|
| 578 |
+
576, 0x916dc33c
|
| 579 |
+
577, 0x8f67d1d7
|
| 580 |
+
578, 0x3b26a667
|
| 581 |
+
579, 0xe4ddeb4b
|
| 582 |
+
580, 0x1a9d8c33
|
| 583 |
+
581, 0x81c9b74f
|
| 584 |
+
582, 0x9ed1e9df
|
| 585 |
+
583, 0x6e61aecf
|
| 586 |
+
584, 0x95e95a5d
|
| 587 |
+
585, 0x68864ff5
|
| 588 |
+
586, 0xb8fa5b9
|
| 589 |
+
587, 0x72b1b3de
|
| 590 |
+
588, 0x5e18a86b
|
| 591 |
+
589, 0xd7f2337d
|
| 592 |
+
590, 0xd70e0925
|
| 593 |
+
591, 0xb573a4c1
|
| 594 |
+
592, 0xc77b3f8a
|
| 595 |
+
593, 0x389b20de
|
| 596 |
+
594, 0x16cf6afb
|
| 597 |
+
595, 0xa39bd275
|
| 598 |
+
596, 0xf491cf01
|
| 599 |
+
597, 0x6f88a802
|
| 600 |
+
598, 0x8510af05
|
| 601 |
+
599, 0xe7cd549a
|
| 602 |
+
600, 0x8603179a
|
| 603 |
+
601, 0xef43f191
|
| 604 |
+
602, 0xf9b64c60
|
| 605 |
+
603, 0xb00254a7
|
| 606 |
+
604, 0xd7c06a2d
|
| 607 |
+
605, 0x17e9380b
|
| 608 |
+
606, 0x529e727b
|
| 609 |
+
607, 0xaaa8fe0a
|
| 610 |
+
608, 0xfb64ff4c
|
| 611 |
+
609, 0xcd75af26
|
| 612 |
+
610, 0xfb717c87
|
| 613 |
+
611, 0xa0789899
|
| 614 |
+
612, 0x10391ec9
|
| 615 |
+
613, 0x7e9b40b3
|
| 616 |
+
614, 0x18536554
|
| 617 |
+
615, 0x728c05f7
|
| 618 |
+
616, 0x787dca98
|
| 619 |
+
617, 0xad948d1
|
| 620 |
+
618, 0x44c18def
|
| 621 |
+
619, 0x3303f2ec
|
| 622 |
+
620, 0xa15acb5
|
| 623 |
+
621, 0xb58d38f4
|
| 624 |
+
622, 0xfe041ef8
|
| 625 |
+
623, 0xd151a956
|
| 626 |
+
624, 0x7b9168e8
|
| 627 |
+
625, 0x5ebeca06
|
| 628 |
+
626, 0x90fe95df
|
| 629 |
+
627, 0xf76875aa
|
| 630 |
+
628, 0xb2e0d664
|
| 631 |
+
629, 0x2e3253b7
|
| 632 |
+
630, 0x68e34469
|
| 633 |
+
631, 0x1f0c2d89
|
| 634 |
+
632, 0x13a34ac2
|
| 635 |
+
633, 0x5ffeb841
|
| 636 |
+
634, 0xe381e91c
|
| 637 |
+
635, 0xb8549a92
|
| 638 |
+
636, 0x3f35cf1
|
| 639 |
+
637, 0xda0f9dcb
|
| 640 |
+
638, 0xdd9828a6
|
| 641 |
+
639, 0xe1428f29
|
| 642 |
+
640, 0xf4db80b5
|
| 643 |
+
641, 0xdac30af5
|
| 644 |
+
642, 0x1af1dd17
|
| 645 |
+
643, 0x9a540254
|
| 646 |
+
644, 0xcab68a38
|
| 647 |
+
645, 0x33560361
|
| 648 |
+
646, 0x2fbf3886
|
| 649 |
+
647, 0xbc785923
|
| 650 |
+
648, 0xe081cd10
|
| 651 |
+
649, 0x8e473356
|
| 652 |
+
650, 0xd102c357
|
| 653 |
+
651, 0xeea4fe48
|
| 654 |
+
652, 0x248d3453
|
| 655 |
+
653, 0x1da79ac
|
| 656 |
+
654, 0x815a65ff
|
| 657 |
+
655, 0x27693e76
|
| 658 |
+
656, 0xb7d5af40
|
| 659 |
+
657, 0x6d245d30
|
| 660 |
+
658, 0x9e06fa8f
|
| 661 |
+
659, 0xb0570dcb
|
| 662 |
+
660, 0x469f0005
|
| 663 |
+
661, 0x3e0ca132
|
| 664 |
+
662, 0xd89bbf3
|
| 665 |
+
663, 0xd61ccd47
|
| 666 |
+
664, 0x6383878
|
| 667 |
+
665, 0x62b5956
|
| 668 |
+
666, 0x4dc83675
|
| 669 |
+
667, 0x93fd8492
|
| 670 |
+
668, 0x5a0091f5
|
| 671 |
+
669, 0xc9f9bc3
|
| 672 |
+
670, 0xa26e7778
|
| 673 |
+
671, 0xeabf2d01
|
| 674 |
+
672, 0xe612dc06
|
| 675 |
+
673, 0x85d89ff9
|
| 676 |
+
674, 0xd1763179
|
| 677 |
+
675, 0xcb88947b
|
| 678 |
+
676, 0x9e8757a5
|
| 679 |
+
677, 0xe100e85c
|
| 680 |
+
678, 0x904166eb
|
| 681 |
+
679, 0x4996243d
|
| 682 |
+
680, 0x4038e1cb
|
| 683 |
+
681, 0x2be2c63d
|
| 684 |
+
682, 0x77017e81
|
| 685 |
+
683, 0x3b1f556b
|
| 686 |
+
684, 0x1c785c77
|
| 687 |
+
685, 0x6869b8bd
|
| 688 |
+
686, 0xe1217ed4
|
| 689 |
+
687, 0x4012ab2f
|
| 690 |
+
688, 0xc06c0d8e
|
| 691 |
+
689, 0x2122eb68
|
| 692 |
+
690, 0xad1783fd
|
| 693 |
+
691, 0x5f0c80e3
|
| 694 |
+
692, 0x828f7efa
|
| 695 |
+
693, 0x29328399
|
| 696 |
+
694, 0xeadf1087
|
| 697 |
+
695, 0x85dc0037
|
| 698 |
+
696, 0x9691ef26
|
| 699 |
+
697, 0xc0947a53
|
| 700 |
+
698, 0x2a178d2a
|
| 701 |
+
699, 0x2a2c7e8f
|
| 702 |
+
700, 0x90378380
|
| 703 |
+
701, 0xaad8d326
|
| 704 |
+
702, 0x9cf1c3c8
|
| 705 |
+
703, 0x84eccd44
|
| 706 |
+
704, 0x79e61808
|
| 707 |
+
705, 0x8b3f454e
|
| 708 |
+
706, 0x209e6e1
|
| 709 |
+
707, 0x51f88378
|
| 710 |
+
708, 0xc210226f
|
| 711 |
+
709, 0xd982adb5
|
| 712 |
+
710, 0x55d44a31
|
| 713 |
+
711, 0x9817d443
|
| 714 |
+
712, 0xa328c626
|
| 715 |
+
713, 0x13455966
|
| 716 |
+
714, 0xb8f681d3
|
| 717 |
+
715, 0x2a3c713b
|
| 718 |
+
716, 0xc186959b
|
| 719 |
+
717, 0x814a74b0
|
| 720 |
+
718, 0xed7bc90
|
| 721 |
+
719, 0xa88d3d6d
|
| 722 |
+
720, 0x88a9f561
|
| 723 |
+
721, 0x73aa1c0a
|
| 724 |
+
722, 0xdfeff404
|
| 725 |
+
723, 0xec037e4b
|
| 726 |
+
724, 0xa5c209f0
|
| 727 |
+
725, 0xb3a223b4
|
| 728 |
+
726, 0x24ce3709
|
| 729 |
+
727, 0x3184c790
|
| 730 |
+
728, 0xa1398c62
|
| 731 |
+
729, 0x2f92034e
|
| 732 |
+
730, 0xbb37a79a
|
| 733 |
+
731, 0x605287b4
|
| 734 |
+
732, 0x8faa772c
|
| 735 |
+
733, 0x6ce56c1d
|
| 736 |
+
734, 0xc035fb4c
|
| 737 |
+
735, 0x7cf5b316
|
| 738 |
+
736, 0x6502645
|
| 739 |
+
737, 0xa283d810
|
| 740 |
+
738, 0x778bc2f1
|
| 741 |
+
739, 0xfdf99313
|
| 742 |
+
740, 0x1f513265
|
| 743 |
+
741, 0xbd3837e2
|
| 744 |
+
742, 0x9b84a9a
|
| 745 |
+
743, 0x2139ce91
|
| 746 |
+
744, 0x61a8e890
|
| 747 |
+
745, 0xf9ff12db
|
| 748 |
+
746, 0xb43d2ea7
|
| 749 |
+
747, 0x88532e61
|
| 750 |
+
748, 0x175a6655
|
| 751 |
+
749, 0x7a6c4f72
|
| 752 |
+
750, 0x6dafc1b7
|
| 753 |
+
751, 0x449b1459
|
| 754 |
+
752, 0x514f654f
|
| 755 |
+
753, 0x9a6731e2
|
| 756 |
+
754, 0x8632da43
|
| 757 |
+
755, 0xc81b0422
|
| 758 |
+
756, 0x81fe9005
|
| 759 |
+
757, 0x15b79618
|
| 760 |
+
758, 0xb5fa629f
|
| 761 |
+
759, 0x987a474f
|
| 762 |
+
760, 0x1c74f54e
|
| 763 |
+
761, 0xf9743232
|
| 764 |
+
762, 0xec4b55f
|
| 765 |
+
763, 0x87d761e5
|
| 766 |
+
764, 0xd1ad78b7
|
| 767 |
+
765, 0x453d9350
|
| 768 |
+
766, 0xc7a7d85
|
| 769 |
+
767, 0xb2576ff5
|
| 770 |
+
768, 0xcdde49b7
|
| 771 |
+
769, 0x8e1f763e
|
| 772 |
+
770, 0x1338583e
|
| 773 |
+
771, 0xfd65b9dc
|
| 774 |
+
772, 0x4f19c4f4
|
| 775 |
+
773, 0x3a52d73d
|
| 776 |
+
774, 0xd3509c4c
|
| 777 |
+
775, 0xda24fe31
|
| 778 |
+
776, 0xe2de56ba
|
| 779 |
+
777, 0x2db5e540
|
| 780 |
+
778, 0x23172734
|
| 781 |
+
779, 0x4db572f
|
| 782 |
+
780, 0xeb941718
|
| 783 |
+
781, 0x84c2649a
|
| 784 |
+
782, 0x3b1e5b6a
|
| 785 |
+
783, 0x4c9c61b9
|
| 786 |
+
784, 0x3bccd11
|
| 787 |
+
785, 0xb4d7b78e
|
| 788 |
+
786, 0x48580ae5
|
| 789 |
+
787, 0xd273ab68
|
| 790 |
+
788, 0x25c11615
|
| 791 |
+
789, 0x470b53f6
|
| 792 |
+
790, 0x329c2068
|
| 793 |
+
791, 0x1693721b
|
| 794 |
+
792, 0xf8c9aacf
|
| 795 |
+
793, 0x4c3d5693
|
| 796 |
+
794, 0xd778284e
|
| 797 |
+
795, 0xae1cb24f
|
| 798 |
+
796, 0x3c11d1b3
|
| 799 |
+
797, 0xddd2b0c0
|
| 800 |
+
798, 0x90269fa7
|
| 801 |
+
799, 0x5666e0a2
|
| 802 |
+
800, 0xf9f195a4
|
| 803 |
+
801, 0x61d78eb2
|
| 804 |
+
802, 0xada5a7c0
|
| 805 |
+
803, 0xaa272fbe
|
| 806 |
+
804, 0xba3bae2f
|
| 807 |
+
805, 0xd0b70fc2
|
| 808 |
+
806, 0x529f32b
|
| 809 |
+
807, 0xda7a3e21
|
| 810 |
+
808, 0x9a776a20
|
| 811 |
+
809, 0xb21f9635
|
| 812 |
+
810, 0xb3acc14e
|
| 813 |
+
811, 0xac55f56
|
| 814 |
+
812, 0x29dccf41
|
| 815 |
+
813, 0x32dabdb3
|
| 816 |
+
814, 0xaa032f58
|
| 817 |
+
815, 0xfa406af4
|
| 818 |
+
816, 0xce3c415d
|
| 819 |
+
817, 0xb44fb4d9
|
| 820 |
+
818, 0x32248d1c
|
| 821 |
+
819, 0x680c6440
|
| 822 |
+
820, 0xae2337b
|
| 823 |
+
821, 0x294cb597
|
| 824 |
+
822, 0x5bca48fe
|
| 825 |
+
823, 0xaef19f40
|
| 826 |
+
824, 0xad60406
|
| 827 |
+
825, 0x4781f090
|
| 828 |
+
826, 0xfd691ffc
|
| 829 |
+
827, 0xb6568268
|
| 830 |
+
828, 0xa56c72cb
|
| 831 |
+
829, 0xf8a9e0fc
|
| 832 |
+
830, 0x9af4fd02
|
| 833 |
+
831, 0x2cd30932
|
| 834 |
+
832, 0x776cefd7
|
| 835 |
+
833, 0xe31f476e
|
| 836 |
+
834, 0x6d94a437
|
| 837 |
+
835, 0xb3cab598
|
| 838 |
+
836, 0xf582d13f
|
| 839 |
+
837, 0x3bf8759d
|
| 840 |
+
838, 0xc3777dc
|
| 841 |
+
839, 0x5e425ea8
|
| 842 |
+
840, 0x1c7ff4ed
|
| 843 |
+
841, 0x1c2e97d1
|
| 844 |
+
842, 0xc062d2b4
|
| 845 |
+
843, 0x46dc80e0
|
| 846 |
+
844, 0xbcdb47e6
|
| 847 |
+
845, 0x32282fe0
|
| 848 |
+
846, 0xaba89063
|
| 849 |
+
847, 0x5e94e9bb
|
| 850 |
+
848, 0x3e667f78
|
| 851 |
+
849, 0xea6eb21a
|
| 852 |
+
850, 0xe56e54e8
|
| 853 |
+
851, 0xa0383510
|
| 854 |
+
852, 0x6768fe2b
|
| 855 |
+
853, 0xb53ac3e0
|
| 856 |
+
854, 0x779569a0
|
| 857 |
+
855, 0xeca83c6a
|
| 858 |
+
856, 0x24db4d2d
|
| 859 |
+
857, 0x4585f696
|
| 860 |
+
858, 0xf84748b2
|
| 861 |
+
859, 0xf6a4dd5b
|
| 862 |
+
860, 0x31fb524d
|
| 863 |
+
861, 0x67ab39fe
|
| 864 |
+
862, 0x5882a899
|
| 865 |
+
863, 0x9a05fcf6
|
| 866 |
+
864, 0x712b5674
|
| 867 |
+
865, 0xe8c6958f
|
| 868 |
+
866, 0x4b448bb3
|
| 869 |
+
867, 0x530b9abf
|
| 870 |
+
868, 0xb491f491
|
| 871 |
+
869, 0x98352c62
|
| 872 |
+
870, 0x2d0a50e3
|
| 873 |
+
871, 0xeb4384da
|
| 874 |
+
872, 0x36246f07
|
| 875 |
+
873, 0xcbc5c1a
|
| 876 |
+
874, 0xae24031d
|
| 877 |
+
875, 0x44d11ed6
|
| 878 |
+
876, 0xf07f1608
|
| 879 |
+
877, 0xf296aadd
|
| 880 |
+
878, 0x3bcfe3be
|
| 881 |
+
879, 0x8fa1e7df
|
| 882 |
+
880, 0xfd317a6e
|
| 883 |
+
881, 0xe4975c44
|
| 884 |
+
882, 0x15205892
|
| 885 |
+
883, 0xa762d4df
|
| 886 |
+
884, 0xf1167365
|
| 887 |
+
885, 0x6811cc00
|
| 888 |
+
886, 0x8315f23
|
| 889 |
+
887, 0xe045b4b1
|
| 890 |
+
888, 0xa8496414
|
| 891 |
+
889, 0xbed313ae
|
| 892 |
+
890, 0xcdae3ddb
|
| 893 |
+
891, 0xa9c22c9
|
| 894 |
+
892, 0x275fab1a
|
| 895 |
+
893, 0xedd65fa
|
| 896 |
+
894, 0x4c188229
|
| 897 |
+
895, 0x63a83e58
|
| 898 |
+
896, 0x18aa9207
|
| 899 |
+
897, 0xa41f2e78
|
| 900 |
+
898, 0xd9f63653
|
| 901 |
+
899, 0xbe2be73b
|
| 902 |
+
900, 0xa3364d39
|
| 903 |
+
901, 0x896d5428
|
| 904 |
+
902, 0xc737539e
|
| 905 |
+
903, 0x745a78c6
|
| 906 |
+
904, 0xf0b2b042
|
| 907 |
+
905, 0x510773b4
|
| 908 |
+
906, 0x92ad8e37
|
| 909 |
+
907, 0x27f2f8c4
|
| 910 |
+
908, 0x23704cc8
|
| 911 |
+
909, 0x3d95a77f
|
| 912 |
+
910, 0xf08587a4
|
| 913 |
+
911, 0xbd696a25
|
| 914 |
+
912, 0x948924f3
|
| 915 |
+
913, 0x8cddb634
|
| 916 |
+
914, 0xcd2a4910
|
| 917 |
+
915, 0x8e0e300e
|
| 918 |
+
916, 0x83815a9b
|
| 919 |
+
917, 0x67383510
|
| 920 |
+
918, 0x3c18f0d0
|
| 921 |
+
919, 0xc7a7bccc
|
| 922 |
+
920, 0x7cc2d3a2
|
| 923 |
+
921, 0x52eb2eeb
|
| 924 |
+
922, 0xe4a257e5
|
| 925 |
+
923, 0xec76160e
|
| 926 |
+
924, 0x63f9ad68
|
| 927 |
+
925, 0x36d0bbbf
|
| 928 |
+
926, 0x957bc4e4
|
| 929 |
+
927, 0xc9ed90ff
|
| 930 |
+
928, 0x4cb6059d
|
| 931 |
+
929, 0x2f86eca1
|
| 932 |
+
930, 0x3e3665a3
|
| 933 |
+
931, 0x9b7eb6f4
|
| 934 |
+
932, 0x492e7e18
|
| 935 |
+
933, 0xa098aa51
|
| 936 |
+
934, 0x7eb568b2
|
| 937 |
+
935, 0x3fd639ba
|
| 938 |
+
936, 0x7bebcf1
|
| 939 |
+
937, 0x99c844ad
|
| 940 |
+
938, 0x43cb5ec7
|
| 941 |
+
939, 0x8dfbbef5
|
| 942 |
+
940, 0x5be413ff
|
| 943 |
+
941, 0xd93b976d
|
| 944 |
+
942, 0xc1c7a86d
|
| 945 |
+
943, 0x1f0e93d0
|
| 946 |
+
944, 0x498204a2
|
| 947 |
+
945, 0xe8fe832a
|
| 948 |
+
946, 0x2236bd7
|
| 949 |
+
947, 0x89953769
|
| 950 |
+
948, 0x2acc3491
|
| 951 |
+
949, 0x2c4f22c6
|
| 952 |
+
950, 0xd7996277
|
| 953 |
+
951, 0x3bcdc349
|
| 954 |
+
952, 0xfc286630
|
| 955 |
+
953, 0x5f8909fd
|
| 956 |
+
954, 0x242677c0
|
| 957 |
+
955, 0x4cb34104
|
| 958 |
+
956, 0xa6ff8100
|
| 959 |
+
957, 0x39ea47ec
|
| 960 |
+
958, 0x9bd54140
|
| 961 |
+
959, 0x7502ffe8
|
| 962 |
+
960, 0x7ebef8ae
|
| 963 |
+
961, 0x1ed8abe4
|
| 964 |
+
962, 0xfaba8450
|
| 965 |
+
963, 0xc197b65f
|
| 966 |
+
964, 0x19431455
|
| 967 |
+
965, 0xe229c176
|
| 968 |
+
966, 0xeb2967da
|
| 969 |
+
967, 0xe0c5dc05
|
| 970 |
+
968, 0xa84e3227
|
| 971 |
+
969, 0x10dd9e0f
|
| 972 |
+
970, 0xbdb70b02
|
| 973 |
+
971, 0xce24808a
|
| 974 |
+
972, 0x423edab8
|
| 975 |
+
973, 0x194caf71
|
| 976 |
+
974, 0x144f150d
|
| 977 |
+
975, 0xf811c2d2
|
| 978 |
+
976, 0xc224ee85
|
| 979 |
+
977, 0x2b217a5b
|
| 980 |
+
978, 0xf78a5a79
|
| 981 |
+
979, 0x6554a4b1
|
| 982 |
+
980, 0x769582df
|
| 983 |
+
981, 0xf4b2cf93
|
| 984 |
+
982, 0x89648483
|
| 985 |
+
983, 0xb3283a3e
|
| 986 |
+
984, 0x82b895db
|
| 987 |
+
985, 0x79388ef0
|
| 988 |
+
986, 0x54bc42a6
|
| 989 |
+
987, 0xc4dd39d9
|
| 990 |
+
988, 0x45b33b7d
|
| 991 |
+
989, 0x8703b2c1
|
| 992 |
+
990, 0x1cc94806
|
| 993 |
+
991, 0xe0f43e49
|
| 994 |
+
992, 0xcaa7b6bc
|
| 995 |
+
993, 0x4f88e9af
|
| 996 |
+
994, 0x1477cce5
|
| 997 |
+
995, 0x347dd115
|
| 998 |
+
996, 0x36e335fa
|
| 999 |
+
997, 0xb93c9a31
|
| 1000 |
+
998, 0xaac3a175
|
| 1001 |
+
999, 0x68a19647
|
deepseekvl2/lib/python3.10/site-packages/numpy/random/tests/data/mt19937-testset-2.csv
ADDED
|
@@ -0,0 +1,1001 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 25 |
+
23, 0x9c90034d
|
| 26 |
+
24, 0x1f17a796
|
| 27 |
+
25, 0x3833caa8
|
| 28 |
+
26, 0xb8795528
|
| 29 |
+
27, 0xebc595a2
|
| 30 |
+
28, 0xf8f5b5dd
|
| 31 |
+
29, 0xc2881f72
|
| 32 |
+
30, 0x18e5d3f0
|
| 33 |
+
31, 0x9b19ac7a
|
| 34 |
+
32, 0xb9992436
|
| 35 |
+
33, 0xc00052b3
|
| 36 |
+
34, 0xb63f4475
|
| 37 |
+
35, 0x962642d9
|
| 38 |
+
36, 0x63506c10
|
| 39 |
+
37, 0x2be6b127
|
| 40 |
+
38, 0x569bdbc6
|
| 41 |
+
39, 0x7f185e01
|
| 42 |
+
40, 0xebb55f53
|
| 43 |
+
41, 0x1c30198c
|
| 44 |
+
42, 0x7c8d75c6
|
| 45 |
+
43, 0xd3f2186b
|
| 46 |
+
44, 0xaca5b9b1
|
| 47 |
+
45, 0xbc49ff45
|
| 48 |
+
46, 0xc4a802af
|
| 49 |
+
47, 0x2cecd86f
|
| 50 |
+
48, 0x8e0da529
|
| 51 |
+
49, 0x1f22b00e
|
| 52 |
+
50, 0x4559ea80
|
| 53 |
+
51, 0x60f587d8
|
| 54 |
+
52, 0x7c7460e9
|
| 55 |
+
53, 0x67be0a4a
|
| 56 |
+
54, 0x987a0183
|
| 57 |
+
55, 0x7bd30f1
|
| 58 |
+
56, 0xab18c4ac
|
| 59 |
+
57, 0xffdbfb64
|
| 60 |
+
58, 0x9ea917f9
|
| 61 |
+
59, 0x1239dab7
|
| 62 |
+
60, 0x38efabeb
|
| 63 |
+
61, 0x5da91888
|
| 64 |
+
62, 0x8f49ed62
|
| 65 |
+
63, 0x83f60b1e
|
| 66 |
+
64, 0x5950a3fc
|
| 67 |
+
65, 0xd8911104
|
| 68 |
+
66, 0x19e8859e
|
| 69 |
+
67, 0x1a4d89ec
|
| 70 |
+
68, 0x968ca180
|
| 71 |
+
69, 0x9e1b6da3
|
| 72 |
+
70, 0x3d99c2c
|
| 73 |
+
71, 0x55f76289
|
| 74 |
+
72, 0x8fa28b9e
|
| 75 |
+
73, 0x9fe01d33
|
| 76 |
+
74, 0xdade4e38
|
| 77 |
+
75, 0x1ea04290
|
| 78 |
+
76, 0xa7263313
|
| 79 |
+
77, 0xaafc762e
|
| 80 |
+
78, 0x460476d6
|
| 81 |
+
79, 0x31226e12
|
| 82 |
+
80, 0x451d3f05
|
| 83 |
+
81, 0xd0d2764b
|
| 84 |
+
82, 0xd06e1ab3
|
| 85 |
+
83, 0x1394e3f4
|
| 86 |
+
84, 0x2fc04ea3
|
| 87 |
+
85, 0x5b8401c
|
| 88 |
+
86, 0xebd6c929
|
| 89 |
+
87, 0xe881687c
|
| 90 |
+
88, 0x94bdd66a
|
| 91 |
+
89, 0xabf85983
|
| 92 |
+
90, 0x223ad12d
|
| 93 |
+
91, 0x2aaeeaa3
|
| 94 |
+
92, 0x1f704934
|
| 95 |
+
93, 0x2db2efb6
|
| 96 |
+
94, 0xf49b8dfb
|
| 97 |
+
95, 0x5bdbbb9d
|
| 98 |
+
96, 0xba0cd0db
|
| 99 |
+
97, 0x4ec4674e
|
| 100 |
+
98, 0xad0129e
|
| 101 |
+
99, 0x7a66129b
|
| 102 |
+
100, 0x50d12c5e
|
| 103 |
+
101, 0x85b1d335
|
| 104 |
+
102, 0x3efda58a
|
| 105 |
+
103, 0xecd886fb
|
| 106 |
+
104, 0x8ecadd3d
|
| 107 |
+
105, 0x60ebac0f
|
| 108 |
+
106, 0x5e10fe79
|
| 109 |
+
107, 0xa84f7e5d
|
| 110 |
+
108, 0x43931288
|
| 111 |
+
109, 0xfacf448
|
| 112 |
+
110, 0x4ee01997
|
| 113 |
+
111, 0xcdc0a651
|
| 114 |
+
112, 0x33c87037
|
| 115 |
+
113, 0x8b50fc03
|
| 116 |
+
114, 0xf52aad34
|
| 117 |
+
115, 0xda6cd856
|
| 118 |
+
116, 0x7585bea0
|
| 119 |
+
117, 0xe947c762
|
| 120 |
+
118, 0x4ddff5d8
|
| 121 |
+
119, 0xe0e79b3b
|
| 122 |
+
120, 0xb804cf09
|
| 123 |
+
121, 0x84765c44
|
| 124 |
+
122, 0x3ff666b4
|
| 125 |
+
123, 0xe31621ad
|
| 126 |
+
124, 0x816f2236
|
| 127 |
+
125, 0x228176bc
|
| 128 |
+
126, 0xfdc14904
|
| 129 |
+
127, 0x635f5077
|
| 130 |
+
128, 0x6981a817
|
| 131 |
+
129, 0xfd9a0300
|
| 132 |
+
130, 0xd3fa8a24
|
| 133 |
+
131, 0xd67c1a77
|
| 134 |
+
132, 0x903fe97a
|
| 135 |
+
133, 0xf7c4a4d5
|
| 136 |
+
134, 0x109f2058
|
| 137 |
+
135, 0x48ab87fe
|
| 138 |
+
136, 0xfd6f1928
|
| 139 |
+
137, 0x707e9452
|
| 140 |
+
138, 0xf327db9e
|
| 141 |
+
139, 0x7b80d76d
|
| 142 |
+
140, 0xfb6ba193
|
| 143 |
+
141, 0x454a1ad0
|
| 144 |
+
142, 0xe20b51e
|
| 145 |
+
143, 0xb774d085
|
| 146 |
+
144, 0x6b1ed574
|
| 147 |
+
145, 0xb1e77de4
|
| 148 |
+
146, 0xe2a83b37
|
| 149 |
+
147, 0x33d3176f
|
| 150 |
+
148, 0x2f0ca0fc
|
| 151 |
+
149, 0x17f51e2
|
| 152 |
+
150, 0x7c1fbf55
|
| 153 |
+
151, 0xf09e9cd0
|
| 154 |
+
152, 0xe3d9bacd
|
| 155 |
+
153, 0x4244db0a
|
| 156 |
+
154, 0x876c09fc
|
| 157 |
+
155, 0x9db4fc2f
|
| 158 |
+
156, 0xd3771d60
|
| 159 |
+
157, 0x25fc6a75
|
| 160 |
+
158, 0xb309915c
|
| 161 |
+
159, 0xc50ee027
|
| 162 |
+
160, 0xaa5b7b38
|
| 163 |
+
161, 0x4c650ded
|
| 164 |
+
162, 0x1acb2879
|
| 165 |
+
163, 0x50db5887
|
| 166 |
+
164, 0x90054847
|
| 167 |
+
165, 0xfef23e5b
|
| 168 |
+
166, 0x2dd7b7d5
|
| 169 |
+
167, 0x990b8c2e
|
| 170 |
+
168, 0x6001a601
|
| 171 |
+
169, 0xb5d314c4
|
| 172 |
+
170, 0xfbfb7bf9
|
| 173 |
+
171, 0x1aba997d
|
| 174 |
+
172, 0x814e7304
|
| 175 |
+
173, 0x989d956a
|
| 176 |
+
174, 0x86d5a29c
|
| 177 |
+
175, 0x70a9fa08
|
| 178 |
+
176, 0xc4ccba87
|
| 179 |
+
177, 0x7e9cb366
|
| 180 |
+
178, 0xee18eb0a
|
| 181 |
+
179, 0x44f5be58
|
| 182 |
+
180, 0x91d4af2d
|
| 183 |
+
181, 0x5ab6e593
|
| 184 |
+
182, 0x9fd6bb4d
|
| 185 |
+
183, 0x85894ce
|
| 186 |
+
184, 0x728a2401
|
| 187 |
+
185, 0xf006f6d4
|
| 188 |
+
186, 0xd782741e
|
| 189 |
+
187, 0x842cd5bd
|
| 190 |
+
188, 0xfb5883aa
|
| 191 |
+
189, 0x7e5a471
|
| 192 |
+
190, 0x83ff6965
|
| 193 |
+
191, 0xc9675c6b
|
| 194 |
+
192, 0xb6ced3c7
|
| 195 |
+
193, 0x3de6425b
|
| 196 |
+
194, 0x25e14db4
|
| 197 |
+
195, 0x69ca3dec
|
| 198 |
+
196, 0x81342d13
|
| 199 |
+
197, 0xd7cd8417
|
| 200 |
+
198, 0x88d15e69
|
| 201 |
+
199, 0xefba17c9
|
| 202 |
+
200, 0x43d595e6
|
| 203 |
+
201, 0x89d4cf25
|
| 204 |
+
202, 0x7cae9b9b
|
| 205 |
+
203, 0x2242c621
|
| 206 |
+
204, 0x27fc3598
|
| 207 |
+
205, 0x467b1d84
|
| 208 |
+
206, 0xe84d4622
|
| 209 |
+
207, 0xa26bf980
|
| 210 |
+
208, 0x80411010
|
| 211 |
+
209, 0xe2c2bfea
|
| 212 |
+
210, 0xbc6ca25a
|
| 213 |
+
211, 0x3ddb592a
|
| 214 |
+
212, 0xdd46eb9e
|
| 215 |
+
213, 0xdfe8f657
|
| 216 |
+
214, 0x2cedc974
|
| 217 |
+
215, 0xf0dc546b
|
| 218 |
+
216, 0xd46be68f
|
| 219 |
+
217, 0x26d8a5aa
|
| 220 |
+
218, 0x76e96ba3
|
| 221 |
+
219, 0x7d5b5353
|
| 222 |
+
220, 0xf532237c
|
| 223 |
+
221, 0x6478b79
|
| 224 |
+
222, 0x9b81a5e5
|
| 225 |
+
223, 0x5fc68e5c
|
| 226 |
+
224, 0x68436e70
|
| 227 |
+
225, 0x2a0043f9
|
| 228 |
+
226, 0x108d523c
|
| 229 |
+
227, 0x7a4c32a3
|
| 230 |
+
228, 0x9c84c742
|
| 231 |
+
229, 0x6f813dae
|
| 232 |
+
230, 0xfcc5bbcc
|
| 233 |
+
231, 0x215b6f3a
|
| 234 |
+
232, 0x84cb321d
|
| 235 |
+
233, 0x7913a248
|
| 236 |
+
234, 0xb1e6b585
|
| 237 |
+
235, 0x49376b31
|
| 238 |
+
236, 0x1dc896b0
|
| 239 |
+
237, 0x347051ad
|
| 240 |
+
238, 0x5524c042
|
| 241 |
+
239, 0xda0eef9d
|
| 242 |
+
240, 0xf2e73342
|
| 243 |
+
241, 0xbeee2f9d
|
| 244 |
+
242, 0x7c702874
|
| 245 |
+
243, 0x9eb3bd34
|
| 246 |
+
244, 0x97b09700
|
| 247 |
+
245, 0xcdbab1d4
|
| 248 |
+
246, 0x4a2f6ed1
|
| 249 |
+
247, 0x2047bda5
|
| 250 |
+
248, 0x3ecc7005
|
| 251 |
+
249, 0x8d0d5e67
|
| 252 |
+
250, 0x40876fb5
|
| 253 |
+
251, 0xb5fd2187
|
| 254 |
+
252, 0xe915d8af
|
| 255 |
+
253, 0x9a2351c7
|
| 256 |
+
254, 0xccc658ae
|
| 257 |
+
255, 0xebb1eddc
|
| 258 |
+
256, 0xc4a83671
|
| 259 |
+
257, 0xffb2548f
|
| 260 |
+
258, 0xe4fe387a
|
| 261 |
+
259, 0x477aaab4
|
| 262 |
+
260, 0x8475a4e4
|
| 263 |
+
261, 0xf8823e46
|
| 264 |
+
262, 0xe4130f71
|
| 265 |
+
263, 0xbdb54482
|
| 266 |
+
264, 0x98fe0462
|
| 267 |
+
265, 0xf36b27b8
|
| 268 |
+
266, 0xed7733da
|
| 269 |
+
267, 0x5f428afc
|
| 270 |
+
268, 0x43a3a21a
|
| 271 |
+
269, 0xf8370b55
|
| 272 |
+
270, 0xfade1de1
|
| 273 |
+
271, 0xd9a038ea
|
| 274 |
+
272, 0x3c69af23
|
| 275 |
+
273, 0x24df7dd0
|
| 276 |
+
274, 0xf66d9353
|
| 277 |
+
275, 0x71d811be
|
| 278 |
+
276, 0xcc4d024b
|
| 279 |
+
277, 0xb8c30bf0
|
| 280 |
+
278, 0x4198509d
|
| 281 |
+
279, 0x8b37ba36
|
| 282 |
+
280, 0xa41ae29a
|
| 283 |
+
281, 0x8cf7799e
|
| 284 |
+
282, 0x5cd0136a
|
| 285 |
+
283, 0xa11324ef
|
| 286 |
+
284, 0x2f8b6d4b
|
| 287 |
+
285, 0x3657cf17
|
| 288 |
+
286, 0x35b6873f
|
| 289 |
+
287, 0xee6e5bd7
|
| 290 |
+
288, 0xbeeaa98
|
| 291 |
+
289, 0x9ad3c581
|
| 292 |
+
290, 0xe2376c3f
|
| 293 |
+
291, 0x738027cc
|
| 294 |
+
292, 0x536ac839
|
| 295 |
+
293, 0xf066227
|
| 296 |
+
294, 0x6c9cb0f9
|
| 297 |
+
295, 0x84082ae6
|
| 298 |
+
296, 0xab38ae9d
|
| 299 |
+
297, 0x493eade9
|
| 300 |
+
298, 0xcb630b3a
|
| 301 |
+
299, 0x64d44250
|
| 302 |
+
300, 0xe5efb557
|
| 303 |
+
301, 0xea2424d9
|
| 304 |
+
302, 0x11a690ba
|
| 305 |
+
303, 0x30a48ae4
|
| 306 |
+
304, 0x58987e53
|
| 307 |
+
305, 0x94ec6076
|
| 308 |
+
306, 0x5d3308fa
|
| 309 |
+
307, 0xf1635ebb
|
| 310 |
+
308, 0x56a5ab90
|
| 311 |
+
309, 0x2b2f2ee4
|
| 312 |
+
310, 0x6f9e6483
|
| 313 |
+
311, 0x8b93e327
|
| 314 |
+
312, 0xa7ce140b
|
| 315 |
+
313, 0x4c8aa42
|
| 316 |
+
314, 0x7657bb3f
|
| 317 |
+
315, 0xf250fd75
|
| 318 |
+
316, 0x1edfcb0f
|
| 319 |
+
317, 0xdb42ace3
|
| 320 |
+
318, 0xf8147e16
|
| 321 |
+
319, 0xd1992bd
|
| 322 |
+
320, 0x64bb14d1
|
| 323 |
+
321, 0x423e724d
|
| 324 |
+
322, 0x7b172f7c
|
| 325 |
+
323, 0x17171696
|
| 326 |
+
324, 0x4acaf83b
|
| 327 |
+
325, 0x7a83527e
|
| 328 |
+
326, 0xfc980c60
|
| 329 |
+
327, 0xc8b56bb
|
| 330 |
+
328, 0x2453f77f
|
| 331 |
+
329, 0x85ad1bf9
|
| 332 |
+
330, 0x62a85dfe
|
| 333 |
+
331, 0x48238c4d
|
| 334 |
+
332, 0xbb3ec1eb
|
| 335 |
+
333, 0x4c1c039c
|
| 336 |
+
334, 0x1f37f571
|
| 337 |
+
335, 0x98aecb63
|
| 338 |
+
336, 0xc3b3ddd6
|
| 339 |
+
337, 0xd22dad4
|
| 340 |
+
338, 0xe49671a3
|
| 341 |
+
339, 0xe3baf945
|
| 342 |
+
340, 0xb9e21680
|
| 343 |
+
341, 0xda562856
|
| 344 |
+
342, 0xe8b88ce4
|
| 345 |
+
343, 0x86f88de2
|
| 346 |
+
344, 0x986faf76
|
| 347 |
+
345, 0x6f0025c3
|
| 348 |
+
346, 0x3fe21234
|
| 349 |
+
347, 0xd8d3f729
|
| 350 |
+
348, 0xc2d11c6f
|
| 351 |
+
349, 0xd4f9e8f
|
| 352 |
+
350, 0xf61a0aa
|
| 353 |
+
351, 0xc48bb313
|
| 354 |
+
352, 0xe944e940
|
| 355 |
+
353, 0xf1801b2e
|
| 356 |
+
354, 0x253590be
|
| 357 |
+
355, 0x981f069d
|
| 358 |
+
356, 0x891454d8
|
| 359 |
+
357, 0xa4f824ad
|
| 360 |
+
358, 0x6dd2cc48
|
| 361 |
+
359, 0x3018827e
|
| 362 |
+
360, 0x3fb329e6
|
| 363 |
+
361, 0x65276517
|
| 364 |
+
362, 0x8d2c0dd2
|
| 365 |
+
363, 0xc965b48e
|
| 366 |
+
364, 0x85d14d90
|
| 367 |
+
365, 0x5a51623c
|
| 368 |
+
366, 0xa9573d6a
|
| 369 |
+
367, 0x82d00edf
|
| 370 |
+
368, 0x5ed7ce07
|
| 371 |
+
369, 0x1d946abc
|
| 372 |
+
370, 0x24fa567b
|
| 373 |
+
371, 0x83ef5ecc
|
| 374 |
+
372, 0x9001724a
|
| 375 |
+
373, 0xc4fe48f3
|
| 376 |
+
374, 0x1e07c25c
|
| 377 |
+
375, 0xf4d5e65e
|
| 378 |
+
376, 0xb734f6e9
|
| 379 |
+
377, 0x327a2df8
|
| 380 |
+
378, 0x766d59b7
|
| 381 |
+
379, 0x625e6b61
|
| 382 |
+
380, 0xe82f32d7
|
| 383 |
+
381, 0x1566c638
|
| 384 |
+
382, 0x2e815871
|
| 385 |
+
383, 0x606514aa
|
| 386 |
+
384, 0x36b7386e
|
| 387 |
+
385, 0xcaa8ce08
|
| 388 |
+
386, 0xb453fe9c
|
| 389 |
+
387, 0x48574e23
|
| 390 |
+
388, 0x71f0da06
|
| 391 |
+
389, 0xa8a79463
|
| 392 |
+
390, 0x6b590210
|
| 393 |
+
391, 0x86e989db
|
| 394 |
+
392, 0x42899f4f
|
| 395 |
+
393, 0x7a654ef9
|
| 396 |
+
394, 0x4c4fe932
|
| 397 |
+
395, 0x77b2fd10
|
| 398 |
+
396, 0xb6b4565c
|
| 399 |
+
397, 0xa2e537a3
|
| 400 |
+
398, 0xef5a3dca
|
| 401 |
+
399, 0x41235ea8
|
| 402 |
+
400, 0x95c90541
|
| 403 |
+
401, 0x50ad32c4
|
| 404 |
+
402, 0xc1b8e0a4
|
| 405 |
+
403, 0x498e9aab
|
| 406 |
+
404, 0xffc965f1
|
| 407 |
+
405, 0x72633485
|
| 408 |
+
406, 0x3a731aef
|
| 409 |
+
407, 0x7cfddd0b
|
| 410 |
+
408, 0xb04d4129
|
| 411 |
+
409, 0x184fc28e
|
| 412 |
+
410, 0x424369b0
|
| 413 |
+
411, 0xf9ae13a1
|
| 414 |
+
412, 0xaf357c8d
|
| 415 |
+
413, 0x7a19228e
|
| 416 |
+
414, 0xb46de2a8
|
| 417 |
+
415, 0xeff2ac76
|
| 418 |
+
416, 0xa6c9357b
|
| 419 |
+
417, 0x614f19c1
|
| 420 |
+
418, 0x8ee1a53f
|
| 421 |
+
419, 0xbe1257b1
|
| 422 |
+
420, 0xf72651fe
|
| 423 |
+
421, 0xd347c298
|
| 424 |
+
422, 0x96dd2f23
|
| 425 |
+
423, 0x5bb1d63e
|
| 426 |
+
424, 0x32e10887
|
| 427 |
+
425, 0x36a144da
|
| 428 |
+
426, 0x9d70e791
|
| 429 |
+
427, 0x5e535a25
|
| 430 |
+
428, 0x214253da
|
| 431 |
+
429, 0x2e43dd40
|
| 432 |
+
430, 0xfc0413f4
|
| 433 |
+
431, 0x1f5ea409
|
| 434 |
+
432, 0x1754c126
|
| 435 |
+
433, 0xcdbeebbe
|
| 436 |
+
434, 0x1fb44a14
|
| 437 |
+
435, 0xaec7926
|
| 438 |
+
436, 0xb9d9a1e
|
| 439 |
+
437, 0x9e4a6577
|
| 440 |
+
438, 0x8b1f04c5
|
| 441 |
+
439, 0x19854e8a
|
| 442 |
+
440, 0x531080cd
|
| 443 |
+
441, 0xc0cbd73
|
| 444 |
+
442, 0x20399d77
|
| 445 |
+
443, 0x7d8e9ed5
|
| 446 |
+
444, 0x66177598
|
| 447 |
+
445, 0x4d18a5c2
|
| 448 |
+
446, 0xe08ebf58
|
| 449 |
+
447, 0xb1f9c87b
|
| 450 |
+
448, 0x66bedb10
|
| 451 |
+
449, 0x26670d21
|
| 452 |
+
450, 0x7a7892da
|
| 453 |
+
451, 0x69b69d86
|
| 454 |
+
452, 0xd04f1d1c
|
| 455 |
+
453, 0xaf469625
|
| 456 |
+
454, 0x7946b813
|
| 457 |
+
455, 0x1ee596bd
|
| 458 |
+
456, 0x7f365d85
|
| 459 |
+
457, 0x795b662b
|
| 460 |
+
458, 0x194ad02d
|
| 461 |
+
459, 0x5a9649b5
|
| 462 |
+
460, 0x6085e278
|
| 463 |
+
461, 0x2cf54550
|
| 464 |
+
462, 0x9c77ea0b
|
| 465 |
+
463, 0x3c6ff8b
|
| 466 |
+
464, 0x2141cd34
|
| 467 |
+
465, 0xb90bc671
|
| 468 |
+
466, 0x35037c4b
|
| 469 |
+
467, 0xd04c0d76
|
| 470 |
+
468, 0xc75bff8
|
| 471 |
+
469, 0x8f52003b
|
| 472 |
+
470, 0xfad3d031
|
| 473 |
+
471, 0x667024bc
|
| 474 |
+
472, 0xcb04ea36
|
| 475 |
+
473, 0x3e03d587
|
| 476 |
+
474, 0x2644d3a0
|
| 477 |
+
475, 0xa8fe99ba
|
| 478 |
+
476, 0x2b9a55fc
|
| 479 |
+
477, 0x45c4d44a
|
| 480 |
+
478, 0xd059881
|
| 481 |
+
479, 0xe07fcd20
|
| 482 |
+
480, 0x4e22046c
|
| 483 |
+
481, 0x7c2cbf81
|
| 484 |
+
482, 0xbf7f23de
|
| 485 |
+
483, 0x69d924c3
|
| 486 |
+
484, 0xe53cd01
|
| 487 |
+
485, 0x3879017c
|
| 488 |
+
486, 0xa590e558
|
| 489 |
+
487, 0x263bc076
|
| 490 |
+
488, 0x245465b1
|
| 491 |
+
489, 0x449212c6
|
| 492 |
+
490, 0x249dcb29
|
| 493 |
+
491, 0x703d42d7
|
| 494 |
+
492, 0x140eb9ec
|
| 495 |
+
493, 0xc86c5741
|
| 496 |
+
494, 0x7992aa5b
|
| 497 |
+
495, 0xb8b76a91
|
| 498 |
+
496, 0x771dac3d
|
| 499 |
+
497, 0x4ecd81e3
|
| 500 |
+
498, 0xe5ac30b3
|
| 501 |
+
499, 0xf4d7a5a6
|
| 502 |
+
500, 0xac24b97
|
| 503 |
+
501, 0x63494d78
|
| 504 |
+
502, 0x627ffa89
|
| 505 |
+
503, 0xfa4f330
|
| 506 |
+
504, 0x8098a1aa
|
| 507 |
+
505, 0xcc0c61dc
|
| 508 |
+
506, 0x34749fa0
|
| 509 |
+
507, 0x7f217822
|
| 510 |
+
508, 0x418d6f15
|
| 511 |
+
509, 0xa4b6e51e
|
| 512 |
+
510, 0x1036de68
|
| 513 |
+
511, 0x1436986e
|
| 514 |
+
512, 0x44df961d
|
| 515 |
+
513, 0x368e4651
|
| 516 |
+
514, 0x6a9e5d8c
|
| 517 |
+
515, 0x27d1597e
|
| 518 |
+
516, 0xa1926c62
|
| 519 |
+
517, 0x8d1f2b55
|
| 520 |
+
518, 0x5797eb42
|
| 521 |
+
519, 0xa90f9e81
|
| 522 |
+
520, 0x57547b10
|
| 523 |
+
521, 0xdbbcca8e
|
| 524 |
+
522, 0x9edd2d86
|
| 525 |
+
523, 0xbb0a7527
|
| 526 |
+
524, 0x7662380c
|
| 527 |
+
525, 0xe7c98590
|
| 528 |
+
526, 0x950fbf3f
|
| 529 |
+
527, 0xdc2b76b3
|
| 530 |
+
528, 0x8a945102
|
| 531 |
+
529, 0x3f0a1a85
|
| 532 |
+
530, 0xeb215834
|
| 533 |
+
531, 0xc59f2802
|
| 534 |
+
532, 0xe2a4610
|
| 535 |
+
533, 0x8b5a8665
|
| 536 |
+
534, 0x8b2d9933
|
| 537 |
+
535, 0x40a4f0bc
|
| 538 |
+
536, 0xaab5bc67
|
| 539 |
+
537, 0x1442a69e
|
| 540 |
+
538, 0xdf531193
|
| 541 |
+
539, 0x698d3db4
|
| 542 |
+
540, 0x2d40324e
|
| 543 |
+
541, 0x1a25feb2
|
| 544 |
+
542, 0xe8cc898f
|
| 545 |
+
543, 0xf12e98f5
|
| 546 |
+
544, 0xc03ad34c
|
| 547 |
+
545, 0xf62fceff
|
| 548 |
+
546, 0xdd827e1e
|
| 549 |
+
547, 0x7d8ccb3b
|
| 550 |
+
548, 0xab2d6bc1
|
| 551 |
+
549, 0xc323a124
|
| 552 |
+
550, 0x8184a19a
|
| 553 |
+
551, 0xc3c4e934
|
| 554 |
+
552, 0x5487424d
|
| 555 |
+
553, 0xd6a81a44
|
| 556 |
+
554, 0x90a8689d
|
| 557 |
+
555, 0xe69c4c67
|
| 558 |
+
556, 0xbdae02dd
|
| 559 |
+
557, 0x72a18a79
|
| 560 |
+
558, 0x2a88e907
|
| 561 |
+
559, 0x31cf4b5d
|
| 562 |
+
560, 0xb157772f
|
| 563 |
+
561, 0x206ba601
|
| 564 |
+
562, 0x18529232
|
| 565 |
+
563, 0x7dac90d8
|
| 566 |
+
564, 0x3a5f8a09
|
| 567 |
+
565, 0x9f4b64a3
|
| 568 |
+
566, 0xae373af9
|
| 569 |
+
567, 0x1d79447c
|
| 570 |
+
568, 0x2a23684b
|
| 571 |
+
569, 0x41fb7ba4
|
| 572 |
+
570, 0x55e4bb9e
|
| 573 |
+
571, 0xd7619d3e
|
| 574 |
+
572, 0xc04e4dd8
|
| 575 |
+
573, 0x8418d516
|
| 576 |
+
574, 0x2b2ca585
|
| 577 |
+
575, 0xfa8eedf
|
| 578 |
+
576, 0x5bafd977
|
| 579 |
+
577, 0x31974fb0
|
| 580 |
+
578, 0x9eb6697b
|
| 581 |
+
579, 0xc8be22f5
|
| 582 |
+
580, 0x173b126a
|
| 583 |
+
581, 0x8809becf
|
| 584 |
+
582, 0x3e41efe1
|
| 585 |
+
583, 0x3d6cbbb8
|
| 586 |
+
584, 0x278c81d8
|
| 587 |
+
585, 0xa6f08434
|
| 588 |
+
586, 0xa0e6601d
|
| 589 |
+
587, 0x2fccd88d
|
| 590 |
+
588, 0x3cbc8beb
|
| 591 |
+
589, 0x5f65d864
|
| 592 |
+
590, 0xa1ff8ddf
|
| 593 |
+
591, 0x609dcb7c
|
| 594 |
+
592, 0x4a4e1663
|
| 595 |
+
593, 0xeae5531
|
| 596 |
+
594, 0x962a7c85
|
| 597 |
+
595, 0x1e110607
|
| 598 |
+
596, 0x8c5db5d0
|
| 599 |
+
597, 0xc7f2337e
|
| 600 |
+
598, 0xc94fcc9c
|
| 601 |
+
599, 0xe7f62629
|
| 602 |
+
600, 0x6c9aa9f8
|
| 603 |
+
601, 0x2e27fe0e
|
| 604 |
+
602, 0x4d0dae12
|
| 605 |
+
603, 0x9eecf588
|
| 606 |
+
604, 0x977ba3f2
|
| 607 |
+
605, 0xed0a51af
|
| 608 |
+
606, 0x3f3ec633
|
| 609 |
+
607, 0xc174b2ec
|
| 610 |
+
608, 0x590be8a9
|
| 611 |
+
609, 0x4f630d18
|
| 612 |
+
610, 0xf579e989
|
| 613 |
+
611, 0xe2a55584
|
| 614 |
+
612, 0xee11edcd
|
| 615 |
+
613, 0x150a4833
|
| 616 |
+
614, 0xc0a0535c
|
| 617 |
+
615, 0xb5e00993
|
| 618 |
+
616, 0xb6435700
|
| 619 |
+
617, 0xa98dbff
|
| 620 |
+
618, 0x315716af
|
| 621 |
+
619, 0x94395776
|
| 622 |
+
620, 0x6cbd48d9
|
| 623 |
+
621, 0xab17f8fc
|
| 624 |
+
622, 0xa794ffb7
|
| 625 |
+
623, 0x6b55e231
|
| 626 |
+
624, 0x89ff5783
|
| 627 |
+
625, 0x431dcb26
|
| 628 |
+
626, 0x270f9bf8
|
| 629 |
+
627, 0x2af1b8d0
|
| 630 |
+
628, 0x881745ed
|
| 631 |
+
629, 0x17e1be4e
|
| 632 |
+
630, 0x132a0ec4
|
| 633 |
+
631, 0x5712df17
|
| 634 |
+
632, 0x2dfb3334
|
| 635 |
+
633, 0xf5a35519
|
| 636 |
+
634, 0xcafbdac6
|
| 637 |
+
635, 0x73b6189d
|
| 638 |
+
636, 0x10107cac
|
| 639 |
+
637, 0x18c1045e
|
| 640 |
+
638, 0xbc19bbad
|
| 641 |
+
639, 0x8b4f05ac
|
| 642 |
+
640, 0x5830d038
|
| 643 |
+
641, 0x468cd98a
|
| 644 |
+
642, 0x5b83a201
|
| 645 |
+
643, 0xf0ccdd9c
|
| 646 |
+
644, 0xcb20c4bd
|
| 647 |
+
645, 0x1ff186c9
|
| 648 |
+
646, 0xcdddb47f
|
| 649 |
+
647, 0x5c65ce6
|
| 650 |
+
648, 0xb748c580
|
| 651 |
+
649, 0x23b6f262
|
| 652 |
+
650, 0xe2ba8e5c
|
| 653 |
+
651, 0x9a164a03
|
| 654 |
+
652, 0x62d3322e
|
| 655 |
+
653, 0x918d8b43
|
| 656 |
+
654, 0x45c8b49d
|
| 657 |
+
655, 0xce172c6e
|
| 658 |
+
656, 0x23febc6
|
| 659 |
+
657, 0x84fdc5b7
|
| 660 |
+
658, 0xe7d1fd82
|
| 661 |
+
659, 0xf0ddf3a6
|
| 662 |
+
660, 0x87050436
|
| 663 |
+
661, 0x13d46375
|
| 664 |
+
662, 0x5b191c78
|
| 665 |
+
663, 0x2cbd99c0
|
| 666 |
+
664, 0x7686c7f
|
| 667 |
+
665, 0xcff56c84
|
| 668 |
+
666, 0x7f9b4486
|
| 669 |
+
667, 0xefc997fe
|
| 670 |
+
668, 0x984d4588
|
| 671 |
+
669, 0xfa44f36a
|
| 672 |
+
670, 0x7a5276c1
|
| 673 |
+
671, 0xcfde6176
|
| 674 |
+
672, 0xcacf7b1d
|
| 675 |
+
673, 0xcffae9a7
|
| 676 |
+
674, 0xe98848d5
|
| 677 |
+
675, 0xd4346001
|
| 678 |
+
676, 0xa2196cac
|
| 679 |
+
677, 0x217f07dc
|
| 680 |
+
678, 0x42d5bef
|
| 681 |
+
679, 0x6f2e8838
|
| 682 |
+
680, 0x4677a24
|
| 683 |
+
681, 0x4ad9cd54
|
| 684 |
+
682, 0x43df42af
|
| 685 |
+
683, 0x2dde417
|
| 686 |
+
684, 0xaef5acb1
|
| 687 |
+
685, 0xf377f4b3
|
| 688 |
+
686, 0x7d870d40
|
| 689 |
+
687, 0xe53df1c2
|
| 690 |
+
688, 0xaeb5be50
|
| 691 |
+
689, 0x7c92eac0
|
| 692 |
+
690, 0x4f00838c
|
| 693 |
+
691, 0x91e05e84
|
| 694 |
+
692, 0x23856c80
|
| 695 |
+
693, 0xc4266fa6
|
| 696 |
+
694, 0x912fddb
|
| 697 |
+
695, 0x34d42d22
|
| 698 |
+
696, 0x6c02ffa
|
| 699 |
+
697, 0xe47d093
|
| 700 |
+
698, 0x183c55b3
|
| 701 |
+
699, 0xc161d142
|
| 702 |
+
700, 0x3d43ff5f
|
| 703 |
+
701, 0xc944a36
|
| 704 |
+
702, 0x27bb9fc6
|
| 705 |
+
703, 0x75c91080
|
| 706 |
+
704, 0x2460d0dc
|
| 707 |
+
705, 0xd2174558
|
| 708 |
+
706, 0x68062dbf
|
| 709 |
+
707, 0x778e5c6e
|
| 710 |
+
708, 0xa4dc9a
|
| 711 |
+
709, 0x7a191e69
|
| 712 |
+
710, 0xc084b2ba
|
| 713 |
+
711, 0xbb391d2
|
| 714 |
+
712, 0x88849be
|
| 715 |
+
713, 0x69c02714
|
| 716 |
+
714, 0x69d4a389
|
| 717 |
+
715, 0x8f51854d
|
| 718 |
+
716, 0xaf10bb82
|
| 719 |
+
717, 0x4d5d1c77
|
| 720 |
+
718, 0x53b53109
|
| 721 |
+
719, 0xa0a92aa0
|
| 722 |
+
720, 0x83ecb757
|
| 723 |
+
721, 0x5325752a
|
| 724 |
+
722, 0x114e466e
|
| 725 |
+
723, 0x4b3f2780
|
| 726 |
+
724, 0xa7a6a39c
|
| 727 |
+
725, 0x5e723357
|
| 728 |
+
726, 0xa6b8be9b
|
| 729 |
+
727, 0x157c32ff
|
| 730 |
+
728, 0x8b898012
|
| 731 |
+
729, 0xd7ff2b1e
|
| 732 |
+
730, 0x69cd8444
|
| 733 |
+
731, 0x6ad8030c
|
| 734 |
+
732, 0xa08a49ec
|
| 735 |
+
733, 0xfbc055d3
|
| 736 |
+
734, 0xedf17e46
|
| 737 |
+
735, 0xc9526200
|
| 738 |
+
736, 0x3849b88a
|
| 739 |
+
737, 0x2746860b
|
| 740 |
+
738, 0xae13d0c1
|
| 741 |
+
739, 0x4f15154f
|
| 742 |
+
740, 0xd65c3975
|
| 743 |
+
741, 0x6a377278
|
| 744 |
+
742, 0x54d501f7
|
| 745 |
+
743, 0x81a054ea
|
| 746 |
+
744, 0x143592ba
|
| 747 |
+
745, 0x97714ad6
|
| 748 |
+
746, 0x4f9926d9
|
| 749 |
+
747, 0x4f7ac56d
|
| 750 |
+
748, 0xe87ca939
|
| 751 |
+
749, 0x58b76f6f
|
| 752 |
+
750, 0x60901ad8
|
| 753 |
+
751, 0x3e401bb6
|
| 754 |
+
752, 0xa058468e
|
| 755 |
+
753, 0xc0bb14f6
|
| 756 |
+
754, 0x2cb8f02a
|
| 757 |
+
755, 0x7c2cf756
|
| 758 |
+
756, 0x34c31de5
|
| 759 |
+
757, 0x9b243e83
|
| 760 |
+
758, 0xa5c85ab4
|
| 761 |
+
759, 0x2741e3b3
|
| 762 |
+
760, 0x1249000e
|
| 763 |
+
761, 0x3fc4e72b
|
| 764 |
+
762, 0xa3e038a2
|
| 765 |
+
763, 0x952dd92c
|
| 766 |
+
764, 0x2b821966
|
| 767 |
+
765, 0xfa81b365
|
| 768 |
+
766, 0x530919b9
|
| 769 |
+
767, 0x4486d66f
|
| 770 |
+
768, 0xccf4f3c1
|
| 771 |
+
769, 0xa8bddd1d
|
| 772 |
+
770, 0xcc295eb9
|
| 773 |
+
771, 0xfccbe42f
|
| 774 |
+
772, 0x38bacd8d
|
| 775 |
+
773, 0x2261854f
|
| 776 |
+
774, 0x56068c62
|
| 777 |
+
775, 0x9bdaeb8
|
| 778 |
+
776, 0x555fa5b6
|
| 779 |
+
777, 0x20fe615e
|
| 780 |
+
778, 0x49fb23d3
|
| 781 |
+
779, 0xd093bad6
|
| 782 |
+
780, 0x54919e86
|
| 783 |
+
781, 0x7373eb24
|
| 784 |
+
782, 0xfbaa7a98
|
| 785 |
+
783, 0x5f62fb39
|
| 786 |
+
784, 0xe03bc9ec
|
| 787 |
+
785, 0xa5074d41
|
| 788 |
+
786, 0xa1cefb1
|
| 789 |
+
787, 0x13912d74
|
| 790 |
+
788, 0xf6421b8
|
| 791 |
+
789, 0xfcb48812
|
| 792 |
+
790, 0x8f1db50b
|
| 793 |
+
791, 0xc1654b87
|
| 794 |
+
792, 0x948b43c2
|
| 795 |
+
793, 0xf503ef77
|
| 796 |
+
794, 0x117d891d
|
| 797 |
+
795, 0x5493ffa
|
| 798 |
+
796, 0x171313b1
|
| 799 |
+
797, 0xa4b62e1e
|
| 800 |
+
798, 0x77454ea6
|
| 801 |
+
799, 0xbea0aff0
|
| 802 |
+
800, 0x13c36389
|
| 803 |
+
801, 0xe3b60bac
|
| 804 |
+
802, 0xa176bed3
|
| 805 |
+
803, 0x2863d428
|
| 806 |
+
804, 0xe2314f46
|
| 807 |
+
805, 0xa85cd3d4
|
| 808 |
+
806, 0x7866e57
|
| 809 |
+
807, 0x8f03f5bc
|
| 810 |
+
808, 0x239ae
|
| 811 |
+
809, 0x46f279fb
|
| 812 |
+
810, 0xcca00559
|
| 813 |
+
811, 0xaa07a104
|
| 814 |
+
812, 0x89123d08
|
| 815 |
+
813, 0x2e6856ba
|
| 816 |
+
814, 0x43a9780d
|
| 817 |
+
815, 0x676cff25
|
| 818 |
+
816, 0x6744b87d
|
| 819 |
+
817, 0xee260d4f
|
| 820 |
+
818, 0xb98d8b77
|
| 821 |
+
819, 0x9b0ca455
|
| 822 |
+
820, 0x659f6fe
|
| 823 |
+
821, 0x28d20d1c
|
| 824 |
+
822, 0x601f2657
|
| 825 |
+
823, 0xdec3073e
|
| 826 |
+
824, 0x61263863
|
| 827 |
+
825, 0x1a13435a
|
| 828 |
+
826, 0x27497d1e
|
| 829 |
+
827, 0x17a8458e
|
| 830 |
+
828, 0xdddc407d
|
| 831 |
+
829, 0x4bb2e8ac
|
| 832 |
+
830, 0x16b2aedb
|
| 833 |
+
831, 0x77ccd696
|
| 834 |
+
832, 0x9d108fcd
|
| 835 |
+
833, 0x25ad233e
|
| 836 |
+
834, 0xaa9bc370
|
| 837 |
+
835, 0xa873ab50
|
| 838 |
+
836, 0xaf19c9d9
|
| 839 |
+
837, 0x696e1e6b
|
| 840 |
+
838, 0x1fdc4bf4
|
| 841 |
+
839, 0x4c2ebc81
|
| 842 |
+
840, 0xde4929ed
|
| 843 |
+
841, 0xf4d0c10c
|
| 844 |
+
842, 0xb6595b76
|
| 845 |
+
843, 0x75cbb1b3
|
| 846 |
+
844, 0xbcb6de49
|
| 847 |
+
845, 0xe23157fd
|
| 848 |
+
846, 0x5e596078
|
| 849 |
+
847, 0xa69b0d29
|
| 850 |
+
848, 0x2118a41
|
| 851 |
+
849, 0x7088c16
|
| 852 |
+
850, 0xc75e1e1
|
| 853 |
+
851, 0x6a4af2d6
|
| 854 |
+
852, 0xf19c6521
|
| 855 |
+
853, 0xaff7b3b1
|
| 856 |
+
854, 0x615295c7
|
| 857 |
+
855, 0xbda3a8d7
|
| 858 |
+
856, 0x5b5ca72e
|
| 859 |
+
857, 0xdad9d80f
|
| 860 |
+
858, 0xfa81c084
|
| 861 |
+
859, 0xf4703fa
|
| 862 |
+
860, 0x3ca54540
|
| 863 |
+
861, 0xa8961d51
|
| 864 |
+
862, 0x53d1ecc2
|
| 865 |
+
863, 0x808d83b6
|
| 866 |
+
864, 0x68e8c48e
|
| 867 |
+
865, 0x89be2039
|
| 868 |
+
866, 0x9088ea11
|
| 869 |
+
867, 0xb8665d12
|
| 870 |
+
868, 0x91272f9
|
| 871 |
+
869, 0x53dddff2
|
| 872 |
+
870, 0xb7a54ab
|
| 873 |
+
871, 0xd2b645ca
|
| 874 |
+
872, 0x99fb8590
|
| 875 |
+
873, 0x5315c8e
|
| 876 |
+
874, 0x2a913806
|
| 877 |
+
875, 0x7f15eb2b
|
| 878 |
+
876, 0xa7f1cc5d
|
| 879 |
+
877, 0xbb2ee836
|
| 880 |
+
878, 0xd9fafd60
|
| 881 |
+
879, 0x17448d6f
|
| 882 |
+
880, 0x999ec436
|
| 883 |
+
881, 0x482ec606
|
| 884 |
+
882, 0x9b403c0e
|
| 885 |
+
883, 0x569eb51b
|
| 886 |
+
884, 0xb275d1a6
|
| 887 |
+
885, 0xadd29c31
|
| 888 |
+
886, 0xb7ebdb15
|
| 889 |
+
887, 0xdfef3662
|
| 890 |
+
888, 0x51aba6db
|
| 891 |
+
889, 0x6d41946d
|
| 892 |
+
890, 0x77bf8896
|
| 893 |
+
891, 0xcafa6fab
|
| 894 |
+
892, 0x976ab40f
|
| 895 |
+
893, 0x49a6d86b
|
| 896 |
+
894, 0x56639e55
|
| 897 |
+
895, 0x9945b996
|
| 898 |
+
896, 0x81459b50
|
| 899 |
+
897, 0xbce97542
|
| 900 |
+
898, 0xe397c9c9
|
| 901 |
+
899, 0x247a5955
|
| 902 |
+
900, 0xb72b1573
|
| 903 |
+
901, 0x86306f86
|
| 904 |
+
902, 0x34f65dc5
|
| 905 |
+
903, 0x909360c0
|
| 906 |
+
904, 0xf3f696ef
|
| 907 |
+
905, 0xcb9faae5
|
| 908 |
+
906, 0x93daecd9
|
| 909 |
+
907, 0xde1af7af
|
| 910 |
+
908, 0x43a1f2d
|
| 911 |
+
909, 0x6d75cde5
|
| 912 |
+
910, 0x9e412b6
|
| 913 |
+
911, 0x5673fed
|
| 914 |
+
912, 0x16bb511a
|
| 915 |
+
913, 0x35ef4cca
|
| 916 |
+
914, 0x4e615aca
|
| 917 |
+
915, 0x5cdaf47a
|
| 918 |
+
916, 0x26676047
|
| 919 |
+
917, 0x8c199325
|
| 920 |
+
918, 0x2adf0cb9
|
| 921 |
+
919, 0x84f2e6fd
|
| 922 |
+
920, 0x5e627f64
|
| 923 |
+
921, 0xb7cee354
|
| 924 |
+
922, 0x542ab4a6
|
| 925 |
+
923, 0xe59cd83b
|
| 926 |
+
924, 0x89cc3f10
|
| 927 |
+
925, 0x92b0f5f
|
| 928 |
+
926, 0xc1328370
|
| 929 |
+
927, 0x8208d9f7
|
| 930 |
+
928, 0x68eb00cf
|
| 931 |
+
929, 0xfadd4ac4
|
| 932 |
+
930, 0x2517784f
|
| 933 |
+
931, 0x4042b99
|
| 934 |
+
932, 0x75ce0230
|
| 935 |
+
933, 0x97c5a1b4
|
| 936 |
+
934, 0x1a97f709
|
| 937 |
+
935, 0x4c62781e
|
| 938 |
+
936, 0xf530a83
|
| 939 |
+
937, 0x75776413
|
| 940 |
+
938, 0x321c7240
|
| 941 |
+
939, 0x6afe4e36
|
| 942 |
+
940, 0xad00a2b4
|
| 943 |
+
941, 0xbc05477d
|
| 944 |
+
942, 0xb0911e80
|
| 945 |
+
943, 0x9935b87d
|
| 946 |
+
944, 0xd535eec5
|
| 947 |
+
945, 0x149af45e
|
| 948 |
+
946, 0x786934b0
|
| 949 |
+
947, 0xbc13cdac
|
| 950 |
+
948, 0x208bfa2e
|
| 951 |
+
949, 0xcf4b39cc
|
| 952 |
+
950, 0x6ac6c172
|
| 953 |
+
951, 0xbfa9a37
|
| 954 |
+
952, 0x42d28db6
|
| 955 |
+
953, 0x2bf1ea63
|
| 956 |
+
954, 0xbed6e677
|
| 957 |
+
955, 0x50325d27
|
| 958 |
+
956, 0xa79d3b8b
|
| 959 |
+
957, 0x52448bb1
|
| 960 |
+
958, 0xefaad1bd
|
| 961 |
+
959, 0x833a2e54
|
| 962 |
+
960, 0xd9de549a
|
| 963 |
+
961, 0x9f59672f
|
| 964 |
+
962, 0x9d5f5f16
|
| 965 |
+
963, 0x1c914489
|
| 966 |
+
964, 0xc08fa058
|
| 967 |
+
965, 0xb188698b
|
| 968 |
+
966, 0xdc4672b5
|
| 969 |
+
967, 0x594f720e
|
| 970 |
+
968, 0x56ed428f
|
| 971 |
+
969, 0x9b0898af
|
| 972 |
+
970, 0x8a64d3d5
|
| 973 |
+
971, 0x773308d6
|
| 974 |
+
972, 0x84d62098
|
| 975 |
+
973, 0x46da7cf9
|
| 976 |
+
974, 0x1114eae7
|
| 977 |
+
975, 0xf9f2a092
|
| 978 |
+
976, 0x5363a28
|
| 979 |
+
977, 0xf2db7b3a
|
| 980 |
+
978, 0x102c71a9
|
| 981 |
+
979, 0xe8e76aaf
|
| 982 |
+
980, 0x77a97b3b
|
| 983 |
+
981, 0x77b090d
|
| 984 |
+
982, 0x1099620e
|
| 985 |
+
983, 0xa6daaae6
|
| 986 |
+
984, 0x86ff4713
|
| 987 |
+
985, 0xc0ef85b8
|
| 988 |
+
986, 0xf621d409
|
| 989 |
+
987, 0xfd1561e2
|
| 990 |
+
988, 0x4bcc687d
|
| 991 |
+
989, 0x596f760
|
| 992 |
+
990, 0x7c8819f9
|
| 993 |
+
991, 0x8cb865b8
|
| 994 |
+
992, 0xadea115a
|
| 995 |
+
993, 0x56609348
|
| 996 |
+
994, 0xb321ac14
|
| 997 |
+
995, 0x1bac7db2
|
| 998 |
+
996, 0x5fe6ee2
|
| 999 |
+
997, 0xe9bfe072
|
| 1000 |
+
998, 0x15549e74
|
| 1001 |
+
999, 0xad8c191b
|