Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/about.json +213 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/files +13 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/git +0 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/hash_input.json +3 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/index.json +16 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/link.json +6 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/paths.json +83 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/repodata_record.json +24 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/INSTALLER +1 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/METADATA +79 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/RECORD +17 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/direct_url.json +1 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/__init__.py +249 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/_parse.py +163 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/_version.py +34 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/exceptions.py +16 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/py.typed +0 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/about.json +16 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/hash_input.json +1 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/index.json +15 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/licenses/LICENSE.txt +28 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/link.json +6 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/paths.json +209 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/recipe-scripts-license.txt +27 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/recipe.yaml +75 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/rendered_recipe.yaml +683 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/variant_config.yaml +4 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/repodata_record.json +23 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/tests/tests.yaml +4 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/INSTALLER +1 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/METADATA +84 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/RECORD +59 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/REQUESTED +0 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/WHEEL +4 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/direct_url.json +1 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/entry_points.txt +3 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/licenses/LICENSE.txt +28 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/__init__.py +38 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/_identifier.py +6 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/async_utils.py +99 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/bccache.py +408 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/compiler.py +1998 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/constants.py +20 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/debug.py +191 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/defaults.py +48 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/environment.py +1672 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/exceptions.py +166 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/ext.py +870 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/filters.py +1873 -0
- micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/idtracking.py +318 -0
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/about.json
ADDED
|
@@ -0,0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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"channels": [
|
| 3 |
+
"https://conda.anaconda.org/conda-forge"
|
| 4 |
+
],
|
| 5 |
+
"conda_build_version": "25.9.0",
|
| 6 |
+
"conda_version": "25.9.1",
|
| 7 |
+
"env_vars": {
|
| 8 |
+
"CIO_TEST": "<not set>"
|
| 9 |
+
},
|
| 10 |
+
"extra": {
|
| 11 |
+
"copy_test_source_files": true,
|
| 12 |
+
"final": true,
|
| 13 |
+
"flow_run_id": "azure_20251018.2.1",
|
| 14 |
+
"recipe-maintainers": [
|
| 15 |
+
"nicoddemus"
|
| 16 |
+
],
|
| 17 |
+
"remote_url": "https://github.com/conda-forge/iniconfig-feedstock",
|
| 18 |
+
"sha": "2de21e185da7d67d943e5ba37f409da42ed389f4"
|
| 19 |
+
},
|
| 20 |
+
"home": "http://github.com/RonnyPfannschmidt/iniconfig",
|
| 21 |
+
"identifiers": [],
|
| 22 |
+
"keywords": [],
|
| 23 |
+
"license": "MIT",
|
| 24 |
+
"license_family": "MIT",
|
| 25 |
+
"license_file": "LICENSE",
|
| 26 |
+
"root_pkgs": [
|
| 27 |
+
"pydantic-settings 2.11.0 pyh3cfb1c2_0",
|
| 28 |
+
"ruamel.yaml.clib 0.2.14 py312h4c3975b_0",
|
| 29 |
+
"lzo 2.10 h280c20c_1002",
|
| 30 |
+
"anaconda-client 1.13.0 pyh29332c3_1",
|
| 31 |
+
"python-dotenv 1.1.1 pyhe01879c_0",
|
| 32 |
+
"jsonschema 4.25.1 pyhe01879c_0",
|
| 33 |
+
"pthread-stubs 0.4 hb9d3cd8_1002",
|
| 34 |
+
"archspec 0.2.5 pyhd8ed1ab_0",
|
| 35 |
+
"openssl 3.5.4 h26f9b46_0",
|
| 36 |
+
"xz 5.8.1 hbcc6ac9_2",
|
| 37 |
+
"libgcc 15.2.0 h767d61c_7",
|
| 38 |
+
"libuuid 2.41.2 he9a06e4_0",
|
| 39 |
+
"libsqlite 3.50.4 h0c1763c_0",
|
| 40 |
+
"yaml 0.2.5 h280c20c_3",
|
| 41 |
+
"libgcc-ng 15.2.0 h69a702a_7",
|
| 42 |
+
"libstdcxx-ng 15.2.0 h4852527_7",
|
| 43 |
+
"pixi 0.56.0 h3760c50_0",
|
| 44 |
+
"fmt 12.0.0 h2b0788b_0",
|
| 45 |
+
"zstandard 0.25.0 py312h5253ce2_0",
|
| 46 |
+
"libcurl 8.14.1 h332b0f4_0",
|
| 47 |
+
"click 8.1.8 pyh707e725_0",
|
| 48 |
+
"ruamel.yaml 0.18.15 py312h4c3975b_1",
|
| 49 |
+
"su-exec 0.2 h166bdaf_1003",
|
| 50 |
+
"msgpack-python 1.1.2 py312hd9148b4_0",
|
| 51 |
+
"traitlets 5.14.3 pyhd8ed1ab_1",
|
| 52 |
+
"hyperframe 6.1.0 pyhd8ed1ab_0",
|
| 53 |
+
"setuptools 80.9.0 pyhff2d567_0",
|
| 54 |
+
"lerc 4.0.0 h0aef613_1",
|
| 55 |
+
"typing-extensions 4.15.0 h396c80c_0",
|
| 56 |
+
"pip 25.2 pyh8b19718_0",
|
| 57 |
+
"yaml-cpp 0.8.0 h59595ed_0",
|
| 58 |
+
"xorg-libxau 1.0.12 hb9d3cd8_0",
|
| 59 |
+
"openjpeg 2.5.4 h55fea9a_0",
|
| 60 |
+
"libiconv 1.18 h3b78370_2",
|
| 61 |
+
"conda-build 25.9.0 py312h7900ff3_0",
|
| 62 |
+
"distro 1.9.0 pyhd8ed1ab_1",
|
| 63 |
+
"libnghttp2 1.67.0 had1ee68_0",
|
| 64 |
+
"c-ares 1.34.5 hb9d3cd8_0",
|
| 65 |
+
"typing_extensions 4.15.0 pyhcf101f3_0",
|
| 66 |
+
"pydantic-core 2.41.4 py312h868fb18_0",
|
| 67 |
+
"h2 4.3.0 pyhcf101f3_0",
|
| 68 |
+
"chardet 5.2.0 pyhd8ed1ab_3",
|
| 69 |
+
"reproc-cpp 14.2.5.post0 h5888daf_0",
|
| 70 |
+
"libev 4.33 hd590300_2",
|
| 71 |
+
"git 2.51.1 pl5321h8305f47_0",
|
| 72 |
+
"certifi 2025.10.5 pyhd8ed1ab_0",
|
| 73 |
+
"typing-inspection 0.4.2 pyhd8ed1ab_0",
|
| 74 |
+
"simdjson 4.0.7 hb700be7_0",
|
| 75 |
+
"mbedtls 3.6.3.1 h5888daf_0",
|
| 76 |
+
"bzip2 1.0.8 hda65f42_8",
|
| 77 |
+
"liblzma 5.8.1 hb9d3cd8_2",
|
| 78 |
+
"wheel 0.45.1 pyhd8ed1ab_1",
|
| 79 |
+
"jsonpointer 3.0.0 py312h7900ff3_2",
|
| 80 |
+
"pyyaml 6.0.3 py312h8a5da7c_0",
|
| 81 |
+
"filelock 3.20.0 pyhd8ed1ab_0",
|
| 82 |
+
"typer 0.19.2 pyhef33e25_0",
|
| 83 |
+
"mamba 2.3.3 heaf8479_1",
|
| 84 |
+
"tzdata 2025b h78e105d_0",
|
| 85 |
+
"beautifulsoup4 4.14.2 pyha770c72_0",
|
| 86 |
+
"nbformat 5.10.4 pyhd8ed1ab_1",
|
| 87 |
+
"readline 8.2 h8c095d6_2",
|
| 88 |
+
"readchar 4.2.1 pyhe01879c_0",
|
| 89 |
+
"typer-slim 0.19.2 pyhcf101f3_0",
|
| 90 |
+
"truststore 0.10.3 pyhe01879c_0",
|
| 91 |
+
"python-libarchive-c 5.3 pyhe01879c_1",
|
| 92 |
+
"anaconda-cli-base 0.5.4 pyhd8ed1ab_1",
|
| 93 |
+
"py-lief 0.16.6 py312h2ec8cdc_0",
|
| 94 |
+
"ncurses 6.5 h2d0b736_3",
|
| 95 |
+
"libfreetype 2.14.1 ha770c72_0",
|
| 96 |
+
"libsolv 0.7.35 h9463b59_0",
|
| 97 |
+
"xz-gpl-tools 5.8.1 hbcc6ac9_2",
|
| 98 |
+
"libarchive 3.8.2 gpl_h7be2006_100",
|
| 99 |
+
"pybind11-abi 4 hd8ed1ab_3",
|
| 100 |
+
"pycosat 0.6.6 py312h4c3975b_3",
|
| 101 |
+
"libxml2-16 2.15.0 ha9997c6_1",
|
| 102 |
+
"annotated-types 0.7.0 pyhd8ed1ab_1",
|
| 103 |
+
"nlohmann_json-abi 3.12.0 h0f90c79_1",
|
| 104 |
+
"icu 75.1 he02047a_0",
|
| 105 |
+
"_libgcc_mutex 0.1 conda_forge",
|
| 106 |
+
"pillow 11.3.0 py312h7b42cdd_3",
|
| 107 |
+
"pluggy 1.6.0 pyhd8ed1ab_0",
|
| 108 |
+
"libjpeg-turbo 3.1.0 hb9d3cd8_0",
|
| 109 |
+
"requests 2.32.5 pyhd8ed1ab_0",
|
| 110 |
+
"conda-index 0.7.0 pyhd8ed1ab_0",
|
| 111 |
+
"tk 8.6.13 noxft_hd72426e_102",
|
| 112 |
+
"liblief 0.16.6 h5888daf_0",
|
| 113 |
+
"keyutils 1.6.3 hb9d3cd8_0",
|
| 114 |
+
"ld_impl_linux-64 2.44 ha97dd6f_2",
|
| 115 |
+
"markdown-it-py 4.0.0 pyhd8ed1ab_0",
|
| 116 |
+
"jsonpatch 1.33 pyhd8ed1ab_1",
|
| 117 |
+
"markupsafe 3.0.3 py312h8a5da7c_0",
|
| 118 |
+
"liblzma-devel 5.8.1 hb9d3cd8_2",
|
| 119 |
+
"libstdcxx 15.2.0 h8f9b012_7",
|
| 120 |
+
"typer-slim-standard 0.19.2 h6e3bb38_0",
|
| 121 |
+
"frozendict 2.4.6 py312h4c3975b_1",
|
| 122 |
+
"pcre2 10.46 h1321c63_0",
|
| 123 |
+
"tomli 2.3.0 pyhcf101f3_0",
|
| 124 |
+
"tqdm 4.67.1 pyhd8ed1ab_1",
|
| 125 |
+
"_openmp_mutex 4.5 2_gnu",
|
| 126 |
+
"libssh2 1.11.1 hcf80075_0",
|
| 127 |
+
"cpp-expected 1.3.1 h171cf75_0",
|
| 128 |
+
"conda-package-handling 2.4.0 pyh7900ff3_2",
|
| 129 |
+
"libxcb 1.17.0 h8a09558_0",
|
| 130 |
+
"patchelf 0.17.2 h58526e2_0",
|
| 131 |
+
"ripgrep 15.0.0 hdab8a38_0",
|
| 132 |
+
"pytz 2025.2 pyhd8ed1ab_0",
|
| 133 |
+
"urllib3 2.5.0 pyhd8ed1ab_0",
|
| 134 |
+
"libmamba 2.3.3 h09abcb8_1",
|
| 135 |
+
"menuinst 2.4.0 py312h7900ff3_1",
|
| 136 |
+
"shellingham 1.5.4 pyhd8ed1ab_1",
|
| 137 |
+
"jupyter_core 5.9.1 pyhc90fa1f_0",
|
| 138 |
+
"psutil 7.1.0 py312h4c3975b_0",
|
| 139 |
+
"libpng 1.6.50 h421ea60_1",
|
| 140 |
+
"idna 3.11 pyhd8ed1ab_0",
|
| 141 |
+
"pkginfo 1.12.1.2 pyhd8ed1ab_0",
|
| 142 |
+
"conda-libmamba-solver 25.4.0 pyhd8ed1ab_0",
|
| 143 |
+
"libffi 3.4.6 h2dba641_1",
|
| 144 |
+
"colorama 0.4.6 pyhd8ed1ab_1",
|
| 145 |
+
"python-fastjsonschema 2.21.2 pyhe01879c_0",
|
| 146 |
+
"tini 0.19.0 h166bdaf_1",
|
| 147 |
+
"zstd 1.5.7 hb8e6e7a_2",
|
| 148 |
+
"libzlib 1.3.1 hb9d3cd8_2",
|
| 149 |
+
"conda 25.9.1 py312h7900ff3_0",
|
| 150 |
+
"soupsieve 2.8 pyhd8ed1ab_0",
|
| 151 |
+
"python-dateutil 2.9.0.post0 pyhe01879c_2",
|
| 152 |
+
"hpack 4.1.0 pyhd8ed1ab_0",
|
| 153 |
+
"libdeflate 1.24 h86f0d12_0",
|
| 154 |
+
"libwebp-base 1.6.0 hd42ef1d_0",
|
| 155 |
+
"python 3.12.12 hfe2f287_0_cpython",
|
| 156 |
+
"pycparser 2.22 pyh29332c3_1",
|
| 157 |
+
"attrs 25.4.0 pyh71513ae_0",
|
| 158 |
+
"libxml2 2.15.0 h26afc86_1",
|
| 159 |
+
"pygments 2.19.2 pyhd8ed1ab_0",
|
| 160 |
+
"rpds-py 0.27.1 py312h868fb18_1",
|
| 161 |
+
"libtiff 4.7.1 h8261f1e_0",
|
| 162 |
+
"libedit 3.1.20250104 pl5321h7949ede_0",
|
| 163 |
+
"rich 14.2.0 pyhcf101f3_0",
|
| 164 |
+
"libmambapy 2.3.3 py312h9b917ee_1",
|
| 165 |
+
"perl 5.32.1 7_hd590300_perl5",
|
| 166 |
+
"cffi 2.0.0 py312h35888ee_0",
|
| 167 |
+
"brotli-python 1.1.0 py312h1289d80_4",
|
| 168 |
+
"xorg-libxdmcp 1.1.5 hb9d3cd8_0",
|
| 169 |
+
"conda-package-streaming 0.12.0 pyhd8ed1ab_0",
|
| 170 |
+
"libnsl 2.0.1 hb9d3cd8_1",
|
| 171 |
+
"libexpat 2.7.1 hecca717_0",
|
| 172 |
+
"platformdirs 4.5.0 pyhcf101f3_0",
|
| 173 |
+
"python_abi 3.12 8_cp312",
|
| 174 |
+
"lz4-c 1.10.0 h5888daf_1",
|
| 175 |
+
"jsonschema-specifications 2025.9.1 pyhcf101f3_0",
|
| 176 |
+
"lcms2 2.17 h717163a_0",
|
| 177 |
+
"krb5 1.21.3 h659f571_0",
|
| 178 |
+
"ca-certificates 2025.10.5 hbd8a1cb_0",
|
| 179 |
+
"xz-tools 5.8.1 hb9d3cd8_2",
|
| 180 |
+
"defusedxml 0.7.1 pyhd8ed1ab_0",
|
| 181 |
+
"patch 2.8 hb03c661_1002",
|
| 182 |
+
"referencing 0.37.0 pyhcf101f3_0",
|
| 183 |
+
"six 1.17.0 pyhe01879c_1",
|
| 184 |
+
"pydantic 2.12.3 pyh3cfb1c2_0",
|
| 185 |
+
"charset-normalizer 3.4.4 pyhd8ed1ab_0",
|
| 186 |
+
"mdurl 0.1.2 pyhd8ed1ab_1",
|
| 187 |
+
"pysocks 1.7.1 pyha55dd90_7",
|
| 188 |
+
"packaging 25.0 pyh29332c3_1",
|
| 189 |
+
"evalidate 2.0.5 pyhe01879c_0",
|
| 190 |
+
"reproc 14.2.5.post0 hb9d3cd8_0",
|
| 191 |
+
"jinja2 3.1.6 pyhd8ed1ab_0",
|
| 192 |
+
"libxcrypt 4.4.36 hd590300_1",
|
| 193 |
+
"boltons 25.0.0 pyhd8ed1ab_0",
|
| 194 |
+
"requests-toolbelt 1.0.0 pyhd8ed1ab_1",
|
| 195 |
+
"libgomp 15.2.0 h767d61c_7",
|
| 196 |
+
"libfreetype6 2.14.1 h73754d4_0",
|
| 197 |
+
"joblib 1.5.2 pyhd8ed1ab_0",
|
| 198 |
+
"oras-py 0.1.14 pyhd8ed1ab_0",
|
| 199 |
+
"rattler-build 0.48.1 h60886be_0",
|
| 200 |
+
"conda-oci-mirror 0.2.3 pyhd8ed1ab_0",
|
| 201 |
+
"wrapt 1.17.3 py312h4c3975b_1",
|
| 202 |
+
"jq 1.8.1 h73b1eb8_0",
|
| 203 |
+
"shyaml 0.6.2 pyhd3deb0d_0",
|
| 204 |
+
"conda-env 2.6.0 1",
|
| 205 |
+
"deprecated 1.2.18 pyhd8ed1ab_0",
|
| 206 |
+
"conda-forge-ci-setup 4.22.1 py312hef7310e_100",
|
| 207 |
+
"oniguruma 6.9.10 hb9d3cd8_0",
|
| 208 |
+
"conda-forge-metadata 0.11.0 pyhd8ed1ab_1",
|
| 209 |
+
"rattler-build-conda-compat 1.4.9 pyhd8ed1ab_0"
|
| 210 |
+
],
|
| 211 |
+
"summary": "iniconfig: brain-dead simple config-ini parsing",
|
| 212 |
+
"tags": []
|
| 213 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/files
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
site-packages/iniconfig-2.3.0.dist-info/INSTALLER
|
| 2 |
+
site-packages/iniconfig-2.3.0.dist-info/METADATA
|
| 3 |
+
site-packages/iniconfig-2.3.0.dist-info/RECORD
|
| 4 |
+
site-packages/iniconfig-2.3.0.dist-info/REQUESTED
|
| 5 |
+
site-packages/iniconfig-2.3.0.dist-info/WHEEL
|
| 6 |
+
site-packages/iniconfig-2.3.0.dist-info/direct_url.json
|
| 7 |
+
site-packages/iniconfig-2.3.0.dist-info/licenses/LICENSE
|
| 8 |
+
site-packages/iniconfig-2.3.0.dist-info/top_level.txt
|
| 9 |
+
site-packages/iniconfig/__init__.py
|
| 10 |
+
site-packages/iniconfig/_parse.py
|
| 11 |
+
site-packages/iniconfig/_version.py
|
| 12 |
+
site-packages/iniconfig/exceptions.py
|
| 13 |
+
site-packages/iniconfig/py.typed
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/git
ADDED
|
File without changes
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/hash_input.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"channel_targets": "conda-forge main"
|
| 3 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/index.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"arch": null,
|
| 3 |
+
"build": "pyhd8ed1ab_0",
|
| 4 |
+
"build_number": 0,
|
| 5 |
+
"depends": [
|
| 6 |
+
"python >=3.10"
|
| 7 |
+
],
|
| 8 |
+
"license": "MIT",
|
| 9 |
+
"license_family": "MIT",
|
| 10 |
+
"name": "iniconfig",
|
| 11 |
+
"noarch": "python",
|
| 12 |
+
"platform": null,
|
| 13 |
+
"subdir": "noarch",
|
| 14 |
+
"timestamp": 1760831448842,
|
| 15 |
+
"version": "2.3.0"
|
| 16 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/link.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"noarch": {
|
| 3 |
+
"type": "python"
|
| 4 |
+
},
|
| 5 |
+
"package_metadata_version": 1
|
| 6 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/paths.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"paths": [
|
| 3 |
+
{
|
| 4 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/INSTALLER",
|
| 5 |
+
"path_type": "hardlink",
|
| 6 |
+
"sha256": "d0edee15f91b406f3f99726e44eb990be6e34fd0345b52b910c568e0eef6a2a8",
|
| 7 |
+
"size_in_bytes": 5
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/METADATA",
|
| 11 |
+
"path_type": "hardlink",
|
| 12 |
+
"sha256": "40d773f84e4e112f495bbf4f1be9cbd2d456c0aeb6ef5311f75d1bf322f2165b",
|
| 13 |
+
"size_in_bytes": 2526
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/RECORD",
|
| 17 |
+
"path_type": "hardlink",
|
| 18 |
+
"sha256": "2d922fb78770faf101091dcc12a46ff24519cba76c84584722bc736115decb97",
|
| 19 |
+
"size_in_bytes": 1275
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/REQUESTED",
|
| 23 |
+
"path_type": "hardlink",
|
| 24 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
| 25 |
+
"size_in_bytes": 0
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/WHEEL",
|
| 29 |
+
"path_type": "hardlink",
|
| 30 |
+
"sha256": "ff309ddcdd65ebd02bc724dbf2bcc4a0ff53a5b61792a44548d383e4ebb19d3b",
|
| 31 |
+
"size_in_bytes": 91
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/direct_url.json",
|
| 35 |
+
"path_type": "hardlink",
|
| 36 |
+
"sha256": "963af9f7f040af5a1312ebb57e5458deb00fad62a6fb4bc44c9b428637594bef",
|
| 37 |
+
"size_in_bytes": 105
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/licenses/LICENSE",
|
| 41 |
+
"path_type": "hardlink",
|
| 42 |
+
"sha256": "3409fa91f7ace557894632676656e32264fe5ef7581535725dc9a23774551bd4",
|
| 43 |
+
"size_in_bytes": 1098
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"_path": "site-packages/iniconfig-2.3.0.dist-info/top_level.txt",
|
| 47 |
+
"path_type": "hardlink",
|
| 48 |
+
"sha256": "eca7ccd1fba07654e88fd516ede9ca5e4d876002d00fca878b22ad8e14b380df",
|
| 49 |
+
"size_in_bytes": 10
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"_path": "site-packages/iniconfig/__init__.py",
|
| 53 |
+
"path_type": "hardlink",
|
| 54 |
+
"sha256": "5cbe5ea94623e26b2400ea2b6798df4408a726f2734c8f9f271a4fe317d7b5ac",
|
| 55 |
+
"size_in_bytes": 7497
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"_path": "site-packages/iniconfig/_parse.py",
|
| 59 |
+
"path_type": "hardlink",
|
| 60 |
+
"sha256": "e6770197b30042268f367a51aecf45478b7a1ba0e480e52ce39f0e63fd42476f",
|
| 61 |
+
"size_in_bytes": 5223
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"_path": "site-packages/iniconfig/_version.py",
|
| 65 |
+
"path_type": "hardlink",
|
| 66 |
+
"sha256": "28d1587be56d76ded9fa81f297c8e60c043da97a0234c0045e2823e814754142",
|
| 67 |
+
"size_in_bytes": 704
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"_path": "site-packages/iniconfig/exceptions.py",
|
| 71 |
+
"path_type": "hardlink",
|
| 72 |
+
"sha256": "9a2a50fda3310fd0af4af156375a135d8e10b919ca00c6757f7b027668c34d4d",
|
| 73 |
+
"size_in_bytes": 399
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"_path": "site-packages/iniconfig/py.typed",
|
| 77 |
+
"path_type": "hardlink",
|
| 78 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
| 79 |
+
"size_in_bytes": 0
|
| 80 |
+
}
|
| 81 |
+
],
|
| 82 |
+
"paths_version": 1
|
| 83 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/info/repodata_record.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"arch": null,
|
| 3 |
+
"build": "pyhd8ed1ab_0",
|
| 4 |
+
"build_number": 0,
|
| 5 |
+
"build_string": "pyhd8ed1ab_0",
|
| 6 |
+
"channel": "conda-forge",
|
| 7 |
+
"constrains": [],
|
| 8 |
+
"depends": [
|
| 9 |
+
"python >=3.10"
|
| 10 |
+
],
|
| 11 |
+
"fn": "iniconfig-2.3.0-pyhd8ed1ab_0.conda",
|
| 12 |
+
"license": "MIT",
|
| 13 |
+
"license_family": "MIT",
|
| 14 |
+
"md5": "9614359868482abba1bd15ce465e3c42",
|
| 15 |
+
"name": "iniconfig",
|
| 16 |
+
"noarch": "python",
|
| 17 |
+
"platform": null,
|
| 18 |
+
"sha256": "e1a9e3b1c8fe62dc3932a616c284b5d8cbe3124bbfbedcf4ce5c828cb166ee19",
|
| 19 |
+
"size": 13387,
|
| 20 |
+
"subdir": "noarch",
|
| 21 |
+
"timestamp": 1760831448,
|
| 22 |
+
"url": "https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda",
|
| 23 |
+
"version": "2.3.0"
|
| 24 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
conda
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: iniconfig
|
| 3 |
+
Version: 2.3.0
|
| 4 |
+
Summary: brain-dead simple config-ini parsing
|
| 5 |
+
Author-email: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>, Holger Krekel <holger.krekel@gmail.com>
|
| 6 |
+
License-Expression: MIT
|
| 7 |
+
Project-URL: Homepage, https://github.com/pytest-dev/iniconfig
|
| 8 |
+
Classifier: Development Status :: 4 - Beta
|
| 9 |
+
Classifier: Intended Audience :: Developers
|
| 10 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 11 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 12 |
+
Classifier: Operating System :: POSIX
|
| 13 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 14 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 19 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 20 |
+
Classifier: Topic :: Utilities
|
| 21 |
+
Requires-Python: >=3.10
|
| 22 |
+
Description-Content-Type: text/x-rst
|
| 23 |
+
License-File: LICENSE
|
| 24 |
+
Dynamic: license-file
|
| 25 |
+
|
| 26 |
+
iniconfig: brain-dead simple parsing of ini files
|
| 27 |
+
=======================================================
|
| 28 |
+
|
| 29 |
+
iniconfig is a small and simple INI-file parser module
|
| 30 |
+
having a unique set of features:
|
| 31 |
+
|
| 32 |
+
* maintains order of sections and entries
|
| 33 |
+
* supports multi-line values with or without line-continuations
|
| 34 |
+
* supports "#" comments everywhere
|
| 35 |
+
* raises errors with proper line-numbers
|
| 36 |
+
* no bells and whistles like automatic substitutions
|
| 37 |
+
* iniconfig raises an Error if two sections have the same name.
|
| 38 |
+
|
| 39 |
+
If you encounter issues or have feature wishes please report them to:
|
| 40 |
+
|
| 41 |
+
https://github.com/RonnyPfannschmidt/iniconfig/issues
|
| 42 |
+
|
| 43 |
+
Basic Example
|
| 44 |
+
===================================
|
| 45 |
+
|
| 46 |
+
If you have an ini file like this:
|
| 47 |
+
|
| 48 |
+
.. code-block:: ini
|
| 49 |
+
|
| 50 |
+
# content of example.ini
|
| 51 |
+
[section1] # comment
|
| 52 |
+
name1=value1 # comment
|
| 53 |
+
name1b=value1,value2 # comment
|
| 54 |
+
|
| 55 |
+
[section2]
|
| 56 |
+
name2=
|
| 57 |
+
line1
|
| 58 |
+
line2
|
| 59 |
+
|
| 60 |
+
then you can do:
|
| 61 |
+
|
| 62 |
+
.. code-block:: pycon
|
| 63 |
+
|
| 64 |
+
>>> import iniconfig
|
| 65 |
+
>>> ini = iniconfig.IniConfig("example.ini")
|
| 66 |
+
>>> ini['section1']['name1'] # raises KeyError if not exists
|
| 67 |
+
'value1'
|
| 68 |
+
>>> ini.get('section1', 'name1b', [], lambda x: x.split(","))
|
| 69 |
+
['value1', 'value2']
|
| 70 |
+
>>> ini.get('section1', 'notexist', [], lambda x: x.split(","))
|
| 71 |
+
[]
|
| 72 |
+
>>> [x.name for x in list(ini)]
|
| 73 |
+
['section1', 'section2']
|
| 74 |
+
>>> list(list(ini)[0].items())
|
| 75 |
+
[('name1', 'value1'), ('name1b', 'value1,value2')]
|
| 76 |
+
>>> 'section1' in ini
|
| 77 |
+
True
|
| 78 |
+
>>> 'inexistendsection' in ini
|
| 79 |
+
False
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
iniconfig-2.3.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
iniconfig-2.3.0.dist-info/METADATA,sha256=QNdz-E5OES9JW79PG-nL0tRWwK6271MR910b8yLyFls,2526
|
| 3 |
+
iniconfig-2.3.0.dist-info/RECORD,,
|
| 4 |
+
iniconfig-2.3.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 5 |
+
iniconfig-2.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
| 6 |
+
iniconfig-2.3.0.dist-info/direct_url.json,sha256=ljr59_BAr1oTEuu1flRY3rAPrWKm-0vETJtChjdZS-8,105
|
| 7 |
+
iniconfig-2.3.0.dist-info/licenses/LICENSE,sha256=NAn6kfes5VeJRjJnZlbjImT-XvdYFTVyXcmiN3RVG9Q,1098
|
| 8 |
+
iniconfig-2.3.0.dist-info/top_level.txt,sha256=7KfM0fugdlToj9UW7enKXk2HYALQD8qHiyKtjhSzgN8,10
|
| 9 |
+
iniconfig/__init__.py,sha256=XL5eqUYj4mskAOorZ5jfRAinJvJzTI-fJxpP4xfXtaw,7497
|
| 10 |
+
iniconfig/__pycache__/__init__.cpython-310.pyc,,
|
| 11 |
+
iniconfig/__pycache__/_parse.cpython-310.pyc,,
|
| 12 |
+
iniconfig/__pycache__/_version.cpython-310.pyc,,
|
| 13 |
+
iniconfig/__pycache__/exceptions.cpython-310.pyc,,
|
| 14 |
+
iniconfig/_parse.py,sha256=5ncBl7MAQiaPNnpRrs9FR4t6G6DkgOUs458OY_1CR28,5223
|
| 15 |
+
iniconfig/_version.py,sha256=KNFYe-Vtdt7Z-oHyl8jmDAQ9qXoCNMAEXigj6BR1QUI,704
|
| 16 |
+
iniconfig/exceptions.py,sha256=mipQ_aMxD9CvSvFWN1oTXY4QuRnKAMZ1f3sCdmjDTU0,399
|
| 17 |
+
iniconfig/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig-2.3.0.dist-info/direct_url.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"dir_info": {}, "url": "file:///home/conda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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""brain-dead simple parser for ini-style files.
|
| 2 |
+
(C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
from collections.abc import Callable
|
| 7 |
+
from collections.abc import Iterator
|
| 8 |
+
from collections.abc import Mapping
|
| 9 |
+
from typing import Final
|
| 10 |
+
from typing import TypeVar
|
| 11 |
+
from typing import overload
|
| 12 |
+
|
| 13 |
+
__all__ = ["IniConfig", "ParseError", "COMMENTCHARS", "iscommentline"]
|
| 14 |
+
|
| 15 |
+
from . import _parse
|
| 16 |
+
from ._parse import COMMENTCHARS
|
| 17 |
+
from ._parse import iscommentline
|
| 18 |
+
from .exceptions import ParseError
|
| 19 |
+
|
| 20 |
+
_D = TypeVar("_D")
|
| 21 |
+
_T = TypeVar("_T")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class SectionWrapper:
|
| 25 |
+
config: Final["IniConfig"]
|
| 26 |
+
name: Final[str]
|
| 27 |
+
|
| 28 |
+
def __init__(self, config: "IniConfig", name: str) -> None:
|
| 29 |
+
self.config = config
|
| 30 |
+
self.name = name
|
| 31 |
+
|
| 32 |
+
def lineof(self, name: str) -> int | None:
|
| 33 |
+
return self.config.lineof(self.name, name)
|
| 34 |
+
|
| 35 |
+
@overload
|
| 36 |
+
def get(self, key: str) -> str | None: ...
|
| 37 |
+
|
| 38 |
+
@overload
|
| 39 |
+
def get(
|
| 40 |
+
self,
|
| 41 |
+
key: str,
|
| 42 |
+
convert: Callable[[str], _T],
|
| 43 |
+
) -> _T | None: ...
|
| 44 |
+
|
| 45 |
+
@overload
|
| 46 |
+
def get(
|
| 47 |
+
self,
|
| 48 |
+
key: str,
|
| 49 |
+
default: None,
|
| 50 |
+
convert: Callable[[str], _T],
|
| 51 |
+
) -> _T | None: ...
|
| 52 |
+
|
| 53 |
+
@overload
|
| 54 |
+
def get(self, key: str, default: _D, convert: None = None) -> str | _D: ...
|
| 55 |
+
|
| 56 |
+
@overload
|
| 57 |
+
def get(
|
| 58 |
+
self,
|
| 59 |
+
key: str,
|
| 60 |
+
default: _D,
|
| 61 |
+
convert: Callable[[str], _T],
|
| 62 |
+
) -> _T | _D: ...
|
| 63 |
+
|
| 64 |
+
# TODO: investigate possible mypy bug wrt matching the passed over data
|
| 65 |
+
def get( # type: ignore [misc]
|
| 66 |
+
self,
|
| 67 |
+
key: str,
|
| 68 |
+
default: _D | None = None,
|
| 69 |
+
convert: Callable[[str], _T] | None = None,
|
| 70 |
+
) -> _D | _T | str | None:
|
| 71 |
+
return self.config.get(self.name, key, convert=convert, default=default)
|
| 72 |
+
|
| 73 |
+
def __getitem__(self, key: str) -> str:
|
| 74 |
+
return self.config.sections[self.name][key]
|
| 75 |
+
|
| 76 |
+
def __iter__(self) -> Iterator[str]:
|
| 77 |
+
section: Mapping[str, str] = self.config.sections.get(self.name, {})
|
| 78 |
+
|
| 79 |
+
def lineof(key: str) -> int:
|
| 80 |
+
return self.config.lineof(self.name, key) # type: ignore[return-value]
|
| 81 |
+
|
| 82 |
+
yield from sorted(section, key=lineof)
|
| 83 |
+
|
| 84 |
+
def items(self) -> Iterator[tuple[str, str]]:
|
| 85 |
+
for name in self:
|
| 86 |
+
yield name, self[name]
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class IniConfig:
|
| 90 |
+
path: Final[str]
|
| 91 |
+
sections: Final[Mapping[str, Mapping[str, str]]]
|
| 92 |
+
_sources: Final[Mapping[tuple[str, str | None], int]]
|
| 93 |
+
|
| 94 |
+
def __init__(
|
| 95 |
+
self,
|
| 96 |
+
path: str | os.PathLike[str],
|
| 97 |
+
data: str | None = None,
|
| 98 |
+
encoding: str = "utf-8",
|
| 99 |
+
*,
|
| 100 |
+
_sections: Mapping[str, Mapping[str, str]] | None = None,
|
| 101 |
+
_sources: Mapping[tuple[str, str | None], int] | None = None,
|
| 102 |
+
) -> None:
|
| 103 |
+
self.path = os.fspath(path)
|
| 104 |
+
|
| 105 |
+
# Determine sections and sources
|
| 106 |
+
if _sections is not None and _sources is not None:
|
| 107 |
+
# Use provided pre-parsed data (called from parse())
|
| 108 |
+
sections_data = _sections
|
| 109 |
+
sources = _sources
|
| 110 |
+
else:
|
| 111 |
+
# Parse the data (backward compatible path)
|
| 112 |
+
if data is None:
|
| 113 |
+
with open(self.path, encoding=encoding) as fp:
|
| 114 |
+
data = fp.read()
|
| 115 |
+
|
| 116 |
+
# Use old behavior (no stripping) for backward compatibility
|
| 117 |
+
sections_data, sources = _parse.parse_ini_data(
|
| 118 |
+
self.path, data, strip_inline_comments=False
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# Assign once to Final attributes
|
| 122 |
+
self._sources = sources
|
| 123 |
+
self.sections = sections_data
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def parse(
|
| 127 |
+
cls,
|
| 128 |
+
path: str | os.PathLike[str],
|
| 129 |
+
data: str | None = None,
|
| 130 |
+
encoding: str = "utf-8",
|
| 131 |
+
*,
|
| 132 |
+
strip_inline_comments: bool = True,
|
| 133 |
+
strip_section_whitespace: bool = False,
|
| 134 |
+
) -> "IniConfig":
|
| 135 |
+
"""Parse an INI file.
|
| 136 |
+
|
| 137 |
+
Args:
|
| 138 |
+
path: Path to the INI file (used for error messages)
|
| 139 |
+
data: Optional INI content as string. If None, reads from path.
|
| 140 |
+
encoding: Encoding to use when reading the file (default: utf-8)
|
| 141 |
+
strip_inline_comments: Whether to strip inline comments from values
|
| 142 |
+
(default: True). When True, comments starting with # or ; are
|
| 143 |
+
removed from values, matching the behavior for section comments.
|
| 144 |
+
strip_section_whitespace: Whether to strip whitespace from section and key names
|
| 145 |
+
(default: False). When True, strips Unicode whitespace from section and key names,
|
| 146 |
+
addressing issue #4. When False, preserves existing behavior for backward compatibility.
|
| 147 |
+
|
| 148 |
+
Returns:
|
| 149 |
+
IniConfig instance with parsed configuration
|
| 150 |
+
|
| 151 |
+
Example:
|
| 152 |
+
# With comment stripping (default):
|
| 153 |
+
config = IniConfig.parse("setup.cfg")
|
| 154 |
+
# value = "foo" instead of "foo # comment"
|
| 155 |
+
|
| 156 |
+
# Without comment stripping (old behavior):
|
| 157 |
+
config = IniConfig.parse("setup.cfg", strip_inline_comments=False)
|
| 158 |
+
# value = "foo # comment"
|
| 159 |
+
|
| 160 |
+
# With section name stripping (opt-in for issue #4):
|
| 161 |
+
config = IniConfig.parse("setup.cfg", strip_section_whitespace=True)
|
| 162 |
+
# section names and keys have Unicode whitespace stripped
|
| 163 |
+
"""
|
| 164 |
+
fspath = os.fspath(path)
|
| 165 |
+
|
| 166 |
+
if data is None:
|
| 167 |
+
with open(fspath, encoding=encoding) as fp:
|
| 168 |
+
data = fp.read()
|
| 169 |
+
|
| 170 |
+
sections_data, sources = _parse.parse_ini_data(
|
| 171 |
+
fspath,
|
| 172 |
+
data,
|
| 173 |
+
strip_inline_comments=strip_inline_comments,
|
| 174 |
+
strip_section_whitespace=strip_section_whitespace,
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
# Call constructor with pre-parsed sections and sources
|
| 178 |
+
return cls(path=fspath, _sections=sections_data, _sources=sources)
|
| 179 |
+
|
| 180 |
+
def lineof(self, section: str, name: str | None = None) -> int | None:
|
| 181 |
+
lineno = self._sources.get((section, name))
|
| 182 |
+
return None if lineno is None else lineno + 1
|
| 183 |
+
|
| 184 |
+
@overload
|
| 185 |
+
def get(
|
| 186 |
+
self,
|
| 187 |
+
section: str,
|
| 188 |
+
name: str,
|
| 189 |
+
) -> str | None: ...
|
| 190 |
+
|
| 191 |
+
@overload
|
| 192 |
+
def get(
|
| 193 |
+
self,
|
| 194 |
+
section: str,
|
| 195 |
+
name: str,
|
| 196 |
+
convert: Callable[[str], _T],
|
| 197 |
+
) -> _T | None: ...
|
| 198 |
+
|
| 199 |
+
@overload
|
| 200 |
+
def get(
|
| 201 |
+
self,
|
| 202 |
+
section: str,
|
| 203 |
+
name: str,
|
| 204 |
+
default: None,
|
| 205 |
+
convert: Callable[[str], _T],
|
| 206 |
+
) -> _T | None: ...
|
| 207 |
+
|
| 208 |
+
@overload
|
| 209 |
+
def get(
|
| 210 |
+
self, section: str, name: str, default: _D, convert: None = None
|
| 211 |
+
) -> str | _D: ...
|
| 212 |
+
|
| 213 |
+
@overload
|
| 214 |
+
def get(
|
| 215 |
+
self,
|
| 216 |
+
section: str,
|
| 217 |
+
name: str,
|
| 218 |
+
default: _D,
|
| 219 |
+
convert: Callable[[str], _T],
|
| 220 |
+
) -> _T | _D: ...
|
| 221 |
+
|
| 222 |
+
def get( # type: ignore
|
| 223 |
+
self,
|
| 224 |
+
section: str,
|
| 225 |
+
name: str,
|
| 226 |
+
default: _D | None = None,
|
| 227 |
+
convert: Callable[[str], _T] | None = None,
|
| 228 |
+
) -> _D | _T | str | None:
|
| 229 |
+
try:
|
| 230 |
+
value: str = self.sections[section][name]
|
| 231 |
+
except KeyError:
|
| 232 |
+
return default
|
| 233 |
+
else:
|
| 234 |
+
if convert is not None:
|
| 235 |
+
return convert(value)
|
| 236 |
+
else:
|
| 237 |
+
return value
|
| 238 |
+
|
| 239 |
+
def __getitem__(self, name: str) -> SectionWrapper:
|
| 240 |
+
if name not in self.sections:
|
| 241 |
+
raise KeyError(name)
|
| 242 |
+
return SectionWrapper(self, name)
|
| 243 |
+
|
| 244 |
+
def __iter__(self) -> Iterator[SectionWrapper]:
|
| 245 |
+
for name in sorted(self.sections, key=self.lineof): # type: ignore
|
| 246 |
+
yield SectionWrapper(self, name)
|
| 247 |
+
|
| 248 |
+
def __contains__(self, arg: str) -> bool:
|
| 249 |
+
return arg in self.sections
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/_parse.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Mapping
|
| 2 |
+
from typing import NamedTuple
|
| 3 |
+
|
| 4 |
+
from .exceptions import ParseError
|
| 5 |
+
|
| 6 |
+
COMMENTCHARS = "#;"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class ParsedLine(NamedTuple):
|
| 10 |
+
lineno: int
|
| 11 |
+
section: str | None
|
| 12 |
+
name: str | None
|
| 13 |
+
value: str | None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def parse_ini_data(
|
| 17 |
+
path: str,
|
| 18 |
+
data: str,
|
| 19 |
+
*,
|
| 20 |
+
strip_inline_comments: bool,
|
| 21 |
+
strip_section_whitespace: bool = False,
|
| 22 |
+
) -> tuple[Mapping[str, Mapping[str, str]], Mapping[tuple[str, str | None], int]]:
|
| 23 |
+
"""Parse INI data and return sections and sources mappings.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
path: Path for error messages
|
| 27 |
+
data: INI content as string
|
| 28 |
+
strip_inline_comments: Whether to strip inline comments from values
|
| 29 |
+
strip_section_whitespace: Whether to strip whitespace from section and key names
|
| 30 |
+
(default: False). When True, addresses issue #4 by stripping Unicode whitespace.
|
| 31 |
+
|
| 32 |
+
Returns:
|
| 33 |
+
Tuple of (sections_data, sources) where:
|
| 34 |
+
- sections_data: mapping of section -> {name -> value}
|
| 35 |
+
- sources: mapping of (section, name) -> line number
|
| 36 |
+
"""
|
| 37 |
+
tokens = parse_lines(
|
| 38 |
+
path,
|
| 39 |
+
data.splitlines(True),
|
| 40 |
+
strip_inline_comments=strip_inline_comments,
|
| 41 |
+
strip_section_whitespace=strip_section_whitespace,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
sources: dict[tuple[str, str | None], int] = {}
|
| 45 |
+
sections_data: dict[str, dict[str, str]] = {}
|
| 46 |
+
|
| 47 |
+
for lineno, section, name, value in tokens:
|
| 48 |
+
if section is None:
|
| 49 |
+
raise ParseError(path, lineno, "no section header defined")
|
| 50 |
+
sources[section, name] = lineno
|
| 51 |
+
if name is None:
|
| 52 |
+
if section in sections_data:
|
| 53 |
+
raise ParseError(path, lineno, f"duplicate section {section!r}")
|
| 54 |
+
sections_data[section] = {}
|
| 55 |
+
else:
|
| 56 |
+
if name in sections_data[section]:
|
| 57 |
+
raise ParseError(path, lineno, f"duplicate name {name!r}")
|
| 58 |
+
assert value is not None
|
| 59 |
+
sections_data[section][name] = value
|
| 60 |
+
|
| 61 |
+
return sections_data, sources
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def parse_lines(
|
| 65 |
+
path: str,
|
| 66 |
+
line_iter: list[str],
|
| 67 |
+
*,
|
| 68 |
+
strip_inline_comments: bool = False,
|
| 69 |
+
strip_section_whitespace: bool = False,
|
| 70 |
+
) -> list[ParsedLine]:
|
| 71 |
+
result: list[ParsedLine] = []
|
| 72 |
+
section = None
|
| 73 |
+
for lineno, line in enumerate(line_iter):
|
| 74 |
+
name, data = _parseline(
|
| 75 |
+
path, line, lineno, strip_inline_comments, strip_section_whitespace
|
| 76 |
+
)
|
| 77 |
+
# new value
|
| 78 |
+
if name is not None and data is not None:
|
| 79 |
+
result.append(ParsedLine(lineno, section, name, data))
|
| 80 |
+
# new section
|
| 81 |
+
elif name is not None and data is None:
|
| 82 |
+
if not name:
|
| 83 |
+
raise ParseError(path, lineno, "empty section name")
|
| 84 |
+
section = name
|
| 85 |
+
result.append(ParsedLine(lineno, section, None, None))
|
| 86 |
+
# continuation
|
| 87 |
+
elif name is None and data is not None:
|
| 88 |
+
if not result:
|
| 89 |
+
raise ParseError(path, lineno, "unexpected value continuation")
|
| 90 |
+
last = result.pop()
|
| 91 |
+
if last.name is None:
|
| 92 |
+
raise ParseError(path, lineno, "unexpected value continuation")
|
| 93 |
+
|
| 94 |
+
if last.value:
|
| 95 |
+
last = last._replace(value=f"{last.value}\n{data}")
|
| 96 |
+
else:
|
| 97 |
+
last = last._replace(value=data)
|
| 98 |
+
result.append(last)
|
| 99 |
+
return result
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _parseline(
|
| 103 |
+
path: str,
|
| 104 |
+
line: str,
|
| 105 |
+
lineno: int,
|
| 106 |
+
strip_inline_comments: bool,
|
| 107 |
+
strip_section_whitespace: bool,
|
| 108 |
+
) -> tuple[str | None, str | None]:
|
| 109 |
+
# blank lines
|
| 110 |
+
if iscommentline(line):
|
| 111 |
+
line = ""
|
| 112 |
+
else:
|
| 113 |
+
line = line.rstrip()
|
| 114 |
+
if not line:
|
| 115 |
+
return None, None
|
| 116 |
+
# section
|
| 117 |
+
if line[0] == "[":
|
| 118 |
+
realline = line
|
| 119 |
+
for c in COMMENTCHARS:
|
| 120 |
+
line = line.split(c)[0].rstrip()
|
| 121 |
+
if line[-1] == "]":
|
| 122 |
+
section_name = line[1:-1]
|
| 123 |
+
# Optionally strip whitespace from section name (issue #4)
|
| 124 |
+
if strip_section_whitespace:
|
| 125 |
+
section_name = section_name.strip()
|
| 126 |
+
return section_name, None
|
| 127 |
+
return None, realline.strip()
|
| 128 |
+
# value
|
| 129 |
+
elif not line[0].isspace():
|
| 130 |
+
try:
|
| 131 |
+
name, value = line.split("=", 1)
|
| 132 |
+
if ":" in name:
|
| 133 |
+
raise ValueError()
|
| 134 |
+
except ValueError:
|
| 135 |
+
try:
|
| 136 |
+
name, value = line.split(":", 1)
|
| 137 |
+
except ValueError:
|
| 138 |
+
raise ParseError(path, lineno, f"unexpected line: {line!r}") from None
|
| 139 |
+
|
| 140 |
+
# Strip key name (always for backward compatibility, optionally with unicode awareness)
|
| 141 |
+
key_name = name.strip()
|
| 142 |
+
|
| 143 |
+
# Strip value
|
| 144 |
+
value = value.strip()
|
| 145 |
+
# Strip inline comments from values if requested (issue #55)
|
| 146 |
+
if strip_inline_comments:
|
| 147 |
+
for c in COMMENTCHARS:
|
| 148 |
+
value = value.split(c)[0].rstrip()
|
| 149 |
+
|
| 150 |
+
return key_name, value
|
| 151 |
+
# continuation
|
| 152 |
+
else:
|
| 153 |
+
line = line.strip()
|
| 154 |
+
# Strip inline comments from continuations if requested (issue #55)
|
| 155 |
+
if strip_inline_comments:
|
| 156 |
+
for c in COMMENTCHARS:
|
| 157 |
+
line = line.split(c)[0].rstrip()
|
| 158 |
+
return None, line
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def iscommentline(line: str) -> bool:
|
| 162 |
+
c = line.lstrip()[:1]
|
| 163 |
+
return c in COMMENTCHARS
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by setuptools-scm
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
|
| 4 |
+
__all__ = [
|
| 5 |
+
"__version__",
|
| 6 |
+
"__version_tuple__",
|
| 7 |
+
"version",
|
| 8 |
+
"version_tuple",
|
| 9 |
+
"__commit_id__",
|
| 10 |
+
"commit_id",
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
TYPE_CHECKING = False
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from typing import Tuple
|
| 16 |
+
from typing import Union
|
| 17 |
+
|
| 18 |
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
| 19 |
+
COMMIT_ID = Union[str, None]
|
| 20 |
+
else:
|
| 21 |
+
VERSION_TUPLE = object
|
| 22 |
+
COMMIT_ID = object
|
| 23 |
+
|
| 24 |
+
version: str
|
| 25 |
+
__version__: str
|
| 26 |
+
__version_tuple__: VERSION_TUPLE
|
| 27 |
+
version_tuple: VERSION_TUPLE
|
| 28 |
+
commit_id: COMMIT_ID
|
| 29 |
+
__commit_id__: COMMIT_ID
|
| 30 |
+
|
| 31 |
+
__version__ = version = '2.3.0'
|
| 32 |
+
__version_tuple__ = version_tuple = (2, 3, 0)
|
| 33 |
+
|
| 34 |
+
__commit_id__ = commit_id = None
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/exceptions.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Final
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ParseError(Exception):
|
| 5 |
+
path: Final[str]
|
| 6 |
+
lineno: Final[int]
|
| 7 |
+
msg: Final[str]
|
| 8 |
+
|
| 9 |
+
def __init__(self, path: str, lineno: int, msg: str) -> None:
|
| 10 |
+
super().__init__(path, lineno, msg)
|
| 11 |
+
self.path = path
|
| 12 |
+
self.lineno = lineno
|
| 13 |
+
self.msg = msg
|
| 14 |
+
|
| 15 |
+
def __str__(self) -> str:
|
| 16 |
+
return f"{self.path}:{self.lineno + 1}: {self.msg}"
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0/site-packages/iniconfig/py.typed
ADDED
|
File without changes
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/about.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"channels": [
|
| 3 |
+
"https://conda.anaconda.org/conda-forge/"
|
| 4 |
+
],
|
| 5 |
+
"description": "Jinja is a fast, expressive, extensible templating engine. Special\nplaceholders in the template allow writing code similar to Python\nsyntax. Then the template is passed data to render the final document.\n\nIt includes:\n\n- Template inheritance and inclusion.\n- Define and import macros within templates.\n- HTML templates can use autoescaping to prevent XSS from untrusted\n user input.\n- A sandboxed environment can safely render untrusted templates.\n- AsyncIO support for generating templates and calling async\n functions.\n- I18N support with Babel.\n- Templates are compiled to optimized Python code just-in-time and\n cached, or can be compiled ahead-of-time.\n- Exceptions point to the correct line in templates to make debugging\n easier.\n- Extensible filters, tests, functions, and even syntax.\n\nJinja's philosophy is that while application logic belongs in Python if\npossible, it shouldn't make the template designer's job difficult by\nrestricting functionality too much.",
|
| 6 |
+
"dev_url": "https://github.com/pallets/jinja/",
|
| 7 |
+
"doc_url": "https://jinja.palletsprojects.com/",
|
| 8 |
+
"extra": {
|
| 9 |
+
"flow_run_id": "azure_20251130.1.1",
|
| 10 |
+
"remote_url": "https://github.com/conda-forge/jinja2-feedstock",
|
| 11 |
+
"sha": "8bd6e62c7d52ad5bb585c456a7989f04e51e9c51"
|
| 12 |
+
},
|
| 13 |
+
"home": "https://palletsprojects.com/p/jinja/",
|
| 14 |
+
"license": "BSD-3-Clause",
|
| 15 |
+
"summary": "A very fast and expressive template engine."
|
| 16 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/hash_input.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"channel_sources": "conda-forge", "channel_targets": "conda-forge main", "python_min": "3.10", "target_platform": "noarch"}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/index.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"build": "pyhcf101f3_1",
|
| 3 |
+
"build_number": 1,
|
| 4 |
+
"depends": [
|
| 5 |
+
"markupsafe >=2.0",
|
| 6 |
+
"python >=3.10",
|
| 7 |
+
"python"
|
| 8 |
+
],
|
| 9 |
+
"license": "BSD-3-Clause",
|
| 10 |
+
"name": "jinja2",
|
| 11 |
+
"noarch": "python",
|
| 12 |
+
"subdir": "noarch",
|
| 13 |
+
"timestamp": 1764517220861,
|
| 14 |
+
"version": "3.1.6"
|
| 15 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/licenses/LICENSE.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2007 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/link.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"noarch": {
|
| 3 |
+
"type": "python"
|
| 4 |
+
},
|
| 5 |
+
"package_metadata_version": 1
|
| 6 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/paths.json
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"paths": [
|
| 3 |
+
{
|
| 4 |
+
"_path": "site-packages/jinja2/__init__.py",
|
| 5 |
+
"path_type": "hardlink",
|
| 6 |
+
"sha256": "c717a93bd8bb0c7b2a910ae004476e2ed7e8cf6402b93ebf81b2f85d237585b5",
|
| 7 |
+
"size_in_bytes": 1928
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"_path": "site-packages/jinja2/_identifier.py",
|
| 11 |
+
"path_type": "hardlink",
|
| 12 |
+
"sha256": "ff361cb4d2b346a964fe6bab4cd973ae3bb514524bed56bf223aaa77b8a2da55",
|
| 13 |
+
"size_in_bytes": 1958
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"_path": "site-packages/jinja2/async_utils.py",
|
| 17 |
+
"path_type": "hardlink",
|
| 18 |
+
"sha256": "bcaf8f76cba8ace3275929c4913de25094489139d880ed93e8c9c6c43807239a",
|
| 19 |
+
"size_in_bytes": 2834
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"_path": "site-packages/jinja2/bccache.py",
|
| 23 |
+
"path_type": "hardlink",
|
| 24 |
+
"sha256": "821d2ab3daee9675e8d0f857e634c9cb6507cc8f3016743ade8fefc3b9e1cd18",
|
| 25 |
+
"size_in_bytes": 14061
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"_path": "site-packages/jinja2/compiler.py",
|
| 29 |
+
"path_type": "hardlink",
|
| 30 |
+
"sha256": "f51a42425e57f3c0479652623ec1cf876f791e1d2e029bf0149350baeb542de3",
|
| 31 |
+
"size_in_bytes": 74131
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"_path": "site-packages/jinja2/constants.py",
|
| 35 |
+
"path_type": "hardlink",
|
| 36 |
+
"sha256": "18ca05c9d045fe476969128fa0ce5c97932f8aab9544b57266d7e9e7ed7a8e0d",
|
| 37 |
+
"size_in_bytes": 1433
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"_path": "site-packages/jinja2/debug.py",
|
| 41 |
+
"path_type": "hardlink",
|
| 42 |
+
"sha256": "0a71ea0831ddf81546bed8bff19b13a259d7361037102b18fba9ffda9c14f07c",
|
| 43 |
+
"size_in_bytes": 6297
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"_path": "site-packages/jinja2/defaults.py",
|
| 47 |
+
"path_type": "hardlink",
|
| 48 |
+
"sha256": "6e805c4b0efc87e969db461b697489b2a900236b8dfe60ff4ed0b27697aae705",
|
| 49 |
+
"size_in_bytes": 1267
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"_path": "site-packages/jinja2/environment.py",
|
| 53 |
+
"path_type": "hardlink",
|
| 54 |
+
"sha256": "f6786b3fb0a1f8d6c65f4d30bf2af8cb2fae84d1ead8e09ceb48201ab9e2fdf9",
|
| 55 |
+
"size_in_bytes": 61513
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"_path": "site-packages/jinja2/exceptions.py",
|
| 59 |
+
"path_type": "hardlink",
|
| 60 |
+
"sha256": "8a81de1eb5b009635a5d7d629c798755b96f73885a3bb017b230a9dc67d6bf1d",
|
| 61 |
+
"size_in_bytes": 5071
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"_path": "site-packages/jinja2/ext.py",
|
| 65 |
+
"path_type": "hardlink",
|
| 66 |
+
"sha256": "e4f1797877e1f265c02315c71d1076c576d7a218bca44de71d23b16baeae4bb1",
|
| 67 |
+
"size_in_bytes": 31875
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"_path": "site-packages/jinja2/filters.py",
|
| 71 |
+
"path_type": "hardlink",
|
| 72 |
+
"sha256": "3d0fc481df67f634a0b671906321782b98f69d8c21508ba584f9f28a691dafe9",
|
| 73 |
+
"size_in_bytes": 55212
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"_path": "site-packages/jinja2/idtracking.py",
|
| 77 |
+
"path_type": "hardlink",
|
| 78 |
+
"sha256": "fa5979948a7bde930bdc4ad46222098fbb5d996c5c1ff2250efdf203f862658a",
|
| 79 |
+
"size_in_bytes": 10555
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"_path": "site-packages/jinja2/lexer.py",
|
| 83 |
+
"path_type": "hardlink",
|
| 84 |
+
"sha256": "2d88988a8e9bafe4dea7d9cf72ea565ec3c4b6396ec37a75994fa534155151f9",
|
| 85 |
+
"size_in_bytes": 29786
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"_path": "site-packages/jinja2/loaders.py",
|
| 89 |
+
"path_type": "hardlink",
|
| 90 |
+
"sha256": "c08ae7c63bdc6ea8795705b6f0d4a47e8b620eaf2a342c4839215b1948922c1e",
|
| 91 |
+
"size_in_bytes": 24055
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"_path": "site-packages/jinja2/meta.py",
|
| 95 |
+
"path_type": "hardlink",
|
| 96 |
+
"sha256": "3930cf91a16f5361e0bf1fba6a4cfbd79e05f012166919af25c045bf0a291f0c",
|
| 97 |
+
"size_in_bytes": 4397
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"_path": "site-packages/jinja2/nativetypes.py",
|
| 101 |
+
"path_type": "hardlink",
|
| 102 |
+
"sha256": "ec620600b54981dc8bf34a1925d4146947f04ade6ada549265b5edd1d35ffcce",
|
| 103 |
+
"size_in_bytes": 4210
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
"_path": "site-packages/jinja2/nodes.py",
|
| 107 |
+
"path_type": "hardlink",
|
| 108 |
+
"sha256": "9b50eecdcafaaa1648f0943a57226050d8a78c07f96d0ce28d29839ccb2f531f",
|
| 109 |
+
"size_in_bytes": 34579
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"_path": "site-packages/jinja2/optimizer.py",
|
| 113 |
+
"path_type": "hardlink",
|
| 114 |
+
"sha256": "ac99c246543ba59b04126321b100e00bfa4ac831f13f94cf4bacd53c6b2072ef",
|
| 115 |
+
"size_in_bytes": 1651
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"_path": "site-packages/jinja2/parser.py",
|
| 119 |
+
"path_type": "hardlink",
|
| 120 |
+
"sha256": "94b385cb7b0498773921a1074621f5b1056721dda6a14433872789653b5d637d",
|
| 121 |
+
"size_in_bytes": 40383
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"_path": "site-packages/jinja2/py.typed",
|
| 125 |
+
"path_type": "hardlink",
|
| 126 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
| 127 |
+
"size_in_bytes": 0
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"_path": "site-packages/jinja2/runtime.py",
|
| 131 |
+
"path_type": "hardlink",
|
| 132 |
+
"sha256": "80393e1af76b8895ea82c19b1e0adc2933f4629eb33d7ce1ceb2290851f78c05",
|
| 133 |
+
"size_in_bytes": 34249
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"_path": "site-packages/jinja2/sandbox.py",
|
| 137 |
+
"path_type": "hardlink",
|
| 138 |
+
"sha256": "330d9a8ad958d88f256bb15885c5f6606f41b5461c2e70f41a1ddddbd7035ab6",
|
| 139 |
+
"size_in_bytes": 15009
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"_path": "site-packages/jinja2/tests.py",
|
| 143 |
+
"path_type": "hardlink",
|
| 144 |
+
"sha256": "54bb018551675a0f8fc52073d4c8519cd5a03f5a2f5e4de778ed452d031e0bd4",
|
| 145 |
+
"size_in_bytes": 5926
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"_path": "site-packages/jinja2/utils.py",
|
| 149 |
+
"path_type": "hardlink",
|
| 150 |
+
"sha256": "ad1a77a3d7bb64a4b87f2ad645b10bc8b729b8655315c9e8a1a39ad6ac7f1489",
|
| 151 |
+
"size_in_bytes": 24129
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"_path": "site-packages/jinja2/visitor.py",
|
| 155 |
+
"path_type": "hardlink",
|
| 156 |
+
"sha256": "11c9cbd4f2307ffe1154238cc6c44db91f005c76d2d6a7c074c384da780a273e",
|
| 157 |
+
"size_in_bytes": 3557
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/INSTALLER",
|
| 161 |
+
"path_type": "hardlink",
|
| 162 |
+
"sha256": "bc33022edcb7639ff53355b4e91dade50a0bbf0299efeb6171d1ec0ba5029cfc",
|
| 163 |
+
"size_in_bytes": 6
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/METADATA",
|
| 167 |
+
"path_type": "hardlink",
|
| 168 |
+
"sha256": "68c5548fb67c4132a13898d9b31ec50c6bea2abdd915d921f214355c3a6499c8",
|
| 169 |
+
"size_in_bytes": 2871
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/RECORD",
|
| 173 |
+
"path_type": "hardlink",
|
| 174 |
+
"sha256": "db137955528155bc95214947bd76e6822f0399618f19c4480f6f90d374b286de",
|
| 175 |
+
"size_in_bytes": 3801
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/REQUESTED",
|
| 179 |
+
"path_type": "hardlink",
|
| 180 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
| 181 |
+
"size_in_bytes": 0
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/WHEEL",
|
| 185 |
+
"path_type": "hardlink",
|
| 186 |
+
"sha256": "1b68144734c4b66791f27add5d425f3620775585718a03d0f9b110ba3a4d88db",
|
| 187 |
+
"size_in_bytes": 82
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/direct_url.json",
|
| 191 |
+
"path_type": "hardlink",
|
| 192 |
+
"sha256": "ac45b47351f29f358e358b15fe254983e6ca12148d73bfdfbe66d07f661b466c",
|
| 193 |
+
"size_in_bytes": 117
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/entry_points.txt",
|
| 197 |
+
"path_type": "hardlink",
|
| 198 |
+
"sha256": "38bf39818535783f1cb8f9629227c59e05e97818dac65eab209f0a902ff7afe2",
|
| 199 |
+
"size_in_bytes": 58
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"_path": "site-packages/jinja2-3.1.6.dist-info/licenses/LICENSE.txt",
|
| 203 |
+
"path_type": "hardlink",
|
| 204 |
+
"sha256": "3b49dcee4105eb37bac10faf1be260408fe85d252b8e9df2e0979fc1e094437b",
|
| 205 |
+
"size_in_bytes": 1475
|
| 206 |
+
}
|
| 207 |
+
],
|
| 208 |
+
"paths_version": 1
|
| 209 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/recipe-scripts-license.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD-3-Clause license
|
| 2 |
+
Copyright (c) 2015-2022, conda-forge contributors
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are met:
|
| 7 |
+
|
| 8 |
+
1. Redistributions of source code must retain the above copyright notice,
|
| 9 |
+
this list of conditions and the following disclaimer.
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 14 |
+
contributors may be used to endorse or promote products derived from
|
| 15 |
+
this software without specific prior written permission.
|
| 16 |
+
|
| 17 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 18 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 19 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 20 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
| 21 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 22 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 23 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 24 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 25 |
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 26 |
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
| 27 |
+
DAMAGE.
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/recipe.yaml
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version: 1
|
| 2 |
+
|
| 3 |
+
context:
|
| 4 |
+
name: jinja2
|
| 5 |
+
version: "3.1.6"
|
| 6 |
+
|
| 7 |
+
package:
|
| 8 |
+
name: ${{ name }}
|
| 9 |
+
version: ${{ version }}
|
| 10 |
+
|
| 11 |
+
source:
|
| 12 |
+
url: https://pypi.org/packages/source/j/jinja2/jinja2-${{ version }}.tar.gz
|
| 13 |
+
sha256: 0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d
|
| 14 |
+
|
| 15 |
+
build:
|
| 16 |
+
noarch: python
|
| 17 |
+
number: 1
|
| 18 |
+
script: ${{ PYTHON }} -m pip install . --no-deps -vv --no-build-isolation
|
| 19 |
+
|
| 20 |
+
requirements:
|
| 21 |
+
host:
|
| 22 |
+
- flit-core <4
|
| 23 |
+
- pip
|
| 24 |
+
- python ${{ python_min }}.*
|
| 25 |
+
run:
|
| 26 |
+
- markupsafe >=2.0
|
| 27 |
+
- python >=${{ python_min }}
|
| 28 |
+
|
| 29 |
+
tests:
|
| 30 |
+
- python:
|
| 31 |
+
python_version: ${{ python_min }}.*
|
| 32 |
+
imports:
|
| 33 |
+
- jinja2
|
| 34 |
+
pip_check: true
|
| 35 |
+
|
| 36 |
+
about:
|
| 37 |
+
homepage: https://palletsprojects.com/p/jinja/
|
| 38 |
+
license: BSD-3-Clause
|
| 39 |
+
license_file: LICENSE.txt
|
| 40 |
+
summary: A very fast and expressive template engine.
|
| 41 |
+
description: |
|
| 42 |
+
Jinja is a fast, expressive, extensible templating engine. Special
|
| 43 |
+
placeholders in the template allow writing code similar to Python
|
| 44 |
+
syntax. Then the template is passed data to render the final document.
|
| 45 |
+
|
| 46 |
+
It includes:
|
| 47 |
+
|
| 48 |
+
- Template inheritance and inclusion.
|
| 49 |
+
- Define and import macros within templates.
|
| 50 |
+
- HTML templates can use autoescaping to prevent XSS from untrusted
|
| 51 |
+
user input.
|
| 52 |
+
- A sandboxed environment can safely render untrusted templates.
|
| 53 |
+
- AsyncIO support for generating templates and calling async
|
| 54 |
+
functions.
|
| 55 |
+
- I18N support with Babel.
|
| 56 |
+
- Templates are compiled to optimized Python code just-in-time and
|
| 57 |
+
cached, or can be compiled ahead-of-time.
|
| 58 |
+
- Exceptions point to the correct line in templates to make debugging
|
| 59 |
+
easier.
|
| 60 |
+
- Extensible filters, tests, functions, and even syntax.
|
| 61 |
+
|
| 62 |
+
Jinja's philosophy is that while application logic belongs in Python if
|
| 63 |
+
possible, it shouldn't make the template designer's job difficult by
|
| 64 |
+
restricting functionality too much.
|
| 65 |
+
documentation: https://jinja.palletsprojects.com/
|
| 66 |
+
repository: https://github.com/pallets/jinja/
|
| 67 |
+
|
| 68 |
+
extra:
|
| 69 |
+
recipe-maintainers:
|
| 70 |
+
- jakirkham
|
| 71 |
+
- msarahan
|
| 72 |
+
- scopatz
|
| 73 |
+
- nehaljwani
|
| 74 |
+
- xylar
|
| 75 |
+
- bollwyvl
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/rendered_recipe.yaml
ADDED
|
@@ -0,0 +1,683 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
recipe:
|
| 2 |
+
schema_version: 1
|
| 3 |
+
context:
|
| 4 |
+
name: jinja2
|
| 5 |
+
version: 3.1.6
|
| 6 |
+
package:
|
| 7 |
+
name: jinja2
|
| 8 |
+
version: 3.1.6
|
| 9 |
+
source:
|
| 10 |
+
- url: https://pypi.org/packages/source/j/jinja2/jinja2-3.1.6.tar.gz
|
| 11 |
+
sha256: 0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d
|
| 12 |
+
build:
|
| 13 |
+
number: 1
|
| 14 |
+
string: pyhcf101f3_1
|
| 15 |
+
script: ${{ PYTHON }} -m pip install . --no-deps -vv --no-build-isolation
|
| 16 |
+
noarch: python
|
| 17 |
+
requirements:
|
| 18 |
+
host:
|
| 19 |
+
- flit-core <4
|
| 20 |
+
- pip
|
| 21 |
+
- python 3.10.*
|
| 22 |
+
run:
|
| 23 |
+
- markupsafe >=2.0
|
| 24 |
+
- python >=3.10
|
| 25 |
+
tests:
|
| 26 |
+
- python:
|
| 27 |
+
imports:
|
| 28 |
+
- jinja2
|
| 29 |
+
python_version: 3.10.*
|
| 30 |
+
about:
|
| 31 |
+
homepage: https://palletsprojects.com/p/jinja/
|
| 32 |
+
repository: https://github.com/pallets/jinja/
|
| 33 |
+
documentation: https://jinja.palletsprojects.com/
|
| 34 |
+
license: BSD-3-Clause
|
| 35 |
+
license_file:
|
| 36 |
+
- LICENSE.txt
|
| 37 |
+
summary: A very fast and expressive template engine.
|
| 38 |
+
description: |-
|
| 39 |
+
Jinja is a fast, expressive, extensible templating engine. Special
|
| 40 |
+
placeholders in the template allow writing code similar to Python
|
| 41 |
+
syntax. Then the template is passed data to render the final document.
|
| 42 |
+
|
| 43 |
+
It includes:
|
| 44 |
+
|
| 45 |
+
- Template inheritance and inclusion.
|
| 46 |
+
- Define and import macros within templates.
|
| 47 |
+
- HTML templates can use autoescaping to prevent XSS from untrusted
|
| 48 |
+
user input.
|
| 49 |
+
- A sandboxed environment can safely render untrusted templates.
|
| 50 |
+
- AsyncIO support for generating templates and calling async
|
| 51 |
+
functions.
|
| 52 |
+
- I18N support with Babel.
|
| 53 |
+
- Templates are compiled to optimized Python code just-in-time and
|
| 54 |
+
cached, or can be compiled ahead-of-time.
|
| 55 |
+
- Exceptions point to the correct line in templates to make debugging
|
| 56 |
+
easier.
|
| 57 |
+
- Extensible filters, tests, functions, and even syntax.
|
| 58 |
+
|
| 59 |
+
Jinja's philosophy is that while application logic belongs in Python if
|
| 60 |
+
possible, it shouldn't make the template designer's job difficult by
|
| 61 |
+
restricting functionality too much.
|
| 62 |
+
extra:
|
| 63 |
+
recipe-maintainers:
|
| 64 |
+
- jakirkham
|
| 65 |
+
- msarahan
|
| 66 |
+
- scopatz
|
| 67 |
+
- nehaljwani
|
| 68 |
+
- xylar
|
| 69 |
+
- bollwyvl
|
| 70 |
+
build_configuration:
|
| 71 |
+
target_platform: noarch
|
| 72 |
+
host_platform:
|
| 73 |
+
platform: linux-64
|
| 74 |
+
virtual_packages:
|
| 75 |
+
- __unix=0=0
|
| 76 |
+
- __linux=6.11.0=0
|
| 77 |
+
- __glibc=2.34=0
|
| 78 |
+
- __archspec=1=zen2
|
| 79 |
+
build_platform:
|
| 80 |
+
platform: linux-64
|
| 81 |
+
virtual_packages:
|
| 82 |
+
- __unix=0=0
|
| 83 |
+
- __linux=6.11.0=0
|
| 84 |
+
- __glibc=2.34=0
|
| 85 |
+
- __archspec=1=zen2
|
| 86 |
+
variant:
|
| 87 |
+
channel_sources: conda-forge
|
| 88 |
+
channel_targets: conda-forge main
|
| 89 |
+
python_min: '3.10'
|
| 90 |
+
target_platform: noarch
|
| 91 |
+
hash:
|
| 92 |
+
hash: cf101f3
|
| 93 |
+
prefix: py
|
| 94 |
+
directories:
|
| 95 |
+
host_prefix: /home/conda/feedstock_root/build_artifacts/bld/rattler-build_jinja2_1764517220/host_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho
|
| 96 |
+
build_prefix: /home/conda/feedstock_root/build_artifacts/bld/rattler-build_jinja2_1764517220/build_env
|
| 97 |
+
work_dir: /home/conda/feedstock_root/build_artifacts/bld/rattler-build_jinja2_1764517220/work
|
| 98 |
+
build_dir: /home/conda/feedstock_root/build_artifacts/bld/rattler-build_jinja2_1764517220
|
| 99 |
+
channels:
|
| 100 |
+
- https://conda.anaconda.org/conda-forge
|
| 101 |
+
channel_priority: strict
|
| 102 |
+
solve_strategy: highest
|
| 103 |
+
timestamp: 2025-11-30T15:40:20.861482210Z
|
| 104 |
+
subpackages:
|
| 105 |
+
jinja2:
|
| 106 |
+
name: jinja2
|
| 107 |
+
version: 3.1.6
|
| 108 |
+
build_string: pyhcf101f3_1
|
| 109 |
+
packaging_settings:
|
| 110 |
+
archive_type: conda
|
| 111 |
+
compression_level: 15
|
| 112 |
+
finalized_dependencies:
|
| 113 |
+
build: null
|
| 114 |
+
host:
|
| 115 |
+
specs:
|
| 116 |
+
- source: flit-core <4
|
| 117 |
+
- source: pip
|
| 118 |
+
- source: python 3.10.*
|
| 119 |
+
resolved:
|
| 120 |
+
- build: pyhd8ed1ab_0
|
| 121 |
+
build_number: 0
|
| 122 |
+
constrains:
|
| 123 |
+
- flit 3.12.0
|
| 124 |
+
depends:
|
| 125 |
+
- python >=3.9
|
| 126 |
+
license: BSD-3-Clause
|
| 127 |
+
license_family: BSD
|
| 128 |
+
md5: 398b491697697ec20c6e76599902d994
|
| 129 |
+
name: flit-core
|
| 130 |
+
noarch: python
|
| 131 |
+
run_exports: {}
|
| 132 |
+
sha256: 59fa12dca53b466f1866782a59a35bbb8220a20ff0589b0c424b52d0f2c52793
|
| 133 |
+
size: 44262
|
| 134 |
+
subdir: noarch
|
| 135 |
+
timestamp: 1742900933050
|
| 136 |
+
version: 3.12.0
|
| 137 |
+
fn: flit-core-3.12.0-pyhd8ed1ab_0.conda
|
| 138 |
+
url: https://conda.anaconda.org/conda-forge/noarch/flit-core-3.12.0-pyhd8ed1ab_0.conda
|
| 139 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 140 |
+
- build: pyh8b19718_0
|
| 141 |
+
build_number: 0
|
| 142 |
+
depends:
|
| 143 |
+
- python >=3.10,<3.13.0a0
|
| 144 |
+
- setuptools
|
| 145 |
+
- wheel
|
| 146 |
+
license: MIT
|
| 147 |
+
license_family: MIT
|
| 148 |
+
md5: c55515ca43c6444d2572e0f0d93cb6b9
|
| 149 |
+
name: pip
|
| 150 |
+
noarch: python
|
| 151 |
+
run_exports: {}
|
| 152 |
+
sha256: b67692da1c0084516ac1c9ada4d55eaf3c5891b54980f30f3f444541c2706f1e
|
| 153 |
+
size: 1177534
|
| 154 |
+
subdir: noarch
|
| 155 |
+
timestamp: 1762776258783
|
| 156 |
+
version: '25.3'
|
| 157 |
+
fn: pip-25.3-pyh8b19718_0.conda
|
| 158 |
+
url: https://conda.anaconda.org/conda-forge/noarch/pip-25.3-pyh8b19718_0.conda
|
| 159 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 160 |
+
- build: h3c07f61_2_cpython
|
| 161 |
+
build_number: 2
|
| 162 |
+
constrains:
|
| 163 |
+
- python_abi 3.10.* *_cp310
|
| 164 |
+
depends:
|
| 165 |
+
- __glibc >=2.17,<3.0.a0
|
| 166 |
+
- bzip2 >=1.0.8,<2.0a0
|
| 167 |
+
- ld_impl_linux-64 >=2.36.1
|
| 168 |
+
- libexpat >=2.7.1,<3.0a0
|
| 169 |
+
- libffi >=3.4,<4.0a0
|
| 170 |
+
- libgcc >=14
|
| 171 |
+
- liblzma >=5.8.1,<6.0a0
|
| 172 |
+
- libnsl >=2.0.1,<2.1.0a0
|
| 173 |
+
- libsqlite >=3.50.4,<4.0a0
|
| 174 |
+
- libuuid >=2.41.2,<3.0a0
|
| 175 |
+
- libxcrypt >=4.4.36
|
| 176 |
+
- libzlib >=1.3.1,<2.0a0
|
| 177 |
+
- ncurses >=6.5,<7.0a0
|
| 178 |
+
- openssl >=3.5.4,<4.0a0
|
| 179 |
+
- readline >=8.2,<9.0a0
|
| 180 |
+
- tk >=8.6.13,<8.7.0a0
|
| 181 |
+
- tzdata
|
| 182 |
+
license: Python-2.0
|
| 183 |
+
md5: 27ac896a8b4970f8977503a9e70dc745
|
| 184 |
+
name: python
|
| 185 |
+
run_exports:
|
| 186 |
+
weak:
|
| 187 |
+
- python_abi 3.10.* *_cp310
|
| 188 |
+
noarch:
|
| 189 |
+
- python
|
| 190 |
+
sha256: 6e3b6b69b3cacfc7610155d58407a003820eaacd50fbe039abff52b5e70b1e9b
|
| 191 |
+
size: 25311690
|
| 192 |
+
subdir: linux-64
|
| 193 |
+
timestamp: 1761173015969
|
| 194 |
+
version: 3.10.19
|
| 195 |
+
fn: python-3.10.19-h3c07f61_2_cpython.conda
|
| 196 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/python-3.10.19-h3c07f61_2_cpython.conda
|
| 197 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 198 |
+
- build: he9a06e4_0
|
| 199 |
+
build_number: 0
|
| 200 |
+
depends:
|
| 201 |
+
- __glibc >=2.17,<3.0.a0
|
| 202 |
+
- libgcc >=14
|
| 203 |
+
license: BSD-3-Clause
|
| 204 |
+
license_family: BSD
|
| 205 |
+
md5: 80c07c68d2f6870250959dcc95b209d1
|
| 206 |
+
name: libuuid
|
| 207 |
+
run_exports:
|
| 208 |
+
weak:
|
| 209 |
+
- libuuid >=2.41.2,<3.0a0
|
| 210 |
+
sha256: e5ec6d2ad7eef538ddcb9ea62ad4346fde70a4736342c4ad87bd713641eb9808
|
| 211 |
+
size: 37135
|
| 212 |
+
subdir: linux-64
|
| 213 |
+
timestamp: 1758626800002
|
| 214 |
+
version: 2.41.2
|
| 215 |
+
fn: libuuid-2.41.2-he9a06e4_0.conda
|
| 216 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.41.2-he9a06e4_0.conda
|
| 217 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 218 |
+
- build: pyhff2d567_0
|
| 219 |
+
build_number: 0
|
| 220 |
+
depends:
|
| 221 |
+
- python >=3.9
|
| 222 |
+
license: MIT
|
| 223 |
+
license_family: MIT
|
| 224 |
+
md5: 4de79c071274a53dcaf2a8c749d1499e
|
| 225 |
+
name: setuptools
|
| 226 |
+
noarch: python
|
| 227 |
+
run_exports: {}
|
| 228 |
+
sha256: 972560fcf9657058e3e1f97186cc94389144b46dbdf58c807ce62e83f977e863
|
| 229 |
+
size: 748788
|
| 230 |
+
subdir: noarch
|
| 231 |
+
timestamp: 1748804951958
|
| 232 |
+
version: 80.9.0
|
| 233 |
+
fn: setuptools-80.9.0-pyhff2d567_0.conda
|
| 234 |
+
url: https://conda.anaconda.org/conda-forge/noarch/setuptools-80.9.0-pyhff2d567_0.conda
|
| 235 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 236 |
+
- build: pyhd8ed1ab_1
|
| 237 |
+
build_number: 1
|
| 238 |
+
depends:
|
| 239 |
+
- python >=3.9
|
| 240 |
+
license: MIT
|
| 241 |
+
license_family: MIT
|
| 242 |
+
md5: 75cb7132eb58d97896e173ef12ac9986
|
| 243 |
+
name: wheel
|
| 244 |
+
noarch: python
|
| 245 |
+
run_exports: {}
|
| 246 |
+
sha256: 1b34021e815ff89a4d902d879c3bd2040bc1bd6169b32e9427497fa05c55f1ce
|
| 247 |
+
size: 62931
|
| 248 |
+
subdir: noarch
|
| 249 |
+
timestamp: 1733130309598
|
| 250 |
+
version: 0.45.1
|
| 251 |
+
fn: wheel-0.45.1-pyhd8ed1ab_1.conda
|
| 252 |
+
url: https://conda.anaconda.org/conda-forge/noarch/wheel-0.45.1-pyhd8ed1ab_1.conda
|
| 253 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 254 |
+
- build: hda65f42_8
|
| 255 |
+
build_number: 8
|
| 256 |
+
depends:
|
| 257 |
+
- __glibc >=2.17,<3.0.a0
|
| 258 |
+
- libgcc >=14
|
| 259 |
+
license: bzip2-1.0.6
|
| 260 |
+
license_family: BSD
|
| 261 |
+
md5: 51a19bba1b8ebfb60df25cde030b7ebc
|
| 262 |
+
name: bzip2
|
| 263 |
+
run_exports:
|
| 264 |
+
weak:
|
| 265 |
+
- bzip2 >=1.0.8,<2.0a0
|
| 266 |
+
sha256: c30daba32ddebbb7ded490f0e371eae90f51e72db620554089103b4a6934b0d5
|
| 267 |
+
size: 260341
|
| 268 |
+
subdir: linux-64
|
| 269 |
+
timestamp: 1757437258798
|
| 270 |
+
version: 1.0.8
|
| 271 |
+
fn: bzip2-1.0.8-hda65f42_8.conda
|
| 272 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hda65f42_8.conda
|
| 273 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 274 |
+
- build: default_hbd61a6d_104
|
| 275 |
+
build_number: 104
|
| 276 |
+
constrains:
|
| 277 |
+
- binutils_impl_linux-64 2.45
|
| 278 |
+
depends:
|
| 279 |
+
- __glibc >=2.17,<3.0.a0
|
| 280 |
+
- zstd >=1.5.7,<1.6.0a0
|
| 281 |
+
license: GPL-3.0-only
|
| 282 |
+
license_family: GPL
|
| 283 |
+
md5: a6abd2796fc332536735f68ba23f7901
|
| 284 |
+
name: ld_impl_linux-64
|
| 285 |
+
run_exports: {}
|
| 286 |
+
sha256: 9e191baf2426a19507f1d0a17be0fdb7aa155cdf0f61d5a09c808e0a69464312
|
| 287 |
+
size: 725545
|
| 288 |
+
subdir: linux-64
|
| 289 |
+
timestamp: 1764007826689
|
| 290 |
+
version: '2.45'
|
| 291 |
+
fn: ld_impl_linux-64-2.45-default_hbd61a6d_104.conda
|
| 292 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.45-default_hbd61a6d_104.conda
|
| 293 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 294 |
+
- build: hecca717_0
|
| 295 |
+
build_number: 0
|
| 296 |
+
constrains:
|
| 297 |
+
- expat 2.7.3.*
|
| 298 |
+
depends:
|
| 299 |
+
- __glibc >=2.17,<3.0.a0
|
| 300 |
+
- libgcc >=14
|
| 301 |
+
license: MIT
|
| 302 |
+
license_family: MIT
|
| 303 |
+
md5: 8b09ae86839581147ef2e5c5e229d164
|
| 304 |
+
name: libexpat
|
| 305 |
+
run_exports: {}
|
| 306 |
+
sha256: 1e1b08f6211629cbc2efe7a5bca5953f8f6b3cae0eeb04ca4dacee1bd4e2db2f
|
| 307 |
+
size: 76643
|
| 308 |
+
subdir: linux-64
|
| 309 |
+
timestamp: 1763549731408
|
| 310 |
+
version: 2.7.3
|
| 311 |
+
fn: libexpat-2.7.3-hecca717_0.conda
|
| 312 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.7.3-hecca717_0.conda
|
| 313 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 314 |
+
- build: h9ec8514_0
|
| 315 |
+
build_number: 0
|
| 316 |
+
depends:
|
| 317 |
+
- __glibc >=2.17,<3.0.a0
|
| 318 |
+
- libgcc >=14
|
| 319 |
+
license: MIT
|
| 320 |
+
license_family: MIT
|
| 321 |
+
md5: 35f29eec58405aaf55e01cb470d8c26a
|
| 322 |
+
name: libffi
|
| 323 |
+
run_exports:
|
| 324 |
+
weak:
|
| 325 |
+
- libffi >=3.5.2,<3.6.0a0
|
| 326 |
+
sha256: 25cbdfa65580cfab1b8d15ee90b4c9f1e0d72128f1661449c9a999d341377d54
|
| 327 |
+
size: 57821
|
| 328 |
+
subdir: linux-64
|
| 329 |
+
timestamp: 1760295480630
|
| 330 |
+
version: 3.5.2
|
| 331 |
+
fn: libffi-3.5.2-h9ec8514_0.conda
|
| 332 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libffi-3.5.2-h9ec8514_0.conda
|
| 333 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 334 |
+
- build: he0feb66_14
|
| 335 |
+
build_number: 14
|
| 336 |
+
constrains:
|
| 337 |
+
- libgomp 15.2.0 he0feb66_14
|
| 338 |
+
- libgcc-ng ==15.2.0=*_14
|
| 339 |
+
depends:
|
| 340 |
+
- __glibc >=2.17,<3.0.a0
|
| 341 |
+
- _openmp_mutex >=4.5
|
| 342 |
+
license: GPL-3.0-only WITH GCC-exception-3.1
|
| 343 |
+
license_family: GPL
|
| 344 |
+
md5: 550dceb769d23bcf0e2f97fd4062d720
|
| 345 |
+
name: libgcc
|
| 346 |
+
run_exports: {}
|
| 347 |
+
sha256: 947bfbe5e47cd5d0cbdb0926d4baadb3e9be25caca7c6c6ef516f7ef85052cec
|
| 348 |
+
size: 1041047
|
| 349 |
+
subdir: linux-64
|
| 350 |
+
timestamp: 1764277103389
|
| 351 |
+
version: 15.2.0
|
| 352 |
+
fn: libgcc-15.2.0-he0feb66_14.conda
|
| 353 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libgcc-15.2.0-he0feb66_14.conda
|
| 354 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 355 |
+
- build: hb9d3cd8_2
|
| 356 |
+
build_number: 2
|
| 357 |
+
constrains:
|
| 358 |
+
- xz 5.8.1.*
|
| 359 |
+
depends:
|
| 360 |
+
- __glibc >=2.17,<3.0.a0
|
| 361 |
+
- libgcc >=13
|
| 362 |
+
license: 0BSD
|
| 363 |
+
md5: 1a580f7796c7bf6393fddb8bbbde58dc
|
| 364 |
+
name: liblzma
|
| 365 |
+
run_exports:
|
| 366 |
+
weak:
|
| 367 |
+
- liblzma >=5.8.1,<6.0a0
|
| 368 |
+
sha256: f2591c0069447bbe28d4d696b7fcb0c5bd0b4ac582769b89addbcf26fb3430d8
|
| 369 |
+
size: 112894
|
| 370 |
+
subdir: linux-64
|
| 371 |
+
timestamp: 1749230047870
|
| 372 |
+
version: 5.8.1
|
| 373 |
+
fn: liblzma-5.8.1-hb9d3cd8_2.conda
|
| 374 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/liblzma-5.8.1-hb9d3cd8_2.conda
|
| 375 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 376 |
+
- build: hb9d3cd8_1
|
| 377 |
+
build_number: 1
|
| 378 |
+
depends:
|
| 379 |
+
- __glibc >=2.17,<3.0.a0
|
| 380 |
+
- libgcc >=13
|
| 381 |
+
license: LGPL-2.1-only
|
| 382 |
+
license_family: GPL
|
| 383 |
+
md5: d864d34357c3b65a4b731f78c0801dc4
|
| 384 |
+
name: libnsl
|
| 385 |
+
run_exports:
|
| 386 |
+
weak:
|
| 387 |
+
- libnsl >=2.0.1,<2.1.0a0
|
| 388 |
+
sha256: 927fe72b054277cde6cb82597d0fcf6baf127dcbce2e0a9d8925a68f1265eef5
|
| 389 |
+
size: 33731
|
| 390 |
+
subdir: linux-64
|
| 391 |
+
timestamp: 1750274110928
|
| 392 |
+
version: 2.0.1
|
| 393 |
+
fn: libnsl-2.0.1-hb9d3cd8_1.conda
|
| 394 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libnsl-2.0.1-hb9d3cd8_1.conda
|
| 395 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 396 |
+
- build: h0c1763c_0
|
| 397 |
+
build_number: 0
|
| 398 |
+
depends:
|
| 399 |
+
- __glibc >=2.17,<3.0.a0
|
| 400 |
+
- libgcc >=14
|
| 401 |
+
- libzlib >=1.3.1,<2.0a0
|
| 402 |
+
license: blessing
|
| 403 |
+
md5: 2e1b84d273b01835256e53fd938de355
|
| 404 |
+
name: libsqlite
|
| 405 |
+
run_exports:
|
| 406 |
+
weak:
|
| 407 |
+
- libsqlite >=3.51.1,<4.0a0
|
| 408 |
+
sha256: 6f0e8a812e8e33a4d8b7a0e595efe28373080d27b78ee4828aa4f6649a088454
|
| 409 |
+
size: 938979
|
| 410 |
+
subdir: linux-64
|
| 411 |
+
timestamp: 1764359444435
|
| 412 |
+
version: 3.51.1
|
| 413 |
+
fn: libsqlite-3.51.1-h0c1763c_0.conda
|
| 414 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.51.1-h0c1763c_0.conda
|
| 415 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 416 |
+
- build: hd590300_1
|
| 417 |
+
build_number: 1
|
| 418 |
+
depends:
|
| 419 |
+
- libgcc-ng >=12
|
| 420 |
+
license: LGPL-2.1-or-later
|
| 421 |
+
md5: 5aa797f8787fe7a17d1b0821485b5adc
|
| 422 |
+
name: libxcrypt
|
| 423 |
+
run_exports:
|
| 424 |
+
weak:
|
| 425 |
+
- libxcrypt >=4.4.36
|
| 426 |
+
sha256: 6ae68e0b86423ef188196fff6207ed0c8195dd84273cb5623b85aa08033a410c
|
| 427 |
+
size: 100393
|
| 428 |
+
subdir: linux-64
|
| 429 |
+
timestamp: 1702724383534
|
| 430 |
+
version: 4.4.36
|
| 431 |
+
fn: libxcrypt-4.4.36-hd590300_1.conda
|
| 432 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda
|
| 433 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 434 |
+
- build: h69a702a_14
|
| 435 |
+
build_number: 14
|
| 436 |
+
depends:
|
| 437 |
+
- libgcc 15.2.0 he0feb66_14
|
| 438 |
+
license: GPL-3.0-only WITH GCC-exception-3.1
|
| 439 |
+
license_family: GPL
|
| 440 |
+
md5: 6c13aaae36d7514f28bd5544da1a7bb8
|
| 441 |
+
name: libgcc-ng
|
| 442 |
+
run_exports:
|
| 443 |
+
strong:
|
| 444 |
+
- libgcc
|
| 445 |
+
sha256: 48a77fde940b4b877c0ed24efd562c135170a46d100c07cd2d7b67e842e30642
|
| 446 |
+
size: 27157
|
| 447 |
+
subdir: linux-64
|
| 448 |
+
timestamp: 1764277114484
|
| 449 |
+
version: 15.2.0
|
| 450 |
+
fn: libgcc-ng-15.2.0-h69a702a_14.conda
|
| 451 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-15.2.0-h69a702a_14.conda
|
| 452 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 453 |
+
- build: hb9d3cd8_2
|
| 454 |
+
build_number: 2
|
| 455 |
+
constrains:
|
| 456 |
+
- zlib 1.3.1 *_2
|
| 457 |
+
depends:
|
| 458 |
+
- __glibc >=2.17,<3.0.a0
|
| 459 |
+
- libgcc >=13
|
| 460 |
+
license: Zlib
|
| 461 |
+
license_family: Other
|
| 462 |
+
md5: edb0dca6bc32e4f4789199455a1dbeb8
|
| 463 |
+
name: libzlib
|
| 464 |
+
run_exports:
|
| 465 |
+
weak:
|
| 466 |
+
- libzlib >=1.3.1,<2.0a0
|
| 467 |
+
sha256: d4bfe88d7cb447768e31650f06257995601f89076080e76df55e3112d4e47dc4
|
| 468 |
+
size: 60963
|
| 469 |
+
subdir: linux-64
|
| 470 |
+
timestamp: 1727963148474
|
| 471 |
+
version: 1.3.1
|
| 472 |
+
fn: libzlib-1.3.1-hb9d3cd8_2.conda
|
| 473 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.1-hb9d3cd8_2.conda
|
| 474 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 475 |
+
- build: h2d0b736_3
|
| 476 |
+
build_number: 3
|
| 477 |
+
depends:
|
| 478 |
+
- __glibc >=2.17,<3.0.a0
|
| 479 |
+
- libgcc >=13
|
| 480 |
+
license: X11 AND BSD-3-Clause
|
| 481 |
+
md5: 47e340acb35de30501a76c7c799c41d7
|
| 482 |
+
name: ncurses
|
| 483 |
+
run_exports:
|
| 484 |
+
weak:
|
| 485 |
+
- ncurses >=6.5,<7.0a0
|
| 486 |
+
sha256: 3fde293232fa3fca98635e1167de6b7c7fda83caf24b9d6c91ec9eefb4f4d586
|
| 487 |
+
size: 891641
|
| 488 |
+
subdir: linux-64
|
| 489 |
+
timestamp: 1738195959188
|
| 490 |
+
version: '6.5'
|
| 491 |
+
fn: ncurses-6.5-h2d0b736_3.conda
|
| 492 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.5-h2d0b736_3.conda
|
| 493 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 494 |
+
- build: h26f9b46_0
|
| 495 |
+
build_number: 0
|
| 496 |
+
depends:
|
| 497 |
+
- __glibc >=2.17,<3.0.a0
|
| 498 |
+
- ca-certificates
|
| 499 |
+
- libgcc >=14
|
| 500 |
+
license: Apache-2.0
|
| 501 |
+
license_family: Apache
|
| 502 |
+
md5: 9ee58d5c534af06558933af3c845a780
|
| 503 |
+
name: openssl
|
| 504 |
+
run_exports:
|
| 505 |
+
weak:
|
| 506 |
+
- openssl >=3.6.0,<4.0a0
|
| 507 |
+
sha256: a47271202f4518a484956968335b2521409c8173e123ab381e775c358c67fe6d
|
| 508 |
+
size: 3165399
|
| 509 |
+
subdir: linux-64
|
| 510 |
+
timestamp: 1762839186699
|
| 511 |
+
version: 3.6.0
|
| 512 |
+
fn: openssl-3.6.0-h26f9b46_0.conda
|
| 513 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/openssl-3.6.0-h26f9b46_0.conda
|
| 514 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 515 |
+
- build: h8c095d6_2
|
| 516 |
+
build_number: 2
|
| 517 |
+
depends:
|
| 518 |
+
- libgcc >=13
|
| 519 |
+
- ncurses >=6.5,<7.0a0
|
| 520 |
+
license: GPL-3.0-only
|
| 521 |
+
license_family: GPL
|
| 522 |
+
md5: 283b96675859b20a825f8fa30f311446
|
| 523 |
+
name: readline
|
| 524 |
+
run_exports:
|
| 525 |
+
weak:
|
| 526 |
+
- readline >=8.2,<9.0a0
|
| 527 |
+
sha256: 2d6d0c026902561ed77cd646b5021aef2d4db22e57a5b0178dfc669231e06d2c
|
| 528 |
+
size: 282480
|
| 529 |
+
subdir: linux-64
|
| 530 |
+
timestamp: 1740379431762
|
| 531 |
+
version: '8.2'
|
| 532 |
+
fn: readline-8.2-h8c095d6_2.conda
|
| 533 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8c095d6_2.conda
|
| 534 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 535 |
+
- build: noxft_ha0e22de_103
|
| 536 |
+
build_number: 103
|
| 537 |
+
constrains:
|
| 538 |
+
- xorg-libx11 >=1.8.12,<2.0a0
|
| 539 |
+
depends:
|
| 540 |
+
- __glibc >=2.17,<3.0.a0
|
| 541 |
+
- libgcc >=13
|
| 542 |
+
- libzlib >=1.3.1,<2.0a0
|
| 543 |
+
license: TCL
|
| 544 |
+
license_family: BSD
|
| 545 |
+
md5: 86bc20552bf46075e3d92b67f089172d
|
| 546 |
+
name: tk
|
| 547 |
+
run_exports:
|
| 548 |
+
weak:
|
| 549 |
+
- tk >=8.6.13,<8.7.0a0
|
| 550 |
+
sha256: 1544760538a40bcd8ace2b1d8ebe3eb5807ac268641f8acdc18c69c5ebfeaf64
|
| 551 |
+
size: 3284905
|
| 552 |
+
subdir: linux-64
|
| 553 |
+
timestamp: 1763054914403
|
| 554 |
+
version: 8.6.13
|
| 555 |
+
fn: tk-8.6.13-noxft_ha0e22de_103.conda
|
| 556 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_ha0e22de_103.conda
|
| 557 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 558 |
+
- build: h78e105d_0
|
| 559 |
+
build_number: 0
|
| 560 |
+
depends: []
|
| 561 |
+
license: LicenseRef-Public-Domain
|
| 562 |
+
md5: 4222072737ccff51314b5ece9c7d6f5a
|
| 563 |
+
name: tzdata
|
| 564 |
+
noarch: generic
|
| 565 |
+
run_exports: {}
|
| 566 |
+
sha256: 5aaa366385d716557e365f0a4e9c3fca43ba196872abbbe3d56bb610d131e192
|
| 567 |
+
size: 122968
|
| 568 |
+
subdir: noarch
|
| 569 |
+
timestamp: 1742727099393
|
| 570 |
+
version: 2025b
|
| 571 |
+
fn: tzdata-2025b-h78e105d_0.conda
|
| 572 |
+
url: https://conda.anaconda.org/conda-forge/noarch/tzdata-2025b-h78e105d_0.conda
|
| 573 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 574 |
+
- build: h3691f8a_4
|
| 575 |
+
build_number: 4
|
| 576 |
+
depends:
|
| 577 |
+
- __glibc >=2.17,<3.0.a0
|
| 578 |
+
- libzlib >=1.3.1,<2.0a0
|
| 579 |
+
license: BSD-3-Clause
|
| 580 |
+
license_family: BSD
|
| 581 |
+
md5: af7715829219de9043fcc5575e66d22e
|
| 582 |
+
name: zstd
|
| 583 |
+
run_exports:
|
| 584 |
+
weak:
|
| 585 |
+
- zstd >=1.5.7,<1.6.0a0
|
| 586 |
+
sha256: 58e0344d81520c8734533fff64a28a5be7edf84618341fc70d3e20bd0a1fdc3e
|
| 587 |
+
size: 559888
|
| 588 |
+
subdir: linux-64
|
| 589 |
+
timestamp: 1764431250718
|
| 590 |
+
version: 1.5.7
|
| 591 |
+
fn: zstd-1.5.7-h3691f8a_4.conda
|
| 592 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.7-h3691f8a_4.conda
|
| 593 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 594 |
+
- build: 2_gnu
|
| 595 |
+
build_number: 16
|
| 596 |
+
constrains:
|
| 597 |
+
- openmp_impl 9999
|
| 598 |
+
depends:
|
| 599 |
+
- _libgcc_mutex 0.1 conda_forge
|
| 600 |
+
- libgomp >=7.5.0
|
| 601 |
+
license: BSD-3-Clause
|
| 602 |
+
license_family: BSD
|
| 603 |
+
md5: 73aaf86a425cc6e73fcf236a5a46396d
|
| 604 |
+
name: _openmp_mutex
|
| 605 |
+
run_exports:
|
| 606 |
+
strong:
|
| 607 |
+
- _openmp_mutex >=4.5
|
| 608 |
+
sha256: fbe2c5e56a653bebb982eda4876a9178aedfc2b545f25d0ce9c4c0b508253d22
|
| 609 |
+
size: 23621
|
| 610 |
+
subdir: linux-64
|
| 611 |
+
timestamp: 1650670423406
|
| 612 |
+
version: '4.5'
|
| 613 |
+
fn: _openmp_mutex-4.5-2_gnu.tar.bz2
|
| 614 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2
|
| 615 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 616 |
+
- build: he0feb66_14
|
| 617 |
+
build_number: 14
|
| 618 |
+
depends:
|
| 619 |
+
- __glibc >=2.17,<3.0.a0
|
| 620 |
+
license: GPL-3.0-only WITH GCC-exception-3.1
|
| 621 |
+
license_family: GPL
|
| 622 |
+
md5: 91349c276f84f590487e4c7f6e90e077
|
| 623 |
+
name: libgomp
|
| 624 |
+
run_exports:
|
| 625 |
+
strong:
|
| 626 |
+
- _openmp_mutex >=4.5
|
| 627 |
+
sha256: 2017cbc0f0f3b1d15df9ca681960eef015f9f58ba0d6e841694277a9f7eae0fc
|
| 628 |
+
size: 604220
|
| 629 |
+
subdir: linux-64
|
| 630 |
+
timestamp: 1764277020855
|
| 631 |
+
version: 15.2.0
|
| 632 |
+
fn: libgomp-15.2.0-he0feb66_14.conda
|
| 633 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/libgomp-15.2.0-he0feb66_14.conda
|
| 634 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 635 |
+
- build: conda_forge
|
| 636 |
+
build_number: 0
|
| 637 |
+
depends: []
|
| 638 |
+
license: None
|
| 639 |
+
md5: d7c89558ba9fa0495403155b64376d81
|
| 640 |
+
name: _libgcc_mutex
|
| 641 |
+
run_exports: {}
|
| 642 |
+
sha256: fe51de6107f9edc7aa4f786a70f4a883943bc9d39b3bb7307c04c41410990726
|
| 643 |
+
size: 2562
|
| 644 |
+
subdir: linux-64
|
| 645 |
+
timestamp: 1578324546067
|
| 646 |
+
version: '0.1'
|
| 647 |
+
fn: _libgcc_mutex-0.1-conda_forge.tar.bz2
|
| 648 |
+
url: https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2
|
| 649 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 650 |
+
- build: hbd8a1cb_0
|
| 651 |
+
build_number: 0
|
| 652 |
+
depends:
|
| 653 |
+
- __unix
|
| 654 |
+
license: ISC
|
| 655 |
+
md5: f0991f0f84902f6b6009b4d2350a83aa
|
| 656 |
+
name: ca-certificates
|
| 657 |
+
noarch: generic
|
| 658 |
+
run_exports: {}
|
| 659 |
+
sha256: b986ba796d42c9d3265602bc038f6f5264095702dd546c14bc684e60c385e773
|
| 660 |
+
size: 152432
|
| 661 |
+
subdir: noarch
|
| 662 |
+
timestamp: 1762967197890
|
| 663 |
+
version: 2025.11.12
|
| 664 |
+
fn: ca-certificates-2025.11.12-hbd8a1cb_0.conda
|
| 665 |
+
url: https://conda.anaconda.org/conda-forge/noarch/ca-certificates-2025.11.12-hbd8a1cb_0.conda
|
| 666 |
+
channel: https://conda.anaconda.org/conda-forge/
|
| 667 |
+
run:
|
| 668 |
+
depends:
|
| 669 |
+
- source: markupsafe >=2.0
|
| 670 |
+
- source: python >=3.10
|
| 671 |
+
- spec: python
|
| 672 |
+
from: host
|
| 673 |
+
run_export: python
|
| 674 |
+
constraints: []
|
| 675 |
+
finalized_sources:
|
| 676 |
+
- url: https://pypi.org/packages/source/j/jinja2/jinja2-3.1.6.tar.gz
|
| 677 |
+
sha256: 0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d
|
| 678 |
+
system_tools:
|
| 679 |
+
rattler-build: 0.53.0
|
| 680 |
+
extra_meta:
|
| 681 |
+
flow_run_id: azure_20251130.1.1
|
| 682 |
+
remote_url: https://github.com/conda-forge/jinja2-feedstock
|
| 683 |
+
sha: 8bd6e62c7d52ad5bb585c456a7989f04e51e9c51
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/recipe/variant_config.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
channel_sources: conda-forge
|
| 2 |
+
channel_targets: conda-forge main
|
| 3 |
+
python_min: '3.10'
|
| 4 |
+
target_platform: noarch
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/repodata_record.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"build": "pyhcf101f3_1",
|
| 3 |
+
"build_number": 1,
|
| 4 |
+
"build_string": "pyhcf101f3_1",
|
| 5 |
+
"channel": "conda-forge",
|
| 6 |
+
"constrains": [],
|
| 7 |
+
"depends": [
|
| 8 |
+
"markupsafe >=2.0",
|
| 9 |
+
"python >=3.10",
|
| 10 |
+
"python"
|
| 11 |
+
],
|
| 12 |
+
"fn": "jinja2-3.1.6-pyhcf101f3_1.conda",
|
| 13 |
+
"license": "BSD-3-Clause",
|
| 14 |
+
"md5": "04558c96691bed63104678757beb4f8d",
|
| 15 |
+
"name": "jinja2",
|
| 16 |
+
"noarch": "python",
|
| 17 |
+
"sha256": "fc9ca7348a4f25fed2079f2153ecdcf5f9cf2a0bc36c4172420ca09e1849df7b",
|
| 18 |
+
"size": 120685,
|
| 19 |
+
"subdir": "noarch",
|
| 20 |
+
"timestamp": 1764517220,
|
| 21 |
+
"url": "https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1.conda",
|
| 22 |
+
"version": "3.1.6"
|
| 23 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/info/tests/tests.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- python:
|
| 2 |
+
imports:
|
| 3 |
+
- jinja2
|
| 4 |
+
python_version: 3.10.*
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
conda
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/METADATA
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: Jinja2
|
| 3 |
+
Version: 3.1.6
|
| 4 |
+
Summary: A very fast and expressive template engine.
|
| 5 |
+
Maintainer-email: Pallets <contact@palletsprojects.com>
|
| 6 |
+
Requires-Python: >=3.7
|
| 7 |
+
Description-Content-Type: text/markdown
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Environment :: Web Environment
|
| 10 |
+
Classifier: Intended Audience :: Developers
|
| 11 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 12 |
+
Classifier: Operating System :: OS Independent
|
| 13 |
+
Classifier: Programming Language :: Python
|
| 14 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 15 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
| 16 |
+
Classifier: Typing :: Typed
|
| 17 |
+
License-File: LICENSE.txt
|
| 18 |
+
Requires-Dist: MarkupSafe>=2.0
|
| 19 |
+
Requires-Dist: Babel>=2.7 ; extra == "i18n"
|
| 20 |
+
Project-URL: Changes, https://jinja.palletsprojects.com/changes/
|
| 21 |
+
Project-URL: Chat, https://discord.gg/pallets
|
| 22 |
+
Project-URL: Documentation, https://jinja.palletsprojects.com/
|
| 23 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
| 24 |
+
Project-URL: Source, https://github.com/pallets/jinja/
|
| 25 |
+
Provides-Extra: i18n
|
| 26 |
+
|
| 27 |
+
# Jinja
|
| 28 |
+
|
| 29 |
+
Jinja is a fast, expressive, extensible templating engine. Special
|
| 30 |
+
placeholders in the template allow writing code similar to Python
|
| 31 |
+
syntax. Then the template is passed data to render the final document.
|
| 32 |
+
|
| 33 |
+
It includes:
|
| 34 |
+
|
| 35 |
+
- Template inheritance and inclusion.
|
| 36 |
+
- Define and import macros within templates.
|
| 37 |
+
- HTML templates can use autoescaping to prevent XSS from untrusted
|
| 38 |
+
user input.
|
| 39 |
+
- A sandboxed environment can safely render untrusted templates.
|
| 40 |
+
- AsyncIO support for generating templates and calling async
|
| 41 |
+
functions.
|
| 42 |
+
- I18N support with Babel.
|
| 43 |
+
- Templates are compiled to optimized Python code just-in-time and
|
| 44 |
+
cached, or can be compiled ahead-of-time.
|
| 45 |
+
- Exceptions point to the correct line in templates to make debugging
|
| 46 |
+
easier.
|
| 47 |
+
- Extensible filters, tests, functions, and even syntax.
|
| 48 |
+
|
| 49 |
+
Jinja's philosophy is that while application logic belongs in Python if
|
| 50 |
+
possible, it shouldn't make the template designer's job difficult by
|
| 51 |
+
restricting functionality too much.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
## In A Nutshell
|
| 55 |
+
|
| 56 |
+
```jinja
|
| 57 |
+
{% extends "base.html" %}
|
| 58 |
+
{% block title %}Members{% endblock %}
|
| 59 |
+
{% block content %}
|
| 60 |
+
<ul>
|
| 61 |
+
{% for user in users %}
|
| 62 |
+
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
|
| 63 |
+
{% endfor %}
|
| 64 |
+
</ul>
|
| 65 |
+
{% endblock %}
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Donate
|
| 69 |
+
|
| 70 |
+
The Pallets organization develops and supports Jinja and other popular
|
| 71 |
+
packages. In order to grow the community of contributors and users, and
|
| 72 |
+
allow the maintainers to devote more time to the projects, [please
|
| 73 |
+
donate today][].
|
| 74 |
+
|
| 75 |
+
[please donate today]: https://palletsprojects.com/donate
|
| 76 |
+
|
| 77 |
+
## Contributing
|
| 78 |
+
|
| 79 |
+
See our [detailed contributing documentation][contrib] for many ways to
|
| 80 |
+
contribute, including reporting issues, requesting features, asking or answering
|
| 81 |
+
questions, and making PRs.
|
| 82 |
+
|
| 83 |
+
[contrib]: https://palletsprojects.com/contributing/
|
| 84 |
+
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/RECORD
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jinja2-3.1.6.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
jinja2-3.1.6.dist-info/METADATA,sha256=aMVUj7Z8QTKhOJjZsx7FDGvqKr3ZFdkh8hQ1XDpkmcg,2871
|
| 3 |
+
jinja2-3.1.6.dist-info/RECORD,,
|
| 4 |
+
jinja2-3.1.6.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 5 |
+
jinja2-3.1.6.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
| 6 |
+
jinja2-3.1.6.dist-info/direct_url.json,sha256=rEW0c1HynzWONYsV_iVJg-bKEhSNc7_fvmbQf2YbRmw,117
|
| 7 |
+
jinja2-3.1.6.dist-info/entry_points.txt,sha256=OL85gYU1eD8cuPlikifFngXpeBjaxl6rIJ8KkC_3r-I,58
|
| 8 |
+
jinja2-3.1.6.dist-info/licenses/LICENSE.txt,sha256=O0nc7kEF6ze6wQ-vG-JgQI_oXSUrjp3y4JefweCUQ3s,1475
|
| 9 |
+
jinja2/__init__.py,sha256=xxepO9i7DHsqkQrgBEduLtfoz2QCuT6_gbL4XSN1hbU,1928
|
| 10 |
+
jinja2/__pycache__/__init__.cpython-310.pyc,,
|
| 11 |
+
jinja2/__pycache__/_identifier.cpython-310.pyc,,
|
| 12 |
+
jinja2/__pycache__/async_utils.cpython-310.pyc,,
|
| 13 |
+
jinja2/__pycache__/bccache.cpython-310.pyc,,
|
| 14 |
+
jinja2/__pycache__/compiler.cpython-310.pyc,,
|
| 15 |
+
jinja2/__pycache__/constants.cpython-310.pyc,,
|
| 16 |
+
jinja2/__pycache__/debug.cpython-310.pyc,,
|
| 17 |
+
jinja2/__pycache__/defaults.cpython-310.pyc,,
|
| 18 |
+
jinja2/__pycache__/environment.cpython-310.pyc,,
|
| 19 |
+
jinja2/__pycache__/exceptions.cpython-310.pyc,,
|
| 20 |
+
jinja2/__pycache__/ext.cpython-310.pyc,,
|
| 21 |
+
jinja2/__pycache__/filters.cpython-310.pyc,,
|
| 22 |
+
jinja2/__pycache__/idtracking.cpython-310.pyc,,
|
| 23 |
+
jinja2/__pycache__/lexer.cpython-310.pyc,,
|
| 24 |
+
jinja2/__pycache__/loaders.cpython-310.pyc,,
|
| 25 |
+
jinja2/__pycache__/meta.cpython-310.pyc,,
|
| 26 |
+
jinja2/__pycache__/nativetypes.cpython-310.pyc,,
|
| 27 |
+
jinja2/__pycache__/nodes.cpython-310.pyc,,
|
| 28 |
+
jinja2/__pycache__/optimizer.cpython-310.pyc,,
|
| 29 |
+
jinja2/__pycache__/parser.cpython-310.pyc,,
|
| 30 |
+
jinja2/__pycache__/runtime.cpython-310.pyc,,
|
| 31 |
+
jinja2/__pycache__/sandbox.cpython-310.pyc,,
|
| 32 |
+
jinja2/__pycache__/tests.cpython-310.pyc,,
|
| 33 |
+
jinja2/__pycache__/utils.cpython-310.pyc,,
|
| 34 |
+
jinja2/__pycache__/visitor.cpython-310.pyc,,
|
| 35 |
+
jinja2/_identifier.py,sha256=_zYctNKzRqlk_murTNlzrju1FFJL7Va_Ijqqd7ii2lU,1958
|
| 36 |
+
jinja2/async_utils.py,sha256=vK-PdsuorOMnWSnEkT3iUJRIkTnYgO2T6MnGxDgHI5o,2834
|
| 37 |
+
jinja2/bccache.py,sha256=gh0qs9rulnXo0PhX5jTJy2UHzI8wFnQ63o_vw7nhzRg,14061
|
| 38 |
+
jinja2/compiler.py,sha256=9RpCQl5X88BHllJiPsHPh295Hh0uApvwFJNQuutULeM,74131
|
| 39 |
+
jinja2/constants.py,sha256=GMoFydBF_kdpaRKPoM5cl5MviquVRLVyZtfp5-16jg0,1433
|
| 40 |
+
jinja2/debug.py,sha256=CnHqCDHd-BVGvti_8ZsTolnXNhA3ECsY-6n_2pwU8Hw,6297
|
| 41 |
+
jinja2/defaults.py,sha256=boBcSw78h-lp20YbaXSJsqkAI2uN_mD_TtCydpeq5wU,1267
|
| 42 |
+
jinja2/environment.py,sha256=9nhrP7Ch-NbGX00wvyr4yy-uhNHq2OCc60ggGrni_fk,61513
|
| 43 |
+
jinja2/exceptions.py,sha256=ioHeHrWwCWNaXX1inHmHVblvc4haO7AXsjCp3GfWvx0,5071
|
| 44 |
+
jinja2/ext.py,sha256=5PF5eHfh8mXAIxXHHRB2xXbXohi8pE3nHSOxa66uS7E,31875
|
| 45 |
+
jinja2/filters.py,sha256=PQ_Egd9n9jSgtnGQYyF4K5j2nYwhUIulhPnyimkdr-k,55212
|
| 46 |
+
jinja2/idtracking.py,sha256=-ll5lIp73pML3ErUYiIJj7tdmWxcH_IlDv3yA_hiZYo,10555
|
| 47 |
+
jinja2/lexer.py,sha256=LYiYio6br-Tep9nPcupWXsPEtjluw3p1mU-lNBVRUfk,29786
|
| 48 |
+
jinja2/loaders.py,sha256=wIrnxjvcbqh5VwW28NSkfotiDq8qNCxIOSFbGUiSLB4,24055
|
| 49 |
+
jinja2/meta.py,sha256=OTDPkaFvU2Hgvx-6akz7154F8BIWaRmvJcBFvwopHww,4397
|
| 50 |
+
jinja2/nativetypes.py,sha256=7GIGALVJgdyL80oZJdQUaUfwSt5q2lSSZbXt0dNf_M4,4210
|
| 51 |
+
jinja2/nodes.py,sha256=m1Duzcr6qhZI8JQ6VyJgUNinjAf5bQzijSmDnMsvUx8,34579
|
| 52 |
+
jinja2/optimizer.py,sha256=rJnCRlQ7pZsEEmMhsQDgC_pKyDHxP5TPS6zVPGsgcu8,1651
|
| 53 |
+
jinja2/parser.py,sha256=lLOFy3sEmHc5IaEHRiH1sQVnId2moUQzhyeJZTtdY30,40383
|
| 54 |
+
jinja2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 55 |
+
jinja2/runtime.py,sha256=gDk-GvdriJXqgsGbHgrcKTP0Yp6zPXzhzrIpCFH3jAU,34249
|
| 56 |
+
jinja2/sandbox.py,sha256=Mw2aitlY2I8la7FYhcX2YG9BtUYcLnD0Gh3d29cDWrY,15009
|
| 57 |
+
jinja2/tests.py,sha256=VLsBhVFnWg-PxSBz1MhRnNWgP1ovXk3neO1FLQMeC9Q,5926
|
| 58 |
+
jinja2/utils.py,sha256=rRp3o9e7ZKS4fyrWRbELyLcpuGVTFcnooaOa1qx_FIk,24129
|
| 59 |
+
jinja2/visitor.py,sha256=EcnL1PIwf_4RVCOMxsRNuR8AXHbS1qfAdMOE2ngKJz4,3557
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/REQUESTED
ADDED
|
File without changes
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: flit 3.12.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/direct_url.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"dir_info": {}, "url": "file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_jinja2_1764517220/work"}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[babel.extractors]
|
| 2 |
+
jinja2=jinja2.ext:babel_extract[i18n]
|
| 3 |
+
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2-3.1.6.dist-info/licenses/LICENSE.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2007 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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.6"
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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 |
+
)
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/async_utils.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import typing as t
|
| 3 |
+
from functools import WRAPPER_ASSIGNMENTS
|
| 4 |
+
from functools import wraps
|
| 5 |
+
|
| 6 |
+
from .utils import _PassArg
|
| 7 |
+
from .utils import pass_eval_context
|
| 8 |
+
|
| 9 |
+
if t.TYPE_CHECKING:
|
| 10 |
+
import typing_extensions as te
|
| 11 |
+
|
| 12 |
+
V = t.TypeVar("V")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def async_variant(normal_func): # type: ignore
|
| 16 |
+
def decorator(async_func): # type: ignore
|
| 17 |
+
pass_arg = _PassArg.from_obj(normal_func)
|
| 18 |
+
need_eval_context = pass_arg is None
|
| 19 |
+
|
| 20 |
+
if pass_arg is _PassArg.environment:
|
| 21 |
+
|
| 22 |
+
def is_async(args: t.Any) -> bool:
|
| 23 |
+
return t.cast(bool, args[0].is_async)
|
| 24 |
+
|
| 25 |
+
else:
|
| 26 |
+
|
| 27 |
+
def is_async(args: t.Any) -> bool:
|
| 28 |
+
return t.cast(bool, args[0].environment.is_async)
|
| 29 |
+
|
| 30 |
+
# Take the doc and annotations from the sync function, but the
|
| 31 |
+
# name from the async function. Pallets-Sphinx-Themes
|
| 32 |
+
# build_function_directive expects __wrapped__ to point to the
|
| 33 |
+
# sync function.
|
| 34 |
+
async_func_attrs = ("__module__", "__name__", "__qualname__")
|
| 35 |
+
normal_func_attrs = tuple(set(WRAPPER_ASSIGNMENTS).difference(async_func_attrs))
|
| 36 |
+
|
| 37 |
+
@wraps(normal_func, assigned=normal_func_attrs)
|
| 38 |
+
@wraps(async_func, assigned=async_func_attrs, updated=())
|
| 39 |
+
def wrapper(*args, **kwargs): # type: ignore
|
| 40 |
+
b = is_async(args)
|
| 41 |
+
|
| 42 |
+
if need_eval_context:
|
| 43 |
+
args = args[1:]
|
| 44 |
+
|
| 45 |
+
if b:
|
| 46 |
+
return async_func(*args, **kwargs)
|
| 47 |
+
|
| 48 |
+
return normal_func(*args, **kwargs)
|
| 49 |
+
|
| 50 |
+
if need_eval_context:
|
| 51 |
+
wrapper = pass_eval_context(wrapper)
|
| 52 |
+
|
| 53 |
+
wrapper.jinja_async_variant = True # type: ignore[attr-defined]
|
| 54 |
+
return wrapper
|
| 55 |
+
|
| 56 |
+
return decorator
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
_common_primitives = {int, float, bool, str, list, dict, tuple, type(None)}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
async def auto_await(value: t.Union[t.Awaitable["V"], "V"]) -> "V":
|
| 63 |
+
# Avoid a costly call to isawaitable
|
| 64 |
+
if type(value) in _common_primitives:
|
| 65 |
+
return t.cast("V", value)
|
| 66 |
+
|
| 67 |
+
if inspect.isawaitable(value):
|
| 68 |
+
return await t.cast("t.Awaitable[V]", value)
|
| 69 |
+
|
| 70 |
+
return value
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class _IteratorToAsyncIterator(t.Generic[V]):
|
| 74 |
+
def __init__(self, iterator: "t.Iterator[V]"):
|
| 75 |
+
self._iterator = iterator
|
| 76 |
+
|
| 77 |
+
def __aiter__(self) -> "te.Self":
|
| 78 |
+
return self
|
| 79 |
+
|
| 80 |
+
async def __anext__(self) -> V:
|
| 81 |
+
try:
|
| 82 |
+
return next(self._iterator)
|
| 83 |
+
except StopIteration as e:
|
| 84 |
+
raise StopAsyncIteration(e.value) from e
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def auto_aiter(
|
| 88 |
+
iterable: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 89 |
+
) -> "t.AsyncIterator[V]":
|
| 90 |
+
if hasattr(iterable, "__aiter__"):
|
| 91 |
+
return iterable.__aiter__()
|
| 92 |
+
else:
|
| 93 |
+
return _IteratorToAsyncIterator(iter(iterable))
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
async def auto_to_list(
|
| 97 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 98 |
+
) -> t.List["V"]:
|
| 99 |
+
return [x async for x in auto_aiter(value)]
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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})")
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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"""
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/debug.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 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
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/environment.py
ADDED
|
@@ -0,0 +1,1672 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Classes for managing templates and their runtime and compile time
|
| 2 |
+
options.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import typing
|
| 7 |
+
import typing as t
|
| 8 |
+
import weakref
|
| 9 |
+
from collections import ChainMap
|
| 10 |
+
from functools import lru_cache
|
| 11 |
+
from functools import partial
|
| 12 |
+
from functools import reduce
|
| 13 |
+
from types import CodeType
|
| 14 |
+
|
| 15 |
+
from markupsafe import Markup
|
| 16 |
+
|
| 17 |
+
from . import nodes
|
| 18 |
+
from .compiler import CodeGenerator
|
| 19 |
+
from .compiler import generate
|
| 20 |
+
from .defaults import BLOCK_END_STRING
|
| 21 |
+
from .defaults import BLOCK_START_STRING
|
| 22 |
+
from .defaults import COMMENT_END_STRING
|
| 23 |
+
from .defaults import COMMENT_START_STRING
|
| 24 |
+
from .defaults import DEFAULT_FILTERS # type: ignore[attr-defined]
|
| 25 |
+
from .defaults import DEFAULT_NAMESPACE
|
| 26 |
+
from .defaults import DEFAULT_POLICIES
|
| 27 |
+
from .defaults import DEFAULT_TESTS # type: ignore[attr-defined]
|
| 28 |
+
from .defaults import KEEP_TRAILING_NEWLINE
|
| 29 |
+
from .defaults import LINE_COMMENT_PREFIX
|
| 30 |
+
from .defaults import LINE_STATEMENT_PREFIX
|
| 31 |
+
from .defaults import LSTRIP_BLOCKS
|
| 32 |
+
from .defaults import NEWLINE_SEQUENCE
|
| 33 |
+
from .defaults import TRIM_BLOCKS
|
| 34 |
+
from .defaults import VARIABLE_END_STRING
|
| 35 |
+
from .defaults import VARIABLE_START_STRING
|
| 36 |
+
from .exceptions import TemplateNotFound
|
| 37 |
+
from .exceptions import TemplateRuntimeError
|
| 38 |
+
from .exceptions import TemplatesNotFound
|
| 39 |
+
from .exceptions import TemplateSyntaxError
|
| 40 |
+
from .exceptions import UndefinedError
|
| 41 |
+
from .lexer import get_lexer
|
| 42 |
+
from .lexer import Lexer
|
| 43 |
+
from .lexer import TokenStream
|
| 44 |
+
from .nodes import EvalContext
|
| 45 |
+
from .parser import Parser
|
| 46 |
+
from .runtime import Context
|
| 47 |
+
from .runtime import new_context
|
| 48 |
+
from .runtime import Undefined
|
| 49 |
+
from .utils import _PassArg
|
| 50 |
+
from .utils import concat
|
| 51 |
+
from .utils import consume
|
| 52 |
+
from .utils import import_string
|
| 53 |
+
from .utils import internalcode
|
| 54 |
+
from .utils import LRUCache
|
| 55 |
+
from .utils import missing
|
| 56 |
+
|
| 57 |
+
if t.TYPE_CHECKING:
|
| 58 |
+
import typing_extensions as te
|
| 59 |
+
|
| 60 |
+
from .bccache import BytecodeCache
|
| 61 |
+
from .ext import Extension
|
| 62 |
+
from .loaders import BaseLoader
|
| 63 |
+
|
| 64 |
+
_env_bound = t.TypeVar("_env_bound", bound="Environment")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# for direct template usage we have up to ten living environments
|
| 68 |
+
@lru_cache(maxsize=10)
|
| 69 |
+
def get_spontaneous_environment(cls: t.Type[_env_bound], *args: t.Any) -> _env_bound:
|
| 70 |
+
"""Return a new spontaneous environment. A spontaneous environment
|
| 71 |
+
is used for templates created directly rather than through an
|
| 72 |
+
existing environment.
|
| 73 |
+
|
| 74 |
+
:param cls: Environment class to create.
|
| 75 |
+
:param args: Positional arguments passed to environment.
|
| 76 |
+
"""
|
| 77 |
+
env = cls(*args)
|
| 78 |
+
env.shared = True
|
| 79 |
+
return env
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def create_cache(
|
| 83 |
+
size: int,
|
| 84 |
+
) -> t.Optional[t.MutableMapping[t.Tuple["weakref.ref[t.Any]", str], "Template"]]:
|
| 85 |
+
"""Return the cache class for the given size."""
|
| 86 |
+
if size == 0:
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
if size < 0:
|
| 90 |
+
return {}
|
| 91 |
+
|
| 92 |
+
return LRUCache(size) # type: ignore
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def copy_cache(
|
| 96 |
+
cache: t.Optional[t.MutableMapping[t.Any, t.Any]],
|
| 97 |
+
) -> t.Optional[t.MutableMapping[t.Tuple["weakref.ref[t.Any]", str], "Template"]]:
|
| 98 |
+
"""Create an empty copy of the given cache."""
|
| 99 |
+
if cache is None:
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
if type(cache) is dict: # noqa E721
|
| 103 |
+
return {}
|
| 104 |
+
|
| 105 |
+
return LRUCache(cache.capacity) # type: ignore
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def load_extensions(
|
| 109 |
+
environment: "Environment",
|
| 110 |
+
extensions: t.Sequence[t.Union[str, t.Type["Extension"]]],
|
| 111 |
+
) -> t.Dict[str, "Extension"]:
|
| 112 |
+
"""Load the extensions from the list and bind it to the environment.
|
| 113 |
+
Returns a dict of instantiated extensions.
|
| 114 |
+
"""
|
| 115 |
+
result = {}
|
| 116 |
+
|
| 117 |
+
for extension in extensions:
|
| 118 |
+
if isinstance(extension, str):
|
| 119 |
+
extension = t.cast(t.Type["Extension"], import_string(extension))
|
| 120 |
+
|
| 121 |
+
result[extension.identifier] = extension(environment)
|
| 122 |
+
|
| 123 |
+
return result
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def _environment_config_check(environment: _env_bound) -> _env_bound:
|
| 127 |
+
"""Perform a sanity check on the environment."""
|
| 128 |
+
assert issubclass(
|
| 129 |
+
environment.undefined, Undefined
|
| 130 |
+
), "'undefined' must be a subclass of 'jinja2.Undefined'."
|
| 131 |
+
assert (
|
| 132 |
+
environment.block_start_string
|
| 133 |
+
!= environment.variable_start_string
|
| 134 |
+
!= environment.comment_start_string
|
| 135 |
+
), "block, variable and comment start strings must be different."
|
| 136 |
+
assert environment.newline_sequence in {
|
| 137 |
+
"\r",
|
| 138 |
+
"\r\n",
|
| 139 |
+
"\n",
|
| 140 |
+
}, "'newline_sequence' must be one of '\\n', '\\r\\n', or '\\r'."
|
| 141 |
+
return environment
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class Environment:
|
| 145 |
+
r"""The core component of Jinja is the `Environment`. It contains
|
| 146 |
+
important shared variables like configuration, filters, tests,
|
| 147 |
+
globals and others. Instances of this class may be modified if
|
| 148 |
+
they are not shared and if no template was loaded so far.
|
| 149 |
+
Modifications on environments after the first template was loaded
|
| 150 |
+
will lead to surprising effects and undefined behavior.
|
| 151 |
+
|
| 152 |
+
Here are the possible initialization parameters:
|
| 153 |
+
|
| 154 |
+
`block_start_string`
|
| 155 |
+
The string marking the beginning of a block. Defaults to ``'{%'``.
|
| 156 |
+
|
| 157 |
+
`block_end_string`
|
| 158 |
+
The string marking the end of a block. Defaults to ``'%}'``.
|
| 159 |
+
|
| 160 |
+
`variable_start_string`
|
| 161 |
+
The string marking the beginning of a print statement.
|
| 162 |
+
Defaults to ``'{{'``.
|
| 163 |
+
|
| 164 |
+
`variable_end_string`
|
| 165 |
+
The string marking the end of a print statement. Defaults to
|
| 166 |
+
``'}}'``.
|
| 167 |
+
|
| 168 |
+
`comment_start_string`
|
| 169 |
+
The string marking the beginning of a comment. Defaults to ``'{#'``.
|
| 170 |
+
|
| 171 |
+
`comment_end_string`
|
| 172 |
+
The string marking the end of a comment. Defaults to ``'#}'``.
|
| 173 |
+
|
| 174 |
+
`line_statement_prefix`
|
| 175 |
+
If given and a string, this will be used as prefix for line based
|
| 176 |
+
statements. See also :ref:`line-statements`.
|
| 177 |
+
|
| 178 |
+
`line_comment_prefix`
|
| 179 |
+
If given and a string, this will be used as prefix for line based
|
| 180 |
+
comments. See also :ref:`line-statements`.
|
| 181 |
+
|
| 182 |
+
.. versionadded:: 2.2
|
| 183 |
+
|
| 184 |
+
`trim_blocks`
|
| 185 |
+
If this is set to ``True`` the first newline after a block is
|
| 186 |
+
removed (block, not variable tag!). Defaults to `False`.
|
| 187 |
+
|
| 188 |
+
`lstrip_blocks`
|
| 189 |
+
If this is set to ``True`` leading spaces and tabs are stripped
|
| 190 |
+
from the start of a line to a block. Defaults to `False`.
|
| 191 |
+
|
| 192 |
+
`newline_sequence`
|
| 193 |
+
The sequence that starts a newline. Must be one of ``'\r'``,
|
| 194 |
+
``'\n'`` or ``'\r\n'``. The default is ``'\n'`` which is a
|
| 195 |
+
useful default for Linux and OS X systems as well as web
|
| 196 |
+
applications.
|
| 197 |
+
|
| 198 |
+
`keep_trailing_newline`
|
| 199 |
+
Preserve the trailing newline when rendering templates.
|
| 200 |
+
The default is ``False``, which causes a single newline,
|
| 201 |
+
if present, to be stripped from the end of the template.
|
| 202 |
+
|
| 203 |
+
.. versionadded:: 2.7
|
| 204 |
+
|
| 205 |
+
`extensions`
|
| 206 |
+
List of Jinja extensions to use. This can either be import paths
|
| 207 |
+
as strings or extension classes. For more information have a
|
| 208 |
+
look at :ref:`the extensions documentation <jinja-extensions>`.
|
| 209 |
+
|
| 210 |
+
`optimized`
|
| 211 |
+
should the optimizer be enabled? Default is ``True``.
|
| 212 |
+
|
| 213 |
+
`undefined`
|
| 214 |
+
:class:`Undefined` or a subclass of it that is used to represent
|
| 215 |
+
undefined values in the template.
|
| 216 |
+
|
| 217 |
+
`finalize`
|
| 218 |
+
A callable that can be used to process the result of a variable
|
| 219 |
+
expression before it is output. For example one can convert
|
| 220 |
+
``None`` implicitly into an empty string here.
|
| 221 |
+
|
| 222 |
+
`autoescape`
|
| 223 |
+
If set to ``True`` the XML/HTML autoescaping feature is enabled by
|
| 224 |
+
default. For more details about autoescaping see
|
| 225 |
+
:class:`~markupsafe.Markup`. As of Jinja 2.4 this can also
|
| 226 |
+
be a callable that is passed the template name and has to
|
| 227 |
+
return ``True`` or ``False`` depending on autoescape should be
|
| 228 |
+
enabled by default.
|
| 229 |
+
|
| 230 |
+
.. versionchanged:: 2.4
|
| 231 |
+
`autoescape` can now be a function
|
| 232 |
+
|
| 233 |
+
`loader`
|
| 234 |
+
The template loader for this environment.
|
| 235 |
+
|
| 236 |
+
`cache_size`
|
| 237 |
+
The size of the cache. Per default this is ``400`` which means
|
| 238 |
+
that if more than 400 templates are loaded the loader will clean
|
| 239 |
+
out the least recently used template. If the cache size is set to
|
| 240 |
+
``0`` templates are recompiled all the time, if the cache size is
|
| 241 |
+
``-1`` the cache will not be cleaned.
|
| 242 |
+
|
| 243 |
+
.. versionchanged:: 2.8
|
| 244 |
+
The cache size was increased to 400 from a low 50.
|
| 245 |
+
|
| 246 |
+
`auto_reload`
|
| 247 |
+
Some loaders load templates from locations where the template
|
| 248 |
+
sources may change (ie: file system or database). If
|
| 249 |
+
``auto_reload`` is set to ``True`` (default) every time a template is
|
| 250 |
+
requested the loader checks if the source changed and if yes, it
|
| 251 |
+
will reload the template. For higher performance it's possible to
|
| 252 |
+
disable that.
|
| 253 |
+
|
| 254 |
+
`bytecode_cache`
|
| 255 |
+
If set to a bytecode cache object, this object will provide a
|
| 256 |
+
cache for the internal Jinja bytecode so that templates don't
|
| 257 |
+
have to be parsed if they were not changed.
|
| 258 |
+
|
| 259 |
+
See :ref:`bytecode-cache` for more information.
|
| 260 |
+
|
| 261 |
+
`enable_async`
|
| 262 |
+
If set to true this enables async template execution which
|
| 263 |
+
allows using async functions and generators.
|
| 264 |
+
"""
|
| 265 |
+
|
| 266 |
+
#: if this environment is sandboxed. Modifying this variable won't make
|
| 267 |
+
#: the environment sandboxed though. For a real sandboxed environment
|
| 268 |
+
#: have a look at jinja2.sandbox. This flag alone controls the code
|
| 269 |
+
#: generation by the compiler.
|
| 270 |
+
sandboxed = False
|
| 271 |
+
|
| 272 |
+
#: True if the environment is just an overlay
|
| 273 |
+
overlayed = False
|
| 274 |
+
|
| 275 |
+
#: the environment this environment is linked to if it is an overlay
|
| 276 |
+
linked_to: t.Optional["Environment"] = None
|
| 277 |
+
|
| 278 |
+
#: shared environments have this set to `True`. A shared environment
|
| 279 |
+
#: must not be modified
|
| 280 |
+
shared = False
|
| 281 |
+
|
| 282 |
+
#: the class that is used for code generation. See
|
| 283 |
+
#: :class:`~jinja2.compiler.CodeGenerator` for more information.
|
| 284 |
+
code_generator_class: t.Type["CodeGenerator"] = CodeGenerator
|
| 285 |
+
|
| 286 |
+
concat = "".join
|
| 287 |
+
|
| 288 |
+
#: the context class that is used for templates. See
|
| 289 |
+
#: :class:`~jinja2.runtime.Context` for more information.
|
| 290 |
+
context_class: t.Type[Context] = Context
|
| 291 |
+
|
| 292 |
+
template_class: t.Type["Template"]
|
| 293 |
+
|
| 294 |
+
def __init__(
|
| 295 |
+
self,
|
| 296 |
+
block_start_string: str = BLOCK_START_STRING,
|
| 297 |
+
block_end_string: str = BLOCK_END_STRING,
|
| 298 |
+
variable_start_string: str = VARIABLE_START_STRING,
|
| 299 |
+
variable_end_string: str = VARIABLE_END_STRING,
|
| 300 |
+
comment_start_string: str = COMMENT_START_STRING,
|
| 301 |
+
comment_end_string: str = COMMENT_END_STRING,
|
| 302 |
+
line_statement_prefix: t.Optional[str] = LINE_STATEMENT_PREFIX,
|
| 303 |
+
line_comment_prefix: t.Optional[str] = LINE_COMMENT_PREFIX,
|
| 304 |
+
trim_blocks: bool = TRIM_BLOCKS,
|
| 305 |
+
lstrip_blocks: bool = LSTRIP_BLOCKS,
|
| 306 |
+
newline_sequence: "te.Literal['\\n', '\\r\\n', '\\r']" = NEWLINE_SEQUENCE,
|
| 307 |
+
keep_trailing_newline: bool = KEEP_TRAILING_NEWLINE,
|
| 308 |
+
extensions: t.Sequence[t.Union[str, t.Type["Extension"]]] = (),
|
| 309 |
+
optimized: bool = True,
|
| 310 |
+
undefined: t.Type[Undefined] = Undefined,
|
| 311 |
+
finalize: t.Optional[t.Callable[..., t.Any]] = None,
|
| 312 |
+
autoescape: t.Union[bool, t.Callable[[t.Optional[str]], bool]] = False,
|
| 313 |
+
loader: t.Optional["BaseLoader"] = None,
|
| 314 |
+
cache_size: int = 400,
|
| 315 |
+
auto_reload: bool = True,
|
| 316 |
+
bytecode_cache: t.Optional["BytecodeCache"] = None,
|
| 317 |
+
enable_async: bool = False,
|
| 318 |
+
):
|
| 319 |
+
# !!Important notice!!
|
| 320 |
+
# The constructor accepts quite a few arguments that should be
|
| 321 |
+
# passed by keyword rather than position. However it's important to
|
| 322 |
+
# not change the order of arguments because it's used at least
|
| 323 |
+
# internally in those cases:
|
| 324 |
+
# - spontaneous environments (i18n extension and Template)
|
| 325 |
+
# - unittests
|
| 326 |
+
# If parameter changes are required only add parameters at the end
|
| 327 |
+
# and don't change the arguments (or the defaults!) of the arguments
|
| 328 |
+
# existing already.
|
| 329 |
+
|
| 330 |
+
# lexer / parser information
|
| 331 |
+
self.block_start_string = block_start_string
|
| 332 |
+
self.block_end_string = block_end_string
|
| 333 |
+
self.variable_start_string = variable_start_string
|
| 334 |
+
self.variable_end_string = variable_end_string
|
| 335 |
+
self.comment_start_string = comment_start_string
|
| 336 |
+
self.comment_end_string = comment_end_string
|
| 337 |
+
self.line_statement_prefix = line_statement_prefix
|
| 338 |
+
self.line_comment_prefix = line_comment_prefix
|
| 339 |
+
self.trim_blocks = trim_blocks
|
| 340 |
+
self.lstrip_blocks = lstrip_blocks
|
| 341 |
+
self.newline_sequence = newline_sequence
|
| 342 |
+
self.keep_trailing_newline = keep_trailing_newline
|
| 343 |
+
|
| 344 |
+
# runtime information
|
| 345 |
+
self.undefined: t.Type[Undefined] = undefined
|
| 346 |
+
self.optimized = optimized
|
| 347 |
+
self.finalize = finalize
|
| 348 |
+
self.autoescape = autoescape
|
| 349 |
+
|
| 350 |
+
# defaults
|
| 351 |
+
self.filters = DEFAULT_FILTERS.copy()
|
| 352 |
+
self.tests = DEFAULT_TESTS.copy()
|
| 353 |
+
self.globals = DEFAULT_NAMESPACE.copy()
|
| 354 |
+
|
| 355 |
+
# set the loader provided
|
| 356 |
+
self.loader = loader
|
| 357 |
+
self.cache = create_cache(cache_size)
|
| 358 |
+
self.bytecode_cache = bytecode_cache
|
| 359 |
+
self.auto_reload = auto_reload
|
| 360 |
+
|
| 361 |
+
# configurable policies
|
| 362 |
+
self.policies = DEFAULT_POLICIES.copy()
|
| 363 |
+
|
| 364 |
+
# load extensions
|
| 365 |
+
self.extensions = load_extensions(self, extensions)
|
| 366 |
+
|
| 367 |
+
self.is_async = enable_async
|
| 368 |
+
_environment_config_check(self)
|
| 369 |
+
|
| 370 |
+
def add_extension(self, extension: t.Union[str, t.Type["Extension"]]) -> None:
|
| 371 |
+
"""Adds an extension after the environment was created.
|
| 372 |
+
|
| 373 |
+
.. versionadded:: 2.5
|
| 374 |
+
"""
|
| 375 |
+
self.extensions.update(load_extensions(self, [extension]))
|
| 376 |
+
|
| 377 |
+
def extend(self, **attributes: t.Any) -> None:
|
| 378 |
+
"""Add the items to the instance of the environment if they do not exist
|
| 379 |
+
yet. This is used by :ref:`extensions <writing-extensions>` to register
|
| 380 |
+
callbacks and configuration values without breaking inheritance.
|
| 381 |
+
"""
|
| 382 |
+
for key, value in attributes.items():
|
| 383 |
+
if not hasattr(self, key):
|
| 384 |
+
setattr(self, key, value)
|
| 385 |
+
|
| 386 |
+
def overlay(
|
| 387 |
+
self,
|
| 388 |
+
block_start_string: str = missing,
|
| 389 |
+
block_end_string: str = missing,
|
| 390 |
+
variable_start_string: str = missing,
|
| 391 |
+
variable_end_string: str = missing,
|
| 392 |
+
comment_start_string: str = missing,
|
| 393 |
+
comment_end_string: str = missing,
|
| 394 |
+
line_statement_prefix: t.Optional[str] = missing,
|
| 395 |
+
line_comment_prefix: t.Optional[str] = missing,
|
| 396 |
+
trim_blocks: bool = missing,
|
| 397 |
+
lstrip_blocks: bool = missing,
|
| 398 |
+
newline_sequence: "te.Literal['\\n', '\\r\\n', '\\r']" = missing,
|
| 399 |
+
keep_trailing_newline: bool = missing,
|
| 400 |
+
extensions: t.Sequence[t.Union[str, t.Type["Extension"]]] = missing,
|
| 401 |
+
optimized: bool = missing,
|
| 402 |
+
undefined: t.Type[Undefined] = missing,
|
| 403 |
+
finalize: t.Optional[t.Callable[..., t.Any]] = missing,
|
| 404 |
+
autoescape: t.Union[bool, t.Callable[[t.Optional[str]], bool]] = missing,
|
| 405 |
+
loader: t.Optional["BaseLoader"] = missing,
|
| 406 |
+
cache_size: int = missing,
|
| 407 |
+
auto_reload: bool = missing,
|
| 408 |
+
bytecode_cache: t.Optional["BytecodeCache"] = missing,
|
| 409 |
+
enable_async: bool = missing,
|
| 410 |
+
) -> "te.Self":
|
| 411 |
+
"""Create a new overlay environment that shares all the data with the
|
| 412 |
+
current environment except for cache and the overridden attributes.
|
| 413 |
+
Extensions cannot be removed for an overlayed environment. An overlayed
|
| 414 |
+
environment automatically gets all the extensions of the environment it
|
| 415 |
+
is linked to plus optional extra extensions.
|
| 416 |
+
|
| 417 |
+
Creating overlays should happen after the initial environment was set
|
| 418 |
+
up completely. Not all attributes are truly linked, some are just
|
| 419 |
+
copied over so modifications on the original environment may not shine
|
| 420 |
+
through.
|
| 421 |
+
|
| 422 |
+
.. versionchanged:: 3.1.5
|
| 423 |
+
``enable_async`` is applied correctly.
|
| 424 |
+
|
| 425 |
+
.. versionchanged:: 3.1.2
|
| 426 |
+
Added the ``newline_sequence``, ``keep_trailing_newline``,
|
| 427 |
+
and ``enable_async`` parameters to match ``__init__``.
|
| 428 |
+
"""
|
| 429 |
+
args = dict(locals())
|
| 430 |
+
del args["self"], args["cache_size"], args["extensions"], args["enable_async"]
|
| 431 |
+
|
| 432 |
+
rv = object.__new__(self.__class__)
|
| 433 |
+
rv.__dict__.update(self.__dict__)
|
| 434 |
+
rv.overlayed = True
|
| 435 |
+
rv.linked_to = self
|
| 436 |
+
|
| 437 |
+
for key, value in args.items():
|
| 438 |
+
if value is not missing:
|
| 439 |
+
setattr(rv, key, value)
|
| 440 |
+
|
| 441 |
+
if cache_size is not missing:
|
| 442 |
+
rv.cache = create_cache(cache_size)
|
| 443 |
+
else:
|
| 444 |
+
rv.cache = copy_cache(self.cache)
|
| 445 |
+
|
| 446 |
+
rv.extensions = {}
|
| 447 |
+
for key, value in self.extensions.items():
|
| 448 |
+
rv.extensions[key] = value.bind(rv)
|
| 449 |
+
if extensions is not missing:
|
| 450 |
+
rv.extensions.update(load_extensions(rv, extensions))
|
| 451 |
+
|
| 452 |
+
if enable_async is not missing:
|
| 453 |
+
rv.is_async = enable_async
|
| 454 |
+
|
| 455 |
+
return _environment_config_check(rv)
|
| 456 |
+
|
| 457 |
+
@property
|
| 458 |
+
def lexer(self) -> Lexer:
|
| 459 |
+
"""The lexer for this environment."""
|
| 460 |
+
return get_lexer(self)
|
| 461 |
+
|
| 462 |
+
def iter_extensions(self) -> t.Iterator["Extension"]:
|
| 463 |
+
"""Iterates over the extensions by priority."""
|
| 464 |
+
return iter(sorted(self.extensions.values(), key=lambda x: x.priority))
|
| 465 |
+
|
| 466 |
+
def getitem(
|
| 467 |
+
self, obj: t.Any, argument: t.Union[str, t.Any]
|
| 468 |
+
) -> t.Union[t.Any, Undefined]:
|
| 469 |
+
"""Get an item or attribute of an object but prefer the item."""
|
| 470 |
+
try:
|
| 471 |
+
return obj[argument]
|
| 472 |
+
except (AttributeError, TypeError, LookupError):
|
| 473 |
+
if isinstance(argument, str):
|
| 474 |
+
try:
|
| 475 |
+
attr = str(argument)
|
| 476 |
+
except Exception:
|
| 477 |
+
pass
|
| 478 |
+
else:
|
| 479 |
+
try:
|
| 480 |
+
return getattr(obj, attr)
|
| 481 |
+
except AttributeError:
|
| 482 |
+
pass
|
| 483 |
+
return self.undefined(obj=obj, name=argument)
|
| 484 |
+
|
| 485 |
+
def getattr(self, obj: t.Any, attribute: str) -> t.Any:
|
| 486 |
+
"""Get an item or attribute of an object but prefer the attribute.
|
| 487 |
+
Unlike :meth:`getitem` the attribute *must* be a string.
|
| 488 |
+
"""
|
| 489 |
+
try:
|
| 490 |
+
return getattr(obj, attribute)
|
| 491 |
+
except AttributeError:
|
| 492 |
+
pass
|
| 493 |
+
try:
|
| 494 |
+
return obj[attribute]
|
| 495 |
+
except (TypeError, LookupError, AttributeError):
|
| 496 |
+
return self.undefined(obj=obj, name=attribute)
|
| 497 |
+
|
| 498 |
+
def _filter_test_common(
|
| 499 |
+
self,
|
| 500 |
+
name: t.Union[str, Undefined],
|
| 501 |
+
value: t.Any,
|
| 502 |
+
args: t.Optional[t.Sequence[t.Any]],
|
| 503 |
+
kwargs: t.Optional[t.Mapping[str, t.Any]],
|
| 504 |
+
context: t.Optional[Context],
|
| 505 |
+
eval_ctx: t.Optional[EvalContext],
|
| 506 |
+
is_filter: bool,
|
| 507 |
+
) -> t.Any:
|
| 508 |
+
if is_filter:
|
| 509 |
+
env_map = self.filters
|
| 510 |
+
type_name = "filter"
|
| 511 |
+
else:
|
| 512 |
+
env_map = self.tests
|
| 513 |
+
type_name = "test"
|
| 514 |
+
|
| 515 |
+
func = env_map.get(name) # type: ignore
|
| 516 |
+
|
| 517 |
+
if func is None:
|
| 518 |
+
msg = f"No {type_name} named {name!r}."
|
| 519 |
+
|
| 520 |
+
if isinstance(name, Undefined):
|
| 521 |
+
try:
|
| 522 |
+
name._fail_with_undefined_error()
|
| 523 |
+
except Exception as e:
|
| 524 |
+
msg = f"{msg} ({e}; did you forget to quote the callable name?)"
|
| 525 |
+
|
| 526 |
+
raise TemplateRuntimeError(msg)
|
| 527 |
+
|
| 528 |
+
args = [value, *(args if args is not None else ())]
|
| 529 |
+
kwargs = kwargs if kwargs is not None else {}
|
| 530 |
+
pass_arg = _PassArg.from_obj(func)
|
| 531 |
+
|
| 532 |
+
if pass_arg is _PassArg.context:
|
| 533 |
+
if context is None:
|
| 534 |
+
raise TemplateRuntimeError(
|
| 535 |
+
f"Attempted to invoke a context {type_name} without context."
|
| 536 |
+
)
|
| 537 |
+
|
| 538 |
+
args.insert(0, context)
|
| 539 |
+
elif pass_arg is _PassArg.eval_context:
|
| 540 |
+
if eval_ctx is None:
|
| 541 |
+
if context is not None:
|
| 542 |
+
eval_ctx = context.eval_ctx
|
| 543 |
+
else:
|
| 544 |
+
eval_ctx = EvalContext(self)
|
| 545 |
+
|
| 546 |
+
args.insert(0, eval_ctx)
|
| 547 |
+
elif pass_arg is _PassArg.environment:
|
| 548 |
+
args.insert(0, self)
|
| 549 |
+
|
| 550 |
+
return func(*args, **kwargs)
|
| 551 |
+
|
| 552 |
+
def call_filter(
|
| 553 |
+
self,
|
| 554 |
+
name: str,
|
| 555 |
+
value: t.Any,
|
| 556 |
+
args: t.Optional[t.Sequence[t.Any]] = None,
|
| 557 |
+
kwargs: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 558 |
+
context: t.Optional[Context] = None,
|
| 559 |
+
eval_ctx: t.Optional[EvalContext] = None,
|
| 560 |
+
) -> t.Any:
|
| 561 |
+
"""Invoke a filter on a value the same way the compiler does.
|
| 562 |
+
|
| 563 |
+
This might return a coroutine if the filter is running from an
|
| 564 |
+
environment in async mode and the filter supports async
|
| 565 |
+
execution. It's your responsibility to await this if needed.
|
| 566 |
+
|
| 567 |
+
.. versionadded:: 2.7
|
| 568 |
+
"""
|
| 569 |
+
return self._filter_test_common(
|
| 570 |
+
name, value, args, kwargs, context, eval_ctx, True
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
def call_test(
|
| 574 |
+
self,
|
| 575 |
+
name: str,
|
| 576 |
+
value: t.Any,
|
| 577 |
+
args: t.Optional[t.Sequence[t.Any]] = None,
|
| 578 |
+
kwargs: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 579 |
+
context: t.Optional[Context] = None,
|
| 580 |
+
eval_ctx: t.Optional[EvalContext] = None,
|
| 581 |
+
) -> t.Any:
|
| 582 |
+
"""Invoke a test on a value the same way the compiler does.
|
| 583 |
+
|
| 584 |
+
This might return a coroutine if the test is running from an
|
| 585 |
+
environment in async mode and the test supports async execution.
|
| 586 |
+
It's your responsibility to await this if needed.
|
| 587 |
+
|
| 588 |
+
.. versionchanged:: 3.0
|
| 589 |
+
Tests support ``@pass_context``, etc. decorators. Added
|
| 590 |
+
the ``context`` and ``eval_ctx`` parameters.
|
| 591 |
+
|
| 592 |
+
.. versionadded:: 2.7
|
| 593 |
+
"""
|
| 594 |
+
return self._filter_test_common(
|
| 595 |
+
name, value, args, kwargs, context, eval_ctx, False
|
| 596 |
+
)
|
| 597 |
+
|
| 598 |
+
@internalcode
|
| 599 |
+
def parse(
|
| 600 |
+
self,
|
| 601 |
+
source: str,
|
| 602 |
+
name: t.Optional[str] = None,
|
| 603 |
+
filename: t.Optional[str] = None,
|
| 604 |
+
) -> nodes.Template:
|
| 605 |
+
"""Parse the sourcecode and return the abstract syntax tree. This
|
| 606 |
+
tree of nodes is used by the compiler to convert the template into
|
| 607 |
+
executable source- or bytecode. This is useful for debugging or to
|
| 608 |
+
extract information from templates.
|
| 609 |
+
|
| 610 |
+
If you are :ref:`developing Jinja extensions <writing-extensions>`
|
| 611 |
+
this gives you a good overview of the node tree generated.
|
| 612 |
+
"""
|
| 613 |
+
try:
|
| 614 |
+
return self._parse(source, name, filename)
|
| 615 |
+
except TemplateSyntaxError:
|
| 616 |
+
self.handle_exception(source=source)
|
| 617 |
+
|
| 618 |
+
def _parse(
|
| 619 |
+
self, source: str, name: t.Optional[str], filename: t.Optional[str]
|
| 620 |
+
) -> nodes.Template:
|
| 621 |
+
"""Internal parsing function used by `parse` and `compile`."""
|
| 622 |
+
return Parser(self, source, name, filename).parse()
|
| 623 |
+
|
| 624 |
+
def lex(
|
| 625 |
+
self,
|
| 626 |
+
source: str,
|
| 627 |
+
name: t.Optional[str] = None,
|
| 628 |
+
filename: t.Optional[str] = None,
|
| 629 |
+
) -> t.Iterator[t.Tuple[int, str, str]]:
|
| 630 |
+
"""Lex the given sourcecode and return a generator that yields
|
| 631 |
+
tokens as tuples in the form ``(lineno, token_type, value)``.
|
| 632 |
+
This can be useful for :ref:`extension development <writing-extensions>`
|
| 633 |
+
and debugging templates.
|
| 634 |
+
|
| 635 |
+
This does not perform preprocessing. If you want the preprocessing
|
| 636 |
+
of the extensions to be applied you have to filter source through
|
| 637 |
+
the :meth:`preprocess` method.
|
| 638 |
+
"""
|
| 639 |
+
source = str(source)
|
| 640 |
+
try:
|
| 641 |
+
return self.lexer.tokeniter(source, name, filename)
|
| 642 |
+
except TemplateSyntaxError:
|
| 643 |
+
self.handle_exception(source=source)
|
| 644 |
+
|
| 645 |
+
def preprocess(
|
| 646 |
+
self,
|
| 647 |
+
source: str,
|
| 648 |
+
name: t.Optional[str] = None,
|
| 649 |
+
filename: t.Optional[str] = None,
|
| 650 |
+
) -> str:
|
| 651 |
+
"""Preprocesses the source with all extensions. This is automatically
|
| 652 |
+
called for all parsing and compiling methods but *not* for :meth:`lex`
|
| 653 |
+
because there you usually only want the actual source tokenized.
|
| 654 |
+
"""
|
| 655 |
+
return reduce(
|
| 656 |
+
lambda s, e: e.preprocess(s, name, filename),
|
| 657 |
+
self.iter_extensions(),
|
| 658 |
+
str(source),
|
| 659 |
+
)
|
| 660 |
+
|
| 661 |
+
def _tokenize(
|
| 662 |
+
self,
|
| 663 |
+
source: str,
|
| 664 |
+
name: t.Optional[str],
|
| 665 |
+
filename: t.Optional[str] = None,
|
| 666 |
+
state: t.Optional[str] = None,
|
| 667 |
+
) -> TokenStream:
|
| 668 |
+
"""Called by the parser to do the preprocessing and filtering
|
| 669 |
+
for all the extensions. Returns a :class:`~jinja2.lexer.TokenStream`.
|
| 670 |
+
"""
|
| 671 |
+
source = self.preprocess(source, name, filename)
|
| 672 |
+
stream = self.lexer.tokenize(source, name, filename, state)
|
| 673 |
+
|
| 674 |
+
for ext in self.iter_extensions():
|
| 675 |
+
stream = ext.filter_stream(stream) # type: ignore
|
| 676 |
+
|
| 677 |
+
if not isinstance(stream, TokenStream):
|
| 678 |
+
stream = TokenStream(stream, name, filename)
|
| 679 |
+
|
| 680 |
+
return stream
|
| 681 |
+
|
| 682 |
+
def _generate(
|
| 683 |
+
self,
|
| 684 |
+
source: nodes.Template,
|
| 685 |
+
name: t.Optional[str],
|
| 686 |
+
filename: t.Optional[str],
|
| 687 |
+
defer_init: bool = False,
|
| 688 |
+
) -> str:
|
| 689 |
+
"""Internal hook that can be overridden to hook a different generate
|
| 690 |
+
method in.
|
| 691 |
+
|
| 692 |
+
.. versionadded:: 2.5
|
| 693 |
+
"""
|
| 694 |
+
return generate( # type: ignore
|
| 695 |
+
source,
|
| 696 |
+
self,
|
| 697 |
+
name,
|
| 698 |
+
filename,
|
| 699 |
+
defer_init=defer_init,
|
| 700 |
+
optimized=self.optimized,
|
| 701 |
+
)
|
| 702 |
+
|
| 703 |
+
def _compile(self, source: str, filename: str) -> CodeType:
|
| 704 |
+
"""Internal hook that can be overridden to hook a different compile
|
| 705 |
+
method in.
|
| 706 |
+
|
| 707 |
+
.. versionadded:: 2.5
|
| 708 |
+
"""
|
| 709 |
+
return compile(source, filename, "exec")
|
| 710 |
+
|
| 711 |
+
@typing.overload
|
| 712 |
+
def compile(
|
| 713 |
+
self,
|
| 714 |
+
source: t.Union[str, nodes.Template],
|
| 715 |
+
name: t.Optional[str] = None,
|
| 716 |
+
filename: t.Optional[str] = None,
|
| 717 |
+
raw: "te.Literal[False]" = False,
|
| 718 |
+
defer_init: bool = False,
|
| 719 |
+
) -> CodeType: ...
|
| 720 |
+
|
| 721 |
+
@typing.overload
|
| 722 |
+
def compile(
|
| 723 |
+
self,
|
| 724 |
+
source: t.Union[str, nodes.Template],
|
| 725 |
+
name: t.Optional[str] = None,
|
| 726 |
+
filename: t.Optional[str] = None,
|
| 727 |
+
raw: "te.Literal[True]" = ...,
|
| 728 |
+
defer_init: bool = False,
|
| 729 |
+
) -> str: ...
|
| 730 |
+
|
| 731 |
+
@internalcode
|
| 732 |
+
def compile(
|
| 733 |
+
self,
|
| 734 |
+
source: t.Union[str, nodes.Template],
|
| 735 |
+
name: t.Optional[str] = None,
|
| 736 |
+
filename: t.Optional[str] = None,
|
| 737 |
+
raw: bool = False,
|
| 738 |
+
defer_init: bool = False,
|
| 739 |
+
) -> t.Union[str, CodeType]:
|
| 740 |
+
"""Compile a node or template source code. The `name` parameter is
|
| 741 |
+
the load name of the template after it was joined using
|
| 742 |
+
:meth:`join_path` if necessary, not the filename on the file system.
|
| 743 |
+
the `filename` parameter is the estimated filename of the template on
|
| 744 |
+
the file system. If the template came from a database or memory this
|
| 745 |
+
can be omitted.
|
| 746 |
+
|
| 747 |
+
The return value of this method is a python code object. If the `raw`
|
| 748 |
+
parameter is `True` the return value will be a string with python
|
| 749 |
+
code equivalent to the bytecode returned otherwise. This method is
|
| 750 |
+
mainly used internally.
|
| 751 |
+
|
| 752 |
+
`defer_init` is use internally to aid the module code generator. This
|
| 753 |
+
causes the generated code to be able to import without the global
|
| 754 |
+
environment variable to be set.
|
| 755 |
+
|
| 756 |
+
.. versionadded:: 2.4
|
| 757 |
+
`defer_init` parameter added.
|
| 758 |
+
"""
|
| 759 |
+
source_hint = None
|
| 760 |
+
try:
|
| 761 |
+
if isinstance(source, str):
|
| 762 |
+
source_hint = source
|
| 763 |
+
source = self._parse(source, name, filename)
|
| 764 |
+
source = self._generate(source, name, filename, defer_init=defer_init)
|
| 765 |
+
if raw:
|
| 766 |
+
return source
|
| 767 |
+
if filename is None:
|
| 768 |
+
filename = "<template>"
|
| 769 |
+
return self._compile(source, filename)
|
| 770 |
+
except TemplateSyntaxError:
|
| 771 |
+
self.handle_exception(source=source_hint)
|
| 772 |
+
|
| 773 |
+
def compile_expression(
|
| 774 |
+
self, source: str, undefined_to_none: bool = True
|
| 775 |
+
) -> "TemplateExpression":
|
| 776 |
+
"""A handy helper method that returns a callable that accepts keyword
|
| 777 |
+
arguments that appear as variables in the expression. If called it
|
| 778 |
+
returns the result of the expression.
|
| 779 |
+
|
| 780 |
+
This is useful if applications want to use the same rules as Jinja
|
| 781 |
+
in template "configuration files" or similar situations.
|
| 782 |
+
|
| 783 |
+
Example usage:
|
| 784 |
+
|
| 785 |
+
>>> env = Environment()
|
| 786 |
+
>>> expr = env.compile_expression('foo == 42')
|
| 787 |
+
>>> expr(foo=23)
|
| 788 |
+
False
|
| 789 |
+
>>> expr(foo=42)
|
| 790 |
+
True
|
| 791 |
+
|
| 792 |
+
Per default the return value is converted to `None` if the
|
| 793 |
+
expression returns an undefined value. This can be changed
|
| 794 |
+
by setting `undefined_to_none` to `False`.
|
| 795 |
+
|
| 796 |
+
>>> env.compile_expression('var')() is None
|
| 797 |
+
True
|
| 798 |
+
>>> env.compile_expression('var', undefined_to_none=False)()
|
| 799 |
+
Undefined
|
| 800 |
+
|
| 801 |
+
.. versionadded:: 2.1
|
| 802 |
+
"""
|
| 803 |
+
parser = Parser(self, source, state="variable")
|
| 804 |
+
try:
|
| 805 |
+
expr = parser.parse_expression()
|
| 806 |
+
if not parser.stream.eos:
|
| 807 |
+
raise TemplateSyntaxError(
|
| 808 |
+
"chunk after expression", parser.stream.current.lineno, None, None
|
| 809 |
+
)
|
| 810 |
+
expr.set_environment(self)
|
| 811 |
+
except TemplateSyntaxError:
|
| 812 |
+
self.handle_exception(source=source)
|
| 813 |
+
|
| 814 |
+
body = [nodes.Assign(nodes.Name("result", "store"), expr, lineno=1)]
|
| 815 |
+
template = self.from_string(nodes.Template(body, lineno=1))
|
| 816 |
+
return TemplateExpression(template, undefined_to_none)
|
| 817 |
+
|
| 818 |
+
def compile_templates(
|
| 819 |
+
self,
|
| 820 |
+
target: t.Union[str, "os.PathLike[str]"],
|
| 821 |
+
extensions: t.Optional[t.Collection[str]] = None,
|
| 822 |
+
filter_func: t.Optional[t.Callable[[str], bool]] = None,
|
| 823 |
+
zip: t.Optional[str] = "deflated",
|
| 824 |
+
log_function: t.Optional[t.Callable[[str], None]] = None,
|
| 825 |
+
ignore_errors: bool = True,
|
| 826 |
+
) -> None:
|
| 827 |
+
"""Finds all the templates the loader can find, compiles them
|
| 828 |
+
and stores them in `target`. If `zip` is `None`, instead of in a
|
| 829 |
+
zipfile, the templates will be stored in a directory.
|
| 830 |
+
By default a deflate zip algorithm is used. To switch to
|
| 831 |
+
the stored algorithm, `zip` can be set to ``'stored'``.
|
| 832 |
+
|
| 833 |
+
`extensions` and `filter_func` are passed to :meth:`list_templates`.
|
| 834 |
+
Each template returned will be compiled to the target folder or
|
| 835 |
+
zipfile.
|
| 836 |
+
|
| 837 |
+
By default template compilation errors are ignored. In case a
|
| 838 |
+
log function is provided, errors are logged. If you want template
|
| 839 |
+
syntax errors to abort the compilation you can set `ignore_errors`
|
| 840 |
+
to `False` and you will get an exception on syntax errors.
|
| 841 |
+
|
| 842 |
+
.. versionadded:: 2.4
|
| 843 |
+
"""
|
| 844 |
+
from .loaders import ModuleLoader
|
| 845 |
+
|
| 846 |
+
if log_function is None:
|
| 847 |
+
|
| 848 |
+
def log_function(x: str) -> None:
|
| 849 |
+
pass
|
| 850 |
+
|
| 851 |
+
assert log_function is not None
|
| 852 |
+
assert self.loader is not None, "No loader configured."
|
| 853 |
+
|
| 854 |
+
def write_file(filename: str, data: str) -> None:
|
| 855 |
+
if zip:
|
| 856 |
+
info = ZipInfo(filename)
|
| 857 |
+
info.external_attr = 0o755 << 16
|
| 858 |
+
zip_file.writestr(info, data)
|
| 859 |
+
else:
|
| 860 |
+
with open(os.path.join(target, filename), "wb") as f:
|
| 861 |
+
f.write(data.encode("utf8"))
|
| 862 |
+
|
| 863 |
+
if zip is not None:
|
| 864 |
+
from zipfile import ZIP_DEFLATED
|
| 865 |
+
from zipfile import ZIP_STORED
|
| 866 |
+
from zipfile import ZipFile
|
| 867 |
+
from zipfile import ZipInfo
|
| 868 |
+
|
| 869 |
+
zip_file = ZipFile(
|
| 870 |
+
target, "w", dict(deflated=ZIP_DEFLATED, stored=ZIP_STORED)[zip]
|
| 871 |
+
)
|
| 872 |
+
log_function(f"Compiling into Zip archive {target!r}")
|
| 873 |
+
else:
|
| 874 |
+
if not os.path.isdir(target):
|
| 875 |
+
os.makedirs(target)
|
| 876 |
+
log_function(f"Compiling into folder {target!r}")
|
| 877 |
+
|
| 878 |
+
try:
|
| 879 |
+
for name in self.list_templates(extensions, filter_func):
|
| 880 |
+
source, filename, _ = self.loader.get_source(self, name)
|
| 881 |
+
try:
|
| 882 |
+
code = self.compile(source, name, filename, True, True)
|
| 883 |
+
except TemplateSyntaxError as e:
|
| 884 |
+
if not ignore_errors:
|
| 885 |
+
raise
|
| 886 |
+
log_function(f'Could not compile "{name}": {e}')
|
| 887 |
+
continue
|
| 888 |
+
|
| 889 |
+
filename = ModuleLoader.get_module_filename(name)
|
| 890 |
+
|
| 891 |
+
write_file(filename, code)
|
| 892 |
+
log_function(f'Compiled "{name}" as {filename}')
|
| 893 |
+
finally:
|
| 894 |
+
if zip:
|
| 895 |
+
zip_file.close()
|
| 896 |
+
|
| 897 |
+
log_function("Finished compiling templates")
|
| 898 |
+
|
| 899 |
+
def list_templates(
|
| 900 |
+
self,
|
| 901 |
+
extensions: t.Optional[t.Collection[str]] = None,
|
| 902 |
+
filter_func: t.Optional[t.Callable[[str], bool]] = None,
|
| 903 |
+
) -> t.List[str]:
|
| 904 |
+
"""Returns a list of templates for this environment. This requires
|
| 905 |
+
that the loader supports the loader's
|
| 906 |
+
:meth:`~BaseLoader.list_templates` method.
|
| 907 |
+
|
| 908 |
+
If there are other files in the template folder besides the
|
| 909 |
+
actual templates, the returned list can be filtered. There are two
|
| 910 |
+
ways: either `extensions` is set to a list of file extensions for
|
| 911 |
+
templates, or a `filter_func` can be provided which is a callable that
|
| 912 |
+
is passed a template name and should return `True` if it should end up
|
| 913 |
+
in the result list.
|
| 914 |
+
|
| 915 |
+
If the loader does not support that, a :exc:`TypeError` is raised.
|
| 916 |
+
|
| 917 |
+
.. versionadded:: 2.4
|
| 918 |
+
"""
|
| 919 |
+
assert self.loader is not None, "No loader configured."
|
| 920 |
+
names = self.loader.list_templates()
|
| 921 |
+
|
| 922 |
+
if extensions is not None:
|
| 923 |
+
if filter_func is not None:
|
| 924 |
+
raise TypeError(
|
| 925 |
+
"either extensions or filter_func can be passed, but not both"
|
| 926 |
+
)
|
| 927 |
+
|
| 928 |
+
def filter_func(x: str) -> bool:
|
| 929 |
+
return "." in x and x.rsplit(".", 1)[1] in extensions
|
| 930 |
+
|
| 931 |
+
if filter_func is not None:
|
| 932 |
+
names = [name for name in names if filter_func(name)]
|
| 933 |
+
|
| 934 |
+
return names
|
| 935 |
+
|
| 936 |
+
def handle_exception(self, source: t.Optional[str] = None) -> "te.NoReturn":
|
| 937 |
+
"""Exception handling helper. This is used internally to either raise
|
| 938 |
+
rewritten exceptions or return a rendered traceback for the template.
|
| 939 |
+
"""
|
| 940 |
+
from .debug import rewrite_traceback_stack
|
| 941 |
+
|
| 942 |
+
raise rewrite_traceback_stack(source=source)
|
| 943 |
+
|
| 944 |
+
def join_path(self, template: str, parent: str) -> str:
|
| 945 |
+
"""Join a template with the parent. By default all the lookups are
|
| 946 |
+
relative to the loader root so this method returns the `template`
|
| 947 |
+
parameter unchanged, but if the paths should be relative to the
|
| 948 |
+
parent template, this function can be used to calculate the real
|
| 949 |
+
template name.
|
| 950 |
+
|
| 951 |
+
Subclasses may override this method and implement template path
|
| 952 |
+
joining here.
|
| 953 |
+
"""
|
| 954 |
+
return template
|
| 955 |
+
|
| 956 |
+
@internalcode
|
| 957 |
+
def _load_template(
|
| 958 |
+
self, name: str, globals: t.Optional[t.MutableMapping[str, t.Any]]
|
| 959 |
+
) -> "Template":
|
| 960 |
+
if self.loader is None:
|
| 961 |
+
raise TypeError("no loader for this environment specified")
|
| 962 |
+
cache_key = (weakref.ref(self.loader), name)
|
| 963 |
+
if self.cache is not None:
|
| 964 |
+
template = self.cache.get(cache_key)
|
| 965 |
+
if template is not None and (
|
| 966 |
+
not self.auto_reload or template.is_up_to_date
|
| 967 |
+
):
|
| 968 |
+
# template.globals is a ChainMap, modifying it will only
|
| 969 |
+
# affect the template, not the environment globals.
|
| 970 |
+
if globals:
|
| 971 |
+
template.globals.update(globals)
|
| 972 |
+
|
| 973 |
+
return template
|
| 974 |
+
|
| 975 |
+
template = self.loader.load(self, name, self.make_globals(globals))
|
| 976 |
+
|
| 977 |
+
if self.cache is not None:
|
| 978 |
+
self.cache[cache_key] = template
|
| 979 |
+
return template
|
| 980 |
+
|
| 981 |
+
@internalcode
|
| 982 |
+
def get_template(
|
| 983 |
+
self,
|
| 984 |
+
name: t.Union[str, "Template"],
|
| 985 |
+
parent: t.Optional[str] = None,
|
| 986 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 987 |
+
) -> "Template":
|
| 988 |
+
"""Load a template by name with :attr:`loader` and return a
|
| 989 |
+
:class:`Template`. If the template does not exist a
|
| 990 |
+
:exc:`TemplateNotFound` exception is raised.
|
| 991 |
+
|
| 992 |
+
:param name: Name of the template to load. When loading
|
| 993 |
+
templates from the filesystem, "/" is used as the path
|
| 994 |
+
separator, even on Windows.
|
| 995 |
+
:param parent: The name of the parent template importing this
|
| 996 |
+
template. :meth:`join_path` can be used to implement name
|
| 997 |
+
transformations with this.
|
| 998 |
+
:param globals: Extend the environment :attr:`globals` with
|
| 999 |
+
these extra variables available for all renders of this
|
| 1000 |
+
template. If the template has already been loaded and
|
| 1001 |
+
cached, its globals are updated with any new items.
|
| 1002 |
+
|
| 1003 |
+
.. versionchanged:: 3.0
|
| 1004 |
+
If a template is loaded from cache, ``globals`` will update
|
| 1005 |
+
the template's globals instead of ignoring the new values.
|
| 1006 |
+
|
| 1007 |
+
.. versionchanged:: 2.4
|
| 1008 |
+
If ``name`` is a :class:`Template` object it is returned
|
| 1009 |
+
unchanged.
|
| 1010 |
+
"""
|
| 1011 |
+
if isinstance(name, Template):
|
| 1012 |
+
return name
|
| 1013 |
+
if parent is not None:
|
| 1014 |
+
name = self.join_path(name, parent)
|
| 1015 |
+
|
| 1016 |
+
return self._load_template(name, globals)
|
| 1017 |
+
|
| 1018 |
+
@internalcode
|
| 1019 |
+
def select_template(
|
| 1020 |
+
self,
|
| 1021 |
+
names: t.Iterable[t.Union[str, "Template"]],
|
| 1022 |
+
parent: t.Optional[str] = None,
|
| 1023 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 1024 |
+
) -> "Template":
|
| 1025 |
+
"""Like :meth:`get_template`, but tries loading multiple names.
|
| 1026 |
+
If none of the names can be loaded a :exc:`TemplatesNotFound`
|
| 1027 |
+
exception is raised.
|
| 1028 |
+
|
| 1029 |
+
:param names: List of template names to try loading in order.
|
| 1030 |
+
:param parent: The name of the parent template importing this
|
| 1031 |
+
template. :meth:`join_path` can be used to implement name
|
| 1032 |
+
transformations with this.
|
| 1033 |
+
:param globals: Extend the environment :attr:`globals` with
|
| 1034 |
+
these extra variables available for all renders of this
|
| 1035 |
+
template. If the template has already been loaded and
|
| 1036 |
+
cached, its globals are updated with any new items.
|
| 1037 |
+
|
| 1038 |
+
.. versionchanged:: 3.0
|
| 1039 |
+
If a template is loaded from cache, ``globals`` will update
|
| 1040 |
+
the template's globals instead of ignoring the new values.
|
| 1041 |
+
|
| 1042 |
+
.. versionchanged:: 2.11
|
| 1043 |
+
If ``names`` is :class:`Undefined`, an :exc:`UndefinedError`
|
| 1044 |
+
is raised instead. If no templates were found and ``names``
|
| 1045 |
+
contains :class:`Undefined`, the message is more helpful.
|
| 1046 |
+
|
| 1047 |
+
.. versionchanged:: 2.4
|
| 1048 |
+
If ``names`` contains a :class:`Template` object it is
|
| 1049 |
+
returned unchanged.
|
| 1050 |
+
|
| 1051 |
+
.. versionadded:: 2.3
|
| 1052 |
+
"""
|
| 1053 |
+
if isinstance(names, Undefined):
|
| 1054 |
+
names._fail_with_undefined_error()
|
| 1055 |
+
|
| 1056 |
+
if not names:
|
| 1057 |
+
raise TemplatesNotFound(
|
| 1058 |
+
message="Tried to select from an empty list of templates."
|
| 1059 |
+
)
|
| 1060 |
+
|
| 1061 |
+
for name in names:
|
| 1062 |
+
if isinstance(name, Template):
|
| 1063 |
+
return name
|
| 1064 |
+
if parent is not None:
|
| 1065 |
+
name = self.join_path(name, parent)
|
| 1066 |
+
try:
|
| 1067 |
+
return self._load_template(name, globals)
|
| 1068 |
+
except (TemplateNotFound, UndefinedError):
|
| 1069 |
+
pass
|
| 1070 |
+
raise TemplatesNotFound(names) # type: ignore
|
| 1071 |
+
|
| 1072 |
+
@internalcode
|
| 1073 |
+
def get_or_select_template(
|
| 1074 |
+
self,
|
| 1075 |
+
template_name_or_list: t.Union[
|
| 1076 |
+
str, "Template", t.List[t.Union[str, "Template"]]
|
| 1077 |
+
],
|
| 1078 |
+
parent: t.Optional[str] = None,
|
| 1079 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 1080 |
+
) -> "Template":
|
| 1081 |
+
"""Use :meth:`select_template` if an iterable of template names
|
| 1082 |
+
is given, or :meth:`get_template` if one name is given.
|
| 1083 |
+
|
| 1084 |
+
.. versionadded:: 2.3
|
| 1085 |
+
"""
|
| 1086 |
+
if isinstance(template_name_or_list, (str, Undefined)):
|
| 1087 |
+
return self.get_template(template_name_or_list, parent, globals)
|
| 1088 |
+
elif isinstance(template_name_or_list, Template):
|
| 1089 |
+
return template_name_or_list
|
| 1090 |
+
return self.select_template(template_name_or_list, parent, globals)
|
| 1091 |
+
|
| 1092 |
+
def from_string(
|
| 1093 |
+
self,
|
| 1094 |
+
source: t.Union[str, nodes.Template],
|
| 1095 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 1096 |
+
template_class: t.Optional[t.Type["Template"]] = None,
|
| 1097 |
+
) -> "Template":
|
| 1098 |
+
"""Load a template from a source string without using
|
| 1099 |
+
:attr:`loader`.
|
| 1100 |
+
|
| 1101 |
+
:param source: Jinja source to compile into a template.
|
| 1102 |
+
:param globals: Extend the environment :attr:`globals` with
|
| 1103 |
+
these extra variables available for all renders of this
|
| 1104 |
+
template. If the template has already been loaded and
|
| 1105 |
+
cached, its globals are updated with any new items.
|
| 1106 |
+
:param template_class: Return an instance of this
|
| 1107 |
+
:class:`Template` class.
|
| 1108 |
+
"""
|
| 1109 |
+
gs = self.make_globals(globals)
|
| 1110 |
+
cls = template_class or self.template_class
|
| 1111 |
+
return cls.from_code(self, self.compile(source), gs, None)
|
| 1112 |
+
|
| 1113 |
+
def make_globals(
|
| 1114 |
+
self, d: t.Optional[t.MutableMapping[str, t.Any]]
|
| 1115 |
+
) -> t.MutableMapping[str, t.Any]:
|
| 1116 |
+
"""Make the globals map for a template. Any given template
|
| 1117 |
+
globals overlay the environment :attr:`globals`.
|
| 1118 |
+
|
| 1119 |
+
Returns a :class:`collections.ChainMap`. This allows any changes
|
| 1120 |
+
to a template's globals to only affect that template, while
|
| 1121 |
+
changes to the environment's globals are still reflected.
|
| 1122 |
+
However, avoid modifying any globals after a template is loaded.
|
| 1123 |
+
|
| 1124 |
+
:param d: Dict of template-specific globals.
|
| 1125 |
+
|
| 1126 |
+
.. versionchanged:: 3.0
|
| 1127 |
+
Use :class:`collections.ChainMap` to always prevent mutating
|
| 1128 |
+
environment globals.
|
| 1129 |
+
"""
|
| 1130 |
+
if d is None:
|
| 1131 |
+
d = {}
|
| 1132 |
+
|
| 1133 |
+
return ChainMap(d, self.globals)
|
| 1134 |
+
|
| 1135 |
+
|
| 1136 |
+
class Template:
|
| 1137 |
+
"""A compiled template that can be rendered.
|
| 1138 |
+
|
| 1139 |
+
Use the methods on :class:`Environment` to create or load templates.
|
| 1140 |
+
The environment is used to configure how templates are compiled and
|
| 1141 |
+
behave.
|
| 1142 |
+
|
| 1143 |
+
It is also possible to create a template object directly. This is
|
| 1144 |
+
not usually recommended. The constructor takes most of the same
|
| 1145 |
+
arguments as :class:`Environment`. All templates created with the
|
| 1146 |
+
same environment arguments share the same ephemeral ``Environment``
|
| 1147 |
+
instance behind the scenes.
|
| 1148 |
+
|
| 1149 |
+
A template object should be considered immutable. Modifications on
|
| 1150 |
+
the object are not supported.
|
| 1151 |
+
"""
|
| 1152 |
+
|
| 1153 |
+
#: Type of environment to create when creating a template directly
|
| 1154 |
+
#: rather than through an existing environment.
|
| 1155 |
+
environment_class: t.Type[Environment] = Environment
|
| 1156 |
+
|
| 1157 |
+
environment: Environment
|
| 1158 |
+
globals: t.MutableMapping[str, t.Any]
|
| 1159 |
+
name: t.Optional[str]
|
| 1160 |
+
filename: t.Optional[str]
|
| 1161 |
+
blocks: t.Dict[str, t.Callable[[Context], t.Iterator[str]]]
|
| 1162 |
+
root_render_func: t.Callable[[Context], t.Iterator[str]]
|
| 1163 |
+
_module: t.Optional["TemplateModule"]
|
| 1164 |
+
_debug_info: str
|
| 1165 |
+
_uptodate: t.Optional[t.Callable[[], bool]]
|
| 1166 |
+
|
| 1167 |
+
def __new__(
|
| 1168 |
+
cls,
|
| 1169 |
+
source: t.Union[str, nodes.Template],
|
| 1170 |
+
block_start_string: str = BLOCK_START_STRING,
|
| 1171 |
+
block_end_string: str = BLOCK_END_STRING,
|
| 1172 |
+
variable_start_string: str = VARIABLE_START_STRING,
|
| 1173 |
+
variable_end_string: str = VARIABLE_END_STRING,
|
| 1174 |
+
comment_start_string: str = COMMENT_START_STRING,
|
| 1175 |
+
comment_end_string: str = COMMENT_END_STRING,
|
| 1176 |
+
line_statement_prefix: t.Optional[str] = LINE_STATEMENT_PREFIX,
|
| 1177 |
+
line_comment_prefix: t.Optional[str] = LINE_COMMENT_PREFIX,
|
| 1178 |
+
trim_blocks: bool = TRIM_BLOCKS,
|
| 1179 |
+
lstrip_blocks: bool = LSTRIP_BLOCKS,
|
| 1180 |
+
newline_sequence: "te.Literal['\\n', '\\r\\n', '\\r']" = NEWLINE_SEQUENCE,
|
| 1181 |
+
keep_trailing_newline: bool = KEEP_TRAILING_NEWLINE,
|
| 1182 |
+
extensions: t.Sequence[t.Union[str, t.Type["Extension"]]] = (),
|
| 1183 |
+
optimized: bool = True,
|
| 1184 |
+
undefined: t.Type[Undefined] = Undefined,
|
| 1185 |
+
finalize: t.Optional[t.Callable[..., t.Any]] = None,
|
| 1186 |
+
autoescape: t.Union[bool, t.Callable[[t.Optional[str]], bool]] = False,
|
| 1187 |
+
enable_async: bool = False,
|
| 1188 |
+
) -> t.Any: # it returns a `Template`, but this breaks the sphinx build...
|
| 1189 |
+
env = get_spontaneous_environment(
|
| 1190 |
+
cls.environment_class, # type: ignore
|
| 1191 |
+
block_start_string,
|
| 1192 |
+
block_end_string,
|
| 1193 |
+
variable_start_string,
|
| 1194 |
+
variable_end_string,
|
| 1195 |
+
comment_start_string,
|
| 1196 |
+
comment_end_string,
|
| 1197 |
+
line_statement_prefix,
|
| 1198 |
+
line_comment_prefix,
|
| 1199 |
+
trim_blocks,
|
| 1200 |
+
lstrip_blocks,
|
| 1201 |
+
newline_sequence,
|
| 1202 |
+
keep_trailing_newline,
|
| 1203 |
+
frozenset(extensions),
|
| 1204 |
+
optimized,
|
| 1205 |
+
undefined, # type: ignore
|
| 1206 |
+
finalize,
|
| 1207 |
+
autoescape,
|
| 1208 |
+
None,
|
| 1209 |
+
0,
|
| 1210 |
+
False,
|
| 1211 |
+
None,
|
| 1212 |
+
enable_async,
|
| 1213 |
+
)
|
| 1214 |
+
return env.from_string(source, template_class=cls)
|
| 1215 |
+
|
| 1216 |
+
@classmethod
|
| 1217 |
+
def from_code(
|
| 1218 |
+
cls,
|
| 1219 |
+
environment: Environment,
|
| 1220 |
+
code: CodeType,
|
| 1221 |
+
globals: t.MutableMapping[str, t.Any],
|
| 1222 |
+
uptodate: t.Optional[t.Callable[[], bool]] = None,
|
| 1223 |
+
) -> "Template":
|
| 1224 |
+
"""Creates a template object from compiled code and the globals. This
|
| 1225 |
+
is used by the loaders and environment to create a template object.
|
| 1226 |
+
"""
|
| 1227 |
+
namespace = {"environment": environment, "__file__": code.co_filename}
|
| 1228 |
+
exec(code, namespace)
|
| 1229 |
+
rv = cls._from_namespace(environment, namespace, globals)
|
| 1230 |
+
rv._uptodate = uptodate
|
| 1231 |
+
return rv
|
| 1232 |
+
|
| 1233 |
+
@classmethod
|
| 1234 |
+
def from_module_dict(
|
| 1235 |
+
cls,
|
| 1236 |
+
environment: Environment,
|
| 1237 |
+
module_dict: t.MutableMapping[str, t.Any],
|
| 1238 |
+
globals: t.MutableMapping[str, t.Any],
|
| 1239 |
+
) -> "Template":
|
| 1240 |
+
"""Creates a template object from a module. This is used by the
|
| 1241 |
+
module loader to create a template object.
|
| 1242 |
+
|
| 1243 |
+
.. versionadded:: 2.4
|
| 1244 |
+
"""
|
| 1245 |
+
return cls._from_namespace(environment, module_dict, globals)
|
| 1246 |
+
|
| 1247 |
+
@classmethod
|
| 1248 |
+
def _from_namespace(
|
| 1249 |
+
cls,
|
| 1250 |
+
environment: Environment,
|
| 1251 |
+
namespace: t.MutableMapping[str, t.Any],
|
| 1252 |
+
globals: t.MutableMapping[str, t.Any],
|
| 1253 |
+
) -> "Template":
|
| 1254 |
+
t: Template = object.__new__(cls)
|
| 1255 |
+
t.environment = environment
|
| 1256 |
+
t.globals = globals
|
| 1257 |
+
t.name = namespace["name"]
|
| 1258 |
+
t.filename = namespace["__file__"]
|
| 1259 |
+
t.blocks = namespace["blocks"]
|
| 1260 |
+
|
| 1261 |
+
# render function and module
|
| 1262 |
+
t.root_render_func = namespace["root"]
|
| 1263 |
+
t._module = None
|
| 1264 |
+
|
| 1265 |
+
# debug and loader helpers
|
| 1266 |
+
t._debug_info = namespace["debug_info"]
|
| 1267 |
+
t._uptodate = None
|
| 1268 |
+
|
| 1269 |
+
# store the reference
|
| 1270 |
+
namespace["environment"] = environment
|
| 1271 |
+
namespace["__jinja_template__"] = t
|
| 1272 |
+
|
| 1273 |
+
return t
|
| 1274 |
+
|
| 1275 |
+
def render(self, *args: t.Any, **kwargs: t.Any) -> str:
|
| 1276 |
+
"""This method accepts the same arguments as the `dict` constructor:
|
| 1277 |
+
A dict, a dict subclass or some keyword arguments. If no arguments
|
| 1278 |
+
are given the context will be empty. These two calls do the same::
|
| 1279 |
+
|
| 1280 |
+
template.render(knights='that say nih')
|
| 1281 |
+
template.render({'knights': 'that say nih'})
|
| 1282 |
+
|
| 1283 |
+
This will return the rendered template as a string.
|
| 1284 |
+
"""
|
| 1285 |
+
if self.environment.is_async:
|
| 1286 |
+
import asyncio
|
| 1287 |
+
|
| 1288 |
+
return asyncio.run(self.render_async(*args, **kwargs))
|
| 1289 |
+
|
| 1290 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 1291 |
+
|
| 1292 |
+
try:
|
| 1293 |
+
return self.environment.concat(self.root_render_func(ctx)) # type: ignore
|
| 1294 |
+
except Exception:
|
| 1295 |
+
self.environment.handle_exception()
|
| 1296 |
+
|
| 1297 |
+
async def render_async(self, *args: t.Any, **kwargs: t.Any) -> str:
|
| 1298 |
+
"""This works similar to :meth:`render` but returns a coroutine
|
| 1299 |
+
that when awaited returns the entire rendered template string. This
|
| 1300 |
+
requires the async feature to be enabled.
|
| 1301 |
+
|
| 1302 |
+
Example usage::
|
| 1303 |
+
|
| 1304 |
+
await template.render_async(knights='that say nih; asynchronously')
|
| 1305 |
+
"""
|
| 1306 |
+
if not self.environment.is_async:
|
| 1307 |
+
raise RuntimeError(
|
| 1308 |
+
"The environment was not created with async mode enabled."
|
| 1309 |
+
)
|
| 1310 |
+
|
| 1311 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 1312 |
+
|
| 1313 |
+
try:
|
| 1314 |
+
return self.environment.concat( # type: ignore
|
| 1315 |
+
[n async for n in self.root_render_func(ctx)] # type: ignore
|
| 1316 |
+
)
|
| 1317 |
+
except Exception:
|
| 1318 |
+
return self.environment.handle_exception()
|
| 1319 |
+
|
| 1320 |
+
def stream(self, *args: t.Any, **kwargs: t.Any) -> "TemplateStream":
|
| 1321 |
+
"""Works exactly like :meth:`generate` but returns a
|
| 1322 |
+
:class:`TemplateStream`.
|
| 1323 |
+
"""
|
| 1324 |
+
return TemplateStream(self.generate(*args, **kwargs))
|
| 1325 |
+
|
| 1326 |
+
def generate(self, *args: t.Any, **kwargs: t.Any) -> t.Iterator[str]:
|
| 1327 |
+
"""For very large templates it can be useful to not render the whole
|
| 1328 |
+
template at once but evaluate each statement after another and yield
|
| 1329 |
+
piece for piece. This method basically does exactly that and returns
|
| 1330 |
+
a generator that yields one item after another as strings.
|
| 1331 |
+
|
| 1332 |
+
It accepts the same arguments as :meth:`render`.
|
| 1333 |
+
"""
|
| 1334 |
+
if self.environment.is_async:
|
| 1335 |
+
import asyncio
|
| 1336 |
+
|
| 1337 |
+
async def to_list() -> t.List[str]:
|
| 1338 |
+
return [x async for x in self.generate_async(*args, **kwargs)]
|
| 1339 |
+
|
| 1340 |
+
yield from asyncio.run(to_list())
|
| 1341 |
+
return
|
| 1342 |
+
|
| 1343 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 1344 |
+
|
| 1345 |
+
try:
|
| 1346 |
+
yield from self.root_render_func(ctx)
|
| 1347 |
+
except Exception:
|
| 1348 |
+
yield self.environment.handle_exception()
|
| 1349 |
+
|
| 1350 |
+
async def generate_async(
|
| 1351 |
+
self, *args: t.Any, **kwargs: t.Any
|
| 1352 |
+
) -> t.AsyncGenerator[str, object]:
|
| 1353 |
+
"""An async version of :meth:`generate`. Works very similarly but
|
| 1354 |
+
returns an async iterator instead.
|
| 1355 |
+
"""
|
| 1356 |
+
if not self.environment.is_async:
|
| 1357 |
+
raise RuntimeError(
|
| 1358 |
+
"The environment was not created with async mode enabled."
|
| 1359 |
+
)
|
| 1360 |
+
|
| 1361 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 1362 |
+
|
| 1363 |
+
try:
|
| 1364 |
+
agen = self.root_render_func(ctx)
|
| 1365 |
+
try:
|
| 1366 |
+
async for event in agen: # type: ignore
|
| 1367 |
+
yield event
|
| 1368 |
+
finally:
|
| 1369 |
+
# we can't use async with aclosing(...) because that's only
|
| 1370 |
+
# in 3.10+
|
| 1371 |
+
await agen.aclose() # type: ignore
|
| 1372 |
+
except Exception:
|
| 1373 |
+
yield self.environment.handle_exception()
|
| 1374 |
+
|
| 1375 |
+
def new_context(
|
| 1376 |
+
self,
|
| 1377 |
+
vars: t.Optional[t.Dict[str, t.Any]] = None,
|
| 1378 |
+
shared: bool = False,
|
| 1379 |
+
locals: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 1380 |
+
) -> Context:
|
| 1381 |
+
"""Create a new :class:`Context` for this template. The vars
|
| 1382 |
+
provided will be passed to the template. Per default the globals
|
| 1383 |
+
are added to the context. If shared is set to `True` the data
|
| 1384 |
+
is passed as is to the context without adding the globals.
|
| 1385 |
+
|
| 1386 |
+
`locals` can be a dict of local variables for internal usage.
|
| 1387 |
+
"""
|
| 1388 |
+
return new_context(
|
| 1389 |
+
self.environment, self.name, self.blocks, vars, shared, self.globals, locals
|
| 1390 |
+
)
|
| 1391 |
+
|
| 1392 |
+
def make_module(
|
| 1393 |
+
self,
|
| 1394 |
+
vars: t.Optional[t.Dict[str, t.Any]] = None,
|
| 1395 |
+
shared: bool = False,
|
| 1396 |
+
locals: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 1397 |
+
) -> "TemplateModule":
|
| 1398 |
+
"""This method works like the :attr:`module` attribute when called
|
| 1399 |
+
without arguments but it will evaluate the template on every call
|
| 1400 |
+
rather than caching it. It's also possible to provide
|
| 1401 |
+
a dict which is then used as context. The arguments are the same
|
| 1402 |
+
as for the :meth:`new_context` method.
|
| 1403 |
+
"""
|
| 1404 |
+
ctx = self.new_context(vars, shared, locals)
|
| 1405 |
+
return TemplateModule(self, ctx)
|
| 1406 |
+
|
| 1407 |
+
async def make_module_async(
|
| 1408 |
+
self,
|
| 1409 |
+
vars: t.Optional[t.Dict[str, t.Any]] = None,
|
| 1410 |
+
shared: bool = False,
|
| 1411 |
+
locals: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 1412 |
+
) -> "TemplateModule":
|
| 1413 |
+
"""As template module creation can invoke template code for
|
| 1414 |
+
asynchronous executions this method must be used instead of the
|
| 1415 |
+
normal :meth:`make_module` one. Likewise the module attribute
|
| 1416 |
+
becomes unavailable in async mode.
|
| 1417 |
+
"""
|
| 1418 |
+
ctx = self.new_context(vars, shared, locals)
|
| 1419 |
+
return TemplateModule(
|
| 1420 |
+
self,
|
| 1421 |
+
ctx,
|
| 1422 |
+
[x async for x in self.root_render_func(ctx)], # type: ignore
|
| 1423 |
+
)
|
| 1424 |
+
|
| 1425 |
+
@internalcode
|
| 1426 |
+
def _get_default_module(self, ctx: t.Optional[Context] = None) -> "TemplateModule":
|
| 1427 |
+
"""If a context is passed in, this means that the template was
|
| 1428 |
+
imported. Imported templates have access to the current
|
| 1429 |
+
template's globals by default, but they can only be accessed via
|
| 1430 |
+
the context during runtime.
|
| 1431 |
+
|
| 1432 |
+
If there are new globals, we need to create a new module because
|
| 1433 |
+
the cached module is already rendered and will not have access
|
| 1434 |
+
to globals from the current context. This new module is not
|
| 1435 |
+
cached because the template can be imported elsewhere, and it
|
| 1436 |
+
should have access to only the current template's globals.
|
| 1437 |
+
"""
|
| 1438 |
+
if self.environment.is_async:
|
| 1439 |
+
raise RuntimeError("Module is not available in async mode.")
|
| 1440 |
+
|
| 1441 |
+
if ctx is not None:
|
| 1442 |
+
keys = ctx.globals_keys - self.globals.keys()
|
| 1443 |
+
|
| 1444 |
+
if keys:
|
| 1445 |
+
return self.make_module({k: ctx.parent[k] for k in keys})
|
| 1446 |
+
|
| 1447 |
+
if self._module is None:
|
| 1448 |
+
self._module = self.make_module()
|
| 1449 |
+
|
| 1450 |
+
return self._module
|
| 1451 |
+
|
| 1452 |
+
async def _get_default_module_async(
|
| 1453 |
+
self, ctx: t.Optional[Context] = None
|
| 1454 |
+
) -> "TemplateModule":
|
| 1455 |
+
if ctx is not None:
|
| 1456 |
+
keys = ctx.globals_keys - self.globals.keys()
|
| 1457 |
+
|
| 1458 |
+
if keys:
|
| 1459 |
+
return await self.make_module_async({k: ctx.parent[k] for k in keys})
|
| 1460 |
+
|
| 1461 |
+
if self._module is None:
|
| 1462 |
+
self._module = await self.make_module_async()
|
| 1463 |
+
|
| 1464 |
+
return self._module
|
| 1465 |
+
|
| 1466 |
+
@property
|
| 1467 |
+
def module(self) -> "TemplateModule":
|
| 1468 |
+
"""The template as module. This is used for imports in the
|
| 1469 |
+
template runtime but is also useful if one wants to access
|
| 1470 |
+
exported template variables from the Python layer:
|
| 1471 |
+
|
| 1472 |
+
>>> t = Template('{% macro foo() %}42{% endmacro %}23')
|
| 1473 |
+
>>> str(t.module)
|
| 1474 |
+
'23'
|
| 1475 |
+
>>> t.module.foo() == u'42'
|
| 1476 |
+
True
|
| 1477 |
+
|
| 1478 |
+
This attribute is not available if async mode is enabled.
|
| 1479 |
+
"""
|
| 1480 |
+
return self._get_default_module()
|
| 1481 |
+
|
| 1482 |
+
def get_corresponding_lineno(self, lineno: int) -> int:
|
| 1483 |
+
"""Return the source line number of a line number in the
|
| 1484 |
+
generated bytecode as they are not in sync.
|
| 1485 |
+
"""
|
| 1486 |
+
for template_line, code_line in reversed(self.debug_info):
|
| 1487 |
+
if code_line <= lineno:
|
| 1488 |
+
return template_line
|
| 1489 |
+
return 1
|
| 1490 |
+
|
| 1491 |
+
@property
|
| 1492 |
+
def is_up_to_date(self) -> bool:
|
| 1493 |
+
"""If this variable is `False` there is a newer version available."""
|
| 1494 |
+
if self._uptodate is None:
|
| 1495 |
+
return True
|
| 1496 |
+
return self._uptodate()
|
| 1497 |
+
|
| 1498 |
+
@property
|
| 1499 |
+
def debug_info(self) -> t.List[t.Tuple[int, int]]:
|
| 1500 |
+
"""The debug info mapping."""
|
| 1501 |
+
if self._debug_info:
|
| 1502 |
+
return [
|
| 1503 |
+
tuple(map(int, x.split("="))) # type: ignore
|
| 1504 |
+
for x in self._debug_info.split("&")
|
| 1505 |
+
]
|
| 1506 |
+
|
| 1507 |
+
return []
|
| 1508 |
+
|
| 1509 |
+
def __repr__(self) -> str:
|
| 1510 |
+
if self.name is None:
|
| 1511 |
+
name = f"memory:{id(self):x}"
|
| 1512 |
+
else:
|
| 1513 |
+
name = repr(self.name)
|
| 1514 |
+
return f"<{type(self).__name__} {name}>"
|
| 1515 |
+
|
| 1516 |
+
|
| 1517 |
+
class TemplateModule:
|
| 1518 |
+
"""Represents an imported template. All the exported names of the
|
| 1519 |
+
template are available as attributes on this object. Additionally
|
| 1520 |
+
converting it into a string renders the contents.
|
| 1521 |
+
"""
|
| 1522 |
+
|
| 1523 |
+
def __init__(
|
| 1524 |
+
self,
|
| 1525 |
+
template: Template,
|
| 1526 |
+
context: Context,
|
| 1527 |
+
body_stream: t.Optional[t.Iterable[str]] = None,
|
| 1528 |
+
) -> None:
|
| 1529 |
+
if body_stream is None:
|
| 1530 |
+
if context.environment.is_async:
|
| 1531 |
+
raise RuntimeError(
|
| 1532 |
+
"Async mode requires a body stream to be passed to"
|
| 1533 |
+
" a template module. Use the async methods of the"
|
| 1534 |
+
" API you are using."
|
| 1535 |
+
)
|
| 1536 |
+
|
| 1537 |
+
body_stream = list(template.root_render_func(context))
|
| 1538 |
+
|
| 1539 |
+
self._body_stream = body_stream
|
| 1540 |
+
self.__dict__.update(context.get_exported())
|
| 1541 |
+
self.__name__ = template.name
|
| 1542 |
+
|
| 1543 |
+
def __html__(self) -> Markup:
|
| 1544 |
+
return Markup(concat(self._body_stream))
|
| 1545 |
+
|
| 1546 |
+
def __str__(self) -> str:
|
| 1547 |
+
return concat(self._body_stream)
|
| 1548 |
+
|
| 1549 |
+
def __repr__(self) -> str:
|
| 1550 |
+
if self.__name__ is None:
|
| 1551 |
+
name = f"memory:{id(self):x}"
|
| 1552 |
+
else:
|
| 1553 |
+
name = repr(self.__name__)
|
| 1554 |
+
return f"<{type(self).__name__} {name}>"
|
| 1555 |
+
|
| 1556 |
+
|
| 1557 |
+
class TemplateExpression:
|
| 1558 |
+
"""The :meth:`jinja2.Environment.compile_expression` method returns an
|
| 1559 |
+
instance of this object. It encapsulates the expression-like access
|
| 1560 |
+
to the template with an expression it wraps.
|
| 1561 |
+
"""
|
| 1562 |
+
|
| 1563 |
+
def __init__(self, template: Template, undefined_to_none: bool) -> None:
|
| 1564 |
+
self._template = template
|
| 1565 |
+
self._undefined_to_none = undefined_to_none
|
| 1566 |
+
|
| 1567 |
+
def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Optional[t.Any]:
|
| 1568 |
+
context = self._template.new_context(dict(*args, **kwargs))
|
| 1569 |
+
consume(self._template.root_render_func(context))
|
| 1570 |
+
rv = context.vars["result"]
|
| 1571 |
+
if self._undefined_to_none and isinstance(rv, Undefined):
|
| 1572 |
+
rv = None
|
| 1573 |
+
return rv
|
| 1574 |
+
|
| 1575 |
+
|
| 1576 |
+
class TemplateStream:
|
| 1577 |
+
"""A template stream works pretty much like an ordinary python generator
|
| 1578 |
+
but it can buffer multiple items to reduce the number of total iterations.
|
| 1579 |
+
Per default the output is unbuffered which means that for every unbuffered
|
| 1580 |
+
instruction in the template one string is yielded.
|
| 1581 |
+
|
| 1582 |
+
If buffering is enabled with a buffer size of 5, five items are combined
|
| 1583 |
+
into a new string. This is mainly useful if you are streaming
|
| 1584 |
+
big templates to a client via WSGI which flushes after each iteration.
|
| 1585 |
+
"""
|
| 1586 |
+
|
| 1587 |
+
def __init__(self, gen: t.Iterator[str]) -> None:
|
| 1588 |
+
self._gen = gen
|
| 1589 |
+
self.disable_buffering()
|
| 1590 |
+
|
| 1591 |
+
def dump(
|
| 1592 |
+
self,
|
| 1593 |
+
fp: t.Union[str, t.IO[bytes]],
|
| 1594 |
+
encoding: t.Optional[str] = None,
|
| 1595 |
+
errors: t.Optional[str] = "strict",
|
| 1596 |
+
) -> None:
|
| 1597 |
+
"""Dump the complete stream into a file or file-like object.
|
| 1598 |
+
Per default strings are written, if you want to encode
|
| 1599 |
+
before writing specify an `encoding`.
|
| 1600 |
+
|
| 1601 |
+
Example usage::
|
| 1602 |
+
|
| 1603 |
+
Template('Hello {{ name }}!').stream(name='foo').dump('hello.html')
|
| 1604 |
+
"""
|
| 1605 |
+
close = False
|
| 1606 |
+
|
| 1607 |
+
if isinstance(fp, str):
|
| 1608 |
+
if encoding is None:
|
| 1609 |
+
encoding = "utf-8"
|
| 1610 |
+
|
| 1611 |
+
real_fp: t.IO[bytes] = open(fp, "wb")
|
| 1612 |
+
close = True
|
| 1613 |
+
else:
|
| 1614 |
+
real_fp = fp
|
| 1615 |
+
|
| 1616 |
+
try:
|
| 1617 |
+
if encoding is not None:
|
| 1618 |
+
iterable = (x.encode(encoding, errors) for x in self) # type: ignore
|
| 1619 |
+
else:
|
| 1620 |
+
iterable = self # type: ignore
|
| 1621 |
+
|
| 1622 |
+
if hasattr(real_fp, "writelines"):
|
| 1623 |
+
real_fp.writelines(iterable)
|
| 1624 |
+
else:
|
| 1625 |
+
for item in iterable:
|
| 1626 |
+
real_fp.write(item)
|
| 1627 |
+
finally:
|
| 1628 |
+
if close:
|
| 1629 |
+
real_fp.close()
|
| 1630 |
+
|
| 1631 |
+
def disable_buffering(self) -> None:
|
| 1632 |
+
"""Disable the output buffering."""
|
| 1633 |
+
self._next = partial(next, self._gen)
|
| 1634 |
+
self.buffered = False
|
| 1635 |
+
|
| 1636 |
+
def _buffered_generator(self, size: int) -> t.Iterator[str]:
|
| 1637 |
+
buf: t.List[str] = []
|
| 1638 |
+
c_size = 0
|
| 1639 |
+
push = buf.append
|
| 1640 |
+
|
| 1641 |
+
while True:
|
| 1642 |
+
try:
|
| 1643 |
+
while c_size < size:
|
| 1644 |
+
c = next(self._gen)
|
| 1645 |
+
push(c)
|
| 1646 |
+
if c:
|
| 1647 |
+
c_size += 1
|
| 1648 |
+
except StopIteration:
|
| 1649 |
+
if not c_size:
|
| 1650 |
+
return
|
| 1651 |
+
yield concat(buf)
|
| 1652 |
+
del buf[:]
|
| 1653 |
+
c_size = 0
|
| 1654 |
+
|
| 1655 |
+
def enable_buffering(self, size: int = 5) -> None:
|
| 1656 |
+
"""Enable buffering. Buffer `size` items before yielding them."""
|
| 1657 |
+
if size <= 1:
|
| 1658 |
+
raise ValueError("buffer size too small")
|
| 1659 |
+
|
| 1660 |
+
self.buffered = True
|
| 1661 |
+
self._next = partial(next, self._buffered_generator(size))
|
| 1662 |
+
|
| 1663 |
+
def __iter__(self) -> "TemplateStream":
|
| 1664 |
+
return self
|
| 1665 |
+
|
| 1666 |
+
def __next__(self) -> str:
|
| 1667 |
+
return self._next() # type: ignore
|
| 1668 |
+
|
| 1669 |
+
|
| 1670 |
+
# hook in default template class. if anyone reads this comment: ignore that
|
| 1671 |
+
# it's possible to use custom templates ;-)
|
| 1672 |
+
Environment.template_class = Template
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/exceptions.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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 |
+
"""
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/site-packages/jinja2/filters.py
ADDED
|
@@ -0,0 +1,1873 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Built-in template filters used with the ``|`` operator."""
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
import random
|
| 5 |
+
import re
|
| 6 |
+
import typing
|
| 7 |
+
import typing as t
|
| 8 |
+
from collections import abc
|
| 9 |
+
from inspect import getattr_static
|
| 10 |
+
from itertools import chain
|
| 11 |
+
from itertools import groupby
|
| 12 |
+
|
| 13 |
+
from markupsafe import escape
|
| 14 |
+
from markupsafe import Markup
|
| 15 |
+
from markupsafe import soft_str
|
| 16 |
+
|
| 17 |
+
from .async_utils import async_variant
|
| 18 |
+
from .async_utils import auto_aiter
|
| 19 |
+
from .async_utils import auto_await
|
| 20 |
+
from .async_utils import auto_to_list
|
| 21 |
+
from .exceptions import FilterArgumentError
|
| 22 |
+
from .runtime import Undefined
|
| 23 |
+
from .utils import htmlsafe_json_dumps
|
| 24 |
+
from .utils import pass_context
|
| 25 |
+
from .utils import pass_environment
|
| 26 |
+
from .utils import pass_eval_context
|
| 27 |
+
from .utils import pformat
|
| 28 |
+
from .utils import url_quote
|
| 29 |
+
from .utils import urlize
|
| 30 |
+
|
| 31 |
+
if t.TYPE_CHECKING:
|
| 32 |
+
import typing_extensions as te
|
| 33 |
+
|
| 34 |
+
from .environment import Environment
|
| 35 |
+
from .nodes import EvalContext
|
| 36 |
+
from .runtime import Context
|
| 37 |
+
from .sandbox import SandboxedEnvironment # noqa: F401
|
| 38 |
+
|
| 39 |
+
class HasHTML(te.Protocol):
|
| 40 |
+
def __html__(self) -> str:
|
| 41 |
+
pass
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 45 |
+
K = t.TypeVar("K")
|
| 46 |
+
V = t.TypeVar("V")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def ignore_case(value: V) -> V:
|
| 50 |
+
"""For use as a postprocessor for :func:`make_attrgetter`. Converts strings
|
| 51 |
+
to lowercase and returns other types as-is."""
|
| 52 |
+
if isinstance(value, str):
|
| 53 |
+
return t.cast(V, value.lower())
|
| 54 |
+
|
| 55 |
+
return value
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def make_attrgetter(
|
| 59 |
+
environment: "Environment",
|
| 60 |
+
attribute: t.Optional[t.Union[str, int]],
|
| 61 |
+
postprocess: t.Optional[t.Callable[[t.Any], t.Any]] = None,
|
| 62 |
+
default: t.Optional[t.Any] = None,
|
| 63 |
+
) -> t.Callable[[t.Any], t.Any]:
|
| 64 |
+
"""Returns a callable that looks up the given attribute from a
|
| 65 |
+
passed object with the rules of the environment. Dots are allowed
|
| 66 |
+
to access attributes of attributes. Integer parts in paths are
|
| 67 |
+
looked up as integers.
|
| 68 |
+
"""
|
| 69 |
+
parts = _prepare_attribute_parts(attribute)
|
| 70 |
+
|
| 71 |
+
def attrgetter(item: t.Any) -> t.Any:
|
| 72 |
+
for part in parts:
|
| 73 |
+
item = environment.getitem(item, part)
|
| 74 |
+
|
| 75 |
+
if default is not None and isinstance(item, Undefined):
|
| 76 |
+
item = default
|
| 77 |
+
|
| 78 |
+
if postprocess is not None:
|
| 79 |
+
item = postprocess(item)
|
| 80 |
+
|
| 81 |
+
return item
|
| 82 |
+
|
| 83 |
+
return attrgetter
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def make_multi_attrgetter(
|
| 87 |
+
environment: "Environment",
|
| 88 |
+
attribute: t.Optional[t.Union[str, int]],
|
| 89 |
+
postprocess: t.Optional[t.Callable[[t.Any], t.Any]] = None,
|
| 90 |
+
) -> t.Callable[[t.Any], t.List[t.Any]]:
|
| 91 |
+
"""Returns a callable that looks up the given comma separated
|
| 92 |
+
attributes from a passed object with the rules of the environment.
|
| 93 |
+
Dots are allowed to access attributes of each attribute. Integer
|
| 94 |
+
parts in paths are looked up as integers.
|
| 95 |
+
|
| 96 |
+
The value returned by the returned callable is a list of extracted
|
| 97 |
+
attribute values.
|
| 98 |
+
|
| 99 |
+
Examples of attribute: "attr1,attr2", "attr1.inner1.0,attr2.inner2.0", etc.
|
| 100 |
+
"""
|
| 101 |
+
if isinstance(attribute, str):
|
| 102 |
+
split: t.Sequence[t.Union[str, int, None]] = attribute.split(",")
|
| 103 |
+
else:
|
| 104 |
+
split = [attribute]
|
| 105 |
+
|
| 106 |
+
parts = [_prepare_attribute_parts(item) for item in split]
|
| 107 |
+
|
| 108 |
+
def attrgetter(item: t.Any) -> t.List[t.Any]:
|
| 109 |
+
items = [None] * len(parts)
|
| 110 |
+
|
| 111 |
+
for i, attribute_part in enumerate(parts):
|
| 112 |
+
item_i = item
|
| 113 |
+
|
| 114 |
+
for part in attribute_part:
|
| 115 |
+
item_i = environment.getitem(item_i, part)
|
| 116 |
+
|
| 117 |
+
if postprocess is not None:
|
| 118 |
+
item_i = postprocess(item_i)
|
| 119 |
+
|
| 120 |
+
items[i] = item_i
|
| 121 |
+
|
| 122 |
+
return items
|
| 123 |
+
|
| 124 |
+
return attrgetter
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _prepare_attribute_parts(
|
| 128 |
+
attr: t.Optional[t.Union[str, int]],
|
| 129 |
+
) -> t.List[t.Union[str, int]]:
|
| 130 |
+
if attr is None:
|
| 131 |
+
return []
|
| 132 |
+
|
| 133 |
+
if isinstance(attr, str):
|
| 134 |
+
return [int(x) if x.isdigit() else x for x in attr.split(".")]
|
| 135 |
+
|
| 136 |
+
return [attr]
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def do_forceescape(value: "t.Union[str, HasHTML]") -> Markup:
|
| 140 |
+
"""Enforce HTML escaping. This will probably double escape variables."""
|
| 141 |
+
if hasattr(value, "__html__"):
|
| 142 |
+
value = t.cast("HasHTML", value).__html__()
|
| 143 |
+
|
| 144 |
+
return escape(str(value))
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def do_urlencode(
|
| 148 |
+
value: t.Union[str, t.Mapping[str, t.Any], t.Iterable[t.Tuple[str, t.Any]]],
|
| 149 |
+
) -> str:
|
| 150 |
+
"""Quote data for use in a URL path or query using UTF-8.
|
| 151 |
+
|
| 152 |
+
Basic wrapper around :func:`urllib.parse.quote` when given a
|
| 153 |
+
string, or :func:`urllib.parse.urlencode` for a dict or iterable.
|
| 154 |
+
|
| 155 |
+
:param value: Data to quote. A string will be quoted directly. A
|
| 156 |
+
dict or iterable of ``(key, value)`` pairs will be joined as a
|
| 157 |
+
query string.
|
| 158 |
+
|
| 159 |
+
When given a string, "/" is not quoted. HTTP servers treat "/" and
|
| 160 |
+
"%2F" equivalently in paths. If you need quoted slashes, use the
|
| 161 |
+
``|replace("/", "%2F")`` filter.
|
| 162 |
+
|
| 163 |
+
.. versionadded:: 2.7
|
| 164 |
+
"""
|
| 165 |
+
if isinstance(value, str) or not isinstance(value, abc.Iterable):
|
| 166 |
+
return url_quote(value)
|
| 167 |
+
|
| 168 |
+
if isinstance(value, dict):
|
| 169 |
+
items: t.Iterable[t.Tuple[str, t.Any]] = value.items()
|
| 170 |
+
else:
|
| 171 |
+
items = value # type: ignore
|
| 172 |
+
|
| 173 |
+
return "&".join(
|
| 174 |
+
f"{url_quote(k, for_qs=True)}={url_quote(v, for_qs=True)}" for k, v in items
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
@pass_eval_context
|
| 179 |
+
def do_replace(
|
| 180 |
+
eval_ctx: "EvalContext", s: str, old: str, new: str, count: t.Optional[int] = None
|
| 181 |
+
) -> str:
|
| 182 |
+
"""Return a copy of the value with all occurrences of a substring
|
| 183 |
+
replaced with a new one. The first argument is the substring
|
| 184 |
+
that should be replaced, the second is the replacement string.
|
| 185 |
+
If the optional third argument ``count`` is given, only the first
|
| 186 |
+
``count`` occurrences are replaced:
|
| 187 |
+
|
| 188 |
+
.. sourcecode:: jinja
|
| 189 |
+
|
| 190 |
+
{{ "Hello World"|replace("Hello", "Goodbye") }}
|
| 191 |
+
-> Goodbye World
|
| 192 |
+
|
| 193 |
+
{{ "aaaaargh"|replace("a", "d'oh, ", 2) }}
|
| 194 |
+
-> d'oh, d'oh, aaargh
|
| 195 |
+
"""
|
| 196 |
+
if count is None:
|
| 197 |
+
count = -1
|
| 198 |
+
|
| 199 |
+
if not eval_ctx.autoescape:
|
| 200 |
+
return str(s).replace(str(old), str(new), count)
|
| 201 |
+
|
| 202 |
+
if (
|
| 203 |
+
hasattr(old, "__html__")
|
| 204 |
+
or hasattr(new, "__html__")
|
| 205 |
+
and not hasattr(s, "__html__")
|
| 206 |
+
):
|
| 207 |
+
s = escape(s)
|
| 208 |
+
else:
|
| 209 |
+
s = soft_str(s)
|
| 210 |
+
|
| 211 |
+
return s.replace(soft_str(old), soft_str(new), count)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def do_upper(s: str) -> str:
|
| 215 |
+
"""Convert a value to uppercase."""
|
| 216 |
+
return soft_str(s).upper()
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def do_lower(s: str) -> str:
|
| 220 |
+
"""Convert a value to lowercase."""
|
| 221 |
+
return soft_str(s).lower()
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def do_items(value: t.Union[t.Mapping[K, V], Undefined]) -> t.Iterator[t.Tuple[K, V]]:
|
| 225 |
+
"""Return an iterator over the ``(key, value)`` items of a mapping.
|
| 226 |
+
|
| 227 |
+
``x|items`` is the same as ``x.items()``, except if ``x`` is
|
| 228 |
+
undefined an empty iterator is returned.
|
| 229 |
+
|
| 230 |
+
This filter is useful if you expect the template to be rendered with
|
| 231 |
+
an implementation of Jinja in another programming language that does
|
| 232 |
+
not have a ``.items()`` method on its mapping type.
|
| 233 |
+
|
| 234 |
+
.. code-block:: html+jinja
|
| 235 |
+
|
| 236 |
+
<dl>
|
| 237 |
+
{% for key, value in my_dict|items %}
|
| 238 |
+
<dt>{{ key }}
|
| 239 |
+
<dd>{{ value }}
|
| 240 |
+
{% endfor %}
|
| 241 |
+
</dl>
|
| 242 |
+
|
| 243 |
+
.. versionadded:: 3.1
|
| 244 |
+
"""
|
| 245 |
+
if isinstance(value, Undefined):
|
| 246 |
+
return
|
| 247 |
+
|
| 248 |
+
if not isinstance(value, abc.Mapping):
|
| 249 |
+
raise TypeError("Can only get item pairs from a mapping.")
|
| 250 |
+
|
| 251 |
+
yield from value.items()
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
# Check for characters that would move the parser state from key to value.
|
| 255 |
+
# https://html.spec.whatwg.org/#attribute-name-state
|
| 256 |
+
_attr_key_re = re.compile(r"[\s/>=]", flags=re.ASCII)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
@pass_eval_context
|
| 260 |
+
def do_xmlattr(
|
| 261 |
+
eval_ctx: "EvalContext", d: t.Mapping[str, t.Any], autospace: bool = True
|
| 262 |
+
) -> str:
|
| 263 |
+
"""Create an SGML/XML attribute string based on the items in a dict.
|
| 264 |
+
|
| 265 |
+
**Values** that are neither ``none`` nor ``undefined`` are automatically
|
| 266 |
+
escaped, safely allowing untrusted user input.
|
| 267 |
+
|
| 268 |
+
User input should not be used as **keys** to this filter. If any key
|
| 269 |
+
contains a space, ``/`` solidus, ``>`` greater-than sign, or ``=`` equals
|
| 270 |
+
sign, this fails with a ``ValueError``. Regardless of this, user input
|
| 271 |
+
should never be used as keys to this filter, or must be separately validated
|
| 272 |
+
first.
|
| 273 |
+
|
| 274 |
+
.. sourcecode:: html+jinja
|
| 275 |
+
|
| 276 |
+
<ul{{ {'class': 'my_list', 'missing': none,
|
| 277 |
+
'id': 'list-%d'|format(variable)}|xmlattr }}>
|
| 278 |
+
...
|
| 279 |
+
</ul>
|
| 280 |
+
|
| 281 |
+
Results in something like this:
|
| 282 |
+
|
| 283 |
+
.. sourcecode:: html
|
| 284 |
+
|
| 285 |
+
<ul class="my_list" id="list-42">
|
| 286 |
+
...
|
| 287 |
+
</ul>
|
| 288 |
+
|
| 289 |
+
As you can see it automatically prepends a space in front of the item
|
| 290 |
+
if the filter returned something unless the second parameter is false.
|
| 291 |
+
|
| 292 |
+
.. versionchanged:: 3.1.4
|
| 293 |
+
Keys with ``/`` solidus, ``>`` greater-than sign, or ``=`` equals sign
|
| 294 |
+
are not allowed.
|
| 295 |
+
|
| 296 |
+
.. versionchanged:: 3.1.3
|
| 297 |
+
Keys with spaces are not allowed.
|
| 298 |
+
"""
|
| 299 |
+
items = []
|
| 300 |
+
|
| 301 |
+
for key, value in d.items():
|
| 302 |
+
if value is None or isinstance(value, Undefined):
|
| 303 |
+
continue
|
| 304 |
+
|
| 305 |
+
if _attr_key_re.search(key) is not None:
|
| 306 |
+
raise ValueError(f"Invalid character in attribute name: {key!r}")
|
| 307 |
+
|
| 308 |
+
items.append(f'{escape(key)}="{escape(value)}"')
|
| 309 |
+
|
| 310 |
+
rv = " ".join(items)
|
| 311 |
+
|
| 312 |
+
if autospace and rv:
|
| 313 |
+
rv = " " + rv
|
| 314 |
+
|
| 315 |
+
if eval_ctx.autoescape:
|
| 316 |
+
rv = Markup(rv)
|
| 317 |
+
|
| 318 |
+
return rv
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def do_capitalize(s: str) -> str:
|
| 322 |
+
"""Capitalize a value. The first character will be uppercase, all others
|
| 323 |
+
lowercase.
|
| 324 |
+
"""
|
| 325 |
+
return soft_str(s).capitalize()
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
_word_beginning_split_re = re.compile(r"([-\s({\[<]+)")
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def do_title(s: str) -> str:
|
| 332 |
+
"""Return a titlecased version of the value. I.e. words will start with
|
| 333 |
+
uppercase letters, all remaining characters are lowercase.
|
| 334 |
+
"""
|
| 335 |
+
return "".join(
|
| 336 |
+
[
|
| 337 |
+
item[0].upper() + item[1:].lower()
|
| 338 |
+
for item in _word_beginning_split_re.split(soft_str(s))
|
| 339 |
+
if item
|
| 340 |
+
]
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def do_dictsort(
|
| 345 |
+
value: t.Mapping[K, V],
|
| 346 |
+
case_sensitive: bool = False,
|
| 347 |
+
by: 'te.Literal["key", "value"]' = "key",
|
| 348 |
+
reverse: bool = False,
|
| 349 |
+
) -> t.List[t.Tuple[K, V]]:
|
| 350 |
+
"""Sort a dict and yield (key, value) pairs. Python dicts may not
|
| 351 |
+
be in the order you want to display them in, so sort them first.
|
| 352 |
+
|
| 353 |
+
.. sourcecode:: jinja
|
| 354 |
+
|
| 355 |
+
{% for key, value in mydict|dictsort %}
|
| 356 |
+
sort the dict by key, case insensitive
|
| 357 |
+
|
| 358 |
+
{% for key, value in mydict|dictsort(reverse=true) %}
|
| 359 |
+
sort the dict by key, case insensitive, reverse order
|
| 360 |
+
|
| 361 |
+
{% for key, value in mydict|dictsort(true) %}
|
| 362 |
+
sort the dict by key, case sensitive
|
| 363 |
+
|
| 364 |
+
{% for key, value in mydict|dictsort(false, 'value') %}
|
| 365 |
+
sort the dict by value, case insensitive
|
| 366 |
+
"""
|
| 367 |
+
if by == "key":
|
| 368 |
+
pos = 0
|
| 369 |
+
elif by == "value":
|
| 370 |
+
pos = 1
|
| 371 |
+
else:
|
| 372 |
+
raise FilterArgumentError('You can only sort by either "key" or "value"')
|
| 373 |
+
|
| 374 |
+
def sort_func(item: t.Tuple[t.Any, t.Any]) -> t.Any:
|
| 375 |
+
value = item[pos]
|
| 376 |
+
|
| 377 |
+
if not case_sensitive:
|
| 378 |
+
value = ignore_case(value)
|
| 379 |
+
|
| 380 |
+
return value
|
| 381 |
+
|
| 382 |
+
return sorted(value.items(), key=sort_func, reverse=reverse)
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
@pass_environment
|
| 386 |
+
def do_sort(
|
| 387 |
+
environment: "Environment",
|
| 388 |
+
value: "t.Iterable[V]",
|
| 389 |
+
reverse: bool = False,
|
| 390 |
+
case_sensitive: bool = False,
|
| 391 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 392 |
+
) -> "t.List[V]":
|
| 393 |
+
"""Sort an iterable using Python's :func:`sorted`.
|
| 394 |
+
|
| 395 |
+
.. sourcecode:: jinja
|
| 396 |
+
|
| 397 |
+
{% for city in cities|sort %}
|
| 398 |
+
...
|
| 399 |
+
{% endfor %}
|
| 400 |
+
|
| 401 |
+
:param reverse: Sort descending instead of ascending.
|
| 402 |
+
:param case_sensitive: When sorting strings, sort upper and lower
|
| 403 |
+
case separately.
|
| 404 |
+
:param attribute: When sorting objects or dicts, an attribute or
|
| 405 |
+
key to sort by. Can use dot notation like ``"address.city"``.
|
| 406 |
+
Can be a list of attributes like ``"age,name"``.
|
| 407 |
+
|
| 408 |
+
The sort is stable, it does not change the relative order of
|
| 409 |
+
elements that compare equal. This makes it is possible to chain
|
| 410 |
+
sorts on different attributes and ordering.
|
| 411 |
+
|
| 412 |
+
.. sourcecode:: jinja
|
| 413 |
+
|
| 414 |
+
{% for user in users|sort(attribute="name")
|
| 415 |
+
|sort(reverse=true, attribute="age") %}
|
| 416 |
+
...
|
| 417 |
+
{% endfor %}
|
| 418 |
+
|
| 419 |
+
As a shortcut to chaining when the direction is the same for all
|
| 420 |
+
attributes, pass a comma separate list of attributes.
|
| 421 |
+
|
| 422 |
+
.. sourcecode:: jinja
|
| 423 |
+
|
| 424 |
+
{% for user in users|sort(attribute="age,name") %}
|
| 425 |
+
...
|
| 426 |
+
{% endfor %}
|
| 427 |
+
|
| 428 |
+
.. versionchanged:: 2.11.0
|
| 429 |
+
The ``attribute`` parameter can be a comma separated list of
|
| 430 |
+
attributes, e.g. ``"age,name"``.
|
| 431 |
+
|
| 432 |
+
.. versionchanged:: 2.6
|
| 433 |
+
The ``attribute`` parameter was added.
|
| 434 |
+
"""
|
| 435 |
+
key_func = make_multi_attrgetter(
|
| 436 |
+
environment, attribute, postprocess=ignore_case if not case_sensitive else None
|
| 437 |
+
)
|
| 438 |
+
return sorted(value, key=key_func, reverse=reverse)
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
@pass_environment
|
| 442 |
+
def sync_do_unique(
|
| 443 |
+
environment: "Environment",
|
| 444 |
+
value: "t.Iterable[V]",
|
| 445 |
+
case_sensitive: bool = False,
|
| 446 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 447 |
+
) -> "t.Iterator[V]":
|
| 448 |
+
"""Returns a list of unique items from the given iterable.
|
| 449 |
+
|
| 450 |
+
.. sourcecode:: jinja
|
| 451 |
+
|
| 452 |
+
{{ ['foo', 'bar', 'foobar', 'FooBar']|unique|list }}
|
| 453 |
+
-> ['foo', 'bar', 'foobar']
|
| 454 |
+
|
| 455 |
+
The unique items are yielded in the same order as their first occurrence in
|
| 456 |
+
the iterable passed to the filter.
|
| 457 |
+
|
| 458 |
+
:param case_sensitive: Treat upper and lower case strings as distinct.
|
| 459 |
+
:param attribute: Filter objects with unique values for this attribute.
|
| 460 |
+
"""
|
| 461 |
+
getter = make_attrgetter(
|
| 462 |
+
environment, attribute, postprocess=ignore_case if not case_sensitive else None
|
| 463 |
+
)
|
| 464 |
+
seen = set()
|
| 465 |
+
|
| 466 |
+
for item in value:
|
| 467 |
+
key = getter(item)
|
| 468 |
+
|
| 469 |
+
if key not in seen:
|
| 470 |
+
seen.add(key)
|
| 471 |
+
yield item
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
@async_variant(sync_do_unique) # type: ignore
|
| 475 |
+
async def do_unique(
|
| 476 |
+
environment: "Environment",
|
| 477 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 478 |
+
case_sensitive: bool = False,
|
| 479 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 480 |
+
) -> "t.Iterator[V]":
|
| 481 |
+
return sync_do_unique(
|
| 482 |
+
environment, await auto_to_list(value), case_sensitive, attribute
|
| 483 |
+
)
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
def _min_or_max(
|
| 487 |
+
environment: "Environment",
|
| 488 |
+
value: "t.Iterable[V]",
|
| 489 |
+
func: "t.Callable[..., V]",
|
| 490 |
+
case_sensitive: bool,
|
| 491 |
+
attribute: t.Optional[t.Union[str, int]],
|
| 492 |
+
) -> "t.Union[V, Undefined]":
|
| 493 |
+
it = iter(value)
|
| 494 |
+
|
| 495 |
+
try:
|
| 496 |
+
first = next(it)
|
| 497 |
+
except StopIteration:
|
| 498 |
+
return environment.undefined("No aggregated item, sequence was empty.")
|
| 499 |
+
|
| 500 |
+
key_func = make_attrgetter(
|
| 501 |
+
environment, attribute, postprocess=ignore_case if not case_sensitive else None
|
| 502 |
+
)
|
| 503 |
+
return func(chain([first], it), key=key_func)
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
@pass_environment
|
| 507 |
+
def do_min(
|
| 508 |
+
environment: "Environment",
|
| 509 |
+
value: "t.Iterable[V]",
|
| 510 |
+
case_sensitive: bool = False,
|
| 511 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 512 |
+
) -> "t.Union[V, Undefined]":
|
| 513 |
+
"""Return the smallest item from the sequence.
|
| 514 |
+
|
| 515 |
+
.. sourcecode:: jinja
|
| 516 |
+
|
| 517 |
+
{{ [1, 2, 3]|min }}
|
| 518 |
+
-> 1
|
| 519 |
+
|
| 520 |
+
:param case_sensitive: Treat upper and lower case strings as distinct.
|
| 521 |
+
:param attribute: Get the object with the min value of this attribute.
|
| 522 |
+
"""
|
| 523 |
+
return _min_or_max(environment, value, min, case_sensitive, attribute)
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
@pass_environment
|
| 527 |
+
def do_max(
|
| 528 |
+
environment: "Environment",
|
| 529 |
+
value: "t.Iterable[V]",
|
| 530 |
+
case_sensitive: bool = False,
|
| 531 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 532 |
+
) -> "t.Union[V, Undefined]":
|
| 533 |
+
"""Return the largest item from the sequence.
|
| 534 |
+
|
| 535 |
+
.. sourcecode:: jinja
|
| 536 |
+
|
| 537 |
+
{{ [1, 2, 3]|max }}
|
| 538 |
+
-> 3
|
| 539 |
+
|
| 540 |
+
:param case_sensitive: Treat upper and lower case strings as distinct.
|
| 541 |
+
:param attribute: Get the object with the max value of this attribute.
|
| 542 |
+
"""
|
| 543 |
+
return _min_or_max(environment, value, max, case_sensitive, attribute)
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def do_default(
|
| 547 |
+
value: V,
|
| 548 |
+
default_value: V = "", # type: ignore
|
| 549 |
+
boolean: bool = False,
|
| 550 |
+
) -> V:
|
| 551 |
+
"""If the value is undefined it will return the passed default value,
|
| 552 |
+
otherwise the value of the variable:
|
| 553 |
+
|
| 554 |
+
.. sourcecode:: jinja
|
| 555 |
+
|
| 556 |
+
{{ my_variable|default('my_variable is not defined') }}
|
| 557 |
+
|
| 558 |
+
This will output the value of ``my_variable`` if the variable was
|
| 559 |
+
defined, otherwise ``'my_variable is not defined'``. If you want
|
| 560 |
+
to use default with variables that evaluate to false you have to
|
| 561 |
+
set the second parameter to `true`:
|
| 562 |
+
|
| 563 |
+
.. sourcecode:: jinja
|
| 564 |
+
|
| 565 |
+
{{ ''|default('the string was empty', true) }}
|
| 566 |
+
|
| 567 |
+
.. versionchanged:: 2.11
|
| 568 |
+
It's now possible to configure the :class:`~jinja2.Environment` with
|
| 569 |
+
:class:`~jinja2.ChainableUndefined` to make the `default` filter work
|
| 570 |
+
on nested elements and attributes that may contain undefined values
|
| 571 |
+
in the chain without getting an :exc:`~jinja2.UndefinedError`.
|
| 572 |
+
"""
|
| 573 |
+
if isinstance(value, Undefined) or (boolean and not value):
|
| 574 |
+
return default_value
|
| 575 |
+
|
| 576 |
+
return value
|
| 577 |
+
|
| 578 |
+
|
| 579 |
+
@pass_eval_context
|
| 580 |
+
def sync_do_join(
|
| 581 |
+
eval_ctx: "EvalContext",
|
| 582 |
+
value: t.Iterable[t.Any],
|
| 583 |
+
d: str = "",
|
| 584 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 585 |
+
) -> str:
|
| 586 |
+
"""Return a string which is the concatenation of the strings in the
|
| 587 |
+
sequence. The separator between elements is an empty string per
|
| 588 |
+
default, you can define it with the optional parameter:
|
| 589 |
+
|
| 590 |
+
.. sourcecode:: jinja
|
| 591 |
+
|
| 592 |
+
{{ [1, 2, 3]|join('|') }}
|
| 593 |
+
-> 1|2|3
|
| 594 |
+
|
| 595 |
+
{{ [1, 2, 3]|join }}
|
| 596 |
+
-> 123
|
| 597 |
+
|
| 598 |
+
It is also possible to join certain attributes of an object:
|
| 599 |
+
|
| 600 |
+
.. sourcecode:: jinja
|
| 601 |
+
|
| 602 |
+
{{ users|join(', ', attribute='username') }}
|
| 603 |
+
|
| 604 |
+
.. versionadded:: 2.6
|
| 605 |
+
The `attribute` parameter was added.
|
| 606 |
+
"""
|
| 607 |
+
if attribute is not None:
|
| 608 |
+
value = map(make_attrgetter(eval_ctx.environment, attribute), value)
|
| 609 |
+
|
| 610 |
+
# no automatic escaping? joining is a lot easier then
|
| 611 |
+
if not eval_ctx.autoescape:
|
| 612 |
+
return str(d).join(map(str, value))
|
| 613 |
+
|
| 614 |
+
# if the delimiter doesn't have an html representation we check
|
| 615 |
+
# if any of the items has. If yes we do a coercion to Markup
|
| 616 |
+
if not hasattr(d, "__html__"):
|
| 617 |
+
value = list(value)
|
| 618 |
+
do_escape = False
|
| 619 |
+
|
| 620 |
+
for idx, item in enumerate(value):
|
| 621 |
+
if hasattr(item, "__html__"):
|
| 622 |
+
do_escape = True
|
| 623 |
+
else:
|
| 624 |
+
value[idx] = str(item)
|
| 625 |
+
|
| 626 |
+
if do_escape:
|
| 627 |
+
d = escape(d)
|
| 628 |
+
else:
|
| 629 |
+
d = str(d)
|
| 630 |
+
|
| 631 |
+
return d.join(value)
|
| 632 |
+
|
| 633 |
+
# no html involved, to normal joining
|
| 634 |
+
return soft_str(d).join(map(soft_str, value))
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
@async_variant(sync_do_join) # type: ignore
|
| 638 |
+
async def do_join(
|
| 639 |
+
eval_ctx: "EvalContext",
|
| 640 |
+
value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],
|
| 641 |
+
d: str = "",
|
| 642 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 643 |
+
) -> str:
|
| 644 |
+
return sync_do_join(eval_ctx, await auto_to_list(value), d, attribute)
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
def do_center(value: str, width: int = 80) -> str:
|
| 648 |
+
"""Centers the value in a field of a given width."""
|
| 649 |
+
return soft_str(value).center(width)
|
| 650 |
+
|
| 651 |
+
|
| 652 |
+
@pass_environment
|
| 653 |
+
def sync_do_first(
|
| 654 |
+
environment: "Environment", seq: "t.Iterable[V]"
|
| 655 |
+
) -> "t.Union[V, Undefined]":
|
| 656 |
+
"""Return the first item of a sequence."""
|
| 657 |
+
try:
|
| 658 |
+
return next(iter(seq))
|
| 659 |
+
except StopIteration:
|
| 660 |
+
return environment.undefined("No first item, sequence was empty.")
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
@async_variant(sync_do_first) # type: ignore
|
| 664 |
+
async def do_first(
|
| 665 |
+
environment: "Environment", seq: "t.Union[t.AsyncIterable[V], t.Iterable[V]]"
|
| 666 |
+
) -> "t.Union[V, Undefined]":
|
| 667 |
+
try:
|
| 668 |
+
return await auto_aiter(seq).__anext__()
|
| 669 |
+
except StopAsyncIteration:
|
| 670 |
+
return environment.undefined("No first item, sequence was empty.")
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
@pass_environment
|
| 674 |
+
def do_last(
|
| 675 |
+
environment: "Environment", seq: "t.Reversible[V]"
|
| 676 |
+
) -> "t.Union[V, Undefined]":
|
| 677 |
+
"""Return the last item of a sequence.
|
| 678 |
+
|
| 679 |
+
Note: Does not work with generators. You may want to explicitly
|
| 680 |
+
convert it to a list:
|
| 681 |
+
|
| 682 |
+
.. sourcecode:: jinja
|
| 683 |
+
|
| 684 |
+
{{ data | selectattr('name', '==', 'Jinja') | list | last }}
|
| 685 |
+
"""
|
| 686 |
+
try:
|
| 687 |
+
return next(iter(reversed(seq)))
|
| 688 |
+
except StopIteration:
|
| 689 |
+
return environment.undefined("No last item, sequence was empty.")
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
# No async do_last, it may not be safe in async mode.
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
@pass_context
|
| 696 |
+
def do_random(context: "Context", seq: "t.Sequence[V]") -> "t.Union[V, Undefined]":
|
| 697 |
+
"""Return a random item from the sequence."""
|
| 698 |
+
try:
|
| 699 |
+
return random.choice(seq)
|
| 700 |
+
except IndexError:
|
| 701 |
+
return context.environment.undefined("No random item, sequence was empty.")
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
def do_filesizeformat(value: t.Union[str, float, int], binary: bool = False) -> str:
|
| 705 |
+
"""Format the value like a 'human-readable' file size (i.e. 13 kB,
|
| 706 |
+
4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega,
|
| 707 |
+
Giga, etc.), if the second parameter is set to `True` the binary
|
| 708 |
+
prefixes are used (Mebi, Gibi).
|
| 709 |
+
"""
|
| 710 |
+
bytes = float(value)
|
| 711 |
+
base = 1024 if binary else 1000
|
| 712 |
+
prefixes = [
|
| 713 |
+
("KiB" if binary else "kB"),
|
| 714 |
+
("MiB" if binary else "MB"),
|
| 715 |
+
("GiB" if binary else "GB"),
|
| 716 |
+
("TiB" if binary else "TB"),
|
| 717 |
+
("PiB" if binary else "PB"),
|
| 718 |
+
("EiB" if binary else "EB"),
|
| 719 |
+
("ZiB" if binary else "ZB"),
|
| 720 |
+
("YiB" if binary else "YB"),
|
| 721 |
+
]
|
| 722 |
+
|
| 723 |
+
if bytes == 1:
|
| 724 |
+
return "1 Byte"
|
| 725 |
+
elif bytes < base:
|
| 726 |
+
return f"{int(bytes)} Bytes"
|
| 727 |
+
else:
|
| 728 |
+
for i, prefix in enumerate(prefixes):
|
| 729 |
+
unit = base ** (i + 2)
|
| 730 |
+
|
| 731 |
+
if bytes < unit:
|
| 732 |
+
return f"{base * bytes / unit:.1f} {prefix}"
|
| 733 |
+
|
| 734 |
+
return f"{base * bytes / unit:.1f} {prefix}"
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
def do_pprint(value: t.Any) -> str:
|
| 738 |
+
"""Pretty print a variable. Useful for debugging."""
|
| 739 |
+
return pformat(value)
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
_uri_scheme_re = re.compile(r"^([\w.+-]{2,}:(/){0,2})$")
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
@pass_eval_context
|
| 746 |
+
def do_urlize(
|
| 747 |
+
eval_ctx: "EvalContext",
|
| 748 |
+
value: str,
|
| 749 |
+
trim_url_limit: t.Optional[int] = None,
|
| 750 |
+
nofollow: bool = False,
|
| 751 |
+
target: t.Optional[str] = None,
|
| 752 |
+
rel: t.Optional[str] = None,
|
| 753 |
+
extra_schemes: t.Optional[t.Iterable[str]] = None,
|
| 754 |
+
) -> str:
|
| 755 |
+
"""Convert URLs in text into clickable links.
|
| 756 |
+
|
| 757 |
+
This may not recognize links in some situations. Usually, a more
|
| 758 |
+
comprehensive formatter, such as a Markdown library, is a better
|
| 759 |
+
choice.
|
| 760 |
+
|
| 761 |
+
Works on ``http://``, ``https://``, ``www.``, ``mailto:``, and email
|
| 762 |
+
addresses. Links with trailing punctuation (periods, commas, closing
|
| 763 |
+
parentheses) and leading punctuation (opening parentheses) are
|
| 764 |
+
recognized excluding the punctuation. Email addresses that include
|
| 765 |
+
header fields are not recognized (for example,
|
| 766 |
+
``mailto:address@example.com?cc=copy@example.com``).
|
| 767 |
+
|
| 768 |
+
:param value: Original text containing URLs to link.
|
| 769 |
+
:param trim_url_limit: Shorten displayed URL values to this length.
|
| 770 |
+
:param nofollow: Add the ``rel=nofollow`` attribute to links.
|
| 771 |
+
:param target: Add the ``target`` attribute to links.
|
| 772 |
+
:param rel: Add the ``rel`` attribute to links.
|
| 773 |
+
:param extra_schemes: Recognize URLs that start with these schemes
|
| 774 |
+
in addition to the default behavior. Defaults to
|
| 775 |
+
``env.policies["urlize.extra_schemes"]``, which defaults to no
|
| 776 |
+
extra schemes.
|
| 777 |
+
|
| 778 |
+
.. versionchanged:: 3.0
|
| 779 |
+
The ``extra_schemes`` parameter was added.
|
| 780 |
+
|
| 781 |
+
.. versionchanged:: 3.0
|
| 782 |
+
Generate ``https://`` links for URLs without a scheme.
|
| 783 |
+
|
| 784 |
+
.. versionchanged:: 3.0
|
| 785 |
+
The parsing rules were updated. Recognize email addresses with
|
| 786 |
+
or without the ``mailto:`` scheme. Validate IP addresses. Ignore
|
| 787 |
+
parentheses and brackets in more cases.
|
| 788 |
+
|
| 789 |
+
.. versionchanged:: 2.8
|
| 790 |
+
The ``target`` parameter was added.
|
| 791 |
+
"""
|
| 792 |
+
policies = eval_ctx.environment.policies
|
| 793 |
+
rel_parts = set((rel or "").split())
|
| 794 |
+
|
| 795 |
+
if nofollow:
|
| 796 |
+
rel_parts.add("nofollow")
|
| 797 |
+
|
| 798 |
+
rel_parts.update((policies["urlize.rel"] or "").split())
|
| 799 |
+
rel = " ".join(sorted(rel_parts)) or None
|
| 800 |
+
|
| 801 |
+
if target is None:
|
| 802 |
+
target = policies["urlize.target"]
|
| 803 |
+
|
| 804 |
+
if extra_schemes is None:
|
| 805 |
+
extra_schemes = policies["urlize.extra_schemes"] or ()
|
| 806 |
+
|
| 807 |
+
for scheme in extra_schemes:
|
| 808 |
+
if _uri_scheme_re.fullmatch(scheme) is None:
|
| 809 |
+
raise FilterArgumentError(f"{scheme!r} is not a valid URI scheme prefix.")
|
| 810 |
+
|
| 811 |
+
rv = urlize(
|
| 812 |
+
value,
|
| 813 |
+
trim_url_limit=trim_url_limit,
|
| 814 |
+
rel=rel,
|
| 815 |
+
target=target,
|
| 816 |
+
extra_schemes=extra_schemes,
|
| 817 |
+
)
|
| 818 |
+
|
| 819 |
+
if eval_ctx.autoescape:
|
| 820 |
+
rv = Markup(rv)
|
| 821 |
+
|
| 822 |
+
return rv
|
| 823 |
+
|
| 824 |
+
|
| 825 |
+
def do_indent(
|
| 826 |
+
s: str, width: t.Union[int, str] = 4, first: bool = False, blank: bool = False
|
| 827 |
+
) -> str:
|
| 828 |
+
"""Return a copy of the string with each line indented by 4 spaces. The
|
| 829 |
+
first line and blank lines are not indented by default.
|
| 830 |
+
|
| 831 |
+
:param width: Number of spaces, or a string, to indent by.
|
| 832 |
+
:param first: Don't skip indenting the first line.
|
| 833 |
+
:param blank: Don't skip indenting empty lines.
|
| 834 |
+
|
| 835 |
+
.. versionchanged:: 3.0
|
| 836 |
+
``width`` can be a string.
|
| 837 |
+
|
| 838 |
+
.. versionchanged:: 2.10
|
| 839 |
+
Blank lines are not indented by default.
|
| 840 |
+
|
| 841 |
+
Rename the ``indentfirst`` argument to ``first``.
|
| 842 |
+
"""
|
| 843 |
+
if isinstance(width, str):
|
| 844 |
+
indention = width
|
| 845 |
+
else:
|
| 846 |
+
indention = " " * width
|
| 847 |
+
|
| 848 |
+
newline = "\n"
|
| 849 |
+
|
| 850 |
+
if isinstance(s, Markup):
|
| 851 |
+
indention = Markup(indention)
|
| 852 |
+
newline = Markup(newline)
|
| 853 |
+
|
| 854 |
+
s += newline # this quirk is necessary for splitlines method
|
| 855 |
+
|
| 856 |
+
if blank:
|
| 857 |
+
rv = (newline + indention).join(s.splitlines())
|
| 858 |
+
else:
|
| 859 |
+
lines = s.splitlines()
|
| 860 |
+
rv = lines.pop(0)
|
| 861 |
+
|
| 862 |
+
if lines:
|
| 863 |
+
rv += newline + newline.join(
|
| 864 |
+
indention + line if line else line for line in lines
|
| 865 |
+
)
|
| 866 |
+
|
| 867 |
+
if first:
|
| 868 |
+
rv = indention + rv
|
| 869 |
+
|
| 870 |
+
return rv
|
| 871 |
+
|
| 872 |
+
|
| 873 |
+
@pass_environment
|
| 874 |
+
def do_truncate(
|
| 875 |
+
env: "Environment",
|
| 876 |
+
s: str,
|
| 877 |
+
length: int = 255,
|
| 878 |
+
killwords: bool = False,
|
| 879 |
+
end: str = "...",
|
| 880 |
+
leeway: t.Optional[int] = None,
|
| 881 |
+
) -> str:
|
| 882 |
+
"""Return a truncated copy of the string. The length is specified
|
| 883 |
+
with the first parameter which defaults to ``255``. If the second
|
| 884 |
+
parameter is ``true`` the filter will cut the text at length. Otherwise
|
| 885 |
+
it will discard the last word. If the text was in fact
|
| 886 |
+
truncated it will append an ellipsis sign (``"..."``). If you want a
|
| 887 |
+
different ellipsis sign than ``"..."`` you can specify it using the
|
| 888 |
+
third parameter. Strings that only exceed the length by the tolerance
|
| 889 |
+
margin given in the fourth parameter will not be truncated.
|
| 890 |
+
|
| 891 |
+
.. sourcecode:: jinja
|
| 892 |
+
|
| 893 |
+
{{ "foo bar baz qux"|truncate(9) }}
|
| 894 |
+
-> "foo..."
|
| 895 |
+
{{ "foo bar baz qux"|truncate(9, True) }}
|
| 896 |
+
-> "foo ba..."
|
| 897 |
+
{{ "foo bar baz qux"|truncate(11) }}
|
| 898 |
+
-> "foo bar baz qux"
|
| 899 |
+
{{ "foo bar baz qux"|truncate(11, False, '...', 0) }}
|
| 900 |
+
-> "foo bar..."
|
| 901 |
+
|
| 902 |
+
The default leeway on newer Jinja versions is 5 and was 0 before but
|
| 903 |
+
can be reconfigured globally.
|
| 904 |
+
"""
|
| 905 |
+
if leeway is None:
|
| 906 |
+
leeway = env.policies["truncate.leeway"]
|
| 907 |
+
|
| 908 |
+
assert length >= len(end), f"expected length >= {len(end)}, got {length}"
|
| 909 |
+
assert leeway >= 0, f"expected leeway >= 0, got {leeway}"
|
| 910 |
+
|
| 911 |
+
if len(s) <= length + leeway:
|
| 912 |
+
return s
|
| 913 |
+
|
| 914 |
+
if killwords:
|
| 915 |
+
return s[: length - len(end)] + end
|
| 916 |
+
|
| 917 |
+
result = s[: length - len(end)].rsplit(" ", 1)[0]
|
| 918 |
+
return result + end
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
@pass_environment
|
| 922 |
+
def do_wordwrap(
|
| 923 |
+
environment: "Environment",
|
| 924 |
+
s: str,
|
| 925 |
+
width: int = 79,
|
| 926 |
+
break_long_words: bool = True,
|
| 927 |
+
wrapstring: t.Optional[str] = None,
|
| 928 |
+
break_on_hyphens: bool = True,
|
| 929 |
+
) -> str:
|
| 930 |
+
"""Wrap a string to the given width. Existing newlines are treated
|
| 931 |
+
as paragraphs to be wrapped separately.
|
| 932 |
+
|
| 933 |
+
:param s: Original text to wrap.
|
| 934 |
+
:param width: Maximum length of wrapped lines.
|
| 935 |
+
:param break_long_words: If a word is longer than ``width``, break
|
| 936 |
+
it across lines.
|
| 937 |
+
:param break_on_hyphens: If a word contains hyphens, it may be split
|
| 938 |
+
across lines.
|
| 939 |
+
:param wrapstring: String to join each wrapped line. Defaults to
|
| 940 |
+
:attr:`Environment.newline_sequence`.
|
| 941 |
+
|
| 942 |
+
.. versionchanged:: 2.11
|
| 943 |
+
Existing newlines are treated as paragraphs wrapped separately.
|
| 944 |
+
|
| 945 |
+
.. versionchanged:: 2.11
|
| 946 |
+
Added the ``break_on_hyphens`` parameter.
|
| 947 |
+
|
| 948 |
+
.. versionchanged:: 2.7
|
| 949 |
+
Added the ``wrapstring`` parameter.
|
| 950 |
+
"""
|
| 951 |
+
import textwrap
|
| 952 |
+
|
| 953 |
+
if wrapstring is None:
|
| 954 |
+
wrapstring = environment.newline_sequence
|
| 955 |
+
|
| 956 |
+
# textwrap.wrap doesn't consider existing newlines when wrapping.
|
| 957 |
+
# If the string has a newline before width, wrap will still insert
|
| 958 |
+
# a newline at width, resulting in a short line. Instead, split and
|
| 959 |
+
# wrap each paragraph individually.
|
| 960 |
+
return wrapstring.join(
|
| 961 |
+
[
|
| 962 |
+
wrapstring.join(
|
| 963 |
+
textwrap.wrap(
|
| 964 |
+
line,
|
| 965 |
+
width=width,
|
| 966 |
+
expand_tabs=False,
|
| 967 |
+
replace_whitespace=False,
|
| 968 |
+
break_long_words=break_long_words,
|
| 969 |
+
break_on_hyphens=break_on_hyphens,
|
| 970 |
+
)
|
| 971 |
+
)
|
| 972 |
+
for line in s.splitlines()
|
| 973 |
+
]
|
| 974 |
+
)
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
_word_re = re.compile(r"\w+")
|
| 978 |
+
|
| 979 |
+
|
| 980 |
+
def do_wordcount(s: str) -> int:
|
| 981 |
+
"""Count the words in that string."""
|
| 982 |
+
return len(_word_re.findall(soft_str(s)))
|
| 983 |
+
|
| 984 |
+
|
| 985 |
+
def do_int(value: t.Any, default: int = 0, base: int = 10) -> int:
|
| 986 |
+
"""Convert the value into an integer. If the
|
| 987 |
+
conversion doesn't work it will return ``0``. You can
|
| 988 |
+
override this default using the first parameter. You
|
| 989 |
+
can also override the default base (10) in the second
|
| 990 |
+
parameter, which handles input with prefixes such as
|
| 991 |
+
0b, 0o and 0x for bases 2, 8 and 16 respectively.
|
| 992 |
+
The base is ignored for decimal numbers and non-string values.
|
| 993 |
+
"""
|
| 994 |
+
try:
|
| 995 |
+
if isinstance(value, str):
|
| 996 |
+
return int(value, base)
|
| 997 |
+
|
| 998 |
+
return int(value)
|
| 999 |
+
except (TypeError, ValueError):
|
| 1000 |
+
# this quirk is necessary so that "42.23"|int gives 42.
|
| 1001 |
+
try:
|
| 1002 |
+
return int(float(value))
|
| 1003 |
+
except (TypeError, ValueError, OverflowError):
|
| 1004 |
+
return default
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
def do_float(value: t.Any, default: float = 0.0) -> float:
|
| 1008 |
+
"""Convert the value into a floating point number. If the
|
| 1009 |
+
conversion doesn't work it will return ``0.0``. You can
|
| 1010 |
+
override this default using the first parameter.
|
| 1011 |
+
"""
|
| 1012 |
+
try:
|
| 1013 |
+
return float(value)
|
| 1014 |
+
except (TypeError, ValueError):
|
| 1015 |
+
return default
|
| 1016 |
+
|
| 1017 |
+
|
| 1018 |
+
def do_format(value: str, *args: t.Any, **kwargs: t.Any) -> str:
|
| 1019 |
+
"""Apply the given values to a `printf-style`_ format string, like
|
| 1020 |
+
``string % values``.
|
| 1021 |
+
|
| 1022 |
+
.. sourcecode:: jinja
|
| 1023 |
+
|
| 1024 |
+
{{ "%s, %s!"|format(greeting, name) }}
|
| 1025 |
+
Hello, World!
|
| 1026 |
+
|
| 1027 |
+
In most cases it should be more convenient and efficient to use the
|
| 1028 |
+
``%`` operator or :meth:`str.format`.
|
| 1029 |
+
|
| 1030 |
+
.. code-block:: text
|
| 1031 |
+
|
| 1032 |
+
{{ "%s, %s!" % (greeting, name) }}
|
| 1033 |
+
{{ "{}, {}!".format(greeting, name) }}
|
| 1034 |
+
|
| 1035 |
+
.. _printf-style: https://docs.python.org/library/stdtypes.html
|
| 1036 |
+
#printf-style-string-formatting
|
| 1037 |
+
"""
|
| 1038 |
+
if args and kwargs:
|
| 1039 |
+
raise FilterArgumentError(
|
| 1040 |
+
"can't handle positional and keyword arguments at the same time"
|
| 1041 |
+
)
|
| 1042 |
+
|
| 1043 |
+
return soft_str(value) % (kwargs or args)
|
| 1044 |
+
|
| 1045 |
+
|
| 1046 |
+
def do_trim(value: str, chars: t.Optional[str] = None) -> str:
|
| 1047 |
+
"""Strip leading and trailing characters, by default whitespace."""
|
| 1048 |
+
return soft_str(value).strip(chars)
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
def do_striptags(value: "t.Union[str, HasHTML]") -> str:
|
| 1052 |
+
"""Strip SGML/XML tags and replace adjacent whitespace by one space."""
|
| 1053 |
+
if hasattr(value, "__html__"):
|
| 1054 |
+
value = t.cast("HasHTML", value).__html__()
|
| 1055 |
+
|
| 1056 |
+
return Markup(str(value)).striptags()
|
| 1057 |
+
|
| 1058 |
+
|
| 1059 |
+
def sync_do_slice(
|
| 1060 |
+
value: "t.Collection[V]", slices: int, fill_with: "t.Optional[V]" = None
|
| 1061 |
+
) -> "t.Iterator[t.List[V]]":
|
| 1062 |
+
"""Slice an iterator and return a list of lists containing
|
| 1063 |
+
those items. Useful if you want to create a div containing
|
| 1064 |
+
three ul tags that represent columns:
|
| 1065 |
+
|
| 1066 |
+
.. sourcecode:: html+jinja
|
| 1067 |
+
|
| 1068 |
+
<div class="columnwrapper">
|
| 1069 |
+
{%- for column in items|slice(3) %}
|
| 1070 |
+
<ul class="column-{{ loop.index }}">
|
| 1071 |
+
{%- for item in column %}
|
| 1072 |
+
<li>{{ item }}</li>
|
| 1073 |
+
{%- endfor %}
|
| 1074 |
+
</ul>
|
| 1075 |
+
{%- endfor %}
|
| 1076 |
+
</div>
|
| 1077 |
+
|
| 1078 |
+
If you pass it a second argument it's used to fill missing
|
| 1079 |
+
values on the last iteration.
|
| 1080 |
+
"""
|
| 1081 |
+
seq = list(value)
|
| 1082 |
+
length = len(seq)
|
| 1083 |
+
items_per_slice = length // slices
|
| 1084 |
+
slices_with_extra = length % slices
|
| 1085 |
+
offset = 0
|
| 1086 |
+
|
| 1087 |
+
for slice_number in range(slices):
|
| 1088 |
+
start = offset + slice_number * items_per_slice
|
| 1089 |
+
|
| 1090 |
+
if slice_number < slices_with_extra:
|
| 1091 |
+
offset += 1
|
| 1092 |
+
|
| 1093 |
+
end = offset + (slice_number + 1) * items_per_slice
|
| 1094 |
+
tmp = seq[start:end]
|
| 1095 |
+
|
| 1096 |
+
if fill_with is not None and slice_number >= slices_with_extra:
|
| 1097 |
+
tmp.append(fill_with)
|
| 1098 |
+
|
| 1099 |
+
yield tmp
|
| 1100 |
+
|
| 1101 |
+
|
| 1102 |
+
@async_variant(sync_do_slice) # type: ignore
|
| 1103 |
+
async def do_slice(
|
| 1104 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1105 |
+
slices: int,
|
| 1106 |
+
fill_with: t.Optional[t.Any] = None,
|
| 1107 |
+
) -> "t.Iterator[t.List[V]]":
|
| 1108 |
+
return sync_do_slice(await auto_to_list(value), slices, fill_with)
|
| 1109 |
+
|
| 1110 |
+
|
| 1111 |
+
def do_batch(
|
| 1112 |
+
value: "t.Iterable[V]", linecount: int, fill_with: "t.Optional[V]" = None
|
| 1113 |
+
) -> "t.Iterator[t.List[V]]":
|
| 1114 |
+
"""
|
| 1115 |
+
A filter that batches items. It works pretty much like `slice`
|
| 1116 |
+
just the other way round. It returns a list of lists with the
|
| 1117 |
+
given number of items. If you provide a second parameter this
|
| 1118 |
+
is used to fill up missing items. See this example:
|
| 1119 |
+
|
| 1120 |
+
.. sourcecode:: html+jinja
|
| 1121 |
+
|
| 1122 |
+
<table>
|
| 1123 |
+
{%- for row in items|batch(3, ' ') %}
|
| 1124 |
+
<tr>
|
| 1125 |
+
{%- for column in row %}
|
| 1126 |
+
<td>{{ column }}</td>
|
| 1127 |
+
{%- endfor %}
|
| 1128 |
+
</tr>
|
| 1129 |
+
{%- endfor %}
|
| 1130 |
+
</table>
|
| 1131 |
+
"""
|
| 1132 |
+
tmp: t.List[V] = []
|
| 1133 |
+
|
| 1134 |
+
for item in value:
|
| 1135 |
+
if len(tmp) == linecount:
|
| 1136 |
+
yield tmp
|
| 1137 |
+
tmp = []
|
| 1138 |
+
|
| 1139 |
+
tmp.append(item)
|
| 1140 |
+
|
| 1141 |
+
if tmp:
|
| 1142 |
+
if fill_with is not None and len(tmp) < linecount:
|
| 1143 |
+
tmp += [fill_with] * (linecount - len(tmp))
|
| 1144 |
+
|
| 1145 |
+
yield tmp
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
def do_round(
|
| 1149 |
+
value: float,
|
| 1150 |
+
precision: int = 0,
|
| 1151 |
+
method: 'te.Literal["common", "ceil", "floor"]' = "common",
|
| 1152 |
+
) -> float:
|
| 1153 |
+
"""Round the number to a given precision. The first
|
| 1154 |
+
parameter specifies the precision (default is ``0``), the
|
| 1155 |
+
second the rounding method:
|
| 1156 |
+
|
| 1157 |
+
- ``'common'`` rounds either up or down
|
| 1158 |
+
- ``'ceil'`` always rounds up
|
| 1159 |
+
- ``'floor'`` always rounds down
|
| 1160 |
+
|
| 1161 |
+
If you don't specify a method ``'common'`` is used.
|
| 1162 |
+
|
| 1163 |
+
.. sourcecode:: jinja
|
| 1164 |
+
|
| 1165 |
+
{{ 42.55|round }}
|
| 1166 |
+
-> 43.0
|
| 1167 |
+
{{ 42.55|round(1, 'floor') }}
|
| 1168 |
+
-> 42.5
|
| 1169 |
+
|
| 1170 |
+
Note that even if rounded to 0 precision, a float is returned. If
|
| 1171 |
+
you need a real integer, pipe it through `int`:
|
| 1172 |
+
|
| 1173 |
+
.. sourcecode:: jinja
|
| 1174 |
+
|
| 1175 |
+
{{ 42.55|round|int }}
|
| 1176 |
+
-> 43
|
| 1177 |
+
"""
|
| 1178 |
+
if method not in {"common", "ceil", "floor"}:
|
| 1179 |
+
raise FilterArgumentError("method must be common, ceil or floor")
|
| 1180 |
+
|
| 1181 |
+
if method == "common":
|
| 1182 |
+
return round(value, precision)
|
| 1183 |
+
|
| 1184 |
+
func = getattr(math, method)
|
| 1185 |
+
return t.cast(float, func(value * (10**precision)) / (10**precision))
|
| 1186 |
+
|
| 1187 |
+
|
| 1188 |
+
class _GroupTuple(t.NamedTuple):
|
| 1189 |
+
grouper: t.Any
|
| 1190 |
+
list: t.List[t.Any]
|
| 1191 |
+
|
| 1192 |
+
# Use the regular tuple repr to hide this subclass if users print
|
| 1193 |
+
# out the value during debugging.
|
| 1194 |
+
def __repr__(self) -> str:
|
| 1195 |
+
return tuple.__repr__(self)
|
| 1196 |
+
|
| 1197 |
+
def __str__(self) -> str:
|
| 1198 |
+
return tuple.__str__(self)
|
| 1199 |
+
|
| 1200 |
+
|
| 1201 |
+
@pass_environment
|
| 1202 |
+
def sync_do_groupby(
|
| 1203 |
+
environment: "Environment",
|
| 1204 |
+
value: "t.Iterable[V]",
|
| 1205 |
+
attribute: t.Union[str, int],
|
| 1206 |
+
default: t.Optional[t.Any] = None,
|
| 1207 |
+
case_sensitive: bool = False,
|
| 1208 |
+
) -> "t.List[_GroupTuple]":
|
| 1209 |
+
"""Group a sequence of objects by an attribute using Python's
|
| 1210 |
+
:func:`itertools.groupby`. The attribute can use dot notation for
|
| 1211 |
+
nested access, like ``"address.city"``. Unlike Python's ``groupby``,
|
| 1212 |
+
the values are sorted first so only one group is returned for each
|
| 1213 |
+
unique value.
|
| 1214 |
+
|
| 1215 |
+
For example, a list of ``User`` objects with a ``city`` attribute
|
| 1216 |
+
can be rendered in groups. In this example, ``grouper`` refers to
|
| 1217 |
+
the ``city`` value of the group.
|
| 1218 |
+
|
| 1219 |
+
.. sourcecode:: html+jinja
|
| 1220 |
+
|
| 1221 |
+
<ul>{% for city, items in users|groupby("city") %}
|
| 1222 |
+
<li>{{ city }}
|
| 1223 |
+
<ul>{% for user in items %}
|
| 1224 |
+
<li>{{ user.name }}
|
| 1225 |
+
{% endfor %}</ul>
|
| 1226 |
+
</li>
|
| 1227 |
+
{% endfor %}</ul>
|
| 1228 |
+
|
| 1229 |
+
``groupby`` yields namedtuples of ``(grouper, list)``, which
|
| 1230 |
+
can be used instead of the tuple unpacking above. ``grouper`` is the
|
| 1231 |
+
value of the attribute, and ``list`` is the items with that value.
|
| 1232 |
+
|
| 1233 |
+
.. sourcecode:: html+jinja
|
| 1234 |
+
|
| 1235 |
+
<ul>{% for group in users|groupby("city") %}
|
| 1236 |
+
<li>{{ group.grouper }}: {{ group.list|join(", ") }}
|
| 1237 |
+
{% endfor %}</ul>
|
| 1238 |
+
|
| 1239 |
+
You can specify a ``default`` value to use if an object in the list
|
| 1240 |
+
does not have the given attribute.
|
| 1241 |
+
|
| 1242 |
+
.. sourcecode:: jinja
|
| 1243 |
+
|
| 1244 |
+
<ul>{% for city, items in users|groupby("city", default="NY") %}
|
| 1245 |
+
<li>{{ city }}: {{ items|map(attribute="name")|join(", ") }}</li>
|
| 1246 |
+
{% endfor %}</ul>
|
| 1247 |
+
|
| 1248 |
+
Like the :func:`~jinja-filters.sort` filter, sorting and grouping is
|
| 1249 |
+
case-insensitive by default. The ``key`` for each group will have
|
| 1250 |
+
the case of the first item in that group of values. For example, if
|
| 1251 |
+
a list of users has cities ``["CA", "NY", "ca"]``, the "CA" group
|
| 1252 |
+
will have two values. This can be disabled by passing
|
| 1253 |
+
``case_sensitive=True``.
|
| 1254 |
+
|
| 1255 |
+
.. versionchanged:: 3.1
|
| 1256 |
+
Added the ``case_sensitive`` parameter. Sorting and grouping is
|
| 1257 |
+
case-insensitive by default, matching other filters that do
|
| 1258 |
+
comparisons.
|
| 1259 |
+
|
| 1260 |
+
.. versionchanged:: 3.0
|
| 1261 |
+
Added the ``default`` parameter.
|
| 1262 |
+
|
| 1263 |
+
.. versionchanged:: 2.6
|
| 1264 |
+
The attribute supports dot notation for nested access.
|
| 1265 |
+
"""
|
| 1266 |
+
expr = make_attrgetter(
|
| 1267 |
+
environment,
|
| 1268 |
+
attribute,
|
| 1269 |
+
postprocess=ignore_case if not case_sensitive else None,
|
| 1270 |
+
default=default,
|
| 1271 |
+
)
|
| 1272 |
+
out = [
|
| 1273 |
+
_GroupTuple(key, list(values))
|
| 1274 |
+
for key, values in groupby(sorted(value, key=expr), expr)
|
| 1275 |
+
]
|
| 1276 |
+
|
| 1277 |
+
if not case_sensitive:
|
| 1278 |
+
# Return the real key from the first value instead of the lowercase key.
|
| 1279 |
+
output_expr = make_attrgetter(environment, attribute, default=default)
|
| 1280 |
+
out = [_GroupTuple(output_expr(values[0]), values) for _, values in out]
|
| 1281 |
+
|
| 1282 |
+
return out
|
| 1283 |
+
|
| 1284 |
+
|
| 1285 |
+
@async_variant(sync_do_groupby) # type: ignore
|
| 1286 |
+
async def do_groupby(
|
| 1287 |
+
environment: "Environment",
|
| 1288 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1289 |
+
attribute: t.Union[str, int],
|
| 1290 |
+
default: t.Optional[t.Any] = None,
|
| 1291 |
+
case_sensitive: bool = False,
|
| 1292 |
+
) -> "t.List[_GroupTuple]":
|
| 1293 |
+
expr = make_attrgetter(
|
| 1294 |
+
environment,
|
| 1295 |
+
attribute,
|
| 1296 |
+
postprocess=ignore_case if not case_sensitive else None,
|
| 1297 |
+
default=default,
|
| 1298 |
+
)
|
| 1299 |
+
out = [
|
| 1300 |
+
_GroupTuple(key, await auto_to_list(values))
|
| 1301 |
+
for key, values in groupby(sorted(await auto_to_list(value), key=expr), expr)
|
| 1302 |
+
]
|
| 1303 |
+
|
| 1304 |
+
if not case_sensitive:
|
| 1305 |
+
# Return the real key from the first value instead of the lowercase key.
|
| 1306 |
+
output_expr = make_attrgetter(environment, attribute, default=default)
|
| 1307 |
+
out = [_GroupTuple(output_expr(values[0]), values) for _, values in out]
|
| 1308 |
+
|
| 1309 |
+
return out
|
| 1310 |
+
|
| 1311 |
+
|
| 1312 |
+
@pass_environment
|
| 1313 |
+
def sync_do_sum(
|
| 1314 |
+
environment: "Environment",
|
| 1315 |
+
iterable: "t.Iterable[V]",
|
| 1316 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 1317 |
+
start: V = 0, # type: ignore
|
| 1318 |
+
) -> V:
|
| 1319 |
+
"""Returns the sum of a sequence of numbers plus the value of parameter
|
| 1320 |
+
'start' (which defaults to 0). When the sequence is empty it returns
|
| 1321 |
+
start.
|
| 1322 |
+
|
| 1323 |
+
It is also possible to sum up only certain attributes:
|
| 1324 |
+
|
| 1325 |
+
.. sourcecode:: jinja
|
| 1326 |
+
|
| 1327 |
+
Total: {{ items|sum(attribute='price') }}
|
| 1328 |
+
|
| 1329 |
+
.. versionchanged:: 2.6
|
| 1330 |
+
The ``attribute`` parameter was added to allow summing up over
|
| 1331 |
+
attributes. Also the ``start`` parameter was moved on to the right.
|
| 1332 |
+
"""
|
| 1333 |
+
if attribute is not None:
|
| 1334 |
+
iterable = map(make_attrgetter(environment, attribute), iterable)
|
| 1335 |
+
|
| 1336 |
+
return sum(iterable, start) # type: ignore[no-any-return, call-overload]
|
| 1337 |
+
|
| 1338 |
+
|
| 1339 |
+
@async_variant(sync_do_sum) # type: ignore
|
| 1340 |
+
async def do_sum(
|
| 1341 |
+
environment: "Environment",
|
| 1342 |
+
iterable: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1343 |
+
attribute: t.Optional[t.Union[str, int]] = None,
|
| 1344 |
+
start: V = 0, # type: ignore
|
| 1345 |
+
) -> V:
|
| 1346 |
+
rv = start
|
| 1347 |
+
|
| 1348 |
+
if attribute is not None:
|
| 1349 |
+
func = make_attrgetter(environment, attribute)
|
| 1350 |
+
else:
|
| 1351 |
+
|
| 1352 |
+
def func(x: V) -> V:
|
| 1353 |
+
return x
|
| 1354 |
+
|
| 1355 |
+
async for item in auto_aiter(iterable):
|
| 1356 |
+
rv += func(item)
|
| 1357 |
+
|
| 1358 |
+
return rv
|
| 1359 |
+
|
| 1360 |
+
|
| 1361 |
+
def sync_do_list(value: "t.Iterable[V]") -> "t.List[V]":
|
| 1362 |
+
"""Convert the value into a list. If it was a string the returned list
|
| 1363 |
+
will be a list of characters.
|
| 1364 |
+
"""
|
| 1365 |
+
return list(value)
|
| 1366 |
+
|
| 1367 |
+
|
| 1368 |
+
@async_variant(sync_do_list) # type: ignore
|
| 1369 |
+
async def do_list(value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]") -> "t.List[V]":
|
| 1370 |
+
return await auto_to_list(value)
|
| 1371 |
+
|
| 1372 |
+
|
| 1373 |
+
def do_mark_safe(value: str) -> Markup:
|
| 1374 |
+
"""Mark the value as safe which means that in an environment with automatic
|
| 1375 |
+
escaping enabled this variable will not be escaped.
|
| 1376 |
+
"""
|
| 1377 |
+
return Markup(value)
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
def do_mark_unsafe(value: str) -> str:
|
| 1381 |
+
"""Mark a value as unsafe. This is the reverse operation for :func:`safe`."""
|
| 1382 |
+
return str(value)
|
| 1383 |
+
|
| 1384 |
+
|
| 1385 |
+
@typing.overload
|
| 1386 |
+
def do_reverse(value: str) -> str: ...
|
| 1387 |
+
|
| 1388 |
+
|
| 1389 |
+
@typing.overload
|
| 1390 |
+
def do_reverse(value: "t.Iterable[V]") -> "t.Iterable[V]": ...
|
| 1391 |
+
|
| 1392 |
+
|
| 1393 |
+
def do_reverse(value: t.Union[str, t.Iterable[V]]) -> t.Union[str, t.Iterable[V]]:
|
| 1394 |
+
"""Reverse the object or return an iterator that iterates over it the other
|
| 1395 |
+
way round.
|
| 1396 |
+
"""
|
| 1397 |
+
if isinstance(value, str):
|
| 1398 |
+
return value[::-1]
|
| 1399 |
+
|
| 1400 |
+
try:
|
| 1401 |
+
return reversed(value) # type: ignore
|
| 1402 |
+
except TypeError:
|
| 1403 |
+
try:
|
| 1404 |
+
rv = list(value)
|
| 1405 |
+
rv.reverse()
|
| 1406 |
+
return rv
|
| 1407 |
+
except TypeError as e:
|
| 1408 |
+
raise FilterArgumentError("argument must be iterable") from e
|
| 1409 |
+
|
| 1410 |
+
|
| 1411 |
+
@pass_environment
|
| 1412 |
+
def do_attr(
|
| 1413 |
+
environment: "Environment", obj: t.Any, name: str
|
| 1414 |
+
) -> t.Union[Undefined, t.Any]:
|
| 1415 |
+
"""Get an attribute of an object. ``foo|attr("bar")`` works like
|
| 1416 |
+
``foo.bar``, but returns undefined instead of falling back to ``foo["bar"]``
|
| 1417 |
+
if the attribute doesn't exist.
|
| 1418 |
+
|
| 1419 |
+
See :ref:`Notes on subscriptions <notes-on-subscriptions>` for more details.
|
| 1420 |
+
"""
|
| 1421 |
+
# Environment.getattr will fall back to obj[name] if obj.name doesn't exist.
|
| 1422 |
+
# But we want to call env.getattr to get behavior such as sandboxing.
|
| 1423 |
+
# Determine if the attr exists first, so we know the fallback won't trigger.
|
| 1424 |
+
try:
|
| 1425 |
+
# This avoids executing properties/descriptors, but misses __getattr__
|
| 1426 |
+
# and __getattribute__ dynamic attrs.
|
| 1427 |
+
getattr_static(obj, name)
|
| 1428 |
+
except AttributeError:
|
| 1429 |
+
# This finds dynamic attrs, and we know it's not a descriptor at this point.
|
| 1430 |
+
if not hasattr(obj, name):
|
| 1431 |
+
return environment.undefined(obj=obj, name=name)
|
| 1432 |
+
|
| 1433 |
+
return environment.getattr(obj, name)
|
| 1434 |
+
|
| 1435 |
+
|
| 1436 |
+
@typing.overload
|
| 1437 |
+
def sync_do_map(
|
| 1438 |
+
context: "Context",
|
| 1439 |
+
value: t.Iterable[t.Any],
|
| 1440 |
+
name: str,
|
| 1441 |
+
*args: t.Any,
|
| 1442 |
+
**kwargs: t.Any,
|
| 1443 |
+
) -> t.Iterable[t.Any]: ...
|
| 1444 |
+
|
| 1445 |
+
|
| 1446 |
+
@typing.overload
|
| 1447 |
+
def sync_do_map(
|
| 1448 |
+
context: "Context",
|
| 1449 |
+
value: t.Iterable[t.Any],
|
| 1450 |
+
*,
|
| 1451 |
+
attribute: str = ...,
|
| 1452 |
+
default: t.Optional[t.Any] = None,
|
| 1453 |
+
) -> t.Iterable[t.Any]: ...
|
| 1454 |
+
|
| 1455 |
+
|
| 1456 |
+
@pass_context
|
| 1457 |
+
def sync_do_map(
|
| 1458 |
+
context: "Context", value: t.Iterable[t.Any], *args: t.Any, **kwargs: t.Any
|
| 1459 |
+
) -> t.Iterable[t.Any]:
|
| 1460 |
+
"""Applies a filter on a sequence of objects or looks up an attribute.
|
| 1461 |
+
This is useful when dealing with lists of objects but you are really
|
| 1462 |
+
only interested in a certain value of it.
|
| 1463 |
+
|
| 1464 |
+
The basic usage is mapping on an attribute. Imagine you have a list
|
| 1465 |
+
of users but you are only interested in a list of usernames:
|
| 1466 |
+
|
| 1467 |
+
.. sourcecode:: jinja
|
| 1468 |
+
|
| 1469 |
+
Users on this page: {{ users|map(attribute='username')|join(', ') }}
|
| 1470 |
+
|
| 1471 |
+
You can specify a ``default`` value to use if an object in the list
|
| 1472 |
+
does not have the given attribute.
|
| 1473 |
+
|
| 1474 |
+
.. sourcecode:: jinja
|
| 1475 |
+
|
| 1476 |
+
{{ users|map(attribute="username", default="Anonymous")|join(", ") }}
|
| 1477 |
+
|
| 1478 |
+
Alternatively you can let it invoke a filter by passing the name of the
|
| 1479 |
+
filter and the arguments afterwards. A good example would be applying a
|
| 1480 |
+
text conversion filter on a sequence:
|
| 1481 |
+
|
| 1482 |
+
.. sourcecode:: jinja
|
| 1483 |
+
|
| 1484 |
+
Users on this page: {{ titles|map('lower')|join(', ') }}
|
| 1485 |
+
|
| 1486 |
+
Similar to a generator comprehension such as:
|
| 1487 |
+
|
| 1488 |
+
.. code-block:: python
|
| 1489 |
+
|
| 1490 |
+
(u.username for u in users)
|
| 1491 |
+
(getattr(u, "username", "Anonymous") for u in users)
|
| 1492 |
+
(do_lower(x) for x in titles)
|
| 1493 |
+
|
| 1494 |
+
.. versionchanged:: 2.11.0
|
| 1495 |
+
Added the ``default`` parameter.
|
| 1496 |
+
|
| 1497 |
+
.. versionadded:: 2.7
|
| 1498 |
+
"""
|
| 1499 |
+
if value:
|
| 1500 |
+
func = prepare_map(context, args, kwargs)
|
| 1501 |
+
|
| 1502 |
+
for item in value:
|
| 1503 |
+
yield func(item)
|
| 1504 |
+
|
| 1505 |
+
|
| 1506 |
+
@typing.overload
|
| 1507 |
+
def do_map(
|
| 1508 |
+
context: "Context",
|
| 1509 |
+
value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],
|
| 1510 |
+
name: str,
|
| 1511 |
+
*args: t.Any,
|
| 1512 |
+
**kwargs: t.Any,
|
| 1513 |
+
) -> t.Iterable[t.Any]: ...
|
| 1514 |
+
|
| 1515 |
+
|
| 1516 |
+
@typing.overload
|
| 1517 |
+
def do_map(
|
| 1518 |
+
context: "Context",
|
| 1519 |
+
value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],
|
| 1520 |
+
*,
|
| 1521 |
+
attribute: str = ...,
|
| 1522 |
+
default: t.Optional[t.Any] = None,
|
| 1523 |
+
) -> t.Iterable[t.Any]: ...
|
| 1524 |
+
|
| 1525 |
+
|
| 1526 |
+
@async_variant(sync_do_map) # type: ignore
|
| 1527 |
+
async def do_map(
|
| 1528 |
+
context: "Context",
|
| 1529 |
+
value: t.Union[t.AsyncIterable[t.Any], t.Iterable[t.Any]],
|
| 1530 |
+
*args: t.Any,
|
| 1531 |
+
**kwargs: t.Any,
|
| 1532 |
+
) -> t.AsyncIterable[t.Any]:
|
| 1533 |
+
if value:
|
| 1534 |
+
func = prepare_map(context, args, kwargs)
|
| 1535 |
+
|
| 1536 |
+
async for item in auto_aiter(value):
|
| 1537 |
+
yield await auto_await(func(item))
|
| 1538 |
+
|
| 1539 |
+
|
| 1540 |
+
@pass_context
|
| 1541 |
+
def sync_do_select(
|
| 1542 |
+
context: "Context", value: "t.Iterable[V]", *args: t.Any, **kwargs: t.Any
|
| 1543 |
+
) -> "t.Iterator[V]":
|
| 1544 |
+
"""Filters a sequence of objects by applying a test to each object,
|
| 1545 |
+
and only selecting the objects with the test succeeding.
|
| 1546 |
+
|
| 1547 |
+
If no test is specified, each object will be evaluated as a boolean.
|
| 1548 |
+
|
| 1549 |
+
Example usage:
|
| 1550 |
+
|
| 1551 |
+
.. sourcecode:: jinja
|
| 1552 |
+
|
| 1553 |
+
{{ numbers|select("odd") }}
|
| 1554 |
+
{{ numbers|select("odd") }}
|
| 1555 |
+
{{ numbers|select("divisibleby", 3) }}
|
| 1556 |
+
{{ numbers|select("lessthan", 42) }}
|
| 1557 |
+
{{ strings|select("equalto", "mystring") }}
|
| 1558 |
+
|
| 1559 |
+
Similar to a generator comprehension such as:
|
| 1560 |
+
|
| 1561 |
+
.. code-block:: python
|
| 1562 |
+
|
| 1563 |
+
(n for n in numbers if test_odd(n))
|
| 1564 |
+
(n for n in numbers if test_divisibleby(n, 3))
|
| 1565 |
+
|
| 1566 |
+
.. versionadded:: 2.7
|
| 1567 |
+
"""
|
| 1568 |
+
return select_or_reject(context, value, args, kwargs, lambda x: x, False)
|
| 1569 |
+
|
| 1570 |
+
|
| 1571 |
+
@async_variant(sync_do_select) # type: ignore
|
| 1572 |
+
async def do_select(
|
| 1573 |
+
context: "Context",
|
| 1574 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1575 |
+
*args: t.Any,
|
| 1576 |
+
**kwargs: t.Any,
|
| 1577 |
+
) -> "t.AsyncIterator[V]":
|
| 1578 |
+
return async_select_or_reject(context, value, args, kwargs, lambda x: x, False)
|
| 1579 |
+
|
| 1580 |
+
|
| 1581 |
+
@pass_context
|
| 1582 |
+
def sync_do_reject(
|
| 1583 |
+
context: "Context", value: "t.Iterable[V]", *args: t.Any, **kwargs: t.Any
|
| 1584 |
+
) -> "t.Iterator[V]":
|
| 1585 |
+
"""Filters a sequence of objects by applying a test to each object,
|
| 1586 |
+
and rejecting the objects with the test succeeding.
|
| 1587 |
+
|
| 1588 |
+
If no test is specified, each object will be evaluated as a boolean.
|
| 1589 |
+
|
| 1590 |
+
Example usage:
|
| 1591 |
+
|
| 1592 |
+
.. sourcecode:: jinja
|
| 1593 |
+
|
| 1594 |
+
{{ numbers|reject("odd") }}
|
| 1595 |
+
|
| 1596 |
+
Similar to a generator comprehension such as:
|
| 1597 |
+
|
| 1598 |
+
.. code-block:: python
|
| 1599 |
+
|
| 1600 |
+
(n for n in numbers if not test_odd(n))
|
| 1601 |
+
|
| 1602 |
+
.. versionadded:: 2.7
|
| 1603 |
+
"""
|
| 1604 |
+
return select_or_reject(context, value, args, kwargs, lambda x: not x, False)
|
| 1605 |
+
|
| 1606 |
+
|
| 1607 |
+
@async_variant(sync_do_reject) # type: ignore
|
| 1608 |
+
async def do_reject(
|
| 1609 |
+
context: "Context",
|
| 1610 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1611 |
+
*args: t.Any,
|
| 1612 |
+
**kwargs: t.Any,
|
| 1613 |
+
) -> "t.AsyncIterator[V]":
|
| 1614 |
+
return async_select_or_reject(context, value, args, kwargs, lambda x: not x, False)
|
| 1615 |
+
|
| 1616 |
+
|
| 1617 |
+
@pass_context
|
| 1618 |
+
def sync_do_selectattr(
|
| 1619 |
+
context: "Context", value: "t.Iterable[V]", *args: t.Any, **kwargs: t.Any
|
| 1620 |
+
) -> "t.Iterator[V]":
|
| 1621 |
+
"""Filters a sequence of objects by applying a test to the specified
|
| 1622 |
+
attribute of each object, and only selecting the objects with the
|
| 1623 |
+
test succeeding.
|
| 1624 |
+
|
| 1625 |
+
If no test is specified, the attribute's value will be evaluated as
|
| 1626 |
+
a boolean.
|
| 1627 |
+
|
| 1628 |
+
Example usage:
|
| 1629 |
+
|
| 1630 |
+
.. sourcecode:: jinja
|
| 1631 |
+
|
| 1632 |
+
{{ users|selectattr("is_active") }}
|
| 1633 |
+
{{ users|selectattr("email", "none") }}
|
| 1634 |
+
|
| 1635 |
+
Similar to a generator comprehension such as:
|
| 1636 |
+
|
| 1637 |
+
.. code-block:: python
|
| 1638 |
+
|
| 1639 |
+
(user for user in users if user.is_active)
|
| 1640 |
+
(user for user in users if test_none(user.email))
|
| 1641 |
+
|
| 1642 |
+
.. versionadded:: 2.7
|
| 1643 |
+
"""
|
| 1644 |
+
return select_or_reject(context, value, args, kwargs, lambda x: x, True)
|
| 1645 |
+
|
| 1646 |
+
|
| 1647 |
+
@async_variant(sync_do_selectattr) # type: ignore
|
| 1648 |
+
async def do_selectattr(
|
| 1649 |
+
context: "Context",
|
| 1650 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1651 |
+
*args: t.Any,
|
| 1652 |
+
**kwargs: t.Any,
|
| 1653 |
+
) -> "t.AsyncIterator[V]":
|
| 1654 |
+
return async_select_or_reject(context, value, args, kwargs, lambda x: x, True)
|
| 1655 |
+
|
| 1656 |
+
|
| 1657 |
+
@pass_context
|
| 1658 |
+
def sync_do_rejectattr(
|
| 1659 |
+
context: "Context", value: "t.Iterable[V]", *args: t.Any, **kwargs: t.Any
|
| 1660 |
+
) -> "t.Iterator[V]":
|
| 1661 |
+
"""Filters a sequence of objects by applying a test to the specified
|
| 1662 |
+
attribute of each object, and rejecting the objects with the test
|
| 1663 |
+
succeeding.
|
| 1664 |
+
|
| 1665 |
+
If no test is specified, the attribute's value will be evaluated as
|
| 1666 |
+
a boolean.
|
| 1667 |
+
|
| 1668 |
+
.. sourcecode:: jinja
|
| 1669 |
+
|
| 1670 |
+
{{ users|rejectattr("is_active") }}
|
| 1671 |
+
{{ users|rejectattr("email", "none") }}
|
| 1672 |
+
|
| 1673 |
+
Similar to a generator comprehension such as:
|
| 1674 |
+
|
| 1675 |
+
.. code-block:: python
|
| 1676 |
+
|
| 1677 |
+
(user for user in users if not user.is_active)
|
| 1678 |
+
(user for user in users if not test_none(user.email))
|
| 1679 |
+
|
| 1680 |
+
.. versionadded:: 2.7
|
| 1681 |
+
"""
|
| 1682 |
+
return select_or_reject(context, value, args, kwargs, lambda x: not x, True)
|
| 1683 |
+
|
| 1684 |
+
|
| 1685 |
+
@async_variant(sync_do_rejectattr) # type: ignore
|
| 1686 |
+
async def do_rejectattr(
|
| 1687 |
+
context: "Context",
|
| 1688 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1689 |
+
*args: t.Any,
|
| 1690 |
+
**kwargs: t.Any,
|
| 1691 |
+
) -> "t.AsyncIterator[V]":
|
| 1692 |
+
return async_select_or_reject(context, value, args, kwargs, lambda x: not x, True)
|
| 1693 |
+
|
| 1694 |
+
|
| 1695 |
+
@pass_eval_context
|
| 1696 |
+
def do_tojson(
|
| 1697 |
+
eval_ctx: "EvalContext", value: t.Any, indent: t.Optional[int] = None
|
| 1698 |
+
) -> Markup:
|
| 1699 |
+
"""Serialize an object to a string of JSON, and mark it safe to
|
| 1700 |
+
render in HTML. This filter is only for use in HTML documents.
|
| 1701 |
+
|
| 1702 |
+
The returned string is safe to render in HTML documents and
|
| 1703 |
+
``<script>`` tags. The exception is in HTML attributes that are
|
| 1704 |
+
double quoted; either use single quotes or the ``|forceescape``
|
| 1705 |
+
filter.
|
| 1706 |
+
|
| 1707 |
+
:param value: The object to serialize to JSON.
|
| 1708 |
+
:param indent: The ``indent`` parameter passed to ``dumps``, for
|
| 1709 |
+
pretty-printing the value.
|
| 1710 |
+
|
| 1711 |
+
.. versionadded:: 2.9
|
| 1712 |
+
"""
|
| 1713 |
+
policies = eval_ctx.environment.policies
|
| 1714 |
+
dumps = policies["json.dumps_function"]
|
| 1715 |
+
kwargs = policies["json.dumps_kwargs"]
|
| 1716 |
+
|
| 1717 |
+
if indent is not None:
|
| 1718 |
+
kwargs = kwargs.copy()
|
| 1719 |
+
kwargs["indent"] = indent
|
| 1720 |
+
|
| 1721 |
+
return htmlsafe_json_dumps(value, dumps=dumps, **kwargs)
|
| 1722 |
+
|
| 1723 |
+
|
| 1724 |
+
def prepare_map(
|
| 1725 |
+
context: "Context", args: t.Tuple[t.Any, ...], kwargs: t.Dict[str, t.Any]
|
| 1726 |
+
) -> t.Callable[[t.Any], t.Any]:
|
| 1727 |
+
if not args and "attribute" in kwargs:
|
| 1728 |
+
attribute = kwargs.pop("attribute")
|
| 1729 |
+
default = kwargs.pop("default", None)
|
| 1730 |
+
|
| 1731 |
+
if kwargs:
|
| 1732 |
+
raise FilterArgumentError(
|
| 1733 |
+
f"Unexpected keyword argument {next(iter(kwargs))!r}"
|
| 1734 |
+
)
|
| 1735 |
+
|
| 1736 |
+
func = make_attrgetter(context.environment, attribute, default=default)
|
| 1737 |
+
else:
|
| 1738 |
+
try:
|
| 1739 |
+
name = args[0]
|
| 1740 |
+
args = args[1:]
|
| 1741 |
+
except LookupError:
|
| 1742 |
+
raise FilterArgumentError("map requires a filter argument") from None
|
| 1743 |
+
|
| 1744 |
+
def func(item: t.Any) -> t.Any:
|
| 1745 |
+
return context.environment.call_filter(
|
| 1746 |
+
name, item, args, kwargs, context=context
|
| 1747 |
+
)
|
| 1748 |
+
|
| 1749 |
+
return func
|
| 1750 |
+
|
| 1751 |
+
|
| 1752 |
+
def prepare_select_or_reject(
|
| 1753 |
+
context: "Context",
|
| 1754 |
+
args: t.Tuple[t.Any, ...],
|
| 1755 |
+
kwargs: t.Dict[str, t.Any],
|
| 1756 |
+
modfunc: t.Callable[[t.Any], t.Any],
|
| 1757 |
+
lookup_attr: bool,
|
| 1758 |
+
) -> t.Callable[[t.Any], t.Any]:
|
| 1759 |
+
if lookup_attr:
|
| 1760 |
+
try:
|
| 1761 |
+
attr = args[0]
|
| 1762 |
+
except LookupError:
|
| 1763 |
+
raise FilterArgumentError("Missing parameter for attribute name") from None
|
| 1764 |
+
|
| 1765 |
+
transfunc = make_attrgetter(context.environment, attr)
|
| 1766 |
+
off = 1
|
| 1767 |
+
else:
|
| 1768 |
+
off = 0
|
| 1769 |
+
|
| 1770 |
+
def transfunc(x: V) -> V:
|
| 1771 |
+
return x
|
| 1772 |
+
|
| 1773 |
+
try:
|
| 1774 |
+
name = args[off]
|
| 1775 |
+
args = args[1 + off :]
|
| 1776 |
+
|
| 1777 |
+
def func(item: t.Any) -> t.Any:
|
| 1778 |
+
return context.environment.call_test(name, item, args, kwargs, context)
|
| 1779 |
+
|
| 1780 |
+
except LookupError:
|
| 1781 |
+
func = bool # type: ignore
|
| 1782 |
+
|
| 1783 |
+
return lambda item: modfunc(func(transfunc(item)))
|
| 1784 |
+
|
| 1785 |
+
|
| 1786 |
+
def select_or_reject(
|
| 1787 |
+
context: "Context",
|
| 1788 |
+
value: "t.Iterable[V]",
|
| 1789 |
+
args: t.Tuple[t.Any, ...],
|
| 1790 |
+
kwargs: t.Dict[str, t.Any],
|
| 1791 |
+
modfunc: t.Callable[[t.Any], t.Any],
|
| 1792 |
+
lookup_attr: bool,
|
| 1793 |
+
) -> "t.Iterator[V]":
|
| 1794 |
+
if value:
|
| 1795 |
+
func = prepare_select_or_reject(context, args, kwargs, modfunc, lookup_attr)
|
| 1796 |
+
|
| 1797 |
+
for item in value:
|
| 1798 |
+
if func(item):
|
| 1799 |
+
yield item
|
| 1800 |
+
|
| 1801 |
+
|
| 1802 |
+
async def async_select_or_reject(
|
| 1803 |
+
context: "Context",
|
| 1804 |
+
value: "t.Union[t.AsyncIterable[V], t.Iterable[V]]",
|
| 1805 |
+
args: t.Tuple[t.Any, ...],
|
| 1806 |
+
kwargs: t.Dict[str, t.Any],
|
| 1807 |
+
modfunc: t.Callable[[t.Any], t.Any],
|
| 1808 |
+
lookup_attr: bool,
|
| 1809 |
+
) -> "t.AsyncIterator[V]":
|
| 1810 |
+
if value:
|
| 1811 |
+
func = prepare_select_or_reject(context, args, kwargs, modfunc, lookup_attr)
|
| 1812 |
+
|
| 1813 |
+
async for item in auto_aiter(value):
|
| 1814 |
+
if func(item):
|
| 1815 |
+
yield item
|
| 1816 |
+
|
| 1817 |
+
|
| 1818 |
+
FILTERS = {
|
| 1819 |
+
"abs": abs,
|
| 1820 |
+
"attr": do_attr,
|
| 1821 |
+
"batch": do_batch,
|
| 1822 |
+
"capitalize": do_capitalize,
|
| 1823 |
+
"center": do_center,
|
| 1824 |
+
"count": len,
|
| 1825 |
+
"d": do_default,
|
| 1826 |
+
"default": do_default,
|
| 1827 |
+
"dictsort": do_dictsort,
|
| 1828 |
+
"e": escape,
|
| 1829 |
+
"escape": escape,
|
| 1830 |
+
"filesizeformat": do_filesizeformat,
|
| 1831 |
+
"first": do_first,
|
| 1832 |
+
"float": do_float,
|
| 1833 |
+
"forceescape": do_forceescape,
|
| 1834 |
+
"format": do_format,
|
| 1835 |
+
"groupby": do_groupby,
|
| 1836 |
+
"indent": do_indent,
|
| 1837 |
+
"int": do_int,
|
| 1838 |
+
"join": do_join,
|
| 1839 |
+
"last": do_last,
|
| 1840 |
+
"length": len,
|
| 1841 |
+
"list": do_list,
|
| 1842 |
+
"lower": do_lower,
|
| 1843 |
+
"items": do_items,
|
| 1844 |
+
"map": do_map,
|
| 1845 |
+
"min": do_min,
|
| 1846 |
+
"max": do_max,
|
| 1847 |
+
"pprint": do_pprint,
|
| 1848 |
+
"random": do_random,
|
| 1849 |
+
"reject": do_reject,
|
| 1850 |
+
"rejectattr": do_rejectattr,
|
| 1851 |
+
"replace": do_replace,
|
| 1852 |
+
"reverse": do_reverse,
|
| 1853 |
+
"round": do_round,
|
| 1854 |
+
"safe": do_mark_safe,
|
| 1855 |
+
"select": do_select,
|
| 1856 |
+
"selectattr": do_selectattr,
|
| 1857 |
+
"slice": do_slice,
|
| 1858 |
+
"sort": do_sort,
|
| 1859 |
+
"string": soft_str,
|
| 1860 |
+
"striptags": do_striptags,
|
| 1861 |
+
"sum": do_sum,
|
| 1862 |
+
"title": do_title,
|
| 1863 |
+
"trim": do_trim,
|
| 1864 |
+
"truncate": do_truncate,
|
| 1865 |
+
"unique": do_unique,
|
| 1866 |
+
"upper": do_upper,
|
| 1867 |
+
"urlencode": do_urlencode,
|
| 1868 |
+
"urlize": do_urlize,
|
| 1869 |
+
"wordcount": do_wordcount,
|
| 1870 |
+
"wordwrap": do_wordwrap,
|
| 1871 |
+
"xmlattr": do_xmlattr,
|
| 1872 |
+
"tojson": do_tojson,
|
| 1873 |
+
}
|
micromamba_root/pkgs/https/conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1/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."""
|