Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/INSTALLER +1 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/METADATA +209 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/RECORD +22 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/WHEEL +4 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/licenses/LICENSE.md +31 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/codec.py +122 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/compat.py +15 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/core.py +437 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/idnadata.py +4309 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/intranges.py +57 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/package_data.py +1 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/py.typed +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/idna/uts46data.py +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/INSTALLER +1 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/LICENSE.txt +50 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/METADATA +25 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/RECORD +8 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/WHEEL +6 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/top_level.txt +1 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/INSTALLER +1 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/METADATA +84 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/RECORD +57 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/WHEEL +4 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/entry_points.txt +3 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/licenses/LICENSE.txt +28 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/__init__.py +38 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/_identifier.py +6 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/async_utils.py +99 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/bccache.py +408 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/compiler.py +1998 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/constants.py +20 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/debug.py +191 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/defaults.py +48 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/environment.py +1672 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/exceptions.py +166 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/ext.py +870 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/filters.py +1873 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/idtracking.py +318 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/lexer.py +868 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/loaders.py +693 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/meta.py +112 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/nativetypes.py +130 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/nodes.py +1206 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/optimizer.py +48 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/parser.py +1049 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/py.typed +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/runtime.py +1062 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/sandbox.py +436 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/tests.py +256 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/utils.py +766 -0
miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/METADATA
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: idna
|
| 3 |
+
Version: 3.11
|
| 4 |
+
Summary: Internationalized Domain Names in Applications (IDNA)
|
| 5 |
+
Author-email: Kim Davies <kim+pypi@gumleaf.org>
|
| 6 |
+
Requires-Python: >=3.8
|
| 7 |
+
Description-Content-Type: text/x-rst
|
| 8 |
+
License-Expression: BSD-3-Clause
|
| 9 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 10 |
+
Classifier: Intended Audience :: Developers
|
| 11 |
+
Classifier: Intended Audience :: System Administrators
|
| 12 |
+
Classifier: Operating System :: OS Independent
|
| 13 |
+
Classifier: Programming Language :: Python
|
| 14 |
+
Classifier: Programming Language :: Python :: 3
|
| 15 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 23 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 24 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 25 |
+
Classifier: Topic :: Internet :: Name Service (DNS)
|
| 26 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 27 |
+
Classifier: Topic :: Utilities
|
| 28 |
+
License-File: LICENSE.md
|
| 29 |
+
Requires-Dist: ruff >= 0.6.2 ; extra == "all"
|
| 30 |
+
Requires-Dist: mypy >= 1.11.2 ; extra == "all"
|
| 31 |
+
Requires-Dist: pytest >= 8.3.2 ; extra == "all"
|
| 32 |
+
Requires-Dist: flake8 >= 7.1.1 ; extra == "all"
|
| 33 |
+
Project-URL: Changelog, https://github.com/kjd/idna/blob/master/HISTORY.rst
|
| 34 |
+
Project-URL: Issue tracker, https://github.com/kjd/idna/issues
|
| 35 |
+
Project-URL: Source, https://github.com/kjd/idna
|
| 36 |
+
Provides-Extra: all
|
| 37 |
+
|
| 38 |
+
Internationalized Domain Names in Applications (IDNA)
|
| 39 |
+
=====================================================
|
| 40 |
+
|
| 41 |
+
Support for `Internationalized Domain Names in
|
| 42 |
+
Applications (IDNA) <https://tools.ietf.org/html/rfc5891>`_
|
| 43 |
+
and `Unicode IDNA Compatibility Processing
|
| 44 |
+
<https://unicode.org/reports/tr46/>`_.
|
| 45 |
+
|
| 46 |
+
The latest versions of these standards supplied here provide
|
| 47 |
+
more comprehensive language coverage and reduce the potential of
|
| 48 |
+
allowing domains with known security vulnerabilities. This library
|
| 49 |
+
is a suitable replacement for the “encodings.idna”
|
| 50 |
+
module that comes with the Python standard library, but which
|
| 51 |
+
only supports an older superseded IDNA specification from 2003.
|
| 52 |
+
|
| 53 |
+
Basic functions are simply executed:
|
| 54 |
+
|
| 55 |
+
.. code-block:: pycon
|
| 56 |
+
|
| 57 |
+
>>> import idna
|
| 58 |
+
>>> idna.encode('ドメイン.テスト')
|
| 59 |
+
b'xn--eckwd4c7c.xn--zckzah'
|
| 60 |
+
>>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
|
| 61 |
+
ドメイン.テスト
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Installation
|
| 65 |
+
------------
|
| 66 |
+
|
| 67 |
+
This package is available for installation from PyPI via the
|
| 68 |
+
typical mechanisms, such as:
|
| 69 |
+
|
| 70 |
+
.. code-block:: bash
|
| 71 |
+
|
| 72 |
+
$ python3 -m pip install idna
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Usage
|
| 76 |
+
-----
|
| 77 |
+
|
| 78 |
+
For typical usage, the ``encode`` and ``decode`` functions will take a
|
| 79 |
+
domain name argument and perform a conversion to ASCII compatible encoding
|
| 80 |
+
(known as A-labels), or to Unicode strings (known as U-labels)
|
| 81 |
+
respectively.
|
| 82 |
+
|
| 83 |
+
.. code-block:: pycon
|
| 84 |
+
|
| 85 |
+
>>> import idna
|
| 86 |
+
>>> idna.encode('ドメイン.テスト')
|
| 87 |
+
b'xn--eckwd4c7c.xn--zckzah'
|
| 88 |
+
>>> print(idna.decode('xn--eckwd4c7c.xn--zckzah'))
|
| 89 |
+
ドメイン.テスト
|
| 90 |
+
|
| 91 |
+
Conversions can be applied at a per-label basis using the ``ulabel`` or
|
| 92 |
+
``alabel`` functions if necessary:
|
| 93 |
+
|
| 94 |
+
.. code-block:: pycon
|
| 95 |
+
|
| 96 |
+
>>> idna.alabel('测试')
|
| 97 |
+
b'xn--0zwm56d'
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
Compatibility Mapping (UTS #46)
|
| 101 |
+
+++++++++++++++++++++++++++++++
|
| 102 |
+
|
| 103 |
+
This library provides support for `Unicode IDNA Compatibility
|
| 104 |
+
Processing <https://unicode.org/reports/tr46/>`_ which normalizes input from
|
| 105 |
+
different potential ways a user may input a domain prior to performing the IDNA
|
| 106 |
+
conversion operations. This functionality, known as a
|
| 107 |
+
`mapping <https://tools.ietf.org/html/rfc5895>`_, is considered by the
|
| 108 |
+
specification to be a local user-interface issue distinct from IDNA
|
| 109 |
+
conversion functionality.
|
| 110 |
+
|
| 111 |
+
For example, “Königsgäßchen” is not a permissible label as *LATIN
|
| 112 |
+
CAPITAL LETTER K* is not allowed (nor are capital letters in general).
|
| 113 |
+
UTS 46 will convert this into lower case prior to applying the IDNA
|
| 114 |
+
conversion.
|
| 115 |
+
|
| 116 |
+
.. code-block:: pycon
|
| 117 |
+
|
| 118 |
+
>>> import idna
|
| 119 |
+
>>> idna.encode('Königsgäßchen')
|
| 120 |
+
...
|
| 121 |
+
idna.core.InvalidCodepoint: Codepoint U+004B at position 1 of 'Königsgäßchen' not allowed
|
| 122 |
+
>>> idna.encode('Königsgäßchen', uts46=True)
|
| 123 |
+
b'xn--knigsgchen-b4a3dun'
|
| 124 |
+
>>> print(idna.decode('xn--knigsgchen-b4a3dun'))
|
| 125 |
+
königsgäßchen
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
Exceptions
|
| 129 |
+
----------
|
| 130 |
+
|
| 131 |
+
All errors raised during the conversion following the specification
|
| 132 |
+
should raise an exception derived from the ``idna.IDNAError`` base
|
| 133 |
+
class.
|
| 134 |
+
|
| 135 |
+
More specific exceptions that may be generated as ``idna.IDNABidiError``
|
| 136 |
+
when the error reflects an illegal combination of left-to-right and
|
| 137 |
+
right-to-left characters in a label; ``idna.InvalidCodepoint`` when
|
| 138 |
+
a specific codepoint is an illegal character in an IDN label (i.e.
|
| 139 |
+
INVALID); and ``idna.InvalidCodepointContext`` when the codepoint is
|
| 140 |
+
illegal based on its position in the string (i.e. it is CONTEXTO or CONTEXTJ
|
| 141 |
+
but the contextual requirements are not satisfied.)
|
| 142 |
+
|
| 143 |
+
Building and Diagnostics
|
| 144 |
+
------------------------
|
| 145 |
+
|
| 146 |
+
The IDNA and UTS 46 functionality relies upon pre-calculated lookup
|
| 147 |
+
tables for performance. These tables are derived from computing against
|
| 148 |
+
eligibility criteria in the respective standards using the command-line
|
| 149 |
+
script ``tools/idna-data``.
|
| 150 |
+
|
| 151 |
+
This tool will fetch relevant codepoint data from the Unicode repository
|
| 152 |
+
and perform the required calculations to identify eligibility. There are
|
| 153 |
+
three main modes:
|
| 154 |
+
|
| 155 |
+
* ``idna-data make-libdata``. Generates ``idnadata.py`` and
|
| 156 |
+
``uts46data.py``, the pre-calculated lookup tables used for IDNA and
|
| 157 |
+
UTS 46 conversions. Implementers who wish to track this library against
|
| 158 |
+
a different Unicode version may use this tool to manually generate a
|
| 159 |
+
different version of the ``idnadata.py`` and ``uts46data.py`` files.
|
| 160 |
+
|
| 161 |
+
* ``idna-data make-table``. Generate a table of the IDNA disposition
|
| 162 |
+
(e.g. PVALID, CONTEXTJ, CONTEXTO) in the format found in Appendix
|
| 163 |
+
B.1 of RFC 5892 and the pre-computed tables published by `IANA
|
| 164 |
+
<https://www.iana.org/>`_.
|
| 165 |
+
|
| 166 |
+
* ``idna-data U+0061``. Prints debugging output on the various
|
| 167 |
+
properties associated with an individual Unicode codepoint (in this
|
| 168 |
+
case, U+0061), that are used to assess the IDNA and UTS 46 status of a
|
| 169 |
+
codepoint. This is helpful in debugging or analysis.
|
| 170 |
+
|
| 171 |
+
The tool accepts a number of arguments, described using ``idna-data
|
| 172 |
+
-h``. Most notably, the ``--version`` argument allows the specification
|
| 173 |
+
of the version of Unicode to be used in computing the table data. For
|
| 174 |
+
example, ``idna-data --version 9.0.0 make-libdata`` will generate
|
| 175 |
+
library data against Unicode 9.0.0.
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
Additional Notes
|
| 179 |
+
----------------
|
| 180 |
+
|
| 181 |
+
* **Packages**. The latest tagged release version is published in the
|
| 182 |
+
`Python Package Index <https://pypi.org/project/idna/>`_.
|
| 183 |
+
|
| 184 |
+
* **Version support**. This library supports Python 3.8 and higher.
|
| 185 |
+
As this library serves as a low-level toolkit for a variety of
|
| 186 |
+
applications, many of which strive for broad compatibility with older
|
| 187 |
+
Python versions, there is no rush to remove older interpreter support.
|
| 188 |
+
Support for older versions are likely to be removed from new releases
|
| 189 |
+
as automated tests can no longer easily be run, i.e. once the Python
|
| 190 |
+
version is officially end-of-life.
|
| 191 |
+
|
| 192 |
+
* **Testing**. The library has a test suite based on each rule of the
|
| 193 |
+
IDNA specification, as well as tests that are provided as part of the
|
| 194 |
+
Unicode Technical Standard 46, `Unicode IDNA Compatibility Processing
|
| 195 |
+
<https://unicode.org/reports/tr46/>`_.
|
| 196 |
+
|
| 197 |
+
* **Emoji**. It is an occasional request to support emoji domains in
|
| 198 |
+
this library. Encoding of symbols like emoji is expressly prohibited by
|
| 199 |
+
the technical standard IDNA 2008 and emoji domains are broadly phased
|
| 200 |
+
out across the domain industry due to associated security risks. For
|
| 201 |
+
now, applications that need to support these non-compliant labels
|
| 202 |
+
may wish to consider trying the encode/decode operation in this library
|
| 203 |
+
first, and then falling back to using `encodings.idna`. See `the Github
|
| 204 |
+
project <https://github.com/kjd/idna/issues/18>`_ for more discussion.
|
| 205 |
+
|
| 206 |
+
* **Transitional processing**. Unicode 16.0.0 removed transitional
|
| 207 |
+
processing so the `transitional` argument for the encode() method
|
| 208 |
+
no longer has any effect and will be removed at a later date.
|
| 209 |
+
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/RECORD
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
idna-3.11.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
idna-3.11.dist-info/METADATA,sha256=fCwSww9SuiN8TIHllFSASUQCW55hAs8dzKnr9RaEEbA,8378
|
| 3 |
+
idna-3.11.dist-info/RECORD,,
|
| 4 |
+
idna-3.11.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
| 5 |
+
idna-3.11.dist-info/licenses/LICENSE.md,sha256=t6M2q_OwThgOwGXN0W5wXQeeHMehT5EKpukYfza5zYc,1541
|
| 6 |
+
idna/__init__.py,sha256=MPqNDLZbXqGaNdXxAFhiqFPKEQXju2jNQhCey6-5eJM,868
|
| 7 |
+
idna/__pycache__/__init__.cpython-310.pyc,,
|
| 8 |
+
idna/__pycache__/codec.cpython-310.pyc,,
|
| 9 |
+
idna/__pycache__/compat.cpython-310.pyc,,
|
| 10 |
+
idna/__pycache__/core.cpython-310.pyc,,
|
| 11 |
+
idna/__pycache__/idnadata.cpython-310.pyc,,
|
| 12 |
+
idna/__pycache__/intranges.cpython-310.pyc,,
|
| 13 |
+
idna/__pycache__/package_data.cpython-310.pyc,,
|
| 14 |
+
idna/__pycache__/uts46data.cpython-310.pyc,,
|
| 15 |
+
idna/codec.py,sha256=M2SGWN7cs_6B32QmKTyTN6xQGZeYQgQ2wiX3_DR6loE,3438
|
| 16 |
+
idna/compat.py,sha256=RzLy6QQCdl9784aFhb2EX9EKGCJjg0P3PilGdeXXcx8,316
|
| 17 |
+
idna/core.py,sha256=P26_XVycuMTZ1R2mNK1ZREVzM5mvTzdabBXfyZVU1Lc,13246
|
| 18 |
+
idna/idnadata.py,sha256=SG8jhaGE53iiD6B49pt2pwTv_UvClciWE-N54oR2p4U,79623
|
| 19 |
+
idna/intranges.py,sha256=amUtkdhYcQG8Zr-CoMM_kVRacxkivC1WgxN1b63KKdU,1898
|
| 20 |
+
idna/package_data.py,sha256=_CUavOxobnbyNG2FLyHoN8QHP3QM9W1tKuw7eq9QwBk,21
|
| 21 |
+
idna/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 22 |
+
idna/uts46data.py,sha256=H9J35VkD0F9L9mKOqjeNGd2A-Va6FlPoz6Jz4K7h-ps,243725
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.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
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna-3.11.dist-info/licenses/LICENSE.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2013-2025, Kim Davies and contributors.
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are
|
| 8 |
+
met:
|
| 9 |
+
|
| 10 |
+
1. Redistributions of source code must retain the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer.
|
| 12 |
+
|
| 13 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 14 |
+
notice, this list of conditions and the following disclaimer in the
|
| 15 |
+
documentation and/or other materials provided with the distribution.
|
| 16 |
+
|
| 17 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 18 |
+
contributors may be used to endorse or promote products derived from
|
| 19 |
+
this software without specific prior written permission.
|
| 20 |
+
|
| 21 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 22 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 23 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 24 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 25 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 26 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 27 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 28 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 29 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 30 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 31 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/codec.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import codecs
|
| 2 |
+
import re
|
| 3 |
+
from typing import Any, Optional, Tuple
|
| 4 |
+
|
| 5 |
+
from .core import IDNAError, alabel, decode, encode, ulabel
|
| 6 |
+
|
| 7 |
+
_unicode_dots_re = re.compile("[\u002e\u3002\uff0e\uff61]")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Codec(codecs.Codec):
|
| 11 |
+
def encode(self, data: str, errors: str = "strict") -> Tuple[bytes, int]:
|
| 12 |
+
if errors != "strict":
|
| 13 |
+
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
| 14 |
+
|
| 15 |
+
if not data:
|
| 16 |
+
return b"", 0
|
| 17 |
+
|
| 18 |
+
return encode(data), len(data)
|
| 19 |
+
|
| 20 |
+
def decode(self, data: bytes, errors: str = "strict") -> Tuple[str, int]:
|
| 21 |
+
if errors != "strict":
|
| 22 |
+
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
| 23 |
+
|
| 24 |
+
if not data:
|
| 25 |
+
return "", 0
|
| 26 |
+
|
| 27 |
+
return decode(data), len(data)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
|
| 31 |
+
def _buffer_encode(self, data: str, errors: str, final: bool) -> Tuple[bytes, int]:
|
| 32 |
+
if errors != "strict":
|
| 33 |
+
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
| 34 |
+
|
| 35 |
+
if not data:
|
| 36 |
+
return b"", 0
|
| 37 |
+
|
| 38 |
+
labels = _unicode_dots_re.split(data)
|
| 39 |
+
trailing_dot = b""
|
| 40 |
+
if labels:
|
| 41 |
+
if not labels[-1]:
|
| 42 |
+
trailing_dot = b"."
|
| 43 |
+
del labels[-1]
|
| 44 |
+
elif not final:
|
| 45 |
+
# Keep potentially unfinished label until the next call
|
| 46 |
+
del labels[-1]
|
| 47 |
+
if labels:
|
| 48 |
+
trailing_dot = b"."
|
| 49 |
+
|
| 50 |
+
result = []
|
| 51 |
+
size = 0
|
| 52 |
+
for label in labels:
|
| 53 |
+
result.append(alabel(label))
|
| 54 |
+
if size:
|
| 55 |
+
size += 1
|
| 56 |
+
size += len(label)
|
| 57 |
+
|
| 58 |
+
# Join with U+002E
|
| 59 |
+
result_bytes = b".".join(result) + trailing_dot
|
| 60 |
+
size += len(trailing_dot)
|
| 61 |
+
return result_bytes, size
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
| 65 |
+
def _buffer_decode(self, data: Any, errors: str, final: bool) -> Tuple[str, int]:
|
| 66 |
+
if errors != "strict":
|
| 67 |
+
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
| 68 |
+
|
| 69 |
+
if not data:
|
| 70 |
+
return ("", 0)
|
| 71 |
+
|
| 72 |
+
if not isinstance(data, str):
|
| 73 |
+
data = str(data, "ascii")
|
| 74 |
+
|
| 75 |
+
labels = _unicode_dots_re.split(data)
|
| 76 |
+
trailing_dot = ""
|
| 77 |
+
if labels:
|
| 78 |
+
if not labels[-1]:
|
| 79 |
+
trailing_dot = "."
|
| 80 |
+
del labels[-1]
|
| 81 |
+
elif not final:
|
| 82 |
+
# Keep potentially unfinished label until the next call
|
| 83 |
+
del labels[-1]
|
| 84 |
+
if labels:
|
| 85 |
+
trailing_dot = "."
|
| 86 |
+
|
| 87 |
+
result = []
|
| 88 |
+
size = 0
|
| 89 |
+
for label in labels:
|
| 90 |
+
result.append(ulabel(label))
|
| 91 |
+
if size:
|
| 92 |
+
size += 1
|
| 93 |
+
size += len(label)
|
| 94 |
+
|
| 95 |
+
result_str = ".".join(result) + trailing_dot
|
| 96 |
+
size += len(trailing_dot)
|
| 97 |
+
return (result_str, size)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class StreamWriter(Codec, codecs.StreamWriter):
|
| 101 |
+
pass
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class StreamReader(Codec, codecs.StreamReader):
|
| 105 |
+
pass
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def search_function(name: str) -> Optional[codecs.CodecInfo]:
|
| 109 |
+
if name != "idna2008":
|
| 110 |
+
return None
|
| 111 |
+
return codecs.CodecInfo(
|
| 112 |
+
name=name,
|
| 113 |
+
encode=Codec().encode,
|
| 114 |
+
decode=Codec().decode, # type: ignore
|
| 115 |
+
incrementalencoder=IncrementalEncoder,
|
| 116 |
+
incrementaldecoder=IncrementalDecoder,
|
| 117 |
+
streamwriter=StreamWriter,
|
| 118 |
+
streamreader=StreamReader,
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
codecs.register(search_function)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/compat.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Union
|
| 2 |
+
|
| 3 |
+
from .core import decode, encode
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def ToASCII(label: str) -> bytes:
|
| 7 |
+
return encode(label)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def ToUnicode(label: Union[bytes, bytearray]) -> str:
|
| 11 |
+
return decode(label)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def nameprep(s: Any) -> None:
|
| 15 |
+
raise NotImplementedError("IDNA 2008 does not utilise nameprep protocol")
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/core.py
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 7 |
+
from .intranges import intranges_contain
|
| 8 |
+
|
| 9 |
+
_virama_combining_class = 9
|
| 10 |
+
_alabel_prefix = b"xn--"
|
| 11 |
+
_unicode_dots_re = re.compile("[\u002e\u3002\uff0e\uff61]")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class IDNAError(UnicodeError):
|
| 15 |
+
"""Base exception for all IDNA-encoding related problems"""
|
| 16 |
+
|
| 17 |
+
pass
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class IDNABidiError(IDNAError):
|
| 21 |
+
"""Exception when bidirectional requirements are not satisfied"""
|
| 22 |
+
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class InvalidCodepoint(IDNAError):
|
| 27 |
+
"""Exception when a disallowed or unallocated codepoint is used"""
|
| 28 |
+
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class InvalidCodepointContext(IDNAError):
|
| 33 |
+
"""Exception when the codepoint is not valid in the context it is used"""
|
| 34 |
+
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _combining_class(cp: int) -> int:
|
| 39 |
+
v = unicodedata.combining(chr(cp))
|
| 40 |
+
if v == 0:
|
| 41 |
+
if not unicodedata.name(chr(cp)):
|
| 42 |
+
raise ValueError("Unknown character in unicodedata")
|
| 43 |
+
return v
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _is_script(cp: str, script: str) -> bool:
|
| 47 |
+
return intranges_contain(ord(cp), idnadata.scripts[script])
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _punycode(s: str) -> bytes:
|
| 51 |
+
return s.encode("punycode")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _unot(s: int) -> str:
|
| 55 |
+
return "U+{:04X}".format(s)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def valid_label_length(label: Union[bytes, str]) -> bool:
|
| 59 |
+
if len(label) > 63:
|
| 60 |
+
return False
|
| 61 |
+
return True
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def valid_string_length(label: Union[bytes, str], trailing_dot: bool) -> bool:
|
| 65 |
+
if len(label) > (254 if trailing_dot else 253):
|
| 66 |
+
return False
|
| 67 |
+
return True
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def check_bidi(label: str, check_ltr: bool = False) -> bool:
|
| 71 |
+
# Bidi rules should only be applied if string contains RTL characters
|
| 72 |
+
bidi_label = False
|
| 73 |
+
for idx, cp in enumerate(label, 1):
|
| 74 |
+
direction = unicodedata.bidirectional(cp)
|
| 75 |
+
if direction == "":
|
| 76 |
+
# String likely comes from a newer version of Unicode
|
| 77 |
+
raise IDNABidiError("Unknown directionality in label {} at position {}".format(repr(label), idx))
|
| 78 |
+
if direction in ["R", "AL", "AN"]:
|
| 79 |
+
bidi_label = True
|
| 80 |
+
if not bidi_label and not check_ltr:
|
| 81 |
+
return True
|
| 82 |
+
|
| 83 |
+
# Bidi rule 1
|
| 84 |
+
direction = unicodedata.bidirectional(label[0])
|
| 85 |
+
if direction in ["R", "AL"]:
|
| 86 |
+
rtl = True
|
| 87 |
+
elif direction == "L":
|
| 88 |
+
rtl = False
|
| 89 |
+
else:
|
| 90 |
+
raise IDNABidiError("First codepoint in label {} must be directionality L, R or AL".format(repr(label)))
|
| 91 |
+
|
| 92 |
+
valid_ending = False
|
| 93 |
+
number_type: Optional[str] = None
|
| 94 |
+
for idx, cp in enumerate(label, 1):
|
| 95 |
+
direction = unicodedata.bidirectional(cp)
|
| 96 |
+
|
| 97 |
+
if rtl:
|
| 98 |
+
# Bidi rule 2
|
| 99 |
+
if direction not in [
|
| 100 |
+
"R",
|
| 101 |
+
"AL",
|
| 102 |
+
"AN",
|
| 103 |
+
"EN",
|
| 104 |
+
"ES",
|
| 105 |
+
"CS",
|
| 106 |
+
"ET",
|
| 107 |
+
"ON",
|
| 108 |
+
"BN",
|
| 109 |
+
"NSM",
|
| 110 |
+
]:
|
| 111 |
+
raise IDNABidiError("Invalid direction for codepoint at position {} in a right-to-left label".format(idx))
|
| 112 |
+
# Bidi rule 3
|
| 113 |
+
if direction in ["R", "AL", "EN", "AN"]:
|
| 114 |
+
valid_ending = True
|
| 115 |
+
elif direction != "NSM":
|
| 116 |
+
valid_ending = False
|
| 117 |
+
# Bidi rule 4
|
| 118 |
+
if direction in ["AN", "EN"]:
|
| 119 |
+
if not number_type:
|
| 120 |
+
number_type = direction
|
| 121 |
+
else:
|
| 122 |
+
if number_type != direction:
|
| 123 |
+
raise IDNABidiError("Can not mix numeral types in a right-to-left label")
|
| 124 |
+
else:
|
| 125 |
+
# Bidi rule 5
|
| 126 |
+
if direction not in ["L", "EN", "ES", "CS", "ET", "ON", "BN", "NSM"]:
|
| 127 |
+
raise IDNABidiError("Invalid direction for codepoint at position {} in a left-to-right label".format(idx))
|
| 128 |
+
# Bidi rule 6
|
| 129 |
+
if direction in ["L", "EN"]:
|
| 130 |
+
valid_ending = True
|
| 131 |
+
elif direction != "NSM":
|
| 132 |
+
valid_ending = False
|
| 133 |
+
|
| 134 |
+
if not valid_ending:
|
| 135 |
+
raise IDNABidiError("Label ends with illegal codepoint directionality")
|
| 136 |
+
|
| 137 |
+
return True
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def check_initial_combiner(label: str) -> bool:
|
| 141 |
+
if unicodedata.category(label[0])[0] == "M":
|
| 142 |
+
raise IDNAError("Label begins with an illegal combining character")
|
| 143 |
+
return True
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def check_hyphen_ok(label: str) -> bool:
|
| 147 |
+
if label[2:4] == "--":
|
| 148 |
+
raise IDNAError("Label has disallowed hyphens in 3rd and 4th position")
|
| 149 |
+
if label[0] == "-" or label[-1] == "-":
|
| 150 |
+
raise IDNAError("Label must not start or end with a hyphen")
|
| 151 |
+
return True
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def check_nfc(label: str) -> None:
|
| 155 |
+
if unicodedata.normalize("NFC", label) != label:
|
| 156 |
+
raise IDNAError("Label must be in Normalization Form C")
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def valid_contextj(label: str, pos: int) -> bool:
|
| 160 |
+
cp_value = ord(label[pos])
|
| 161 |
+
|
| 162 |
+
if cp_value == 0x200C:
|
| 163 |
+
if pos > 0:
|
| 164 |
+
if _combining_class(ord(label[pos - 1])) == _virama_combining_class:
|
| 165 |
+
return True
|
| 166 |
+
|
| 167 |
+
ok = False
|
| 168 |
+
for i in range(pos - 1, -1, -1):
|
| 169 |
+
joining_type = idnadata.joining_types.get(ord(label[i]))
|
| 170 |
+
if joining_type == ord("T"):
|
| 171 |
+
continue
|
| 172 |
+
elif joining_type in [ord("L"), ord("D")]:
|
| 173 |
+
ok = True
|
| 174 |
+
break
|
| 175 |
+
else:
|
| 176 |
+
break
|
| 177 |
+
|
| 178 |
+
if not ok:
|
| 179 |
+
return False
|
| 180 |
+
|
| 181 |
+
ok = False
|
| 182 |
+
for i in range(pos + 1, len(label)):
|
| 183 |
+
joining_type = idnadata.joining_types.get(ord(label[i]))
|
| 184 |
+
if joining_type == ord("T"):
|
| 185 |
+
continue
|
| 186 |
+
elif joining_type in [ord("R"), ord("D")]:
|
| 187 |
+
ok = True
|
| 188 |
+
break
|
| 189 |
+
else:
|
| 190 |
+
break
|
| 191 |
+
return ok
|
| 192 |
+
|
| 193 |
+
if cp_value == 0x200D:
|
| 194 |
+
if pos > 0:
|
| 195 |
+
if _combining_class(ord(label[pos - 1])) == _virama_combining_class:
|
| 196 |
+
return True
|
| 197 |
+
return False
|
| 198 |
+
|
| 199 |
+
else:
|
| 200 |
+
return False
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def valid_contexto(label: str, pos: int, exception: bool = False) -> bool:
|
| 204 |
+
cp_value = ord(label[pos])
|
| 205 |
+
|
| 206 |
+
if cp_value == 0x00B7:
|
| 207 |
+
if 0 < pos < len(label) - 1:
|
| 208 |
+
if ord(label[pos - 1]) == 0x006C and ord(label[pos + 1]) == 0x006C:
|
| 209 |
+
return True
|
| 210 |
+
return False
|
| 211 |
+
|
| 212 |
+
elif cp_value == 0x0375:
|
| 213 |
+
if pos < len(label) - 1 and len(label) > 1:
|
| 214 |
+
return _is_script(label[pos + 1], "Greek")
|
| 215 |
+
return False
|
| 216 |
+
|
| 217 |
+
elif cp_value == 0x05F3 or cp_value == 0x05F4:
|
| 218 |
+
if pos > 0:
|
| 219 |
+
return _is_script(label[pos - 1], "Hebrew")
|
| 220 |
+
return False
|
| 221 |
+
|
| 222 |
+
elif cp_value == 0x30FB:
|
| 223 |
+
for cp in label:
|
| 224 |
+
if cp == "\u30fb":
|
| 225 |
+
continue
|
| 226 |
+
if _is_script(cp, "Hiragana") or _is_script(cp, "Katakana") or _is_script(cp, "Han"):
|
| 227 |
+
return True
|
| 228 |
+
return False
|
| 229 |
+
|
| 230 |
+
elif 0x660 <= cp_value <= 0x669:
|
| 231 |
+
for cp in label:
|
| 232 |
+
if 0x6F0 <= ord(cp) <= 0x06F9:
|
| 233 |
+
return False
|
| 234 |
+
return True
|
| 235 |
+
|
| 236 |
+
elif 0x6F0 <= cp_value <= 0x6F9:
|
| 237 |
+
for cp in label:
|
| 238 |
+
if 0x660 <= ord(cp) <= 0x0669:
|
| 239 |
+
return False
|
| 240 |
+
return True
|
| 241 |
+
|
| 242 |
+
return False
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def check_label(label: Union[str, bytes, bytearray]) -> None:
|
| 246 |
+
if isinstance(label, (bytes, bytearray)):
|
| 247 |
+
label = label.decode("utf-8")
|
| 248 |
+
if len(label) == 0:
|
| 249 |
+
raise IDNAError("Empty Label")
|
| 250 |
+
|
| 251 |
+
check_nfc(label)
|
| 252 |
+
check_hyphen_ok(label)
|
| 253 |
+
check_initial_combiner(label)
|
| 254 |
+
|
| 255 |
+
for pos, cp in enumerate(label):
|
| 256 |
+
cp_value = ord(cp)
|
| 257 |
+
if intranges_contain(cp_value, idnadata.codepoint_classes["PVALID"]):
|
| 258 |
+
continue
|
| 259 |
+
elif intranges_contain(cp_value, idnadata.codepoint_classes["CONTEXTJ"]):
|
| 260 |
+
try:
|
| 261 |
+
if not valid_contextj(label, pos):
|
| 262 |
+
raise InvalidCodepointContext(
|
| 263 |
+
"Joiner {} not allowed at position {} in {}".format(_unot(cp_value), pos + 1, repr(label))
|
| 264 |
+
)
|
| 265 |
+
except ValueError:
|
| 266 |
+
raise IDNAError(
|
| 267 |
+
"Unknown codepoint adjacent to joiner {} at position {} in {}".format(
|
| 268 |
+
_unot(cp_value), pos + 1, repr(label)
|
| 269 |
+
)
|
| 270 |
+
)
|
| 271 |
+
elif intranges_contain(cp_value, idnadata.codepoint_classes["CONTEXTO"]):
|
| 272 |
+
if not valid_contexto(label, pos):
|
| 273 |
+
raise InvalidCodepointContext(
|
| 274 |
+
"Codepoint {} not allowed at position {} in {}".format(_unot(cp_value), pos + 1, repr(label))
|
| 275 |
+
)
|
| 276 |
+
else:
|
| 277 |
+
raise InvalidCodepoint(
|
| 278 |
+
"Codepoint {} at position {} of {} not allowed".format(_unot(cp_value), pos + 1, repr(label))
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
check_bidi(label)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def alabel(label: str) -> bytes:
|
| 285 |
+
try:
|
| 286 |
+
label_bytes = label.encode("ascii")
|
| 287 |
+
ulabel(label_bytes)
|
| 288 |
+
if not valid_label_length(label_bytes):
|
| 289 |
+
raise IDNAError("Label too long")
|
| 290 |
+
return label_bytes
|
| 291 |
+
except UnicodeEncodeError:
|
| 292 |
+
pass
|
| 293 |
+
|
| 294 |
+
check_label(label)
|
| 295 |
+
label_bytes = _alabel_prefix + _punycode(label)
|
| 296 |
+
|
| 297 |
+
if not valid_label_length(label_bytes):
|
| 298 |
+
raise IDNAError("Label too long")
|
| 299 |
+
|
| 300 |
+
return label_bytes
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
def ulabel(label: Union[str, bytes, bytearray]) -> str:
|
| 304 |
+
if not isinstance(label, (bytes, bytearray)):
|
| 305 |
+
try:
|
| 306 |
+
label_bytes = label.encode("ascii")
|
| 307 |
+
except UnicodeEncodeError:
|
| 308 |
+
check_label(label)
|
| 309 |
+
return label
|
| 310 |
+
else:
|
| 311 |
+
label_bytes = bytes(label)
|
| 312 |
+
|
| 313 |
+
label_bytes = label_bytes.lower()
|
| 314 |
+
if label_bytes.startswith(_alabel_prefix):
|
| 315 |
+
label_bytes = label_bytes[len(_alabel_prefix) :]
|
| 316 |
+
if not label_bytes:
|
| 317 |
+
raise IDNAError("Malformed A-label, no Punycode eligible content found")
|
| 318 |
+
if label_bytes.decode("ascii")[-1] == "-":
|
| 319 |
+
raise IDNAError("A-label must not end with a hyphen")
|
| 320 |
+
else:
|
| 321 |
+
check_label(label_bytes)
|
| 322 |
+
return label_bytes.decode("ascii")
|
| 323 |
+
|
| 324 |
+
try:
|
| 325 |
+
label = label_bytes.decode("punycode")
|
| 326 |
+
except UnicodeError:
|
| 327 |
+
raise IDNAError("Invalid A-label")
|
| 328 |
+
check_label(label)
|
| 329 |
+
return label
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False) -> str:
|
| 333 |
+
"""Re-map the characters in the string according to UTS46 processing."""
|
| 334 |
+
from .uts46data import uts46data
|
| 335 |
+
|
| 336 |
+
output = ""
|
| 337 |
+
|
| 338 |
+
for pos, char in enumerate(domain):
|
| 339 |
+
code_point = ord(char)
|
| 340 |
+
try:
|
| 341 |
+
uts46row = uts46data[code_point if code_point < 256 else bisect.bisect_left(uts46data, (code_point, "Z")) - 1]
|
| 342 |
+
status = uts46row[1]
|
| 343 |
+
replacement: Optional[str] = None
|
| 344 |
+
if len(uts46row) == 3:
|
| 345 |
+
replacement = uts46row[2]
|
| 346 |
+
if (
|
| 347 |
+
status == "V"
|
| 348 |
+
or (status == "D" and not transitional)
|
| 349 |
+
or (status == "3" and not std3_rules and replacement is None)
|
| 350 |
+
):
|
| 351 |
+
output += char
|
| 352 |
+
elif replacement is not None and (
|
| 353 |
+
status == "M" or (status == "3" and not std3_rules) or (status == "D" and transitional)
|
| 354 |
+
):
|
| 355 |
+
output += replacement
|
| 356 |
+
elif status != "I":
|
| 357 |
+
raise IndexError()
|
| 358 |
+
except IndexError:
|
| 359 |
+
raise InvalidCodepoint(
|
| 360 |
+
"Codepoint {} not allowed at position {} in {}".format(_unot(code_point), pos + 1, repr(domain))
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
return unicodedata.normalize("NFC", output)
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def encode(
|
| 367 |
+
s: Union[str, bytes, bytearray],
|
| 368 |
+
strict: bool = False,
|
| 369 |
+
uts46: bool = False,
|
| 370 |
+
std3_rules: bool = False,
|
| 371 |
+
transitional: bool = False,
|
| 372 |
+
) -> bytes:
|
| 373 |
+
if not isinstance(s, str):
|
| 374 |
+
try:
|
| 375 |
+
s = str(s, "ascii")
|
| 376 |
+
except UnicodeDecodeError:
|
| 377 |
+
raise IDNAError("should pass a unicode string to the function rather than a byte string.")
|
| 378 |
+
if uts46:
|
| 379 |
+
s = uts46_remap(s, std3_rules, transitional)
|
| 380 |
+
trailing_dot = False
|
| 381 |
+
result = []
|
| 382 |
+
if strict:
|
| 383 |
+
labels = s.split(".")
|
| 384 |
+
else:
|
| 385 |
+
labels = _unicode_dots_re.split(s)
|
| 386 |
+
if not labels or labels == [""]:
|
| 387 |
+
raise IDNAError("Empty domain")
|
| 388 |
+
if labels[-1] == "":
|
| 389 |
+
del labels[-1]
|
| 390 |
+
trailing_dot = True
|
| 391 |
+
for label in labels:
|
| 392 |
+
s = alabel(label)
|
| 393 |
+
if s:
|
| 394 |
+
result.append(s)
|
| 395 |
+
else:
|
| 396 |
+
raise IDNAError("Empty label")
|
| 397 |
+
if trailing_dot:
|
| 398 |
+
result.append(b"")
|
| 399 |
+
s = b".".join(result)
|
| 400 |
+
if not valid_string_length(s, trailing_dot):
|
| 401 |
+
raise IDNAError("Domain too long")
|
| 402 |
+
return s
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def decode(
|
| 406 |
+
s: Union[str, bytes, bytearray],
|
| 407 |
+
strict: bool = False,
|
| 408 |
+
uts46: bool = False,
|
| 409 |
+
std3_rules: bool = False,
|
| 410 |
+
) -> str:
|
| 411 |
+
try:
|
| 412 |
+
if not isinstance(s, str):
|
| 413 |
+
s = str(s, "ascii")
|
| 414 |
+
except UnicodeDecodeError:
|
| 415 |
+
raise IDNAError("Invalid ASCII in A-label")
|
| 416 |
+
if uts46:
|
| 417 |
+
s = uts46_remap(s, std3_rules, False)
|
| 418 |
+
trailing_dot = False
|
| 419 |
+
result = []
|
| 420 |
+
if not strict:
|
| 421 |
+
labels = _unicode_dots_re.split(s)
|
| 422 |
+
else:
|
| 423 |
+
labels = s.split(".")
|
| 424 |
+
if not labels or labels == [""]:
|
| 425 |
+
raise IDNAError("Empty domain")
|
| 426 |
+
if not labels[-1]:
|
| 427 |
+
del labels[-1]
|
| 428 |
+
trailing_dot = True
|
| 429 |
+
for label in labels:
|
| 430 |
+
s = ulabel(label)
|
| 431 |
+
if s:
|
| 432 |
+
result.append(s)
|
| 433 |
+
else:
|
| 434 |
+
raise IDNAError("Empty label")
|
| 435 |
+
if trailing_dot:
|
| 436 |
+
result.append("")
|
| 437 |
+
return ".".join(result)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/idnadata.py
ADDED
|
@@ -0,0 +1,4309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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automatically generated by tools/idna-data
|
| 2 |
+
|
| 3 |
+
__version__ = "16.0.0"
|
| 4 |
+
|
| 5 |
+
scripts = {
|
| 6 |
+
"Greek": (
|
| 7 |
+
0x37000000374,
|
| 8 |
+
0x37500000378,
|
| 9 |
+
0x37A0000037E,
|
| 10 |
+
0x37F00000380,
|
| 11 |
+
0x38400000385,
|
| 12 |
+
0x38600000387,
|
| 13 |
+
0x3880000038B,
|
| 14 |
+
0x38C0000038D,
|
| 15 |
+
0x38E000003A2,
|
| 16 |
+
0x3A3000003E2,
|
| 17 |
+
0x3F000000400,
|
| 18 |
+
0x1D2600001D2B,
|
| 19 |
+
0x1D5D00001D62,
|
| 20 |
+
0x1D6600001D6B,
|
| 21 |
+
0x1DBF00001DC0,
|
| 22 |
+
0x1F0000001F16,
|
| 23 |
+
0x1F1800001F1E,
|
| 24 |
+
0x1F2000001F46,
|
| 25 |
+
0x1F4800001F4E,
|
| 26 |
+
0x1F5000001F58,
|
| 27 |
+
0x1F5900001F5A,
|
| 28 |
+
0x1F5B00001F5C,
|
| 29 |
+
0x1F5D00001F5E,
|
| 30 |
+
0x1F5F00001F7E,
|
| 31 |
+
0x1F8000001FB5,
|
| 32 |
+
0x1FB600001FC5,
|
| 33 |
+
0x1FC600001FD4,
|
| 34 |
+
0x1FD600001FDC,
|
| 35 |
+
0x1FDD00001FF0,
|
| 36 |
+
0x1FF200001FF5,
|
| 37 |
+
0x1FF600001FFF,
|
| 38 |
+
0x212600002127,
|
| 39 |
+
0xAB650000AB66,
|
| 40 |
+
0x101400001018F,
|
| 41 |
+
0x101A0000101A1,
|
| 42 |
+
0x1D2000001D246,
|
| 43 |
+
),
|
| 44 |
+
"Han": (
|
| 45 |
+
0x2E8000002E9A,
|
| 46 |
+
0x2E9B00002EF4,
|
| 47 |
+
0x2F0000002FD6,
|
| 48 |
+
0x300500003006,
|
| 49 |
+
0x300700003008,
|
| 50 |
+
0x30210000302A,
|
| 51 |
+
0x30380000303C,
|
| 52 |
+
0x340000004DC0,
|
| 53 |
+
0x4E000000A000,
|
| 54 |
+
0xF9000000FA6E,
|
| 55 |
+
0xFA700000FADA,
|
| 56 |
+
0x16FE200016FE4,
|
| 57 |
+
0x16FF000016FF2,
|
| 58 |
+
0x200000002A6E0,
|
| 59 |
+
0x2A7000002B73A,
|
| 60 |
+
0x2B7400002B81E,
|
| 61 |
+
0x2B8200002CEA2,
|
| 62 |
+
0x2CEB00002EBE1,
|
| 63 |
+
0x2EBF00002EE5E,
|
| 64 |
+
0x2F8000002FA1E,
|
| 65 |
+
0x300000003134B,
|
| 66 |
+
0x31350000323B0,
|
| 67 |
+
),
|
| 68 |
+
"Hebrew": (
|
| 69 |
+
0x591000005C8,
|
| 70 |
+
0x5D0000005EB,
|
| 71 |
+
0x5EF000005F5,
|
| 72 |
+
0xFB1D0000FB37,
|
| 73 |
+
0xFB380000FB3D,
|
| 74 |
+
0xFB3E0000FB3F,
|
| 75 |
+
0xFB400000FB42,
|
| 76 |
+
0xFB430000FB45,
|
| 77 |
+
0xFB460000FB50,
|
| 78 |
+
),
|
| 79 |
+
"Hiragana": (
|
| 80 |
+
0x304100003097,
|
| 81 |
+
0x309D000030A0,
|
| 82 |
+
0x1B0010001B120,
|
| 83 |
+
0x1B1320001B133,
|
| 84 |
+
0x1B1500001B153,
|
| 85 |
+
0x1F2000001F201,
|
| 86 |
+
),
|
| 87 |
+
"Katakana": (
|
| 88 |
+
0x30A1000030FB,
|
| 89 |
+
0x30FD00003100,
|
| 90 |
+
0x31F000003200,
|
| 91 |
+
0x32D0000032FF,
|
| 92 |
+
0x330000003358,
|
| 93 |
+
0xFF660000FF70,
|
| 94 |
+
0xFF710000FF9E,
|
| 95 |
+
0x1AFF00001AFF4,
|
| 96 |
+
0x1AFF50001AFFC,
|
| 97 |
+
0x1AFFD0001AFFF,
|
| 98 |
+
0x1B0000001B001,
|
| 99 |
+
0x1B1200001B123,
|
| 100 |
+
0x1B1550001B156,
|
| 101 |
+
0x1B1640001B168,
|
| 102 |
+
),
|
| 103 |
+
}
|
| 104 |
+
joining_types = {
|
| 105 |
+
0xAD: 84,
|
| 106 |
+
0x300: 84,
|
| 107 |
+
0x301: 84,
|
| 108 |
+
0x302: 84,
|
| 109 |
+
0x303: 84,
|
| 110 |
+
0x304: 84,
|
| 111 |
+
0x305: 84,
|
| 112 |
+
0x306: 84,
|
| 113 |
+
0x307: 84,
|
| 114 |
+
0x308: 84,
|
| 115 |
+
0x309: 84,
|
| 116 |
+
0x30A: 84,
|
| 117 |
+
0x30B: 84,
|
| 118 |
+
0x30C: 84,
|
| 119 |
+
0x30D: 84,
|
| 120 |
+
0x30E: 84,
|
| 121 |
+
0x30F: 84,
|
| 122 |
+
0x310: 84,
|
| 123 |
+
0x311: 84,
|
| 124 |
+
0x312: 84,
|
| 125 |
+
0x313: 84,
|
| 126 |
+
0x314: 84,
|
| 127 |
+
0x315: 84,
|
| 128 |
+
0x316: 84,
|
| 129 |
+
0x317: 84,
|
| 130 |
+
0x318: 84,
|
| 131 |
+
0x319: 84,
|
| 132 |
+
0x31A: 84,
|
| 133 |
+
0x31B: 84,
|
| 134 |
+
0x31C: 84,
|
| 135 |
+
0x31D: 84,
|
| 136 |
+
0x31E: 84,
|
| 137 |
+
0x31F: 84,
|
| 138 |
+
0x320: 84,
|
| 139 |
+
0x321: 84,
|
| 140 |
+
0x322: 84,
|
| 141 |
+
0x323: 84,
|
| 142 |
+
0x324: 84,
|
| 143 |
+
0x325: 84,
|
| 144 |
+
0x326: 84,
|
| 145 |
+
0x327: 84,
|
| 146 |
+
0x328: 84,
|
| 147 |
+
0x329: 84,
|
| 148 |
+
0x32A: 84,
|
| 149 |
+
0x32B: 84,
|
| 150 |
+
0x32C: 84,
|
| 151 |
+
0x32D: 84,
|
| 152 |
+
0x32E: 84,
|
| 153 |
+
0x32F: 84,
|
| 154 |
+
0x330: 84,
|
| 155 |
+
0x331: 84,
|
| 156 |
+
0x332: 84,
|
| 157 |
+
0x333: 84,
|
| 158 |
+
0x334: 84,
|
| 159 |
+
0x335: 84,
|
| 160 |
+
0x336: 84,
|
| 161 |
+
0x337: 84,
|
| 162 |
+
0x338: 84,
|
| 163 |
+
0x339: 84,
|
| 164 |
+
0x33A: 84,
|
| 165 |
+
0x33B: 84,
|
| 166 |
+
0x33C: 84,
|
| 167 |
+
0x33D: 84,
|
| 168 |
+
0x33E: 84,
|
| 169 |
+
0x33F: 84,
|
| 170 |
+
0x340: 84,
|
| 171 |
+
0x341: 84,
|
| 172 |
+
0x342: 84,
|
| 173 |
+
0x343: 84,
|
| 174 |
+
0x344: 84,
|
| 175 |
+
0x345: 84,
|
| 176 |
+
0x346: 84,
|
| 177 |
+
0x347: 84,
|
| 178 |
+
0x348: 84,
|
| 179 |
+
0x349: 84,
|
| 180 |
+
0x34A: 84,
|
| 181 |
+
0x34B: 84,
|
| 182 |
+
0x34C: 84,
|
| 183 |
+
0x34D: 84,
|
| 184 |
+
0x34E: 84,
|
| 185 |
+
0x34F: 84,
|
| 186 |
+
0x350: 84,
|
| 187 |
+
0x351: 84,
|
| 188 |
+
0x352: 84,
|
| 189 |
+
0x353: 84,
|
| 190 |
+
0x354: 84,
|
| 191 |
+
0x355: 84,
|
| 192 |
+
0x356: 84,
|
| 193 |
+
0x357: 84,
|
| 194 |
+
0x358: 84,
|
| 195 |
+
0x359: 84,
|
| 196 |
+
0x35A: 84,
|
| 197 |
+
0x35B: 84,
|
| 198 |
+
0x35C: 84,
|
| 199 |
+
0x35D: 84,
|
| 200 |
+
0x35E: 84,
|
| 201 |
+
0x35F: 84,
|
| 202 |
+
0x360: 84,
|
| 203 |
+
0x361: 84,
|
| 204 |
+
0x362: 84,
|
| 205 |
+
0x363: 84,
|
| 206 |
+
0x364: 84,
|
| 207 |
+
0x365: 84,
|
| 208 |
+
0x366: 84,
|
| 209 |
+
0x367: 84,
|
| 210 |
+
0x368: 84,
|
| 211 |
+
0x369: 84,
|
| 212 |
+
0x36A: 84,
|
| 213 |
+
0x36B: 84,
|
| 214 |
+
0x36C: 84,
|
| 215 |
+
0x36D: 84,
|
| 216 |
+
0x36E: 84,
|
| 217 |
+
0x36F: 84,
|
| 218 |
+
0x483: 84,
|
| 219 |
+
0x484: 84,
|
| 220 |
+
0x485: 84,
|
| 221 |
+
0x486: 84,
|
| 222 |
+
0x487: 84,
|
| 223 |
+
0x488: 84,
|
| 224 |
+
0x489: 84,
|
| 225 |
+
0x591: 84,
|
| 226 |
+
0x592: 84,
|
| 227 |
+
0x593: 84,
|
| 228 |
+
0x594: 84,
|
| 229 |
+
0x595: 84,
|
| 230 |
+
0x596: 84,
|
| 231 |
+
0x597: 84,
|
| 232 |
+
0x598: 84,
|
| 233 |
+
0x599: 84,
|
| 234 |
+
0x59A: 84,
|
| 235 |
+
0x59B: 84,
|
| 236 |
+
0x59C: 84,
|
| 237 |
+
0x59D: 84,
|
| 238 |
+
0x59E: 84,
|
| 239 |
+
0x59F: 84,
|
| 240 |
+
0x5A0: 84,
|
| 241 |
+
0x5A1: 84,
|
| 242 |
+
0x5A2: 84,
|
| 243 |
+
0x5A3: 84,
|
| 244 |
+
0x5A4: 84,
|
| 245 |
+
0x5A5: 84,
|
| 246 |
+
0x5A6: 84,
|
| 247 |
+
0x5A7: 84,
|
| 248 |
+
0x5A8: 84,
|
| 249 |
+
0x5A9: 84,
|
| 250 |
+
0x5AA: 84,
|
| 251 |
+
0x5AB: 84,
|
| 252 |
+
0x5AC: 84,
|
| 253 |
+
0x5AD: 84,
|
| 254 |
+
0x5AE: 84,
|
| 255 |
+
0x5AF: 84,
|
| 256 |
+
0x5B0: 84,
|
| 257 |
+
0x5B1: 84,
|
| 258 |
+
0x5B2: 84,
|
| 259 |
+
0x5B3: 84,
|
| 260 |
+
0x5B4: 84,
|
| 261 |
+
0x5B5: 84,
|
| 262 |
+
0x5B6: 84,
|
| 263 |
+
0x5B7: 84,
|
| 264 |
+
0x5B8: 84,
|
| 265 |
+
0x5B9: 84,
|
| 266 |
+
0x5BA: 84,
|
| 267 |
+
0x5BB: 84,
|
| 268 |
+
0x5BC: 84,
|
| 269 |
+
0x5BD: 84,
|
| 270 |
+
0x5BF: 84,
|
| 271 |
+
0x5C1: 84,
|
| 272 |
+
0x5C2: 84,
|
| 273 |
+
0x5C4: 84,
|
| 274 |
+
0x5C5: 84,
|
| 275 |
+
0x5C7: 84,
|
| 276 |
+
0x610: 84,
|
| 277 |
+
0x611: 84,
|
| 278 |
+
0x612: 84,
|
| 279 |
+
0x613: 84,
|
| 280 |
+
0x614: 84,
|
| 281 |
+
0x615: 84,
|
| 282 |
+
0x616: 84,
|
| 283 |
+
0x617: 84,
|
| 284 |
+
0x618: 84,
|
| 285 |
+
0x619: 84,
|
| 286 |
+
0x61A: 84,
|
| 287 |
+
0x61C: 84,
|
| 288 |
+
0x620: 68,
|
| 289 |
+
0x622: 82,
|
| 290 |
+
0x623: 82,
|
| 291 |
+
0x624: 82,
|
| 292 |
+
0x625: 82,
|
| 293 |
+
0x626: 68,
|
| 294 |
+
0x627: 82,
|
| 295 |
+
0x628: 68,
|
| 296 |
+
0x629: 82,
|
| 297 |
+
0x62A: 68,
|
| 298 |
+
0x62B: 68,
|
| 299 |
+
0x62C: 68,
|
| 300 |
+
0x62D: 68,
|
| 301 |
+
0x62E: 68,
|
| 302 |
+
0x62F: 82,
|
| 303 |
+
0x630: 82,
|
| 304 |
+
0x631: 82,
|
| 305 |
+
0x632: 82,
|
| 306 |
+
0x633: 68,
|
| 307 |
+
0x634: 68,
|
| 308 |
+
0x635: 68,
|
| 309 |
+
0x636: 68,
|
| 310 |
+
0x637: 68,
|
| 311 |
+
0x638: 68,
|
| 312 |
+
0x639: 68,
|
| 313 |
+
0x63A: 68,
|
| 314 |
+
0x63B: 68,
|
| 315 |
+
0x63C: 68,
|
| 316 |
+
0x63D: 68,
|
| 317 |
+
0x63E: 68,
|
| 318 |
+
0x63F: 68,
|
| 319 |
+
0x640: 67,
|
| 320 |
+
0x641: 68,
|
| 321 |
+
0x642: 68,
|
| 322 |
+
0x643: 68,
|
| 323 |
+
0x644: 68,
|
| 324 |
+
0x645: 68,
|
| 325 |
+
0x646: 68,
|
| 326 |
+
0x647: 68,
|
| 327 |
+
0x648: 82,
|
| 328 |
+
0x649: 68,
|
| 329 |
+
0x64A: 68,
|
| 330 |
+
0x64B: 84,
|
| 331 |
+
0x64C: 84,
|
| 332 |
+
0x64D: 84,
|
| 333 |
+
0x64E: 84,
|
| 334 |
+
0x64F: 84,
|
| 335 |
+
0x650: 84,
|
| 336 |
+
0x651: 84,
|
| 337 |
+
0x652: 84,
|
| 338 |
+
0x653: 84,
|
| 339 |
+
0x654: 84,
|
| 340 |
+
0x655: 84,
|
| 341 |
+
0x656: 84,
|
| 342 |
+
0x657: 84,
|
| 343 |
+
0x658: 84,
|
| 344 |
+
0x659: 84,
|
| 345 |
+
0x65A: 84,
|
| 346 |
+
0x65B: 84,
|
| 347 |
+
0x65C: 84,
|
| 348 |
+
0x65D: 84,
|
| 349 |
+
0x65E: 84,
|
| 350 |
+
0x65F: 84,
|
| 351 |
+
0x66E: 68,
|
| 352 |
+
0x66F: 68,
|
| 353 |
+
0x670: 84,
|
| 354 |
+
0x671: 82,
|
| 355 |
+
0x672: 82,
|
| 356 |
+
0x673: 82,
|
| 357 |
+
0x675: 82,
|
| 358 |
+
0x676: 82,
|
| 359 |
+
0x677: 82,
|
| 360 |
+
0x678: 68,
|
| 361 |
+
0x679: 68,
|
| 362 |
+
0x67A: 68,
|
| 363 |
+
0x67B: 68,
|
| 364 |
+
0x67C: 68,
|
| 365 |
+
0x67D: 68,
|
| 366 |
+
0x67E: 68,
|
| 367 |
+
0x67F: 68,
|
| 368 |
+
0x680: 68,
|
| 369 |
+
0x681: 68,
|
| 370 |
+
0x682: 68,
|
| 371 |
+
0x683: 68,
|
| 372 |
+
0x684: 68,
|
| 373 |
+
0x685: 68,
|
| 374 |
+
0x686: 68,
|
| 375 |
+
0x687: 68,
|
| 376 |
+
0x688: 82,
|
| 377 |
+
0x689: 82,
|
| 378 |
+
0x68A: 82,
|
| 379 |
+
0x68B: 82,
|
| 380 |
+
0x68C: 82,
|
| 381 |
+
0x68D: 82,
|
| 382 |
+
0x68E: 82,
|
| 383 |
+
0x68F: 82,
|
| 384 |
+
0x690: 82,
|
| 385 |
+
0x691: 82,
|
| 386 |
+
0x692: 82,
|
| 387 |
+
0x693: 82,
|
| 388 |
+
0x694: 82,
|
| 389 |
+
0x695: 82,
|
| 390 |
+
0x696: 82,
|
| 391 |
+
0x697: 82,
|
| 392 |
+
0x698: 82,
|
| 393 |
+
0x699: 82,
|
| 394 |
+
0x69A: 68,
|
| 395 |
+
0x69B: 68,
|
| 396 |
+
0x69C: 68,
|
| 397 |
+
0x69D: 68,
|
| 398 |
+
0x69E: 68,
|
| 399 |
+
0x69F: 68,
|
| 400 |
+
0x6A0: 68,
|
| 401 |
+
0x6A1: 68,
|
| 402 |
+
0x6A2: 68,
|
| 403 |
+
0x6A3: 68,
|
| 404 |
+
0x6A4: 68,
|
| 405 |
+
0x6A5: 68,
|
| 406 |
+
0x6A6: 68,
|
| 407 |
+
0x6A7: 68,
|
| 408 |
+
0x6A8: 68,
|
| 409 |
+
0x6A9: 68,
|
| 410 |
+
0x6AA: 68,
|
| 411 |
+
0x6AB: 68,
|
| 412 |
+
0x6AC: 68,
|
| 413 |
+
0x6AD: 68,
|
| 414 |
+
0x6AE: 68,
|
| 415 |
+
0x6AF: 68,
|
| 416 |
+
0x6B0: 68,
|
| 417 |
+
0x6B1: 68,
|
| 418 |
+
0x6B2: 68,
|
| 419 |
+
0x6B3: 68,
|
| 420 |
+
0x6B4: 68,
|
| 421 |
+
0x6B5: 68,
|
| 422 |
+
0x6B6: 68,
|
| 423 |
+
0x6B7: 68,
|
| 424 |
+
0x6B8: 68,
|
| 425 |
+
0x6B9: 68,
|
| 426 |
+
0x6BA: 68,
|
| 427 |
+
0x6BB: 68,
|
| 428 |
+
0x6BC: 68,
|
| 429 |
+
0x6BD: 68,
|
| 430 |
+
0x6BE: 68,
|
| 431 |
+
0x6BF: 68,
|
| 432 |
+
0x6C0: 82,
|
| 433 |
+
0x6C1: 68,
|
| 434 |
+
0x6C2: 68,
|
| 435 |
+
0x6C3: 82,
|
| 436 |
+
0x6C4: 82,
|
| 437 |
+
0x6C5: 82,
|
| 438 |
+
0x6C6: 82,
|
| 439 |
+
0x6C7: 82,
|
| 440 |
+
0x6C8: 82,
|
| 441 |
+
0x6C9: 82,
|
| 442 |
+
0x6CA: 82,
|
| 443 |
+
0x6CB: 82,
|
| 444 |
+
0x6CC: 68,
|
| 445 |
+
0x6CD: 82,
|
| 446 |
+
0x6CE: 68,
|
| 447 |
+
0x6CF: 82,
|
| 448 |
+
0x6D0: 68,
|
| 449 |
+
0x6D1: 68,
|
| 450 |
+
0x6D2: 82,
|
| 451 |
+
0x6D3: 82,
|
| 452 |
+
0x6D5: 82,
|
| 453 |
+
0x6D6: 84,
|
| 454 |
+
0x6D7: 84,
|
| 455 |
+
0x6D8: 84,
|
| 456 |
+
0x6D9: 84,
|
| 457 |
+
0x6DA: 84,
|
| 458 |
+
0x6DB: 84,
|
| 459 |
+
0x6DC: 84,
|
| 460 |
+
0x6DF: 84,
|
| 461 |
+
0x6E0: 84,
|
| 462 |
+
0x6E1: 84,
|
| 463 |
+
0x6E2: 84,
|
| 464 |
+
0x6E3: 84,
|
| 465 |
+
0x6E4: 84,
|
| 466 |
+
0x6E7: 84,
|
| 467 |
+
0x6E8: 84,
|
| 468 |
+
0x6EA: 84,
|
| 469 |
+
0x6EB: 84,
|
| 470 |
+
0x6EC: 84,
|
| 471 |
+
0x6ED: 84,
|
| 472 |
+
0x6EE: 82,
|
| 473 |
+
0x6EF: 82,
|
| 474 |
+
0x6FA: 68,
|
| 475 |
+
0x6FB: 68,
|
| 476 |
+
0x6FC: 68,
|
| 477 |
+
0x6FF: 68,
|
| 478 |
+
0x70F: 84,
|
| 479 |
+
0x710: 82,
|
| 480 |
+
0x711: 84,
|
| 481 |
+
0x712: 68,
|
| 482 |
+
0x713: 68,
|
| 483 |
+
0x714: 68,
|
| 484 |
+
0x715: 82,
|
| 485 |
+
0x716: 82,
|
| 486 |
+
0x717: 82,
|
| 487 |
+
0x718: 82,
|
| 488 |
+
0x719: 82,
|
| 489 |
+
0x71A: 68,
|
| 490 |
+
0x71B: 68,
|
| 491 |
+
0x71C: 68,
|
| 492 |
+
0x71D: 68,
|
| 493 |
+
0x71E: 82,
|
| 494 |
+
0x71F: 68,
|
| 495 |
+
0x720: 68,
|
| 496 |
+
0x721: 68,
|
| 497 |
+
0x722: 68,
|
| 498 |
+
0x723: 68,
|
| 499 |
+
0x724: 68,
|
| 500 |
+
0x725: 68,
|
| 501 |
+
0x726: 68,
|
| 502 |
+
0x727: 68,
|
| 503 |
+
0x728: 82,
|
| 504 |
+
0x729: 68,
|
| 505 |
+
0x72A: 82,
|
| 506 |
+
0x72B: 68,
|
| 507 |
+
0x72C: 82,
|
| 508 |
+
0x72D: 68,
|
| 509 |
+
0x72E: 68,
|
| 510 |
+
0x72F: 82,
|
| 511 |
+
0x730: 84,
|
| 512 |
+
0x731: 84,
|
| 513 |
+
0x732: 84,
|
| 514 |
+
0x733: 84,
|
| 515 |
+
0x734: 84,
|
| 516 |
+
0x735: 84,
|
| 517 |
+
0x736: 84,
|
| 518 |
+
0x737: 84,
|
| 519 |
+
0x738: 84,
|
| 520 |
+
0x739: 84,
|
| 521 |
+
0x73A: 84,
|
| 522 |
+
0x73B: 84,
|
| 523 |
+
0x73C: 84,
|
| 524 |
+
0x73D: 84,
|
| 525 |
+
0x73E: 84,
|
| 526 |
+
0x73F: 84,
|
| 527 |
+
0x740: 84,
|
| 528 |
+
0x741: 84,
|
| 529 |
+
0x742: 84,
|
| 530 |
+
0x743: 84,
|
| 531 |
+
0x744: 84,
|
| 532 |
+
0x745: 84,
|
| 533 |
+
0x746: 84,
|
| 534 |
+
0x747: 84,
|
| 535 |
+
0x748: 84,
|
| 536 |
+
0x749: 84,
|
| 537 |
+
0x74A: 84,
|
| 538 |
+
0x74D: 82,
|
| 539 |
+
0x74E: 68,
|
| 540 |
+
0x74F: 68,
|
| 541 |
+
0x750: 68,
|
| 542 |
+
0x751: 68,
|
| 543 |
+
0x752: 68,
|
| 544 |
+
0x753: 68,
|
| 545 |
+
0x754: 68,
|
| 546 |
+
0x755: 68,
|
| 547 |
+
0x756: 68,
|
| 548 |
+
0x757: 68,
|
| 549 |
+
0x758: 68,
|
| 550 |
+
0x759: 82,
|
| 551 |
+
0x75A: 82,
|
| 552 |
+
0x75B: 82,
|
| 553 |
+
0x75C: 68,
|
| 554 |
+
0x75D: 68,
|
| 555 |
+
0x75E: 68,
|
| 556 |
+
0x75F: 68,
|
| 557 |
+
0x760: 68,
|
| 558 |
+
0x761: 68,
|
| 559 |
+
0x762: 68,
|
| 560 |
+
0x763: 68,
|
| 561 |
+
0x764: 68,
|
| 562 |
+
0x765: 68,
|
| 563 |
+
0x766: 68,
|
| 564 |
+
0x767: 68,
|
| 565 |
+
0x768: 68,
|
| 566 |
+
0x769: 68,
|
| 567 |
+
0x76A: 68,
|
| 568 |
+
0x76B: 82,
|
| 569 |
+
0x76C: 82,
|
| 570 |
+
0x76D: 68,
|
| 571 |
+
0x76E: 68,
|
| 572 |
+
0x76F: 68,
|
| 573 |
+
0x770: 68,
|
| 574 |
+
0x771: 82,
|
| 575 |
+
0x772: 68,
|
| 576 |
+
0x773: 82,
|
| 577 |
+
0x774: 82,
|
| 578 |
+
0x775: 68,
|
| 579 |
+
0x776: 68,
|
| 580 |
+
0x777: 68,
|
| 581 |
+
0x778: 82,
|
| 582 |
+
0x779: 82,
|
| 583 |
+
0x77A: 68,
|
| 584 |
+
0x77B: 68,
|
| 585 |
+
0x77C: 68,
|
| 586 |
+
0x77D: 68,
|
| 587 |
+
0x77E: 68,
|
| 588 |
+
0x77F: 68,
|
| 589 |
+
0x7A6: 84,
|
| 590 |
+
0x7A7: 84,
|
| 591 |
+
0x7A8: 84,
|
| 592 |
+
0x7A9: 84,
|
| 593 |
+
0x7AA: 84,
|
| 594 |
+
0x7AB: 84,
|
| 595 |
+
0x7AC: 84,
|
| 596 |
+
0x7AD: 84,
|
| 597 |
+
0x7AE: 84,
|
| 598 |
+
0x7AF: 84,
|
| 599 |
+
0x7B0: 84,
|
| 600 |
+
0x7CA: 68,
|
| 601 |
+
0x7CB: 68,
|
| 602 |
+
0x7CC: 68,
|
| 603 |
+
0x7CD: 68,
|
| 604 |
+
0x7CE: 68,
|
| 605 |
+
0x7CF: 68,
|
| 606 |
+
0x7D0: 68,
|
| 607 |
+
0x7D1: 68,
|
| 608 |
+
0x7D2: 68,
|
| 609 |
+
0x7D3: 68,
|
| 610 |
+
0x7D4: 68,
|
| 611 |
+
0x7D5: 68,
|
| 612 |
+
0x7D6: 68,
|
| 613 |
+
0x7D7: 68,
|
| 614 |
+
0x7D8: 68,
|
| 615 |
+
0x7D9: 68,
|
| 616 |
+
0x7DA: 68,
|
| 617 |
+
0x7DB: 68,
|
| 618 |
+
0x7DC: 68,
|
| 619 |
+
0x7DD: 68,
|
| 620 |
+
0x7DE: 68,
|
| 621 |
+
0x7DF: 68,
|
| 622 |
+
0x7E0: 68,
|
| 623 |
+
0x7E1: 68,
|
| 624 |
+
0x7E2: 68,
|
| 625 |
+
0x7E3: 68,
|
| 626 |
+
0x7E4: 68,
|
| 627 |
+
0x7E5: 68,
|
| 628 |
+
0x7E6: 68,
|
| 629 |
+
0x7E7: 68,
|
| 630 |
+
0x7E8: 68,
|
| 631 |
+
0x7E9: 68,
|
| 632 |
+
0x7EA: 68,
|
| 633 |
+
0x7EB: 84,
|
| 634 |
+
0x7EC: 84,
|
| 635 |
+
0x7ED: 84,
|
| 636 |
+
0x7EE: 84,
|
| 637 |
+
0x7EF: 84,
|
| 638 |
+
0x7F0: 84,
|
| 639 |
+
0x7F1: 84,
|
| 640 |
+
0x7F2: 84,
|
| 641 |
+
0x7F3: 84,
|
| 642 |
+
0x7FA: 67,
|
| 643 |
+
0x7FD: 84,
|
| 644 |
+
0x816: 84,
|
| 645 |
+
0x817: 84,
|
| 646 |
+
0x818: 84,
|
| 647 |
+
0x819: 84,
|
| 648 |
+
0x81B: 84,
|
| 649 |
+
0x81C: 84,
|
| 650 |
+
0x81D: 84,
|
| 651 |
+
0x81E: 84,
|
| 652 |
+
0x81F: 84,
|
| 653 |
+
0x820: 84,
|
| 654 |
+
0x821: 84,
|
| 655 |
+
0x822: 84,
|
| 656 |
+
0x823: 84,
|
| 657 |
+
0x825: 84,
|
| 658 |
+
0x826: 84,
|
| 659 |
+
0x827: 84,
|
| 660 |
+
0x829: 84,
|
| 661 |
+
0x82A: 84,
|
| 662 |
+
0x82B: 84,
|
| 663 |
+
0x82C: 84,
|
| 664 |
+
0x82D: 84,
|
| 665 |
+
0x840: 82,
|
| 666 |
+
0x841: 68,
|
| 667 |
+
0x842: 68,
|
| 668 |
+
0x843: 68,
|
| 669 |
+
0x844: 68,
|
| 670 |
+
0x845: 68,
|
| 671 |
+
0x846: 82,
|
| 672 |
+
0x847: 82,
|
| 673 |
+
0x848: 68,
|
| 674 |
+
0x849: 82,
|
| 675 |
+
0x84A: 68,
|
| 676 |
+
0x84B: 68,
|
| 677 |
+
0x84C: 68,
|
| 678 |
+
0x84D: 68,
|
| 679 |
+
0x84E: 68,
|
| 680 |
+
0x84F: 68,
|
| 681 |
+
0x850: 68,
|
| 682 |
+
0x851: 68,
|
| 683 |
+
0x852: 68,
|
| 684 |
+
0x853: 68,
|
| 685 |
+
0x854: 82,
|
| 686 |
+
0x855: 68,
|
| 687 |
+
0x856: 82,
|
| 688 |
+
0x857: 82,
|
| 689 |
+
0x858: 82,
|
| 690 |
+
0x859: 84,
|
| 691 |
+
0x85A: 84,
|
| 692 |
+
0x85B: 84,
|
| 693 |
+
0x860: 68,
|
| 694 |
+
0x862: 68,
|
| 695 |
+
0x863: 68,
|
| 696 |
+
0x864: 68,
|
| 697 |
+
0x865: 68,
|
| 698 |
+
0x867: 82,
|
| 699 |
+
0x868: 68,
|
| 700 |
+
0x869: 82,
|
| 701 |
+
0x86A: 82,
|
| 702 |
+
0x870: 82,
|
| 703 |
+
0x871: 82,
|
| 704 |
+
0x872: 82,
|
| 705 |
+
0x873: 82,
|
| 706 |
+
0x874: 82,
|
| 707 |
+
0x875: 82,
|
| 708 |
+
0x876: 82,
|
| 709 |
+
0x877: 82,
|
| 710 |
+
0x878: 82,
|
| 711 |
+
0x879: 82,
|
| 712 |
+
0x87A: 82,
|
| 713 |
+
0x87B: 82,
|
| 714 |
+
0x87C: 82,
|
| 715 |
+
0x87D: 82,
|
| 716 |
+
0x87E: 82,
|
| 717 |
+
0x87F: 82,
|
| 718 |
+
0x880: 82,
|
| 719 |
+
0x881: 82,
|
| 720 |
+
0x882: 82,
|
| 721 |
+
0x883: 67,
|
| 722 |
+
0x884: 67,
|
| 723 |
+
0x885: 67,
|
| 724 |
+
0x886: 68,
|
| 725 |
+
0x889: 68,
|
| 726 |
+
0x88A: 68,
|
| 727 |
+
0x88B: 68,
|
| 728 |
+
0x88C: 68,
|
| 729 |
+
0x88D: 68,
|
| 730 |
+
0x88E: 82,
|
| 731 |
+
0x897: 84,
|
| 732 |
+
0x898: 84,
|
| 733 |
+
0x899: 84,
|
| 734 |
+
0x89A: 84,
|
| 735 |
+
0x89B: 84,
|
| 736 |
+
0x89C: 84,
|
| 737 |
+
0x89D: 84,
|
| 738 |
+
0x89E: 84,
|
| 739 |
+
0x89F: 84,
|
| 740 |
+
0x8A0: 68,
|
| 741 |
+
0x8A1: 68,
|
| 742 |
+
0x8A2: 68,
|
| 743 |
+
0x8A3: 68,
|
| 744 |
+
0x8A4: 68,
|
| 745 |
+
0x8A5: 68,
|
| 746 |
+
0x8A6: 68,
|
| 747 |
+
0x8A7: 68,
|
| 748 |
+
0x8A8: 68,
|
| 749 |
+
0x8A9: 68,
|
| 750 |
+
0x8AA: 82,
|
| 751 |
+
0x8AB: 82,
|
| 752 |
+
0x8AC: 82,
|
| 753 |
+
0x8AE: 82,
|
| 754 |
+
0x8AF: 68,
|
| 755 |
+
0x8B0: 68,
|
| 756 |
+
0x8B1: 82,
|
| 757 |
+
0x8B2: 82,
|
| 758 |
+
0x8B3: 68,
|
| 759 |
+
0x8B4: 68,
|
| 760 |
+
0x8B5: 68,
|
| 761 |
+
0x8B6: 68,
|
| 762 |
+
0x8B7: 68,
|
| 763 |
+
0x8B8: 68,
|
| 764 |
+
0x8B9: 82,
|
| 765 |
+
0x8BA: 68,
|
| 766 |
+
0x8BB: 68,
|
| 767 |
+
0x8BC: 68,
|
| 768 |
+
0x8BD: 68,
|
| 769 |
+
0x8BE: 68,
|
| 770 |
+
0x8BF: 68,
|
| 771 |
+
0x8C0: 68,
|
| 772 |
+
0x8C1: 68,
|
| 773 |
+
0x8C2: 68,
|
| 774 |
+
0x8C3: 68,
|
| 775 |
+
0x8C4: 68,
|
| 776 |
+
0x8C5: 68,
|
| 777 |
+
0x8C6: 68,
|
| 778 |
+
0x8C7: 68,
|
| 779 |
+
0x8C8: 68,
|
| 780 |
+
0x8CA: 84,
|
| 781 |
+
0x8CB: 84,
|
| 782 |
+
0x8CC: 84,
|
| 783 |
+
0x8CD: 84,
|
| 784 |
+
0x8CE: 84,
|
| 785 |
+
0x8CF: 84,
|
| 786 |
+
0x8D0: 84,
|
| 787 |
+
0x8D1: 84,
|
| 788 |
+
0x8D2: 84,
|
| 789 |
+
0x8D3: 84,
|
| 790 |
+
0x8D4: 84,
|
| 791 |
+
0x8D5: 84,
|
| 792 |
+
0x8D6: 84,
|
| 793 |
+
0x8D7: 84,
|
| 794 |
+
0x8D8: 84,
|
| 795 |
+
0x8D9: 84,
|
| 796 |
+
0x8DA: 84,
|
| 797 |
+
0x8DB: 84,
|
| 798 |
+
0x8DC: 84,
|
| 799 |
+
0x8DD: 84,
|
| 800 |
+
0x8DE: 84,
|
| 801 |
+
0x8DF: 84,
|
| 802 |
+
0x8E0: 84,
|
| 803 |
+
0x8E1: 84,
|
| 804 |
+
0x8E3: 84,
|
| 805 |
+
0x8E4: 84,
|
| 806 |
+
0x8E5: 84,
|
| 807 |
+
0x8E6: 84,
|
| 808 |
+
0x8E7: 84,
|
| 809 |
+
0x8E8: 84,
|
| 810 |
+
0x8E9: 84,
|
| 811 |
+
0x8EA: 84,
|
| 812 |
+
0x8EB: 84,
|
| 813 |
+
0x8EC: 84,
|
| 814 |
+
0x8ED: 84,
|
| 815 |
+
0x8EE: 84,
|
| 816 |
+
0x8EF: 84,
|
| 817 |
+
0x8F0: 84,
|
| 818 |
+
0x8F1: 84,
|
| 819 |
+
0x8F2: 84,
|
| 820 |
+
0x8F3: 84,
|
| 821 |
+
0x8F4: 84,
|
| 822 |
+
0x8F5: 84,
|
| 823 |
+
0x8F6: 84,
|
| 824 |
+
0x8F7: 84,
|
| 825 |
+
0x8F8: 84,
|
| 826 |
+
0x8F9: 84,
|
| 827 |
+
0x8FA: 84,
|
| 828 |
+
0x8FB: 84,
|
| 829 |
+
0x8FC: 84,
|
| 830 |
+
0x8FD: 84,
|
| 831 |
+
0x8FE: 84,
|
| 832 |
+
0x8FF: 84,
|
| 833 |
+
0x900: 84,
|
| 834 |
+
0x901: 84,
|
| 835 |
+
0x902: 84,
|
| 836 |
+
0x93A: 84,
|
| 837 |
+
0x93C: 84,
|
| 838 |
+
0x941: 84,
|
| 839 |
+
0x942: 84,
|
| 840 |
+
0x943: 84,
|
| 841 |
+
0x944: 84,
|
| 842 |
+
0x945: 84,
|
| 843 |
+
0x946: 84,
|
| 844 |
+
0x947: 84,
|
| 845 |
+
0x948: 84,
|
| 846 |
+
0x94D: 84,
|
| 847 |
+
0x951: 84,
|
| 848 |
+
0x952: 84,
|
| 849 |
+
0x953: 84,
|
| 850 |
+
0x954: 84,
|
| 851 |
+
0x955: 84,
|
| 852 |
+
0x956: 84,
|
| 853 |
+
0x957: 84,
|
| 854 |
+
0x962: 84,
|
| 855 |
+
0x963: 84,
|
| 856 |
+
0x981: 84,
|
| 857 |
+
0x9BC: 84,
|
| 858 |
+
0x9C1: 84,
|
| 859 |
+
0x9C2: 84,
|
| 860 |
+
0x9C3: 84,
|
| 861 |
+
0x9C4: 84,
|
| 862 |
+
0x9CD: 84,
|
| 863 |
+
0x9E2: 84,
|
| 864 |
+
0x9E3: 84,
|
| 865 |
+
0x9FE: 84,
|
| 866 |
+
0xA01: 84,
|
| 867 |
+
0xA02: 84,
|
| 868 |
+
0xA3C: 84,
|
| 869 |
+
0xA41: 84,
|
| 870 |
+
0xA42: 84,
|
| 871 |
+
0xA47: 84,
|
| 872 |
+
0xA48: 84,
|
| 873 |
+
0xA4B: 84,
|
| 874 |
+
0xA4C: 84,
|
| 875 |
+
0xA4D: 84,
|
| 876 |
+
0xA51: 84,
|
| 877 |
+
0xA70: 84,
|
| 878 |
+
0xA71: 84,
|
| 879 |
+
0xA75: 84,
|
| 880 |
+
0xA81: 84,
|
| 881 |
+
0xA82: 84,
|
| 882 |
+
0xABC: 84,
|
| 883 |
+
0xAC1: 84,
|
| 884 |
+
0xAC2: 84,
|
| 885 |
+
0xAC3: 84,
|
| 886 |
+
0xAC4: 84,
|
| 887 |
+
0xAC5: 84,
|
| 888 |
+
0xAC7: 84,
|
| 889 |
+
0xAC8: 84,
|
| 890 |
+
0xACD: 84,
|
| 891 |
+
0xAE2: 84,
|
| 892 |
+
0xAE3: 84,
|
| 893 |
+
0xAFA: 84,
|
| 894 |
+
0xAFB: 84,
|
| 895 |
+
0xAFC: 84,
|
| 896 |
+
0xAFD: 84,
|
| 897 |
+
0xAFE: 84,
|
| 898 |
+
0xAFF: 84,
|
| 899 |
+
0xB01: 84,
|
| 900 |
+
0xB3C: 84,
|
| 901 |
+
0xB3F: 84,
|
| 902 |
+
0xB41: 84,
|
| 903 |
+
0xB42: 84,
|
| 904 |
+
0xB43: 84,
|
| 905 |
+
0xB44: 84,
|
| 906 |
+
0xB4D: 84,
|
| 907 |
+
0xB55: 84,
|
| 908 |
+
0xB56: 84,
|
| 909 |
+
0xB62: 84,
|
| 910 |
+
0xB63: 84,
|
| 911 |
+
0xB82: 84,
|
| 912 |
+
0xBC0: 84,
|
| 913 |
+
0xBCD: 84,
|
| 914 |
+
0xC00: 84,
|
| 915 |
+
0xC04: 84,
|
| 916 |
+
0xC3C: 84,
|
| 917 |
+
0xC3E: 84,
|
| 918 |
+
0xC3F: 84,
|
| 919 |
+
0xC40: 84,
|
| 920 |
+
0xC46: 84,
|
| 921 |
+
0xC47: 84,
|
| 922 |
+
0xC48: 84,
|
| 923 |
+
0xC4A: 84,
|
| 924 |
+
0xC4B: 84,
|
| 925 |
+
0xC4C: 84,
|
| 926 |
+
0xC4D: 84,
|
| 927 |
+
0xC55: 84,
|
| 928 |
+
0xC56: 84,
|
| 929 |
+
0xC62: 84,
|
| 930 |
+
0xC63: 84,
|
| 931 |
+
0xC81: 84,
|
| 932 |
+
0xCBC: 84,
|
| 933 |
+
0xCBF: 84,
|
| 934 |
+
0xCC6: 84,
|
| 935 |
+
0xCCC: 84,
|
| 936 |
+
0xCCD: 84,
|
| 937 |
+
0xCE2: 84,
|
| 938 |
+
0xCE3: 84,
|
| 939 |
+
0xD00: 84,
|
| 940 |
+
0xD01: 84,
|
| 941 |
+
0xD3B: 84,
|
| 942 |
+
0xD3C: 84,
|
| 943 |
+
0xD41: 84,
|
| 944 |
+
0xD42: 84,
|
| 945 |
+
0xD43: 84,
|
| 946 |
+
0xD44: 84,
|
| 947 |
+
0xD4D: 84,
|
| 948 |
+
0xD62: 84,
|
| 949 |
+
0xD63: 84,
|
| 950 |
+
0xD81: 84,
|
| 951 |
+
0xDCA: 84,
|
| 952 |
+
0xDD2: 84,
|
| 953 |
+
0xDD3: 84,
|
| 954 |
+
0xDD4: 84,
|
| 955 |
+
0xDD6: 84,
|
| 956 |
+
0xE31: 84,
|
| 957 |
+
0xE34: 84,
|
| 958 |
+
0xE35: 84,
|
| 959 |
+
0xE36: 84,
|
| 960 |
+
0xE37: 84,
|
| 961 |
+
0xE38: 84,
|
| 962 |
+
0xE39: 84,
|
| 963 |
+
0xE3A: 84,
|
| 964 |
+
0xE47: 84,
|
| 965 |
+
0xE48: 84,
|
| 966 |
+
0xE49: 84,
|
| 967 |
+
0xE4A: 84,
|
| 968 |
+
0xE4B: 84,
|
| 969 |
+
0xE4C: 84,
|
| 970 |
+
0xE4D: 84,
|
| 971 |
+
0xE4E: 84,
|
| 972 |
+
0xEB1: 84,
|
| 973 |
+
0xEB4: 84,
|
| 974 |
+
0xEB5: 84,
|
| 975 |
+
0xEB6: 84,
|
| 976 |
+
0xEB7: 84,
|
| 977 |
+
0xEB8: 84,
|
| 978 |
+
0xEB9: 84,
|
| 979 |
+
0xEBA: 84,
|
| 980 |
+
0xEBB: 84,
|
| 981 |
+
0xEBC: 84,
|
| 982 |
+
0xEC8: 84,
|
| 983 |
+
0xEC9: 84,
|
| 984 |
+
0xECA: 84,
|
| 985 |
+
0xECB: 84,
|
| 986 |
+
0xECC: 84,
|
| 987 |
+
0xECD: 84,
|
| 988 |
+
0xECE: 84,
|
| 989 |
+
0xF18: 84,
|
| 990 |
+
0xF19: 84,
|
| 991 |
+
0xF35: 84,
|
| 992 |
+
0xF37: 84,
|
| 993 |
+
0xF39: 84,
|
| 994 |
+
0xF71: 84,
|
| 995 |
+
0xF72: 84,
|
| 996 |
+
0xF73: 84,
|
| 997 |
+
0xF74: 84,
|
| 998 |
+
0xF75: 84,
|
| 999 |
+
0xF76: 84,
|
| 1000 |
+
0xF77: 84,
|
| 1001 |
+
0xF78: 84,
|
| 1002 |
+
0xF79: 84,
|
| 1003 |
+
0xF7A: 84,
|
| 1004 |
+
0xF7B: 84,
|
| 1005 |
+
0xF7C: 84,
|
| 1006 |
+
0xF7D: 84,
|
| 1007 |
+
0xF7E: 84,
|
| 1008 |
+
0xF80: 84,
|
| 1009 |
+
0xF81: 84,
|
| 1010 |
+
0xF82: 84,
|
| 1011 |
+
0xF83: 84,
|
| 1012 |
+
0xF84: 84,
|
| 1013 |
+
0xF86: 84,
|
| 1014 |
+
0xF87: 84,
|
| 1015 |
+
0xF8D: 84,
|
| 1016 |
+
0xF8E: 84,
|
| 1017 |
+
0xF8F: 84,
|
| 1018 |
+
0xF90: 84,
|
| 1019 |
+
0xF91: 84,
|
| 1020 |
+
0xF92: 84,
|
| 1021 |
+
0xF93: 84,
|
| 1022 |
+
0xF94: 84,
|
| 1023 |
+
0xF95: 84,
|
| 1024 |
+
0xF96: 84,
|
| 1025 |
+
0xF97: 84,
|
| 1026 |
+
0xF99: 84,
|
| 1027 |
+
0xF9A: 84,
|
| 1028 |
+
0xF9B: 84,
|
| 1029 |
+
0xF9C: 84,
|
| 1030 |
+
0xF9D: 84,
|
| 1031 |
+
0xF9E: 84,
|
| 1032 |
+
0xF9F: 84,
|
| 1033 |
+
0xFA0: 84,
|
| 1034 |
+
0xFA1: 84,
|
| 1035 |
+
0xFA2: 84,
|
| 1036 |
+
0xFA3: 84,
|
| 1037 |
+
0xFA4: 84,
|
| 1038 |
+
0xFA5: 84,
|
| 1039 |
+
0xFA6: 84,
|
| 1040 |
+
0xFA7: 84,
|
| 1041 |
+
0xFA8: 84,
|
| 1042 |
+
0xFA9: 84,
|
| 1043 |
+
0xFAA: 84,
|
| 1044 |
+
0xFAB: 84,
|
| 1045 |
+
0xFAC: 84,
|
| 1046 |
+
0xFAD: 84,
|
| 1047 |
+
0xFAE: 84,
|
| 1048 |
+
0xFAF: 84,
|
| 1049 |
+
0xFB0: 84,
|
| 1050 |
+
0xFB1: 84,
|
| 1051 |
+
0xFB2: 84,
|
| 1052 |
+
0xFB3: 84,
|
| 1053 |
+
0xFB4: 84,
|
| 1054 |
+
0xFB5: 84,
|
| 1055 |
+
0xFB6: 84,
|
| 1056 |
+
0xFB7: 84,
|
| 1057 |
+
0xFB8: 84,
|
| 1058 |
+
0xFB9: 84,
|
| 1059 |
+
0xFBA: 84,
|
| 1060 |
+
0xFBB: 84,
|
| 1061 |
+
0xFBC: 84,
|
| 1062 |
+
0xFC6: 84,
|
| 1063 |
+
0x102D: 84,
|
| 1064 |
+
0x102E: 84,
|
| 1065 |
+
0x102F: 84,
|
| 1066 |
+
0x1030: 84,
|
| 1067 |
+
0x1032: 84,
|
| 1068 |
+
0x1033: 84,
|
| 1069 |
+
0x1034: 84,
|
| 1070 |
+
0x1035: 84,
|
| 1071 |
+
0x1036: 84,
|
| 1072 |
+
0x1037: 84,
|
| 1073 |
+
0x1039: 84,
|
| 1074 |
+
0x103A: 84,
|
| 1075 |
+
0x103D: 84,
|
| 1076 |
+
0x103E: 84,
|
| 1077 |
+
0x1058: 84,
|
| 1078 |
+
0x1059: 84,
|
| 1079 |
+
0x105E: 84,
|
| 1080 |
+
0x105F: 84,
|
| 1081 |
+
0x1060: 84,
|
| 1082 |
+
0x1071: 84,
|
| 1083 |
+
0x1072: 84,
|
| 1084 |
+
0x1073: 84,
|
| 1085 |
+
0x1074: 84,
|
| 1086 |
+
0x1082: 84,
|
| 1087 |
+
0x1085: 84,
|
| 1088 |
+
0x1086: 84,
|
| 1089 |
+
0x108D: 84,
|
| 1090 |
+
0x109D: 84,
|
| 1091 |
+
0x135D: 84,
|
| 1092 |
+
0x135E: 84,
|
| 1093 |
+
0x135F: 84,
|
| 1094 |
+
0x1712: 84,
|
| 1095 |
+
0x1713: 84,
|
| 1096 |
+
0x1714: 84,
|
| 1097 |
+
0x1732: 84,
|
| 1098 |
+
0x1733: 84,
|
| 1099 |
+
0x1752: 84,
|
| 1100 |
+
0x1753: 84,
|
| 1101 |
+
0x1772: 84,
|
| 1102 |
+
0x1773: 84,
|
| 1103 |
+
0x17B4: 84,
|
| 1104 |
+
0x17B5: 84,
|
| 1105 |
+
0x17B7: 84,
|
| 1106 |
+
0x17B8: 84,
|
| 1107 |
+
0x17B9: 84,
|
| 1108 |
+
0x17BA: 84,
|
| 1109 |
+
0x17BB: 84,
|
| 1110 |
+
0x17BC: 84,
|
| 1111 |
+
0x17BD: 84,
|
| 1112 |
+
0x17C6: 84,
|
| 1113 |
+
0x17C9: 84,
|
| 1114 |
+
0x17CA: 84,
|
| 1115 |
+
0x17CB: 84,
|
| 1116 |
+
0x17CC: 84,
|
| 1117 |
+
0x17CD: 84,
|
| 1118 |
+
0x17CE: 84,
|
| 1119 |
+
0x17CF: 84,
|
| 1120 |
+
0x17D0: 84,
|
| 1121 |
+
0x17D1: 84,
|
| 1122 |
+
0x17D2: 84,
|
| 1123 |
+
0x17D3: 84,
|
| 1124 |
+
0x17DD: 84,
|
| 1125 |
+
0x1807: 68,
|
| 1126 |
+
0x180A: 67,
|
| 1127 |
+
0x180B: 84,
|
| 1128 |
+
0x180C: 84,
|
| 1129 |
+
0x180D: 84,
|
| 1130 |
+
0x180F: 84,
|
| 1131 |
+
0x1820: 68,
|
| 1132 |
+
0x1821: 68,
|
| 1133 |
+
0x1822: 68,
|
| 1134 |
+
0x1823: 68,
|
| 1135 |
+
0x1824: 68,
|
| 1136 |
+
0x1825: 68,
|
| 1137 |
+
0x1826: 68,
|
| 1138 |
+
0x1827: 68,
|
| 1139 |
+
0x1828: 68,
|
| 1140 |
+
0x1829: 68,
|
| 1141 |
+
0x182A: 68,
|
| 1142 |
+
0x182B: 68,
|
| 1143 |
+
0x182C: 68,
|
| 1144 |
+
0x182D: 68,
|
| 1145 |
+
0x182E: 68,
|
| 1146 |
+
0x182F: 68,
|
| 1147 |
+
0x1830: 68,
|
| 1148 |
+
0x1831: 68,
|
| 1149 |
+
0x1832: 68,
|
| 1150 |
+
0x1833: 68,
|
| 1151 |
+
0x1834: 68,
|
| 1152 |
+
0x1835: 68,
|
| 1153 |
+
0x1836: 68,
|
| 1154 |
+
0x1837: 68,
|
| 1155 |
+
0x1838: 68,
|
| 1156 |
+
0x1839: 68,
|
| 1157 |
+
0x183A: 68,
|
| 1158 |
+
0x183B: 68,
|
| 1159 |
+
0x183C: 68,
|
| 1160 |
+
0x183D: 68,
|
| 1161 |
+
0x183E: 68,
|
| 1162 |
+
0x183F: 68,
|
| 1163 |
+
0x1840: 68,
|
| 1164 |
+
0x1841: 68,
|
| 1165 |
+
0x1842: 68,
|
| 1166 |
+
0x1843: 68,
|
| 1167 |
+
0x1844: 68,
|
| 1168 |
+
0x1845: 68,
|
| 1169 |
+
0x1846: 68,
|
| 1170 |
+
0x1847: 68,
|
| 1171 |
+
0x1848: 68,
|
| 1172 |
+
0x1849: 68,
|
| 1173 |
+
0x184A: 68,
|
| 1174 |
+
0x184B: 68,
|
| 1175 |
+
0x184C: 68,
|
| 1176 |
+
0x184D: 68,
|
| 1177 |
+
0x184E: 68,
|
| 1178 |
+
0x184F: 68,
|
| 1179 |
+
0x1850: 68,
|
| 1180 |
+
0x1851: 68,
|
| 1181 |
+
0x1852: 68,
|
| 1182 |
+
0x1853: 68,
|
| 1183 |
+
0x1854: 68,
|
| 1184 |
+
0x1855: 68,
|
| 1185 |
+
0x1856: 68,
|
| 1186 |
+
0x1857: 68,
|
| 1187 |
+
0x1858: 68,
|
| 1188 |
+
0x1859: 68,
|
| 1189 |
+
0x185A: 68,
|
| 1190 |
+
0x185B: 68,
|
| 1191 |
+
0x185C: 68,
|
| 1192 |
+
0x185D: 68,
|
| 1193 |
+
0x185E: 68,
|
| 1194 |
+
0x185F: 68,
|
| 1195 |
+
0x1860: 68,
|
| 1196 |
+
0x1861: 68,
|
| 1197 |
+
0x1862: 68,
|
| 1198 |
+
0x1863: 68,
|
| 1199 |
+
0x1864: 68,
|
| 1200 |
+
0x1865: 68,
|
| 1201 |
+
0x1866: 68,
|
| 1202 |
+
0x1867: 68,
|
| 1203 |
+
0x1868: 68,
|
| 1204 |
+
0x1869: 68,
|
| 1205 |
+
0x186A: 68,
|
| 1206 |
+
0x186B: 68,
|
| 1207 |
+
0x186C: 68,
|
| 1208 |
+
0x186D: 68,
|
| 1209 |
+
0x186E: 68,
|
| 1210 |
+
0x186F: 68,
|
| 1211 |
+
0x1870: 68,
|
| 1212 |
+
0x1871: 68,
|
| 1213 |
+
0x1872: 68,
|
| 1214 |
+
0x1873: 68,
|
| 1215 |
+
0x1874: 68,
|
| 1216 |
+
0x1875: 68,
|
| 1217 |
+
0x1876: 68,
|
| 1218 |
+
0x1877: 68,
|
| 1219 |
+
0x1878: 68,
|
| 1220 |
+
0x1885: 84,
|
| 1221 |
+
0x1886: 84,
|
| 1222 |
+
0x1887: 68,
|
| 1223 |
+
0x1888: 68,
|
| 1224 |
+
0x1889: 68,
|
| 1225 |
+
0x188A: 68,
|
| 1226 |
+
0x188B: 68,
|
| 1227 |
+
0x188C: 68,
|
| 1228 |
+
0x188D: 68,
|
| 1229 |
+
0x188E: 68,
|
| 1230 |
+
0x188F: 68,
|
| 1231 |
+
0x1890: 68,
|
| 1232 |
+
0x1891: 68,
|
| 1233 |
+
0x1892: 68,
|
| 1234 |
+
0x1893: 68,
|
| 1235 |
+
0x1894: 68,
|
| 1236 |
+
0x1895: 68,
|
| 1237 |
+
0x1896: 68,
|
| 1238 |
+
0x1897: 68,
|
| 1239 |
+
0x1898: 68,
|
| 1240 |
+
0x1899: 68,
|
| 1241 |
+
0x189A: 68,
|
| 1242 |
+
0x189B: 68,
|
| 1243 |
+
0x189C: 68,
|
| 1244 |
+
0x189D: 68,
|
| 1245 |
+
0x189E: 68,
|
| 1246 |
+
0x189F: 68,
|
| 1247 |
+
0x18A0: 68,
|
| 1248 |
+
0x18A1: 68,
|
| 1249 |
+
0x18A2: 68,
|
| 1250 |
+
0x18A3: 68,
|
| 1251 |
+
0x18A4: 68,
|
| 1252 |
+
0x18A5: 68,
|
| 1253 |
+
0x18A6: 68,
|
| 1254 |
+
0x18A7: 68,
|
| 1255 |
+
0x18A8: 68,
|
| 1256 |
+
0x18A9: 84,
|
| 1257 |
+
0x18AA: 68,
|
| 1258 |
+
0x1920: 84,
|
| 1259 |
+
0x1921: 84,
|
| 1260 |
+
0x1922: 84,
|
| 1261 |
+
0x1927: 84,
|
| 1262 |
+
0x1928: 84,
|
| 1263 |
+
0x1932: 84,
|
| 1264 |
+
0x1939: 84,
|
| 1265 |
+
0x193A: 84,
|
| 1266 |
+
0x193B: 84,
|
| 1267 |
+
0x1A17: 84,
|
| 1268 |
+
0x1A18: 84,
|
| 1269 |
+
0x1A1B: 84,
|
| 1270 |
+
0x1A56: 84,
|
| 1271 |
+
0x1A58: 84,
|
| 1272 |
+
0x1A59: 84,
|
| 1273 |
+
0x1A5A: 84,
|
| 1274 |
+
0x1A5B: 84,
|
| 1275 |
+
0x1A5C: 84,
|
| 1276 |
+
0x1A5D: 84,
|
| 1277 |
+
0x1A5E: 84,
|
| 1278 |
+
0x1A60: 84,
|
| 1279 |
+
0x1A62: 84,
|
| 1280 |
+
0x1A65: 84,
|
| 1281 |
+
0x1A66: 84,
|
| 1282 |
+
0x1A67: 84,
|
| 1283 |
+
0x1A68: 84,
|
| 1284 |
+
0x1A69: 84,
|
| 1285 |
+
0x1A6A: 84,
|
| 1286 |
+
0x1A6B: 84,
|
| 1287 |
+
0x1A6C: 84,
|
| 1288 |
+
0x1A73: 84,
|
| 1289 |
+
0x1A74: 84,
|
| 1290 |
+
0x1A75: 84,
|
| 1291 |
+
0x1A76: 84,
|
| 1292 |
+
0x1A77: 84,
|
| 1293 |
+
0x1A78: 84,
|
| 1294 |
+
0x1A79: 84,
|
| 1295 |
+
0x1A7A: 84,
|
| 1296 |
+
0x1A7B: 84,
|
| 1297 |
+
0x1A7C: 84,
|
| 1298 |
+
0x1A7F: 84,
|
| 1299 |
+
0x1AB0: 84,
|
| 1300 |
+
0x1AB1: 84,
|
| 1301 |
+
0x1AB2: 84,
|
| 1302 |
+
0x1AB3: 84,
|
| 1303 |
+
0x1AB4: 84,
|
| 1304 |
+
0x1AB5: 84,
|
| 1305 |
+
0x1AB6: 84,
|
| 1306 |
+
0x1AB7: 84,
|
| 1307 |
+
0x1AB8: 84,
|
| 1308 |
+
0x1AB9: 84,
|
| 1309 |
+
0x1ABA: 84,
|
| 1310 |
+
0x1ABB: 84,
|
| 1311 |
+
0x1ABC: 84,
|
| 1312 |
+
0x1ABD: 84,
|
| 1313 |
+
0x1ABE: 84,
|
| 1314 |
+
0x1ABF: 84,
|
| 1315 |
+
0x1AC0: 84,
|
| 1316 |
+
0x1AC1: 84,
|
| 1317 |
+
0x1AC2: 84,
|
| 1318 |
+
0x1AC3: 84,
|
| 1319 |
+
0x1AC4: 84,
|
| 1320 |
+
0x1AC5: 84,
|
| 1321 |
+
0x1AC6: 84,
|
| 1322 |
+
0x1AC7: 84,
|
| 1323 |
+
0x1AC8: 84,
|
| 1324 |
+
0x1AC9: 84,
|
| 1325 |
+
0x1ACA: 84,
|
| 1326 |
+
0x1ACB: 84,
|
| 1327 |
+
0x1ACC: 84,
|
| 1328 |
+
0x1ACD: 84,
|
| 1329 |
+
0x1ACE: 84,
|
| 1330 |
+
0x1B00: 84,
|
| 1331 |
+
0x1B01: 84,
|
| 1332 |
+
0x1B02: 84,
|
| 1333 |
+
0x1B03: 84,
|
| 1334 |
+
0x1B34: 84,
|
| 1335 |
+
0x1B36: 84,
|
| 1336 |
+
0x1B37: 84,
|
| 1337 |
+
0x1B38: 84,
|
| 1338 |
+
0x1B39: 84,
|
| 1339 |
+
0x1B3A: 84,
|
| 1340 |
+
0x1B3C: 84,
|
| 1341 |
+
0x1B42: 84,
|
| 1342 |
+
0x1B6B: 84,
|
| 1343 |
+
0x1B6C: 84,
|
| 1344 |
+
0x1B6D: 84,
|
| 1345 |
+
0x1B6E: 84,
|
| 1346 |
+
0x1B6F: 84,
|
| 1347 |
+
0x1B70: 84,
|
| 1348 |
+
0x1B71: 84,
|
| 1349 |
+
0x1B72: 84,
|
| 1350 |
+
0x1B73: 84,
|
| 1351 |
+
0x1B80: 84,
|
| 1352 |
+
0x1B81: 84,
|
| 1353 |
+
0x1BA2: 84,
|
| 1354 |
+
0x1BA3: 84,
|
| 1355 |
+
0x1BA4: 84,
|
| 1356 |
+
0x1BA5: 84,
|
| 1357 |
+
0x1BA8: 84,
|
| 1358 |
+
0x1BA9: 84,
|
| 1359 |
+
0x1BAB: 84,
|
| 1360 |
+
0x1BAC: 84,
|
| 1361 |
+
0x1BAD: 84,
|
| 1362 |
+
0x1BE6: 84,
|
| 1363 |
+
0x1BE8: 84,
|
| 1364 |
+
0x1BE9: 84,
|
| 1365 |
+
0x1BED: 84,
|
| 1366 |
+
0x1BEF: 84,
|
| 1367 |
+
0x1BF0: 84,
|
| 1368 |
+
0x1BF1: 84,
|
| 1369 |
+
0x1C2C: 84,
|
| 1370 |
+
0x1C2D: 84,
|
| 1371 |
+
0x1C2E: 84,
|
| 1372 |
+
0x1C2F: 84,
|
| 1373 |
+
0x1C30: 84,
|
| 1374 |
+
0x1C31: 84,
|
| 1375 |
+
0x1C32: 84,
|
| 1376 |
+
0x1C33: 84,
|
| 1377 |
+
0x1C36: 84,
|
| 1378 |
+
0x1C37: 84,
|
| 1379 |
+
0x1CD0: 84,
|
| 1380 |
+
0x1CD1: 84,
|
| 1381 |
+
0x1CD2: 84,
|
| 1382 |
+
0x1CD4: 84,
|
| 1383 |
+
0x1CD5: 84,
|
| 1384 |
+
0x1CD6: 84,
|
| 1385 |
+
0x1CD7: 84,
|
| 1386 |
+
0x1CD8: 84,
|
| 1387 |
+
0x1CD9: 84,
|
| 1388 |
+
0x1CDA: 84,
|
| 1389 |
+
0x1CDB: 84,
|
| 1390 |
+
0x1CDC: 84,
|
| 1391 |
+
0x1CDD: 84,
|
| 1392 |
+
0x1CDE: 84,
|
| 1393 |
+
0x1CDF: 84,
|
| 1394 |
+
0x1CE0: 84,
|
| 1395 |
+
0x1CE2: 84,
|
| 1396 |
+
0x1CE3: 84,
|
| 1397 |
+
0x1CE4: 84,
|
| 1398 |
+
0x1CE5: 84,
|
| 1399 |
+
0x1CE6: 84,
|
| 1400 |
+
0x1CE7: 84,
|
| 1401 |
+
0x1CE8: 84,
|
| 1402 |
+
0x1CED: 84,
|
| 1403 |
+
0x1CF4: 84,
|
| 1404 |
+
0x1CF8: 84,
|
| 1405 |
+
0x1CF9: 84,
|
| 1406 |
+
0x1DC0: 84,
|
| 1407 |
+
0x1DC1: 84,
|
| 1408 |
+
0x1DC2: 84,
|
| 1409 |
+
0x1DC3: 84,
|
| 1410 |
+
0x1DC4: 84,
|
| 1411 |
+
0x1DC5: 84,
|
| 1412 |
+
0x1DC6: 84,
|
| 1413 |
+
0x1DC7: 84,
|
| 1414 |
+
0x1DC8: 84,
|
| 1415 |
+
0x1DC9: 84,
|
| 1416 |
+
0x1DCA: 84,
|
| 1417 |
+
0x1DCB: 84,
|
| 1418 |
+
0x1DCC: 84,
|
| 1419 |
+
0x1DCD: 84,
|
| 1420 |
+
0x1DCE: 84,
|
| 1421 |
+
0x1DCF: 84,
|
| 1422 |
+
0x1DD0: 84,
|
| 1423 |
+
0x1DD1: 84,
|
| 1424 |
+
0x1DD2: 84,
|
| 1425 |
+
0x1DD3: 84,
|
| 1426 |
+
0x1DD4: 84,
|
| 1427 |
+
0x1DD5: 84,
|
| 1428 |
+
0x1DD6: 84,
|
| 1429 |
+
0x1DD7: 84,
|
| 1430 |
+
0x1DD8: 84,
|
| 1431 |
+
0x1DD9: 84,
|
| 1432 |
+
0x1DDA: 84,
|
| 1433 |
+
0x1DDB: 84,
|
| 1434 |
+
0x1DDC: 84,
|
| 1435 |
+
0x1DDD: 84,
|
| 1436 |
+
0x1DDE: 84,
|
| 1437 |
+
0x1DDF: 84,
|
| 1438 |
+
0x1DE0: 84,
|
| 1439 |
+
0x1DE1: 84,
|
| 1440 |
+
0x1DE2: 84,
|
| 1441 |
+
0x1DE3: 84,
|
| 1442 |
+
0x1DE4: 84,
|
| 1443 |
+
0x1DE5: 84,
|
| 1444 |
+
0x1DE6: 84,
|
| 1445 |
+
0x1DE7: 84,
|
| 1446 |
+
0x1DE8: 84,
|
| 1447 |
+
0x1DE9: 84,
|
| 1448 |
+
0x1DEA: 84,
|
| 1449 |
+
0x1DEB: 84,
|
| 1450 |
+
0x1DEC: 84,
|
| 1451 |
+
0x1DED: 84,
|
| 1452 |
+
0x1DEE: 84,
|
| 1453 |
+
0x1DEF: 84,
|
| 1454 |
+
0x1DF0: 84,
|
| 1455 |
+
0x1DF1: 84,
|
| 1456 |
+
0x1DF2: 84,
|
| 1457 |
+
0x1DF3: 84,
|
| 1458 |
+
0x1DF4: 84,
|
| 1459 |
+
0x1DF5: 84,
|
| 1460 |
+
0x1DF6: 84,
|
| 1461 |
+
0x1DF7: 84,
|
| 1462 |
+
0x1DF8: 84,
|
| 1463 |
+
0x1DF9: 84,
|
| 1464 |
+
0x1DFA: 84,
|
| 1465 |
+
0x1DFB: 84,
|
| 1466 |
+
0x1DFC: 84,
|
| 1467 |
+
0x1DFD: 84,
|
| 1468 |
+
0x1DFE: 84,
|
| 1469 |
+
0x1DFF: 84,
|
| 1470 |
+
0x200B: 84,
|
| 1471 |
+
0x200D: 67,
|
| 1472 |
+
0x200E: 84,
|
| 1473 |
+
0x200F: 84,
|
| 1474 |
+
0x202A: 84,
|
| 1475 |
+
0x202B: 84,
|
| 1476 |
+
0x202C: 84,
|
| 1477 |
+
0x202D: 84,
|
| 1478 |
+
0x202E: 84,
|
| 1479 |
+
0x2060: 84,
|
| 1480 |
+
0x2061: 84,
|
| 1481 |
+
0x2062: 84,
|
| 1482 |
+
0x2063: 84,
|
| 1483 |
+
0x2064: 84,
|
| 1484 |
+
0x206A: 84,
|
| 1485 |
+
0x206B: 84,
|
| 1486 |
+
0x206C: 84,
|
| 1487 |
+
0x206D: 84,
|
| 1488 |
+
0x206E: 84,
|
| 1489 |
+
0x206F: 84,
|
| 1490 |
+
0x20D0: 84,
|
| 1491 |
+
0x20D1: 84,
|
| 1492 |
+
0x20D2: 84,
|
| 1493 |
+
0x20D3: 84,
|
| 1494 |
+
0x20D4: 84,
|
| 1495 |
+
0x20D5: 84,
|
| 1496 |
+
0x20D6: 84,
|
| 1497 |
+
0x20D7: 84,
|
| 1498 |
+
0x20D8: 84,
|
| 1499 |
+
0x20D9: 84,
|
| 1500 |
+
0x20DA: 84,
|
| 1501 |
+
0x20DB: 84,
|
| 1502 |
+
0x20DC: 84,
|
| 1503 |
+
0x20DD: 84,
|
| 1504 |
+
0x20DE: 84,
|
| 1505 |
+
0x20DF: 84,
|
| 1506 |
+
0x20E0: 84,
|
| 1507 |
+
0x20E1: 84,
|
| 1508 |
+
0x20E2: 84,
|
| 1509 |
+
0x20E3: 84,
|
| 1510 |
+
0x20E4: 84,
|
| 1511 |
+
0x20E5: 84,
|
| 1512 |
+
0x20E6: 84,
|
| 1513 |
+
0x20E7: 84,
|
| 1514 |
+
0x20E8: 84,
|
| 1515 |
+
0x20E9: 84,
|
| 1516 |
+
0x20EA: 84,
|
| 1517 |
+
0x20EB: 84,
|
| 1518 |
+
0x20EC: 84,
|
| 1519 |
+
0x20ED: 84,
|
| 1520 |
+
0x20EE: 84,
|
| 1521 |
+
0x20EF: 84,
|
| 1522 |
+
0x20F0: 84,
|
| 1523 |
+
0x2CEF: 84,
|
| 1524 |
+
0x2CF0: 84,
|
| 1525 |
+
0x2CF1: 84,
|
| 1526 |
+
0x2D7F: 84,
|
| 1527 |
+
0x2DE0: 84,
|
| 1528 |
+
0x2DE1: 84,
|
| 1529 |
+
0x2DE2: 84,
|
| 1530 |
+
0x2DE3: 84,
|
| 1531 |
+
0x2DE4: 84,
|
| 1532 |
+
0x2DE5: 84,
|
| 1533 |
+
0x2DE6: 84,
|
| 1534 |
+
0x2DE7: 84,
|
| 1535 |
+
0x2DE8: 84,
|
| 1536 |
+
0x2DE9: 84,
|
| 1537 |
+
0x2DEA: 84,
|
| 1538 |
+
0x2DEB: 84,
|
| 1539 |
+
0x2DEC: 84,
|
| 1540 |
+
0x2DED: 84,
|
| 1541 |
+
0x2DEE: 84,
|
| 1542 |
+
0x2DEF: 84,
|
| 1543 |
+
0x2DF0: 84,
|
| 1544 |
+
0x2DF1: 84,
|
| 1545 |
+
0x2DF2: 84,
|
| 1546 |
+
0x2DF3: 84,
|
| 1547 |
+
0x2DF4: 84,
|
| 1548 |
+
0x2DF5: 84,
|
| 1549 |
+
0x2DF6: 84,
|
| 1550 |
+
0x2DF7: 84,
|
| 1551 |
+
0x2DF8: 84,
|
| 1552 |
+
0x2DF9: 84,
|
| 1553 |
+
0x2DFA: 84,
|
| 1554 |
+
0x2DFB: 84,
|
| 1555 |
+
0x2DFC: 84,
|
| 1556 |
+
0x2DFD: 84,
|
| 1557 |
+
0x2DFE: 84,
|
| 1558 |
+
0x2DFF: 84,
|
| 1559 |
+
0x302A: 84,
|
| 1560 |
+
0x302B: 84,
|
| 1561 |
+
0x302C: 84,
|
| 1562 |
+
0x302D: 84,
|
| 1563 |
+
0x3099: 84,
|
| 1564 |
+
0x309A: 84,
|
| 1565 |
+
0xA66F: 84,
|
| 1566 |
+
0xA670: 84,
|
| 1567 |
+
0xA671: 84,
|
| 1568 |
+
0xA672: 84,
|
| 1569 |
+
0xA674: 84,
|
| 1570 |
+
0xA675: 84,
|
| 1571 |
+
0xA676: 84,
|
| 1572 |
+
0xA677: 84,
|
| 1573 |
+
0xA678: 84,
|
| 1574 |
+
0xA679: 84,
|
| 1575 |
+
0xA67A: 84,
|
| 1576 |
+
0xA67B: 84,
|
| 1577 |
+
0xA67C: 84,
|
| 1578 |
+
0xA67D: 84,
|
| 1579 |
+
0xA69E: 84,
|
| 1580 |
+
0xA69F: 84,
|
| 1581 |
+
0xA6F0: 84,
|
| 1582 |
+
0xA6F1: 84,
|
| 1583 |
+
0xA802: 84,
|
| 1584 |
+
0xA806: 84,
|
| 1585 |
+
0xA80B: 84,
|
| 1586 |
+
0xA825: 84,
|
| 1587 |
+
0xA826: 84,
|
| 1588 |
+
0xA82C: 84,
|
| 1589 |
+
0xA840: 68,
|
| 1590 |
+
0xA841: 68,
|
| 1591 |
+
0xA842: 68,
|
| 1592 |
+
0xA843: 68,
|
| 1593 |
+
0xA844: 68,
|
| 1594 |
+
0xA845: 68,
|
| 1595 |
+
0xA846: 68,
|
| 1596 |
+
0xA847: 68,
|
| 1597 |
+
0xA848: 68,
|
| 1598 |
+
0xA849: 68,
|
| 1599 |
+
0xA84A: 68,
|
| 1600 |
+
0xA84B: 68,
|
| 1601 |
+
0xA84C: 68,
|
| 1602 |
+
0xA84D: 68,
|
| 1603 |
+
0xA84E: 68,
|
| 1604 |
+
0xA84F: 68,
|
| 1605 |
+
0xA850: 68,
|
| 1606 |
+
0xA851: 68,
|
| 1607 |
+
0xA852: 68,
|
| 1608 |
+
0xA853: 68,
|
| 1609 |
+
0xA854: 68,
|
| 1610 |
+
0xA855: 68,
|
| 1611 |
+
0xA856: 68,
|
| 1612 |
+
0xA857: 68,
|
| 1613 |
+
0xA858: 68,
|
| 1614 |
+
0xA859: 68,
|
| 1615 |
+
0xA85A: 68,
|
| 1616 |
+
0xA85B: 68,
|
| 1617 |
+
0xA85C: 68,
|
| 1618 |
+
0xA85D: 68,
|
| 1619 |
+
0xA85E: 68,
|
| 1620 |
+
0xA85F: 68,
|
| 1621 |
+
0xA860: 68,
|
| 1622 |
+
0xA861: 68,
|
| 1623 |
+
0xA862: 68,
|
| 1624 |
+
0xA863: 68,
|
| 1625 |
+
0xA864: 68,
|
| 1626 |
+
0xA865: 68,
|
| 1627 |
+
0xA866: 68,
|
| 1628 |
+
0xA867: 68,
|
| 1629 |
+
0xA868: 68,
|
| 1630 |
+
0xA869: 68,
|
| 1631 |
+
0xA86A: 68,
|
| 1632 |
+
0xA86B: 68,
|
| 1633 |
+
0xA86C: 68,
|
| 1634 |
+
0xA86D: 68,
|
| 1635 |
+
0xA86E: 68,
|
| 1636 |
+
0xA86F: 68,
|
| 1637 |
+
0xA870: 68,
|
| 1638 |
+
0xA871: 68,
|
| 1639 |
+
0xA872: 76,
|
| 1640 |
+
0xA8C4: 84,
|
| 1641 |
+
0xA8C5: 84,
|
| 1642 |
+
0xA8E0: 84,
|
| 1643 |
+
0xA8E1: 84,
|
| 1644 |
+
0xA8E2: 84,
|
| 1645 |
+
0xA8E3: 84,
|
| 1646 |
+
0xA8E4: 84,
|
| 1647 |
+
0xA8E5: 84,
|
| 1648 |
+
0xA8E6: 84,
|
| 1649 |
+
0xA8E7: 84,
|
| 1650 |
+
0xA8E8: 84,
|
| 1651 |
+
0xA8E9: 84,
|
| 1652 |
+
0xA8EA: 84,
|
| 1653 |
+
0xA8EB: 84,
|
| 1654 |
+
0xA8EC: 84,
|
| 1655 |
+
0xA8ED: 84,
|
| 1656 |
+
0xA8EE: 84,
|
| 1657 |
+
0xA8EF: 84,
|
| 1658 |
+
0xA8F0: 84,
|
| 1659 |
+
0xA8F1: 84,
|
| 1660 |
+
0xA8FF: 84,
|
| 1661 |
+
0xA926: 84,
|
| 1662 |
+
0xA927: 84,
|
| 1663 |
+
0xA928: 84,
|
| 1664 |
+
0xA929: 84,
|
| 1665 |
+
0xA92A: 84,
|
| 1666 |
+
0xA92B: 84,
|
| 1667 |
+
0xA92C: 84,
|
| 1668 |
+
0xA92D: 84,
|
| 1669 |
+
0xA947: 84,
|
| 1670 |
+
0xA948: 84,
|
| 1671 |
+
0xA949: 84,
|
| 1672 |
+
0xA94A: 84,
|
| 1673 |
+
0xA94B: 84,
|
| 1674 |
+
0xA94C: 84,
|
| 1675 |
+
0xA94D: 84,
|
| 1676 |
+
0xA94E: 84,
|
| 1677 |
+
0xA94F: 84,
|
| 1678 |
+
0xA950: 84,
|
| 1679 |
+
0xA951: 84,
|
| 1680 |
+
0xA980: 84,
|
| 1681 |
+
0xA981: 84,
|
| 1682 |
+
0xA982: 84,
|
| 1683 |
+
0xA9B3: 84,
|
| 1684 |
+
0xA9B6: 84,
|
| 1685 |
+
0xA9B7: 84,
|
| 1686 |
+
0xA9B8: 84,
|
| 1687 |
+
0xA9B9: 84,
|
| 1688 |
+
0xA9BC: 84,
|
| 1689 |
+
0xA9BD: 84,
|
| 1690 |
+
0xA9E5: 84,
|
| 1691 |
+
0xAA29: 84,
|
| 1692 |
+
0xAA2A: 84,
|
| 1693 |
+
0xAA2B: 84,
|
| 1694 |
+
0xAA2C: 84,
|
| 1695 |
+
0xAA2D: 84,
|
| 1696 |
+
0xAA2E: 84,
|
| 1697 |
+
0xAA31: 84,
|
| 1698 |
+
0xAA32: 84,
|
| 1699 |
+
0xAA35: 84,
|
| 1700 |
+
0xAA36: 84,
|
| 1701 |
+
0xAA43: 84,
|
| 1702 |
+
0xAA4C: 84,
|
| 1703 |
+
0xAA7C: 84,
|
| 1704 |
+
0xAAB0: 84,
|
| 1705 |
+
0xAAB2: 84,
|
| 1706 |
+
0xAAB3: 84,
|
| 1707 |
+
0xAAB4: 84,
|
| 1708 |
+
0xAAB7: 84,
|
| 1709 |
+
0xAAB8: 84,
|
| 1710 |
+
0xAABE: 84,
|
| 1711 |
+
0xAABF: 84,
|
| 1712 |
+
0xAAC1: 84,
|
| 1713 |
+
0xAAEC: 84,
|
| 1714 |
+
0xAAED: 84,
|
| 1715 |
+
0xAAF6: 84,
|
| 1716 |
+
0xABE5: 84,
|
| 1717 |
+
0xABE8: 84,
|
| 1718 |
+
0xABED: 84,
|
| 1719 |
+
0xFB1E: 84,
|
| 1720 |
+
0xFE00: 84,
|
| 1721 |
+
0xFE01: 84,
|
| 1722 |
+
0xFE02: 84,
|
| 1723 |
+
0xFE03: 84,
|
| 1724 |
+
0xFE04: 84,
|
| 1725 |
+
0xFE05: 84,
|
| 1726 |
+
0xFE06: 84,
|
| 1727 |
+
0xFE07: 84,
|
| 1728 |
+
0xFE08: 84,
|
| 1729 |
+
0xFE09: 84,
|
| 1730 |
+
0xFE0A: 84,
|
| 1731 |
+
0xFE0B: 84,
|
| 1732 |
+
0xFE0C: 84,
|
| 1733 |
+
0xFE0D: 84,
|
| 1734 |
+
0xFE0E: 84,
|
| 1735 |
+
0xFE0F: 84,
|
| 1736 |
+
0xFE20: 84,
|
| 1737 |
+
0xFE21: 84,
|
| 1738 |
+
0xFE22: 84,
|
| 1739 |
+
0xFE23: 84,
|
| 1740 |
+
0xFE24: 84,
|
| 1741 |
+
0xFE25: 84,
|
| 1742 |
+
0xFE26: 84,
|
| 1743 |
+
0xFE27: 84,
|
| 1744 |
+
0xFE28: 84,
|
| 1745 |
+
0xFE29: 84,
|
| 1746 |
+
0xFE2A: 84,
|
| 1747 |
+
0xFE2B: 84,
|
| 1748 |
+
0xFE2C: 84,
|
| 1749 |
+
0xFE2D: 84,
|
| 1750 |
+
0xFE2E: 84,
|
| 1751 |
+
0xFE2F: 84,
|
| 1752 |
+
0xFEFF: 84,
|
| 1753 |
+
0xFFF9: 84,
|
| 1754 |
+
0xFFFA: 84,
|
| 1755 |
+
0xFFFB: 84,
|
| 1756 |
+
0x101FD: 84,
|
| 1757 |
+
0x102E0: 84,
|
| 1758 |
+
0x10376: 84,
|
| 1759 |
+
0x10377: 84,
|
| 1760 |
+
0x10378: 84,
|
| 1761 |
+
0x10379: 84,
|
| 1762 |
+
0x1037A: 84,
|
| 1763 |
+
0x10A01: 84,
|
| 1764 |
+
0x10A02: 84,
|
| 1765 |
+
0x10A03: 84,
|
| 1766 |
+
0x10A05: 84,
|
| 1767 |
+
0x10A06: 84,
|
| 1768 |
+
0x10A0C: 84,
|
| 1769 |
+
0x10A0D: 84,
|
| 1770 |
+
0x10A0E: 84,
|
| 1771 |
+
0x10A0F: 84,
|
| 1772 |
+
0x10A38: 84,
|
| 1773 |
+
0x10A39: 84,
|
| 1774 |
+
0x10A3A: 84,
|
| 1775 |
+
0x10A3F: 84,
|
| 1776 |
+
0x10AC0: 68,
|
| 1777 |
+
0x10AC1: 68,
|
| 1778 |
+
0x10AC2: 68,
|
| 1779 |
+
0x10AC3: 68,
|
| 1780 |
+
0x10AC4: 68,
|
| 1781 |
+
0x10AC5: 82,
|
| 1782 |
+
0x10AC7: 82,
|
| 1783 |
+
0x10AC9: 82,
|
| 1784 |
+
0x10ACA: 82,
|
| 1785 |
+
0x10ACD: 76,
|
| 1786 |
+
0x10ACE: 82,
|
| 1787 |
+
0x10ACF: 82,
|
| 1788 |
+
0x10AD0: 82,
|
| 1789 |
+
0x10AD1: 82,
|
| 1790 |
+
0x10AD2: 82,
|
| 1791 |
+
0x10AD3: 68,
|
| 1792 |
+
0x10AD4: 68,
|
| 1793 |
+
0x10AD5: 68,
|
| 1794 |
+
0x10AD6: 68,
|
| 1795 |
+
0x10AD7: 76,
|
| 1796 |
+
0x10AD8: 68,
|
| 1797 |
+
0x10AD9: 68,
|
| 1798 |
+
0x10ADA: 68,
|
| 1799 |
+
0x10ADB: 68,
|
| 1800 |
+
0x10ADC: 68,
|
| 1801 |
+
0x10ADD: 82,
|
| 1802 |
+
0x10ADE: 68,
|
| 1803 |
+
0x10ADF: 68,
|
| 1804 |
+
0x10AE0: 68,
|
| 1805 |
+
0x10AE1: 82,
|
| 1806 |
+
0x10AE4: 82,
|
| 1807 |
+
0x10AE5: 84,
|
| 1808 |
+
0x10AE6: 84,
|
| 1809 |
+
0x10AEB: 68,
|
| 1810 |
+
0x10AEC: 68,
|
| 1811 |
+
0x10AED: 68,
|
| 1812 |
+
0x10AEE: 68,
|
| 1813 |
+
0x10AEF: 82,
|
| 1814 |
+
0x10B80: 68,
|
| 1815 |
+
0x10B81: 82,
|
| 1816 |
+
0x10B82: 68,
|
| 1817 |
+
0x10B83: 82,
|
| 1818 |
+
0x10B84: 82,
|
| 1819 |
+
0x10B85: 82,
|
| 1820 |
+
0x10B86: 68,
|
| 1821 |
+
0x10B87: 68,
|
| 1822 |
+
0x10B88: 68,
|
| 1823 |
+
0x10B89: 82,
|
| 1824 |
+
0x10B8A: 68,
|
| 1825 |
+
0x10B8B: 68,
|
| 1826 |
+
0x10B8C: 82,
|
| 1827 |
+
0x10B8D: 68,
|
| 1828 |
+
0x10B8E: 82,
|
| 1829 |
+
0x10B8F: 82,
|
| 1830 |
+
0x10B90: 68,
|
| 1831 |
+
0x10B91: 82,
|
| 1832 |
+
0x10BA9: 82,
|
| 1833 |
+
0x10BAA: 82,
|
| 1834 |
+
0x10BAB: 82,
|
| 1835 |
+
0x10BAC: 82,
|
| 1836 |
+
0x10BAD: 68,
|
| 1837 |
+
0x10BAE: 68,
|
| 1838 |
+
0x10D00: 76,
|
| 1839 |
+
0x10D01: 68,
|
| 1840 |
+
0x10D02: 68,
|
| 1841 |
+
0x10D03: 68,
|
| 1842 |
+
0x10D04: 68,
|
| 1843 |
+
0x10D05: 68,
|
| 1844 |
+
0x10D06: 68,
|
| 1845 |
+
0x10D07: 68,
|
| 1846 |
+
0x10D08: 68,
|
| 1847 |
+
0x10D09: 68,
|
| 1848 |
+
0x10D0A: 68,
|
| 1849 |
+
0x10D0B: 68,
|
| 1850 |
+
0x10D0C: 68,
|
| 1851 |
+
0x10D0D: 68,
|
| 1852 |
+
0x10D0E: 68,
|
| 1853 |
+
0x10D0F: 68,
|
| 1854 |
+
0x10D10: 68,
|
| 1855 |
+
0x10D11: 68,
|
| 1856 |
+
0x10D12: 68,
|
| 1857 |
+
0x10D13: 68,
|
| 1858 |
+
0x10D14: 68,
|
| 1859 |
+
0x10D15: 68,
|
| 1860 |
+
0x10D16: 68,
|
| 1861 |
+
0x10D17: 68,
|
| 1862 |
+
0x10D18: 68,
|
| 1863 |
+
0x10D19: 68,
|
| 1864 |
+
0x10D1A: 68,
|
| 1865 |
+
0x10D1B: 68,
|
| 1866 |
+
0x10D1C: 68,
|
| 1867 |
+
0x10D1D: 68,
|
| 1868 |
+
0x10D1E: 68,
|
| 1869 |
+
0x10D1F: 68,
|
| 1870 |
+
0x10D20: 68,
|
| 1871 |
+
0x10D21: 68,
|
| 1872 |
+
0x10D22: 82,
|
| 1873 |
+
0x10D23: 68,
|
| 1874 |
+
0x10D24: 84,
|
| 1875 |
+
0x10D25: 84,
|
| 1876 |
+
0x10D26: 84,
|
| 1877 |
+
0x10D27: 84,
|
| 1878 |
+
0x10D69: 84,
|
| 1879 |
+
0x10D6A: 84,
|
| 1880 |
+
0x10D6B: 84,
|
| 1881 |
+
0x10D6C: 84,
|
| 1882 |
+
0x10D6D: 84,
|
| 1883 |
+
0x10EAB: 84,
|
| 1884 |
+
0x10EAC: 84,
|
| 1885 |
+
0x10EC2: 82,
|
| 1886 |
+
0x10EC3: 68,
|
| 1887 |
+
0x10EC4: 68,
|
| 1888 |
+
0x10EFC: 84,
|
| 1889 |
+
0x10EFD: 84,
|
| 1890 |
+
0x10EFE: 84,
|
| 1891 |
+
0x10EFF: 84,
|
| 1892 |
+
0x10F30: 68,
|
| 1893 |
+
0x10F31: 68,
|
| 1894 |
+
0x10F32: 68,
|
| 1895 |
+
0x10F33: 82,
|
| 1896 |
+
0x10F34: 68,
|
| 1897 |
+
0x10F35: 68,
|
| 1898 |
+
0x10F36: 68,
|
| 1899 |
+
0x10F37: 68,
|
| 1900 |
+
0x10F38: 68,
|
| 1901 |
+
0x10F39: 68,
|
| 1902 |
+
0x10F3A: 68,
|
| 1903 |
+
0x10F3B: 68,
|
| 1904 |
+
0x10F3C: 68,
|
| 1905 |
+
0x10F3D: 68,
|
| 1906 |
+
0x10F3E: 68,
|
| 1907 |
+
0x10F3F: 68,
|
| 1908 |
+
0x10F40: 68,
|
| 1909 |
+
0x10F41: 68,
|
| 1910 |
+
0x10F42: 68,
|
| 1911 |
+
0x10F43: 68,
|
| 1912 |
+
0x10F44: 68,
|
| 1913 |
+
0x10F46: 84,
|
| 1914 |
+
0x10F47: 84,
|
| 1915 |
+
0x10F48: 84,
|
| 1916 |
+
0x10F49: 84,
|
| 1917 |
+
0x10F4A: 84,
|
| 1918 |
+
0x10F4B: 84,
|
| 1919 |
+
0x10F4C: 84,
|
| 1920 |
+
0x10F4D: 84,
|
| 1921 |
+
0x10F4E: 84,
|
| 1922 |
+
0x10F4F: 84,
|
| 1923 |
+
0x10F50: 84,
|
| 1924 |
+
0x10F51: 68,
|
| 1925 |
+
0x10F52: 68,
|
| 1926 |
+
0x10F53: 68,
|
| 1927 |
+
0x10F54: 82,
|
| 1928 |
+
0x10F70: 68,
|
| 1929 |
+
0x10F71: 68,
|
| 1930 |
+
0x10F72: 68,
|
| 1931 |
+
0x10F73: 68,
|
| 1932 |
+
0x10F74: 82,
|
| 1933 |
+
0x10F75: 82,
|
| 1934 |
+
0x10F76: 68,
|
| 1935 |
+
0x10F77: 68,
|
| 1936 |
+
0x10F78: 68,
|
| 1937 |
+
0x10F79: 68,
|
| 1938 |
+
0x10F7A: 68,
|
| 1939 |
+
0x10F7B: 68,
|
| 1940 |
+
0x10F7C: 68,
|
| 1941 |
+
0x10F7D: 68,
|
| 1942 |
+
0x10F7E: 68,
|
| 1943 |
+
0x10F7F: 68,
|
| 1944 |
+
0x10F80: 68,
|
| 1945 |
+
0x10F81: 68,
|
| 1946 |
+
0x10F82: 84,
|
| 1947 |
+
0x10F83: 84,
|
| 1948 |
+
0x10F84: 84,
|
| 1949 |
+
0x10F85: 84,
|
| 1950 |
+
0x10FB0: 68,
|
| 1951 |
+
0x10FB2: 68,
|
| 1952 |
+
0x10FB3: 68,
|
| 1953 |
+
0x10FB4: 82,
|
| 1954 |
+
0x10FB5: 82,
|
| 1955 |
+
0x10FB6: 82,
|
| 1956 |
+
0x10FB8: 68,
|
| 1957 |
+
0x10FB9: 82,
|
| 1958 |
+
0x10FBA: 82,
|
| 1959 |
+
0x10FBB: 68,
|
| 1960 |
+
0x10FBC: 68,
|
| 1961 |
+
0x10FBD: 82,
|
| 1962 |
+
0x10FBE: 68,
|
| 1963 |
+
0x10FBF: 68,
|
| 1964 |
+
0x10FC1: 68,
|
| 1965 |
+
0x10FC2: 82,
|
| 1966 |
+
0x10FC3: 82,
|
| 1967 |
+
0x10FC4: 68,
|
| 1968 |
+
0x10FC9: 82,
|
| 1969 |
+
0x10FCA: 68,
|
| 1970 |
+
0x10FCB: 76,
|
| 1971 |
+
0x11001: 84,
|
| 1972 |
+
0x11038: 84,
|
| 1973 |
+
0x11039: 84,
|
| 1974 |
+
0x1103A: 84,
|
| 1975 |
+
0x1103B: 84,
|
| 1976 |
+
0x1103C: 84,
|
| 1977 |
+
0x1103D: 84,
|
| 1978 |
+
0x1103E: 84,
|
| 1979 |
+
0x1103F: 84,
|
| 1980 |
+
0x11040: 84,
|
| 1981 |
+
0x11041: 84,
|
| 1982 |
+
0x11042: 84,
|
| 1983 |
+
0x11043: 84,
|
| 1984 |
+
0x11044: 84,
|
| 1985 |
+
0x11045: 84,
|
| 1986 |
+
0x11046: 84,
|
| 1987 |
+
0x11070: 84,
|
| 1988 |
+
0x11073: 84,
|
| 1989 |
+
0x11074: 84,
|
| 1990 |
+
0x1107F: 84,
|
| 1991 |
+
0x11080: 84,
|
| 1992 |
+
0x11081: 84,
|
| 1993 |
+
0x110B3: 84,
|
| 1994 |
+
0x110B4: 84,
|
| 1995 |
+
0x110B5: 84,
|
| 1996 |
+
0x110B6: 84,
|
| 1997 |
+
0x110B9: 84,
|
| 1998 |
+
0x110BA: 84,
|
| 1999 |
+
0x110C2: 84,
|
| 2000 |
+
0x11100: 84,
|
| 2001 |
+
0x11101: 84,
|
| 2002 |
+
0x11102: 84,
|
| 2003 |
+
0x11127: 84,
|
| 2004 |
+
0x11128: 84,
|
| 2005 |
+
0x11129: 84,
|
| 2006 |
+
0x1112A: 84,
|
| 2007 |
+
0x1112B: 84,
|
| 2008 |
+
0x1112D: 84,
|
| 2009 |
+
0x1112E: 84,
|
| 2010 |
+
0x1112F: 84,
|
| 2011 |
+
0x11130: 84,
|
| 2012 |
+
0x11131: 84,
|
| 2013 |
+
0x11132: 84,
|
| 2014 |
+
0x11133: 84,
|
| 2015 |
+
0x11134: 84,
|
| 2016 |
+
0x11173: 84,
|
| 2017 |
+
0x11180: 84,
|
| 2018 |
+
0x11181: 84,
|
| 2019 |
+
0x111B6: 84,
|
| 2020 |
+
0x111B7: 84,
|
| 2021 |
+
0x111B8: 84,
|
| 2022 |
+
0x111B9: 84,
|
| 2023 |
+
0x111BA: 84,
|
| 2024 |
+
0x111BB: 84,
|
| 2025 |
+
0x111BC: 84,
|
| 2026 |
+
0x111BD: 84,
|
| 2027 |
+
0x111BE: 84,
|
| 2028 |
+
0x111C9: 84,
|
| 2029 |
+
0x111CA: 84,
|
| 2030 |
+
0x111CB: 84,
|
| 2031 |
+
0x111CC: 84,
|
| 2032 |
+
0x111CF: 84,
|
| 2033 |
+
0x1122F: 84,
|
| 2034 |
+
0x11230: 84,
|
| 2035 |
+
0x11231: 84,
|
| 2036 |
+
0x11234: 84,
|
| 2037 |
+
0x11236: 84,
|
| 2038 |
+
0x11237: 84,
|
| 2039 |
+
0x1123E: 84,
|
| 2040 |
+
0x11241: 84,
|
| 2041 |
+
0x112DF: 84,
|
| 2042 |
+
0x112E3: 84,
|
| 2043 |
+
0x112E4: 84,
|
| 2044 |
+
0x112E5: 84,
|
| 2045 |
+
0x112E6: 84,
|
| 2046 |
+
0x112E7: 84,
|
| 2047 |
+
0x112E8: 84,
|
| 2048 |
+
0x112E9: 84,
|
| 2049 |
+
0x112EA: 84,
|
| 2050 |
+
0x11300: 84,
|
| 2051 |
+
0x11301: 84,
|
| 2052 |
+
0x1133B: 84,
|
| 2053 |
+
0x1133C: 84,
|
| 2054 |
+
0x11340: 84,
|
| 2055 |
+
0x11366: 84,
|
| 2056 |
+
0x11367: 84,
|
| 2057 |
+
0x11368: 84,
|
| 2058 |
+
0x11369: 84,
|
| 2059 |
+
0x1136A: 84,
|
| 2060 |
+
0x1136B: 84,
|
| 2061 |
+
0x1136C: 84,
|
| 2062 |
+
0x11370: 84,
|
| 2063 |
+
0x11371: 84,
|
| 2064 |
+
0x11372: 84,
|
| 2065 |
+
0x11373: 84,
|
| 2066 |
+
0x11374: 84,
|
| 2067 |
+
0x113BB: 84,
|
| 2068 |
+
0x113BC: 84,
|
| 2069 |
+
0x113BD: 84,
|
| 2070 |
+
0x113BE: 84,
|
| 2071 |
+
0x113BF: 84,
|
| 2072 |
+
0x113C0: 84,
|
| 2073 |
+
0x113CE: 84,
|
| 2074 |
+
0x113D0: 84,
|
| 2075 |
+
0x113D2: 84,
|
| 2076 |
+
0x113E1: 84,
|
| 2077 |
+
0x113E2: 84,
|
| 2078 |
+
0x11438: 84,
|
| 2079 |
+
0x11439: 84,
|
| 2080 |
+
0x1143A: 84,
|
| 2081 |
+
0x1143B: 84,
|
| 2082 |
+
0x1143C: 84,
|
| 2083 |
+
0x1143D: 84,
|
| 2084 |
+
0x1143E: 84,
|
| 2085 |
+
0x1143F: 84,
|
| 2086 |
+
0x11442: 84,
|
| 2087 |
+
0x11443: 84,
|
| 2088 |
+
0x11444: 84,
|
| 2089 |
+
0x11446: 84,
|
| 2090 |
+
0x1145E: 84,
|
| 2091 |
+
0x114B3: 84,
|
| 2092 |
+
0x114B4: 84,
|
| 2093 |
+
0x114B5: 84,
|
| 2094 |
+
0x114B6: 84,
|
| 2095 |
+
0x114B7: 84,
|
| 2096 |
+
0x114B8: 84,
|
| 2097 |
+
0x114BA: 84,
|
| 2098 |
+
0x114BF: 84,
|
| 2099 |
+
0x114C0: 84,
|
| 2100 |
+
0x114C2: 84,
|
| 2101 |
+
0x114C3: 84,
|
| 2102 |
+
0x115B2: 84,
|
| 2103 |
+
0x115B3: 84,
|
| 2104 |
+
0x115B4: 84,
|
| 2105 |
+
0x115B5: 84,
|
| 2106 |
+
0x115BC: 84,
|
| 2107 |
+
0x115BD: 84,
|
| 2108 |
+
0x115BF: 84,
|
| 2109 |
+
0x115C0: 84,
|
| 2110 |
+
0x115DC: 84,
|
| 2111 |
+
0x115DD: 84,
|
| 2112 |
+
0x11633: 84,
|
| 2113 |
+
0x11634: 84,
|
| 2114 |
+
0x11635: 84,
|
| 2115 |
+
0x11636: 84,
|
| 2116 |
+
0x11637: 84,
|
| 2117 |
+
0x11638: 84,
|
| 2118 |
+
0x11639: 84,
|
| 2119 |
+
0x1163A: 84,
|
| 2120 |
+
0x1163D: 84,
|
| 2121 |
+
0x1163F: 84,
|
| 2122 |
+
0x11640: 84,
|
| 2123 |
+
0x116AB: 84,
|
| 2124 |
+
0x116AD: 84,
|
| 2125 |
+
0x116B0: 84,
|
| 2126 |
+
0x116B1: 84,
|
| 2127 |
+
0x116B2: 84,
|
| 2128 |
+
0x116B3: 84,
|
| 2129 |
+
0x116B4: 84,
|
| 2130 |
+
0x116B5: 84,
|
| 2131 |
+
0x116B7: 84,
|
| 2132 |
+
0x1171D: 84,
|
| 2133 |
+
0x1171F: 84,
|
| 2134 |
+
0x11722: 84,
|
| 2135 |
+
0x11723: 84,
|
| 2136 |
+
0x11724: 84,
|
| 2137 |
+
0x11725: 84,
|
| 2138 |
+
0x11727: 84,
|
| 2139 |
+
0x11728: 84,
|
| 2140 |
+
0x11729: 84,
|
| 2141 |
+
0x1172A: 84,
|
| 2142 |
+
0x1172B: 84,
|
| 2143 |
+
0x1182F: 84,
|
| 2144 |
+
0x11830: 84,
|
| 2145 |
+
0x11831: 84,
|
| 2146 |
+
0x11832: 84,
|
| 2147 |
+
0x11833: 84,
|
| 2148 |
+
0x11834: 84,
|
| 2149 |
+
0x11835: 84,
|
| 2150 |
+
0x11836: 84,
|
| 2151 |
+
0x11837: 84,
|
| 2152 |
+
0x11839: 84,
|
| 2153 |
+
0x1183A: 84,
|
| 2154 |
+
0x1193B: 84,
|
| 2155 |
+
0x1193C: 84,
|
| 2156 |
+
0x1193E: 84,
|
| 2157 |
+
0x11943: 84,
|
| 2158 |
+
0x119D4: 84,
|
| 2159 |
+
0x119D5: 84,
|
| 2160 |
+
0x119D6: 84,
|
| 2161 |
+
0x119D7: 84,
|
| 2162 |
+
0x119DA: 84,
|
| 2163 |
+
0x119DB: 84,
|
| 2164 |
+
0x119E0: 84,
|
| 2165 |
+
0x11A01: 84,
|
| 2166 |
+
0x11A02: 84,
|
| 2167 |
+
0x11A03: 84,
|
| 2168 |
+
0x11A04: 84,
|
| 2169 |
+
0x11A05: 84,
|
| 2170 |
+
0x11A06: 84,
|
| 2171 |
+
0x11A07: 84,
|
| 2172 |
+
0x11A08: 84,
|
| 2173 |
+
0x11A09: 84,
|
| 2174 |
+
0x11A0A: 84,
|
| 2175 |
+
0x11A33: 84,
|
| 2176 |
+
0x11A34: 84,
|
| 2177 |
+
0x11A35: 84,
|
| 2178 |
+
0x11A36: 84,
|
| 2179 |
+
0x11A37: 84,
|
| 2180 |
+
0x11A38: 84,
|
| 2181 |
+
0x11A3B: 84,
|
| 2182 |
+
0x11A3C: 84,
|
| 2183 |
+
0x11A3D: 84,
|
| 2184 |
+
0x11A3E: 84,
|
| 2185 |
+
0x11A47: 84,
|
| 2186 |
+
0x11A51: 84,
|
| 2187 |
+
0x11A52: 84,
|
| 2188 |
+
0x11A53: 84,
|
| 2189 |
+
0x11A54: 84,
|
| 2190 |
+
0x11A55: 84,
|
| 2191 |
+
0x11A56: 84,
|
| 2192 |
+
0x11A59: 84,
|
| 2193 |
+
0x11A5A: 84,
|
| 2194 |
+
0x11A5B: 84,
|
| 2195 |
+
0x11A8A: 84,
|
| 2196 |
+
0x11A8B: 84,
|
| 2197 |
+
0x11A8C: 84,
|
| 2198 |
+
0x11A8D: 84,
|
| 2199 |
+
0x11A8E: 84,
|
| 2200 |
+
0x11A8F: 84,
|
| 2201 |
+
0x11A90: 84,
|
| 2202 |
+
0x11A91: 84,
|
| 2203 |
+
0x11A92: 84,
|
| 2204 |
+
0x11A93: 84,
|
| 2205 |
+
0x11A94: 84,
|
| 2206 |
+
0x11A95: 84,
|
| 2207 |
+
0x11A96: 84,
|
| 2208 |
+
0x11A98: 84,
|
| 2209 |
+
0x11A99: 84,
|
| 2210 |
+
0x11C30: 84,
|
| 2211 |
+
0x11C31: 84,
|
| 2212 |
+
0x11C32: 84,
|
| 2213 |
+
0x11C33: 84,
|
| 2214 |
+
0x11C34: 84,
|
| 2215 |
+
0x11C35: 84,
|
| 2216 |
+
0x11C36: 84,
|
| 2217 |
+
0x11C38: 84,
|
| 2218 |
+
0x11C39: 84,
|
| 2219 |
+
0x11C3A: 84,
|
| 2220 |
+
0x11C3B: 84,
|
| 2221 |
+
0x11C3C: 84,
|
| 2222 |
+
0x11C3D: 84,
|
| 2223 |
+
0x11C3F: 84,
|
| 2224 |
+
0x11C92: 84,
|
| 2225 |
+
0x11C93: 84,
|
| 2226 |
+
0x11C94: 84,
|
| 2227 |
+
0x11C95: 84,
|
| 2228 |
+
0x11C96: 84,
|
| 2229 |
+
0x11C97: 84,
|
| 2230 |
+
0x11C98: 84,
|
| 2231 |
+
0x11C99: 84,
|
| 2232 |
+
0x11C9A: 84,
|
| 2233 |
+
0x11C9B: 84,
|
| 2234 |
+
0x11C9C: 84,
|
| 2235 |
+
0x11C9D: 84,
|
| 2236 |
+
0x11C9E: 84,
|
| 2237 |
+
0x11C9F: 84,
|
| 2238 |
+
0x11CA0: 84,
|
| 2239 |
+
0x11CA1: 84,
|
| 2240 |
+
0x11CA2: 84,
|
| 2241 |
+
0x11CA3: 84,
|
| 2242 |
+
0x11CA4: 84,
|
| 2243 |
+
0x11CA5: 84,
|
| 2244 |
+
0x11CA6: 84,
|
| 2245 |
+
0x11CA7: 84,
|
| 2246 |
+
0x11CAA: 84,
|
| 2247 |
+
0x11CAB: 84,
|
| 2248 |
+
0x11CAC: 84,
|
| 2249 |
+
0x11CAD: 84,
|
| 2250 |
+
0x11CAE: 84,
|
| 2251 |
+
0x11CAF: 84,
|
| 2252 |
+
0x11CB0: 84,
|
| 2253 |
+
0x11CB2: 84,
|
| 2254 |
+
0x11CB3: 84,
|
| 2255 |
+
0x11CB5: 84,
|
| 2256 |
+
0x11CB6: 84,
|
| 2257 |
+
0x11D31: 84,
|
| 2258 |
+
0x11D32: 84,
|
| 2259 |
+
0x11D33: 84,
|
| 2260 |
+
0x11D34: 84,
|
| 2261 |
+
0x11D35: 84,
|
| 2262 |
+
0x11D36: 84,
|
| 2263 |
+
0x11D3A: 84,
|
| 2264 |
+
0x11D3C: 84,
|
| 2265 |
+
0x11D3D: 84,
|
| 2266 |
+
0x11D3F: 84,
|
| 2267 |
+
0x11D40: 84,
|
| 2268 |
+
0x11D41: 84,
|
| 2269 |
+
0x11D42: 84,
|
| 2270 |
+
0x11D43: 84,
|
| 2271 |
+
0x11D44: 84,
|
| 2272 |
+
0x11D45: 84,
|
| 2273 |
+
0x11D47: 84,
|
| 2274 |
+
0x11D90: 84,
|
| 2275 |
+
0x11D91: 84,
|
| 2276 |
+
0x11D95: 84,
|
| 2277 |
+
0x11D97: 84,
|
| 2278 |
+
0x11EF3: 84,
|
| 2279 |
+
0x11EF4: 84,
|
| 2280 |
+
0x11F00: 84,
|
| 2281 |
+
0x11F01: 84,
|
| 2282 |
+
0x11F36: 84,
|
| 2283 |
+
0x11F37: 84,
|
| 2284 |
+
0x11F38: 84,
|
| 2285 |
+
0x11F39: 84,
|
| 2286 |
+
0x11F3A: 84,
|
| 2287 |
+
0x11F40: 84,
|
| 2288 |
+
0x11F42: 84,
|
| 2289 |
+
0x11F5A: 84,
|
| 2290 |
+
0x13430: 84,
|
| 2291 |
+
0x13431: 84,
|
| 2292 |
+
0x13432: 84,
|
| 2293 |
+
0x13433: 84,
|
| 2294 |
+
0x13434: 84,
|
| 2295 |
+
0x13435: 84,
|
| 2296 |
+
0x13436: 84,
|
| 2297 |
+
0x13437: 84,
|
| 2298 |
+
0x13438: 84,
|
| 2299 |
+
0x13439: 84,
|
| 2300 |
+
0x1343A: 84,
|
| 2301 |
+
0x1343B: 84,
|
| 2302 |
+
0x1343C: 84,
|
| 2303 |
+
0x1343D: 84,
|
| 2304 |
+
0x1343E: 84,
|
| 2305 |
+
0x1343F: 84,
|
| 2306 |
+
0x13440: 84,
|
| 2307 |
+
0x13447: 84,
|
| 2308 |
+
0x13448: 84,
|
| 2309 |
+
0x13449: 84,
|
| 2310 |
+
0x1344A: 84,
|
| 2311 |
+
0x1344B: 84,
|
| 2312 |
+
0x1344C: 84,
|
| 2313 |
+
0x1344D: 84,
|
| 2314 |
+
0x1344E: 84,
|
| 2315 |
+
0x1344F: 84,
|
| 2316 |
+
0x13450: 84,
|
| 2317 |
+
0x13451: 84,
|
| 2318 |
+
0x13452: 84,
|
| 2319 |
+
0x13453: 84,
|
| 2320 |
+
0x13454: 84,
|
| 2321 |
+
0x13455: 84,
|
| 2322 |
+
0x1611E: 84,
|
| 2323 |
+
0x1611F: 84,
|
| 2324 |
+
0x16120: 84,
|
| 2325 |
+
0x16121: 84,
|
| 2326 |
+
0x16122: 84,
|
| 2327 |
+
0x16123: 84,
|
| 2328 |
+
0x16124: 84,
|
| 2329 |
+
0x16125: 84,
|
| 2330 |
+
0x16126: 84,
|
| 2331 |
+
0x16127: 84,
|
| 2332 |
+
0x16128: 84,
|
| 2333 |
+
0x16129: 84,
|
| 2334 |
+
0x1612D: 84,
|
| 2335 |
+
0x1612E: 84,
|
| 2336 |
+
0x1612F: 84,
|
| 2337 |
+
0x16AF0: 84,
|
| 2338 |
+
0x16AF1: 84,
|
| 2339 |
+
0x16AF2: 84,
|
| 2340 |
+
0x16AF3: 84,
|
| 2341 |
+
0x16AF4: 84,
|
| 2342 |
+
0x16B30: 84,
|
| 2343 |
+
0x16B31: 84,
|
| 2344 |
+
0x16B32: 84,
|
| 2345 |
+
0x16B33: 84,
|
| 2346 |
+
0x16B34: 84,
|
| 2347 |
+
0x16B35: 84,
|
| 2348 |
+
0x16B36: 84,
|
| 2349 |
+
0x16F4F: 84,
|
| 2350 |
+
0x16F8F: 84,
|
| 2351 |
+
0x16F90: 84,
|
| 2352 |
+
0x16F91: 84,
|
| 2353 |
+
0x16F92: 84,
|
| 2354 |
+
0x16FE4: 84,
|
| 2355 |
+
0x1BC9D: 84,
|
| 2356 |
+
0x1BC9E: 84,
|
| 2357 |
+
0x1BCA0: 84,
|
| 2358 |
+
0x1BCA1: 84,
|
| 2359 |
+
0x1BCA2: 84,
|
| 2360 |
+
0x1BCA3: 84,
|
| 2361 |
+
0x1CF00: 84,
|
| 2362 |
+
0x1CF01: 84,
|
| 2363 |
+
0x1CF02: 84,
|
| 2364 |
+
0x1CF03: 84,
|
| 2365 |
+
0x1CF04: 84,
|
| 2366 |
+
0x1CF05: 84,
|
| 2367 |
+
0x1CF06: 84,
|
| 2368 |
+
0x1CF07: 84,
|
| 2369 |
+
0x1CF08: 84,
|
| 2370 |
+
0x1CF09: 84,
|
| 2371 |
+
0x1CF0A: 84,
|
| 2372 |
+
0x1CF0B: 84,
|
| 2373 |
+
0x1CF0C: 84,
|
| 2374 |
+
0x1CF0D: 84,
|
| 2375 |
+
0x1CF0E: 84,
|
| 2376 |
+
0x1CF0F: 84,
|
| 2377 |
+
0x1CF10: 84,
|
| 2378 |
+
0x1CF11: 84,
|
| 2379 |
+
0x1CF12: 84,
|
| 2380 |
+
0x1CF13: 84,
|
| 2381 |
+
0x1CF14: 84,
|
| 2382 |
+
0x1CF15: 84,
|
| 2383 |
+
0x1CF16: 84,
|
| 2384 |
+
0x1CF17: 84,
|
| 2385 |
+
0x1CF18: 84,
|
| 2386 |
+
0x1CF19: 84,
|
| 2387 |
+
0x1CF1A: 84,
|
| 2388 |
+
0x1CF1B: 84,
|
| 2389 |
+
0x1CF1C: 84,
|
| 2390 |
+
0x1CF1D: 84,
|
| 2391 |
+
0x1CF1E: 84,
|
| 2392 |
+
0x1CF1F: 84,
|
| 2393 |
+
0x1CF20: 84,
|
| 2394 |
+
0x1CF21: 84,
|
| 2395 |
+
0x1CF22: 84,
|
| 2396 |
+
0x1CF23: 84,
|
| 2397 |
+
0x1CF24: 84,
|
| 2398 |
+
0x1CF25: 84,
|
| 2399 |
+
0x1CF26: 84,
|
| 2400 |
+
0x1CF27: 84,
|
| 2401 |
+
0x1CF28: 84,
|
| 2402 |
+
0x1CF29: 84,
|
| 2403 |
+
0x1CF2A: 84,
|
| 2404 |
+
0x1CF2B: 84,
|
| 2405 |
+
0x1CF2C: 84,
|
| 2406 |
+
0x1CF2D: 84,
|
| 2407 |
+
0x1CF30: 84,
|
| 2408 |
+
0x1CF31: 84,
|
| 2409 |
+
0x1CF32: 84,
|
| 2410 |
+
0x1CF33: 84,
|
| 2411 |
+
0x1CF34: 84,
|
| 2412 |
+
0x1CF35: 84,
|
| 2413 |
+
0x1CF36: 84,
|
| 2414 |
+
0x1CF37: 84,
|
| 2415 |
+
0x1CF38: 84,
|
| 2416 |
+
0x1CF39: 84,
|
| 2417 |
+
0x1CF3A: 84,
|
| 2418 |
+
0x1CF3B: 84,
|
| 2419 |
+
0x1CF3C: 84,
|
| 2420 |
+
0x1CF3D: 84,
|
| 2421 |
+
0x1CF3E: 84,
|
| 2422 |
+
0x1CF3F: 84,
|
| 2423 |
+
0x1CF40: 84,
|
| 2424 |
+
0x1CF41: 84,
|
| 2425 |
+
0x1CF42: 84,
|
| 2426 |
+
0x1CF43: 84,
|
| 2427 |
+
0x1CF44: 84,
|
| 2428 |
+
0x1CF45: 84,
|
| 2429 |
+
0x1CF46: 84,
|
| 2430 |
+
0x1D167: 84,
|
| 2431 |
+
0x1D168: 84,
|
| 2432 |
+
0x1D169: 84,
|
| 2433 |
+
0x1D173: 84,
|
| 2434 |
+
0x1D174: 84,
|
| 2435 |
+
0x1D175: 84,
|
| 2436 |
+
0x1D176: 84,
|
| 2437 |
+
0x1D177: 84,
|
| 2438 |
+
0x1D178: 84,
|
| 2439 |
+
0x1D179: 84,
|
| 2440 |
+
0x1D17A: 84,
|
| 2441 |
+
0x1D17B: 84,
|
| 2442 |
+
0x1D17C: 84,
|
| 2443 |
+
0x1D17D: 84,
|
| 2444 |
+
0x1D17E: 84,
|
| 2445 |
+
0x1D17F: 84,
|
| 2446 |
+
0x1D180: 84,
|
| 2447 |
+
0x1D181: 84,
|
| 2448 |
+
0x1D182: 84,
|
| 2449 |
+
0x1D185: 84,
|
| 2450 |
+
0x1D186: 84,
|
| 2451 |
+
0x1D187: 84,
|
| 2452 |
+
0x1D188: 84,
|
| 2453 |
+
0x1D189: 84,
|
| 2454 |
+
0x1D18A: 84,
|
| 2455 |
+
0x1D18B: 84,
|
| 2456 |
+
0x1D1AA: 84,
|
| 2457 |
+
0x1D1AB: 84,
|
| 2458 |
+
0x1D1AC: 84,
|
| 2459 |
+
0x1D1AD: 84,
|
| 2460 |
+
0x1D242: 84,
|
| 2461 |
+
0x1D243: 84,
|
| 2462 |
+
0x1D244: 84,
|
| 2463 |
+
0x1DA00: 84,
|
| 2464 |
+
0x1DA01: 84,
|
| 2465 |
+
0x1DA02: 84,
|
| 2466 |
+
0x1DA03: 84,
|
| 2467 |
+
0x1DA04: 84,
|
| 2468 |
+
0x1DA05: 84,
|
| 2469 |
+
0x1DA06: 84,
|
| 2470 |
+
0x1DA07: 84,
|
| 2471 |
+
0x1DA08: 84,
|
| 2472 |
+
0x1DA09: 84,
|
| 2473 |
+
0x1DA0A: 84,
|
| 2474 |
+
0x1DA0B: 84,
|
| 2475 |
+
0x1DA0C: 84,
|
| 2476 |
+
0x1DA0D: 84,
|
| 2477 |
+
0x1DA0E: 84,
|
| 2478 |
+
0x1DA0F: 84,
|
| 2479 |
+
0x1DA10: 84,
|
| 2480 |
+
0x1DA11: 84,
|
| 2481 |
+
0x1DA12: 84,
|
| 2482 |
+
0x1DA13: 84,
|
| 2483 |
+
0x1DA14: 84,
|
| 2484 |
+
0x1DA15: 84,
|
| 2485 |
+
0x1DA16: 84,
|
| 2486 |
+
0x1DA17: 84,
|
| 2487 |
+
0x1DA18: 84,
|
| 2488 |
+
0x1DA19: 84,
|
| 2489 |
+
0x1DA1A: 84,
|
| 2490 |
+
0x1DA1B: 84,
|
| 2491 |
+
0x1DA1C: 84,
|
| 2492 |
+
0x1DA1D: 84,
|
| 2493 |
+
0x1DA1E: 84,
|
| 2494 |
+
0x1DA1F: 84,
|
| 2495 |
+
0x1DA20: 84,
|
| 2496 |
+
0x1DA21: 84,
|
| 2497 |
+
0x1DA22: 84,
|
| 2498 |
+
0x1DA23: 84,
|
| 2499 |
+
0x1DA24: 84,
|
| 2500 |
+
0x1DA25: 84,
|
| 2501 |
+
0x1DA26: 84,
|
| 2502 |
+
0x1DA27: 84,
|
| 2503 |
+
0x1DA28: 84,
|
| 2504 |
+
0x1DA29: 84,
|
| 2505 |
+
0x1DA2A: 84,
|
| 2506 |
+
0x1DA2B: 84,
|
| 2507 |
+
0x1DA2C: 84,
|
| 2508 |
+
0x1DA2D: 84,
|
| 2509 |
+
0x1DA2E: 84,
|
| 2510 |
+
0x1DA2F: 84,
|
| 2511 |
+
0x1DA30: 84,
|
| 2512 |
+
0x1DA31: 84,
|
| 2513 |
+
0x1DA32: 84,
|
| 2514 |
+
0x1DA33: 84,
|
| 2515 |
+
0x1DA34: 84,
|
| 2516 |
+
0x1DA35: 84,
|
| 2517 |
+
0x1DA36: 84,
|
| 2518 |
+
0x1DA3B: 84,
|
| 2519 |
+
0x1DA3C: 84,
|
| 2520 |
+
0x1DA3D: 84,
|
| 2521 |
+
0x1DA3E: 84,
|
| 2522 |
+
0x1DA3F: 84,
|
| 2523 |
+
0x1DA40: 84,
|
| 2524 |
+
0x1DA41: 84,
|
| 2525 |
+
0x1DA42: 84,
|
| 2526 |
+
0x1DA43: 84,
|
| 2527 |
+
0x1DA44: 84,
|
| 2528 |
+
0x1DA45: 84,
|
| 2529 |
+
0x1DA46: 84,
|
| 2530 |
+
0x1DA47: 84,
|
| 2531 |
+
0x1DA48: 84,
|
| 2532 |
+
0x1DA49: 84,
|
| 2533 |
+
0x1DA4A: 84,
|
| 2534 |
+
0x1DA4B: 84,
|
| 2535 |
+
0x1DA4C: 84,
|
| 2536 |
+
0x1DA4D: 84,
|
| 2537 |
+
0x1DA4E: 84,
|
| 2538 |
+
0x1DA4F: 84,
|
| 2539 |
+
0x1DA50: 84,
|
| 2540 |
+
0x1DA51: 84,
|
| 2541 |
+
0x1DA52: 84,
|
| 2542 |
+
0x1DA53: 84,
|
| 2543 |
+
0x1DA54: 84,
|
| 2544 |
+
0x1DA55: 84,
|
| 2545 |
+
0x1DA56: 84,
|
| 2546 |
+
0x1DA57: 84,
|
| 2547 |
+
0x1DA58: 84,
|
| 2548 |
+
0x1DA59: 84,
|
| 2549 |
+
0x1DA5A: 84,
|
| 2550 |
+
0x1DA5B: 84,
|
| 2551 |
+
0x1DA5C: 84,
|
| 2552 |
+
0x1DA5D: 84,
|
| 2553 |
+
0x1DA5E: 84,
|
| 2554 |
+
0x1DA5F: 84,
|
| 2555 |
+
0x1DA60: 84,
|
| 2556 |
+
0x1DA61: 84,
|
| 2557 |
+
0x1DA62: 84,
|
| 2558 |
+
0x1DA63: 84,
|
| 2559 |
+
0x1DA64: 84,
|
| 2560 |
+
0x1DA65: 84,
|
| 2561 |
+
0x1DA66: 84,
|
| 2562 |
+
0x1DA67: 84,
|
| 2563 |
+
0x1DA68: 84,
|
| 2564 |
+
0x1DA69: 84,
|
| 2565 |
+
0x1DA6A: 84,
|
| 2566 |
+
0x1DA6B: 84,
|
| 2567 |
+
0x1DA6C: 84,
|
| 2568 |
+
0x1DA75: 84,
|
| 2569 |
+
0x1DA84: 84,
|
| 2570 |
+
0x1DA9B: 84,
|
| 2571 |
+
0x1DA9C: 84,
|
| 2572 |
+
0x1DA9D: 84,
|
| 2573 |
+
0x1DA9E: 84,
|
| 2574 |
+
0x1DA9F: 84,
|
| 2575 |
+
0x1DAA1: 84,
|
| 2576 |
+
0x1DAA2: 84,
|
| 2577 |
+
0x1DAA3: 84,
|
| 2578 |
+
0x1DAA4: 84,
|
| 2579 |
+
0x1DAA5: 84,
|
| 2580 |
+
0x1DAA6: 84,
|
| 2581 |
+
0x1DAA7: 84,
|
| 2582 |
+
0x1DAA8: 84,
|
| 2583 |
+
0x1DAA9: 84,
|
| 2584 |
+
0x1DAAA: 84,
|
| 2585 |
+
0x1DAAB: 84,
|
| 2586 |
+
0x1DAAC: 84,
|
| 2587 |
+
0x1DAAD: 84,
|
| 2588 |
+
0x1DAAE: 84,
|
| 2589 |
+
0x1DAAF: 84,
|
| 2590 |
+
0x1E000: 84,
|
| 2591 |
+
0x1E001: 84,
|
| 2592 |
+
0x1E002: 84,
|
| 2593 |
+
0x1E003: 84,
|
| 2594 |
+
0x1E004: 84,
|
| 2595 |
+
0x1E005: 84,
|
| 2596 |
+
0x1E006: 84,
|
| 2597 |
+
0x1E008: 84,
|
| 2598 |
+
0x1E009: 84,
|
| 2599 |
+
0x1E00A: 84,
|
| 2600 |
+
0x1E00B: 84,
|
| 2601 |
+
0x1E00C: 84,
|
| 2602 |
+
0x1E00D: 84,
|
| 2603 |
+
0x1E00E: 84,
|
| 2604 |
+
0x1E00F: 84,
|
| 2605 |
+
0x1E010: 84,
|
| 2606 |
+
0x1E011: 84,
|
| 2607 |
+
0x1E012: 84,
|
| 2608 |
+
0x1E013: 84,
|
| 2609 |
+
0x1E014: 84,
|
| 2610 |
+
0x1E015: 84,
|
| 2611 |
+
0x1E016: 84,
|
| 2612 |
+
0x1E017: 84,
|
| 2613 |
+
0x1E018: 84,
|
| 2614 |
+
0x1E01B: 84,
|
| 2615 |
+
0x1E01C: 84,
|
| 2616 |
+
0x1E01D: 84,
|
| 2617 |
+
0x1E01E: 84,
|
| 2618 |
+
0x1E01F: 84,
|
| 2619 |
+
0x1E020: 84,
|
| 2620 |
+
0x1E021: 84,
|
| 2621 |
+
0x1E023: 84,
|
| 2622 |
+
0x1E024: 84,
|
| 2623 |
+
0x1E026: 84,
|
| 2624 |
+
0x1E027: 84,
|
| 2625 |
+
0x1E028: 84,
|
| 2626 |
+
0x1E029: 84,
|
| 2627 |
+
0x1E02A: 84,
|
| 2628 |
+
0x1E08F: 84,
|
| 2629 |
+
0x1E130: 84,
|
| 2630 |
+
0x1E131: 84,
|
| 2631 |
+
0x1E132: 84,
|
| 2632 |
+
0x1E133: 84,
|
| 2633 |
+
0x1E134: 84,
|
| 2634 |
+
0x1E135: 84,
|
| 2635 |
+
0x1E136: 84,
|
| 2636 |
+
0x1E2AE: 84,
|
| 2637 |
+
0x1E2EC: 84,
|
| 2638 |
+
0x1E2ED: 84,
|
| 2639 |
+
0x1E2EE: 84,
|
| 2640 |
+
0x1E2EF: 84,
|
| 2641 |
+
0x1E4EC: 84,
|
| 2642 |
+
0x1E4ED: 84,
|
| 2643 |
+
0x1E4EE: 84,
|
| 2644 |
+
0x1E4EF: 84,
|
| 2645 |
+
0x1E5EE: 84,
|
| 2646 |
+
0x1E5EF: 84,
|
| 2647 |
+
0x1E8D0: 84,
|
| 2648 |
+
0x1E8D1: 84,
|
| 2649 |
+
0x1E8D2: 84,
|
| 2650 |
+
0x1E8D3: 84,
|
| 2651 |
+
0x1E8D4: 84,
|
| 2652 |
+
0x1E8D5: 84,
|
| 2653 |
+
0x1E8D6: 84,
|
| 2654 |
+
0x1E900: 68,
|
| 2655 |
+
0x1E901: 68,
|
| 2656 |
+
0x1E902: 68,
|
| 2657 |
+
0x1E903: 68,
|
| 2658 |
+
0x1E904: 68,
|
| 2659 |
+
0x1E905: 68,
|
| 2660 |
+
0x1E906: 68,
|
| 2661 |
+
0x1E907: 68,
|
| 2662 |
+
0x1E908: 68,
|
| 2663 |
+
0x1E909: 68,
|
| 2664 |
+
0x1E90A: 68,
|
| 2665 |
+
0x1E90B: 68,
|
| 2666 |
+
0x1E90C: 68,
|
| 2667 |
+
0x1E90D: 68,
|
| 2668 |
+
0x1E90E: 68,
|
| 2669 |
+
0x1E90F: 68,
|
| 2670 |
+
0x1E910: 68,
|
| 2671 |
+
0x1E911: 68,
|
| 2672 |
+
0x1E912: 68,
|
| 2673 |
+
0x1E913: 68,
|
| 2674 |
+
0x1E914: 68,
|
| 2675 |
+
0x1E915: 68,
|
| 2676 |
+
0x1E916: 68,
|
| 2677 |
+
0x1E917: 68,
|
| 2678 |
+
0x1E918: 68,
|
| 2679 |
+
0x1E919: 68,
|
| 2680 |
+
0x1E91A: 68,
|
| 2681 |
+
0x1E91B: 68,
|
| 2682 |
+
0x1E91C: 68,
|
| 2683 |
+
0x1E91D: 68,
|
| 2684 |
+
0x1E91E: 68,
|
| 2685 |
+
0x1E91F: 68,
|
| 2686 |
+
0x1E920: 68,
|
| 2687 |
+
0x1E921: 68,
|
| 2688 |
+
0x1E922: 68,
|
| 2689 |
+
0x1E923: 68,
|
| 2690 |
+
0x1E924: 68,
|
| 2691 |
+
0x1E925: 68,
|
| 2692 |
+
0x1E926: 68,
|
| 2693 |
+
0x1E927: 68,
|
| 2694 |
+
0x1E928: 68,
|
| 2695 |
+
0x1E929: 68,
|
| 2696 |
+
0x1E92A: 68,
|
| 2697 |
+
0x1E92B: 68,
|
| 2698 |
+
0x1E92C: 68,
|
| 2699 |
+
0x1E92D: 68,
|
| 2700 |
+
0x1E92E: 68,
|
| 2701 |
+
0x1E92F: 68,
|
| 2702 |
+
0x1E930: 68,
|
| 2703 |
+
0x1E931: 68,
|
| 2704 |
+
0x1E932: 68,
|
| 2705 |
+
0x1E933: 68,
|
| 2706 |
+
0x1E934: 68,
|
| 2707 |
+
0x1E935: 68,
|
| 2708 |
+
0x1E936: 68,
|
| 2709 |
+
0x1E937: 68,
|
| 2710 |
+
0x1E938: 68,
|
| 2711 |
+
0x1E939: 68,
|
| 2712 |
+
0x1E93A: 68,
|
| 2713 |
+
0x1E93B: 68,
|
| 2714 |
+
0x1E93C: 68,
|
| 2715 |
+
0x1E93D: 68,
|
| 2716 |
+
0x1E93E: 68,
|
| 2717 |
+
0x1E93F: 68,
|
| 2718 |
+
0x1E940: 68,
|
| 2719 |
+
0x1E941: 68,
|
| 2720 |
+
0x1E942: 68,
|
| 2721 |
+
0x1E943: 68,
|
| 2722 |
+
0x1E944: 84,
|
| 2723 |
+
0x1E945: 84,
|
| 2724 |
+
0x1E946: 84,
|
| 2725 |
+
0x1E947: 84,
|
| 2726 |
+
0x1E948: 84,
|
| 2727 |
+
0x1E949: 84,
|
| 2728 |
+
0x1E94A: 84,
|
| 2729 |
+
0x1E94B: 84,
|
| 2730 |
+
0xE0001: 84,
|
| 2731 |
+
0xE0020: 84,
|
| 2732 |
+
0xE0021: 84,
|
| 2733 |
+
0xE0022: 84,
|
| 2734 |
+
0xE0023: 84,
|
| 2735 |
+
0xE0024: 84,
|
| 2736 |
+
0xE0025: 84,
|
| 2737 |
+
0xE0026: 84,
|
| 2738 |
+
0xE0027: 84,
|
| 2739 |
+
0xE0028: 84,
|
| 2740 |
+
0xE0029: 84,
|
| 2741 |
+
0xE002A: 84,
|
| 2742 |
+
0xE002B: 84,
|
| 2743 |
+
0xE002C: 84,
|
| 2744 |
+
0xE002D: 84,
|
| 2745 |
+
0xE002E: 84,
|
| 2746 |
+
0xE002F: 84,
|
| 2747 |
+
0xE0030: 84,
|
| 2748 |
+
0xE0031: 84,
|
| 2749 |
+
0xE0032: 84,
|
| 2750 |
+
0xE0033: 84,
|
| 2751 |
+
0xE0034: 84,
|
| 2752 |
+
0xE0035: 84,
|
| 2753 |
+
0xE0036: 84,
|
| 2754 |
+
0xE0037: 84,
|
| 2755 |
+
0xE0038: 84,
|
| 2756 |
+
0xE0039: 84,
|
| 2757 |
+
0xE003A: 84,
|
| 2758 |
+
0xE003B: 84,
|
| 2759 |
+
0xE003C: 84,
|
| 2760 |
+
0xE003D: 84,
|
| 2761 |
+
0xE003E: 84,
|
| 2762 |
+
0xE003F: 84,
|
| 2763 |
+
0xE0040: 84,
|
| 2764 |
+
0xE0041: 84,
|
| 2765 |
+
0xE0042: 84,
|
| 2766 |
+
0xE0043: 84,
|
| 2767 |
+
0xE0044: 84,
|
| 2768 |
+
0xE0045: 84,
|
| 2769 |
+
0xE0046: 84,
|
| 2770 |
+
0xE0047: 84,
|
| 2771 |
+
0xE0048: 84,
|
| 2772 |
+
0xE0049: 84,
|
| 2773 |
+
0xE004A: 84,
|
| 2774 |
+
0xE004B: 84,
|
| 2775 |
+
0xE004C: 84,
|
| 2776 |
+
0xE004D: 84,
|
| 2777 |
+
0xE004E: 84,
|
| 2778 |
+
0xE004F: 84,
|
| 2779 |
+
0xE0050: 84,
|
| 2780 |
+
0xE0051: 84,
|
| 2781 |
+
0xE0052: 84,
|
| 2782 |
+
0xE0053: 84,
|
| 2783 |
+
0xE0054: 84,
|
| 2784 |
+
0xE0055: 84,
|
| 2785 |
+
0xE0056: 84,
|
| 2786 |
+
0xE0057: 84,
|
| 2787 |
+
0xE0058: 84,
|
| 2788 |
+
0xE0059: 84,
|
| 2789 |
+
0xE005A: 84,
|
| 2790 |
+
0xE005B: 84,
|
| 2791 |
+
0xE005C: 84,
|
| 2792 |
+
0xE005D: 84,
|
| 2793 |
+
0xE005E: 84,
|
| 2794 |
+
0xE005F: 84,
|
| 2795 |
+
0xE0060: 84,
|
| 2796 |
+
0xE0061: 84,
|
| 2797 |
+
0xE0062: 84,
|
| 2798 |
+
0xE0063: 84,
|
| 2799 |
+
0xE0064: 84,
|
| 2800 |
+
0xE0065: 84,
|
| 2801 |
+
0xE0066: 84,
|
| 2802 |
+
0xE0067: 84,
|
| 2803 |
+
0xE0068: 84,
|
| 2804 |
+
0xE0069: 84,
|
| 2805 |
+
0xE006A: 84,
|
| 2806 |
+
0xE006B: 84,
|
| 2807 |
+
0xE006C: 84,
|
| 2808 |
+
0xE006D: 84,
|
| 2809 |
+
0xE006E: 84,
|
| 2810 |
+
0xE006F: 84,
|
| 2811 |
+
0xE0070: 84,
|
| 2812 |
+
0xE0071: 84,
|
| 2813 |
+
0xE0072: 84,
|
| 2814 |
+
0xE0073: 84,
|
| 2815 |
+
0xE0074: 84,
|
| 2816 |
+
0xE0075: 84,
|
| 2817 |
+
0xE0076: 84,
|
| 2818 |
+
0xE0077: 84,
|
| 2819 |
+
0xE0078: 84,
|
| 2820 |
+
0xE0079: 84,
|
| 2821 |
+
0xE007A: 84,
|
| 2822 |
+
0xE007B: 84,
|
| 2823 |
+
0xE007C: 84,
|
| 2824 |
+
0xE007D: 84,
|
| 2825 |
+
0xE007E: 84,
|
| 2826 |
+
0xE007F: 84,
|
| 2827 |
+
0xE0100: 84,
|
| 2828 |
+
0xE0101: 84,
|
| 2829 |
+
0xE0102: 84,
|
| 2830 |
+
0xE0103: 84,
|
| 2831 |
+
0xE0104: 84,
|
| 2832 |
+
0xE0105: 84,
|
| 2833 |
+
0xE0106: 84,
|
| 2834 |
+
0xE0107: 84,
|
| 2835 |
+
0xE0108: 84,
|
| 2836 |
+
0xE0109: 84,
|
| 2837 |
+
0xE010A: 84,
|
| 2838 |
+
0xE010B: 84,
|
| 2839 |
+
0xE010C: 84,
|
| 2840 |
+
0xE010D: 84,
|
| 2841 |
+
0xE010E: 84,
|
| 2842 |
+
0xE010F: 84,
|
| 2843 |
+
0xE0110: 84,
|
| 2844 |
+
0xE0111: 84,
|
| 2845 |
+
0xE0112: 84,
|
| 2846 |
+
0xE0113: 84,
|
| 2847 |
+
0xE0114: 84,
|
| 2848 |
+
0xE0115: 84,
|
| 2849 |
+
0xE0116: 84,
|
| 2850 |
+
0xE0117: 84,
|
| 2851 |
+
0xE0118: 84,
|
| 2852 |
+
0xE0119: 84,
|
| 2853 |
+
0xE011A: 84,
|
| 2854 |
+
0xE011B: 84,
|
| 2855 |
+
0xE011C: 84,
|
| 2856 |
+
0xE011D: 84,
|
| 2857 |
+
0xE011E: 84,
|
| 2858 |
+
0xE011F: 84,
|
| 2859 |
+
0xE0120: 84,
|
| 2860 |
+
0xE0121: 84,
|
| 2861 |
+
0xE0122: 84,
|
| 2862 |
+
0xE0123: 84,
|
| 2863 |
+
0xE0124: 84,
|
| 2864 |
+
0xE0125: 84,
|
| 2865 |
+
0xE0126: 84,
|
| 2866 |
+
0xE0127: 84,
|
| 2867 |
+
0xE0128: 84,
|
| 2868 |
+
0xE0129: 84,
|
| 2869 |
+
0xE012A: 84,
|
| 2870 |
+
0xE012B: 84,
|
| 2871 |
+
0xE012C: 84,
|
| 2872 |
+
0xE012D: 84,
|
| 2873 |
+
0xE012E: 84,
|
| 2874 |
+
0xE012F: 84,
|
| 2875 |
+
0xE0130: 84,
|
| 2876 |
+
0xE0131: 84,
|
| 2877 |
+
0xE0132: 84,
|
| 2878 |
+
0xE0133: 84,
|
| 2879 |
+
0xE0134: 84,
|
| 2880 |
+
0xE0135: 84,
|
| 2881 |
+
0xE0136: 84,
|
| 2882 |
+
0xE0137: 84,
|
| 2883 |
+
0xE0138: 84,
|
| 2884 |
+
0xE0139: 84,
|
| 2885 |
+
0xE013A: 84,
|
| 2886 |
+
0xE013B: 84,
|
| 2887 |
+
0xE013C: 84,
|
| 2888 |
+
0xE013D: 84,
|
| 2889 |
+
0xE013E: 84,
|
| 2890 |
+
0xE013F: 84,
|
| 2891 |
+
0xE0140: 84,
|
| 2892 |
+
0xE0141: 84,
|
| 2893 |
+
0xE0142: 84,
|
| 2894 |
+
0xE0143: 84,
|
| 2895 |
+
0xE0144: 84,
|
| 2896 |
+
0xE0145: 84,
|
| 2897 |
+
0xE0146: 84,
|
| 2898 |
+
0xE0147: 84,
|
| 2899 |
+
0xE0148: 84,
|
| 2900 |
+
0xE0149: 84,
|
| 2901 |
+
0xE014A: 84,
|
| 2902 |
+
0xE014B: 84,
|
| 2903 |
+
0xE014C: 84,
|
| 2904 |
+
0xE014D: 84,
|
| 2905 |
+
0xE014E: 84,
|
| 2906 |
+
0xE014F: 84,
|
| 2907 |
+
0xE0150: 84,
|
| 2908 |
+
0xE0151: 84,
|
| 2909 |
+
0xE0152: 84,
|
| 2910 |
+
0xE0153: 84,
|
| 2911 |
+
0xE0154: 84,
|
| 2912 |
+
0xE0155: 84,
|
| 2913 |
+
0xE0156: 84,
|
| 2914 |
+
0xE0157: 84,
|
| 2915 |
+
0xE0158: 84,
|
| 2916 |
+
0xE0159: 84,
|
| 2917 |
+
0xE015A: 84,
|
| 2918 |
+
0xE015B: 84,
|
| 2919 |
+
0xE015C: 84,
|
| 2920 |
+
0xE015D: 84,
|
| 2921 |
+
0xE015E: 84,
|
| 2922 |
+
0xE015F: 84,
|
| 2923 |
+
0xE0160: 84,
|
| 2924 |
+
0xE0161: 84,
|
| 2925 |
+
0xE0162: 84,
|
| 2926 |
+
0xE0163: 84,
|
| 2927 |
+
0xE0164: 84,
|
| 2928 |
+
0xE0165: 84,
|
| 2929 |
+
0xE0166: 84,
|
| 2930 |
+
0xE0167: 84,
|
| 2931 |
+
0xE0168: 84,
|
| 2932 |
+
0xE0169: 84,
|
| 2933 |
+
0xE016A: 84,
|
| 2934 |
+
0xE016B: 84,
|
| 2935 |
+
0xE016C: 84,
|
| 2936 |
+
0xE016D: 84,
|
| 2937 |
+
0xE016E: 84,
|
| 2938 |
+
0xE016F: 84,
|
| 2939 |
+
0xE0170: 84,
|
| 2940 |
+
0xE0171: 84,
|
| 2941 |
+
0xE0172: 84,
|
| 2942 |
+
0xE0173: 84,
|
| 2943 |
+
0xE0174: 84,
|
| 2944 |
+
0xE0175: 84,
|
| 2945 |
+
0xE0176: 84,
|
| 2946 |
+
0xE0177: 84,
|
| 2947 |
+
0xE0178: 84,
|
| 2948 |
+
0xE0179: 84,
|
| 2949 |
+
0xE017A: 84,
|
| 2950 |
+
0xE017B: 84,
|
| 2951 |
+
0xE017C: 84,
|
| 2952 |
+
0xE017D: 84,
|
| 2953 |
+
0xE017E: 84,
|
| 2954 |
+
0xE017F: 84,
|
| 2955 |
+
0xE0180: 84,
|
| 2956 |
+
0xE0181: 84,
|
| 2957 |
+
0xE0182: 84,
|
| 2958 |
+
0xE0183: 84,
|
| 2959 |
+
0xE0184: 84,
|
| 2960 |
+
0xE0185: 84,
|
| 2961 |
+
0xE0186: 84,
|
| 2962 |
+
0xE0187: 84,
|
| 2963 |
+
0xE0188: 84,
|
| 2964 |
+
0xE0189: 84,
|
| 2965 |
+
0xE018A: 84,
|
| 2966 |
+
0xE018B: 84,
|
| 2967 |
+
0xE018C: 84,
|
| 2968 |
+
0xE018D: 84,
|
| 2969 |
+
0xE018E: 84,
|
| 2970 |
+
0xE018F: 84,
|
| 2971 |
+
0xE0190: 84,
|
| 2972 |
+
0xE0191: 84,
|
| 2973 |
+
0xE0192: 84,
|
| 2974 |
+
0xE0193: 84,
|
| 2975 |
+
0xE0194: 84,
|
| 2976 |
+
0xE0195: 84,
|
| 2977 |
+
0xE0196: 84,
|
| 2978 |
+
0xE0197: 84,
|
| 2979 |
+
0xE0198: 84,
|
| 2980 |
+
0xE0199: 84,
|
| 2981 |
+
0xE019A: 84,
|
| 2982 |
+
0xE019B: 84,
|
| 2983 |
+
0xE019C: 84,
|
| 2984 |
+
0xE019D: 84,
|
| 2985 |
+
0xE019E: 84,
|
| 2986 |
+
0xE019F: 84,
|
| 2987 |
+
0xE01A0: 84,
|
| 2988 |
+
0xE01A1: 84,
|
| 2989 |
+
0xE01A2: 84,
|
| 2990 |
+
0xE01A3: 84,
|
| 2991 |
+
0xE01A4: 84,
|
| 2992 |
+
0xE01A5: 84,
|
| 2993 |
+
0xE01A6: 84,
|
| 2994 |
+
0xE01A7: 84,
|
| 2995 |
+
0xE01A8: 84,
|
| 2996 |
+
0xE01A9: 84,
|
| 2997 |
+
0xE01AA: 84,
|
| 2998 |
+
0xE01AB: 84,
|
| 2999 |
+
0xE01AC: 84,
|
| 3000 |
+
0xE01AD: 84,
|
| 3001 |
+
0xE01AE: 84,
|
| 3002 |
+
0xE01AF: 84,
|
| 3003 |
+
0xE01B0: 84,
|
| 3004 |
+
0xE01B1: 84,
|
| 3005 |
+
0xE01B2: 84,
|
| 3006 |
+
0xE01B3: 84,
|
| 3007 |
+
0xE01B4: 84,
|
| 3008 |
+
0xE01B5: 84,
|
| 3009 |
+
0xE01B6: 84,
|
| 3010 |
+
0xE01B7: 84,
|
| 3011 |
+
0xE01B8: 84,
|
| 3012 |
+
0xE01B9: 84,
|
| 3013 |
+
0xE01BA: 84,
|
| 3014 |
+
0xE01BB: 84,
|
| 3015 |
+
0xE01BC: 84,
|
| 3016 |
+
0xE01BD: 84,
|
| 3017 |
+
0xE01BE: 84,
|
| 3018 |
+
0xE01BF: 84,
|
| 3019 |
+
0xE01C0: 84,
|
| 3020 |
+
0xE01C1: 84,
|
| 3021 |
+
0xE01C2: 84,
|
| 3022 |
+
0xE01C3: 84,
|
| 3023 |
+
0xE01C4: 84,
|
| 3024 |
+
0xE01C5: 84,
|
| 3025 |
+
0xE01C6: 84,
|
| 3026 |
+
0xE01C7: 84,
|
| 3027 |
+
0xE01C8: 84,
|
| 3028 |
+
0xE01C9: 84,
|
| 3029 |
+
0xE01CA: 84,
|
| 3030 |
+
0xE01CB: 84,
|
| 3031 |
+
0xE01CC: 84,
|
| 3032 |
+
0xE01CD: 84,
|
| 3033 |
+
0xE01CE: 84,
|
| 3034 |
+
0xE01CF: 84,
|
| 3035 |
+
0xE01D0: 84,
|
| 3036 |
+
0xE01D1: 84,
|
| 3037 |
+
0xE01D2: 84,
|
| 3038 |
+
0xE01D3: 84,
|
| 3039 |
+
0xE01D4: 84,
|
| 3040 |
+
0xE01D5: 84,
|
| 3041 |
+
0xE01D6: 84,
|
| 3042 |
+
0xE01D7: 84,
|
| 3043 |
+
0xE01D8: 84,
|
| 3044 |
+
0xE01D9: 84,
|
| 3045 |
+
0xE01DA: 84,
|
| 3046 |
+
0xE01DB: 84,
|
| 3047 |
+
0xE01DC: 84,
|
| 3048 |
+
0xE01DD: 84,
|
| 3049 |
+
0xE01DE: 84,
|
| 3050 |
+
0xE01DF: 84,
|
| 3051 |
+
0xE01E0: 84,
|
| 3052 |
+
0xE01E1: 84,
|
| 3053 |
+
0xE01E2: 84,
|
| 3054 |
+
0xE01E3: 84,
|
| 3055 |
+
0xE01E4: 84,
|
| 3056 |
+
0xE01E5: 84,
|
| 3057 |
+
0xE01E6: 84,
|
| 3058 |
+
0xE01E7: 84,
|
| 3059 |
+
0xE01E8: 84,
|
| 3060 |
+
0xE01E9: 84,
|
| 3061 |
+
0xE01EA: 84,
|
| 3062 |
+
0xE01EB: 84,
|
| 3063 |
+
0xE01EC: 84,
|
| 3064 |
+
0xE01ED: 84,
|
| 3065 |
+
0xE01EE: 84,
|
| 3066 |
+
0xE01EF: 84,
|
| 3067 |
+
}
|
| 3068 |
+
codepoint_classes = {
|
| 3069 |
+
"PVALID": (
|
| 3070 |
+
0x2D0000002E,
|
| 3071 |
+
0x300000003A,
|
| 3072 |
+
0x610000007B,
|
| 3073 |
+
0xDF000000F7,
|
| 3074 |
+
0xF800000100,
|
| 3075 |
+
0x10100000102,
|
| 3076 |
+
0x10300000104,
|
| 3077 |
+
0x10500000106,
|
| 3078 |
+
0x10700000108,
|
| 3079 |
+
0x1090000010A,
|
| 3080 |
+
0x10B0000010C,
|
| 3081 |
+
0x10D0000010E,
|
| 3082 |
+
0x10F00000110,
|
| 3083 |
+
0x11100000112,
|
| 3084 |
+
0x11300000114,
|
| 3085 |
+
0x11500000116,
|
| 3086 |
+
0x11700000118,
|
| 3087 |
+
0x1190000011A,
|
| 3088 |
+
0x11B0000011C,
|
| 3089 |
+
0x11D0000011E,
|
| 3090 |
+
0x11F00000120,
|
| 3091 |
+
0x12100000122,
|
| 3092 |
+
0x12300000124,
|
| 3093 |
+
0x12500000126,
|
| 3094 |
+
0x12700000128,
|
| 3095 |
+
0x1290000012A,
|
| 3096 |
+
0x12B0000012C,
|
| 3097 |
+
0x12D0000012E,
|
| 3098 |
+
0x12F00000130,
|
| 3099 |
+
0x13100000132,
|
| 3100 |
+
0x13500000136,
|
| 3101 |
+
0x13700000139,
|
| 3102 |
+
0x13A0000013B,
|
| 3103 |
+
0x13C0000013D,
|
| 3104 |
+
0x13E0000013F,
|
| 3105 |
+
0x14200000143,
|
| 3106 |
+
0x14400000145,
|
| 3107 |
+
0x14600000147,
|
| 3108 |
+
0x14800000149,
|
| 3109 |
+
0x14B0000014C,
|
| 3110 |
+
0x14D0000014E,
|
| 3111 |
+
0x14F00000150,
|
| 3112 |
+
0x15100000152,
|
| 3113 |
+
0x15300000154,
|
| 3114 |
+
0x15500000156,
|
| 3115 |
+
0x15700000158,
|
| 3116 |
+
0x1590000015A,
|
| 3117 |
+
0x15B0000015C,
|
| 3118 |
+
0x15D0000015E,
|
| 3119 |
+
0x15F00000160,
|
| 3120 |
+
0x16100000162,
|
| 3121 |
+
0x16300000164,
|
| 3122 |
+
0x16500000166,
|
| 3123 |
+
0x16700000168,
|
| 3124 |
+
0x1690000016A,
|
| 3125 |
+
0x16B0000016C,
|
| 3126 |
+
0x16D0000016E,
|
| 3127 |
+
0x16F00000170,
|
| 3128 |
+
0x17100000172,
|
| 3129 |
+
0x17300000174,
|
| 3130 |
+
0x17500000176,
|
| 3131 |
+
0x17700000178,
|
| 3132 |
+
0x17A0000017B,
|
| 3133 |
+
0x17C0000017D,
|
| 3134 |
+
0x17E0000017F,
|
| 3135 |
+
0x18000000181,
|
| 3136 |
+
0x18300000184,
|
| 3137 |
+
0x18500000186,
|
| 3138 |
+
0x18800000189,
|
| 3139 |
+
0x18C0000018E,
|
| 3140 |
+
0x19200000193,
|
| 3141 |
+
0x19500000196,
|
| 3142 |
+
0x1990000019C,
|
| 3143 |
+
0x19E0000019F,
|
| 3144 |
+
0x1A1000001A2,
|
| 3145 |
+
0x1A3000001A4,
|
| 3146 |
+
0x1A5000001A6,
|
| 3147 |
+
0x1A8000001A9,
|
| 3148 |
+
0x1AA000001AC,
|
| 3149 |
+
0x1AD000001AE,
|
| 3150 |
+
0x1B0000001B1,
|
| 3151 |
+
0x1B4000001B5,
|
| 3152 |
+
0x1B6000001B7,
|
| 3153 |
+
0x1B9000001BC,
|
| 3154 |
+
0x1BD000001C4,
|
| 3155 |
+
0x1CE000001CF,
|
| 3156 |
+
0x1D0000001D1,
|
| 3157 |
+
0x1D2000001D3,
|
| 3158 |
+
0x1D4000001D5,
|
| 3159 |
+
0x1D6000001D7,
|
| 3160 |
+
0x1D8000001D9,
|
| 3161 |
+
0x1DA000001DB,
|
| 3162 |
+
0x1DC000001DE,
|
| 3163 |
+
0x1DF000001E0,
|
| 3164 |
+
0x1E1000001E2,
|
| 3165 |
+
0x1E3000001E4,
|
| 3166 |
+
0x1E5000001E6,
|
| 3167 |
+
0x1E7000001E8,
|
| 3168 |
+
0x1E9000001EA,
|
| 3169 |
+
0x1EB000001EC,
|
| 3170 |
+
0x1ED000001EE,
|
| 3171 |
+
0x1EF000001F1,
|
| 3172 |
+
0x1F5000001F6,
|
| 3173 |
+
0x1F9000001FA,
|
| 3174 |
+
0x1FB000001FC,
|
| 3175 |
+
0x1FD000001FE,
|
| 3176 |
+
0x1FF00000200,
|
| 3177 |
+
0x20100000202,
|
| 3178 |
+
0x20300000204,
|
| 3179 |
+
0x20500000206,
|
| 3180 |
+
0x20700000208,
|
| 3181 |
+
0x2090000020A,
|
| 3182 |
+
0x20B0000020C,
|
| 3183 |
+
0x20D0000020E,
|
| 3184 |
+
0x20F00000210,
|
| 3185 |
+
0x21100000212,
|
| 3186 |
+
0x21300000214,
|
| 3187 |
+
0x21500000216,
|
| 3188 |
+
0x21700000218,
|
| 3189 |
+
0x2190000021A,
|
| 3190 |
+
0x21B0000021C,
|
| 3191 |
+
0x21D0000021E,
|
| 3192 |
+
0x21F00000220,
|
| 3193 |
+
0x22100000222,
|
| 3194 |
+
0x22300000224,
|
| 3195 |
+
0x22500000226,
|
| 3196 |
+
0x22700000228,
|
| 3197 |
+
0x2290000022A,
|
| 3198 |
+
0x22B0000022C,
|
| 3199 |
+
0x22D0000022E,
|
| 3200 |
+
0x22F00000230,
|
| 3201 |
+
0x23100000232,
|
| 3202 |
+
0x2330000023A,
|
| 3203 |
+
0x23C0000023D,
|
| 3204 |
+
0x23F00000241,
|
| 3205 |
+
0x24200000243,
|
| 3206 |
+
0x24700000248,
|
| 3207 |
+
0x2490000024A,
|
| 3208 |
+
0x24B0000024C,
|
| 3209 |
+
0x24D0000024E,
|
| 3210 |
+
0x24F000002B0,
|
| 3211 |
+
0x2B9000002C2,
|
| 3212 |
+
0x2C6000002D2,
|
| 3213 |
+
0x2EC000002ED,
|
| 3214 |
+
0x2EE000002EF,
|
| 3215 |
+
0x30000000340,
|
| 3216 |
+
0x34200000343,
|
| 3217 |
+
0x3460000034F,
|
| 3218 |
+
0x35000000370,
|
| 3219 |
+
0x37100000372,
|
| 3220 |
+
0x37300000374,
|
| 3221 |
+
0x37700000378,
|
| 3222 |
+
0x37B0000037E,
|
| 3223 |
+
0x39000000391,
|
| 3224 |
+
0x3AC000003CF,
|
| 3225 |
+
0x3D7000003D8,
|
| 3226 |
+
0x3D9000003DA,
|
| 3227 |
+
0x3DB000003DC,
|
| 3228 |
+
0x3DD000003DE,
|
| 3229 |
+
0x3DF000003E0,
|
| 3230 |
+
0x3E1000003E2,
|
| 3231 |
+
0x3E3000003E4,
|
| 3232 |
+
0x3E5000003E6,
|
| 3233 |
+
0x3E7000003E8,
|
| 3234 |
+
0x3E9000003EA,
|
| 3235 |
+
0x3EB000003EC,
|
| 3236 |
+
0x3ED000003EE,
|
| 3237 |
+
0x3EF000003F0,
|
| 3238 |
+
0x3F3000003F4,
|
| 3239 |
+
0x3F8000003F9,
|
| 3240 |
+
0x3FB000003FD,
|
| 3241 |
+
0x43000000460,
|
| 3242 |
+
0x46100000462,
|
| 3243 |
+
0x46300000464,
|
| 3244 |
+
0x46500000466,
|
| 3245 |
+
0x46700000468,
|
| 3246 |
+
0x4690000046A,
|
| 3247 |
+
0x46B0000046C,
|
| 3248 |
+
0x46D0000046E,
|
| 3249 |
+
0x46F00000470,
|
| 3250 |
+
0x47100000472,
|
| 3251 |
+
0x47300000474,
|
| 3252 |
+
0x47500000476,
|
| 3253 |
+
0x47700000478,
|
| 3254 |
+
0x4790000047A,
|
| 3255 |
+
0x47B0000047C,
|
| 3256 |
+
0x47D0000047E,
|
| 3257 |
+
0x47F00000480,
|
| 3258 |
+
0x48100000482,
|
| 3259 |
+
0x48300000488,
|
| 3260 |
+
0x48B0000048C,
|
| 3261 |
+
0x48D0000048E,
|
| 3262 |
+
0x48F00000490,
|
| 3263 |
+
0x49100000492,
|
| 3264 |
+
0x49300000494,
|
| 3265 |
+
0x49500000496,
|
| 3266 |
+
0x49700000498,
|
| 3267 |
+
0x4990000049A,
|
| 3268 |
+
0x49B0000049C,
|
| 3269 |
+
0x49D0000049E,
|
| 3270 |
+
0x49F000004A0,
|
| 3271 |
+
0x4A1000004A2,
|
| 3272 |
+
0x4A3000004A4,
|
| 3273 |
+
0x4A5000004A6,
|
| 3274 |
+
0x4A7000004A8,
|
| 3275 |
+
0x4A9000004AA,
|
| 3276 |
+
0x4AB000004AC,
|
| 3277 |
+
0x4AD000004AE,
|
| 3278 |
+
0x4AF000004B0,
|
| 3279 |
+
0x4B1000004B2,
|
| 3280 |
+
0x4B3000004B4,
|
| 3281 |
+
0x4B5000004B6,
|
| 3282 |
+
0x4B7000004B8,
|
| 3283 |
+
0x4B9000004BA,
|
| 3284 |
+
0x4BB000004BC,
|
| 3285 |
+
0x4BD000004BE,
|
| 3286 |
+
0x4BF000004C0,
|
| 3287 |
+
0x4C2000004C3,
|
| 3288 |
+
0x4C4000004C5,
|
| 3289 |
+
0x4C6000004C7,
|
| 3290 |
+
0x4C8000004C9,
|
| 3291 |
+
0x4CA000004CB,
|
| 3292 |
+
0x4CC000004CD,
|
| 3293 |
+
0x4CE000004D0,
|
| 3294 |
+
0x4D1000004D2,
|
| 3295 |
+
0x4D3000004D4,
|
| 3296 |
+
0x4D5000004D6,
|
| 3297 |
+
0x4D7000004D8,
|
| 3298 |
+
0x4D9000004DA,
|
| 3299 |
+
0x4DB000004DC,
|
| 3300 |
+
0x4DD000004DE,
|
| 3301 |
+
0x4DF000004E0,
|
| 3302 |
+
0x4E1000004E2,
|
| 3303 |
+
0x4E3000004E4,
|
| 3304 |
+
0x4E5000004E6,
|
| 3305 |
+
0x4E7000004E8,
|
| 3306 |
+
0x4E9000004EA,
|
| 3307 |
+
0x4EB000004EC,
|
| 3308 |
+
0x4ED000004EE,
|
| 3309 |
+
0x4EF000004F0,
|
| 3310 |
+
0x4F1000004F2,
|
| 3311 |
+
0x4F3000004F4,
|
| 3312 |
+
0x4F5000004F6,
|
| 3313 |
+
0x4F7000004F8,
|
| 3314 |
+
0x4F9000004FA,
|
| 3315 |
+
0x4FB000004FC,
|
| 3316 |
+
0x4FD000004FE,
|
| 3317 |
+
0x4FF00000500,
|
| 3318 |
+
0x50100000502,
|
| 3319 |
+
0x50300000504,
|
| 3320 |
+
0x50500000506,
|
| 3321 |
+
0x50700000508,
|
| 3322 |
+
0x5090000050A,
|
| 3323 |
+
0x50B0000050C,
|
| 3324 |
+
0x50D0000050E,
|
| 3325 |
+
0x50F00000510,
|
| 3326 |
+
0x51100000512,
|
| 3327 |
+
0x51300000514,
|
| 3328 |
+
0x51500000516,
|
| 3329 |
+
0x51700000518,
|
| 3330 |
+
0x5190000051A,
|
| 3331 |
+
0x51B0000051C,
|
| 3332 |
+
0x51D0000051E,
|
| 3333 |
+
0x51F00000520,
|
| 3334 |
+
0x52100000522,
|
| 3335 |
+
0x52300000524,
|
| 3336 |
+
0x52500000526,
|
| 3337 |
+
0x52700000528,
|
| 3338 |
+
0x5290000052A,
|
| 3339 |
+
0x52B0000052C,
|
| 3340 |
+
0x52D0000052E,
|
| 3341 |
+
0x52F00000530,
|
| 3342 |
+
0x5590000055A,
|
| 3343 |
+
0x56000000587,
|
| 3344 |
+
0x58800000589,
|
| 3345 |
+
0x591000005BE,
|
| 3346 |
+
0x5BF000005C0,
|
| 3347 |
+
0x5C1000005C3,
|
| 3348 |
+
0x5C4000005C6,
|
| 3349 |
+
0x5C7000005C8,
|
| 3350 |
+
0x5D0000005EB,
|
| 3351 |
+
0x5EF000005F3,
|
| 3352 |
+
0x6100000061B,
|
| 3353 |
+
0x62000000640,
|
| 3354 |
+
0x64100000660,
|
| 3355 |
+
0x66E00000675,
|
| 3356 |
+
0x679000006D4,
|
| 3357 |
+
0x6D5000006DD,
|
| 3358 |
+
0x6DF000006E9,
|
| 3359 |
+
0x6EA000006F0,
|
| 3360 |
+
0x6FA00000700,
|
| 3361 |
+
0x7100000074B,
|
| 3362 |
+
0x74D000007B2,
|
| 3363 |
+
0x7C0000007F6,
|
| 3364 |
+
0x7FD000007FE,
|
| 3365 |
+
0x8000000082E,
|
| 3366 |
+
0x8400000085C,
|
| 3367 |
+
0x8600000086B,
|
| 3368 |
+
0x87000000888,
|
| 3369 |
+
0x8890000088F,
|
| 3370 |
+
0x897000008E2,
|
| 3371 |
+
0x8E300000958,
|
| 3372 |
+
0x96000000964,
|
| 3373 |
+
0x96600000970,
|
| 3374 |
+
0x97100000984,
|
| 3375 |
+
0x9850000098D,
|
| 3376 |
+
0x98F00000991,
|
| 3377 |
+
0x993000009A9,
|
| 3378 |
+
0x9AA000009B1,
|
| 3379 |
+
0x9B2000009B3,
|
| 3380 |
+
0x9B6000009BA,
|
| 3381 |
+
0x9BC000009C5,
|
| 3382 |
+
0x9C7000009C9,
|
| 3383 |
+
0x9CB000009CF,
|
| 3384 |
+
0x9D7000009D8,
|
| 3385 |
+
0x9E0000009E4,
|
| 3386 |
+
0x9E6000009F2,
|
| 3387 |
+
0x9FC000009FD,
|
| 3388 |
+
0x9FE000009FF,
|
| 3389 |
+
0xA0100000A04,
|
| 3390 |
+
0xA0500000A0B,
|
| 3391 |
+
0xA0F00000A11,
|
| 3392 |
+
0xA1300000A29,
|
| 3393 |
+
0xA2A00000A31,
|
| 3394 |
+
0xA3200000A33,
|
| 3395 |
+
0xA3500000A36,
|
| 3396 |
+
0xA3800000A3A,
|
| 3397 |
+
0xA3C00000A3D,
|
| 3398 |
+
0xA3E00000A43,
|
| 3399 |
+
0xA4700000A49,
|
| 3400 |
+
0xA4B00000A4E,
|
| 3401 |
+
0xA5100000A52,
|
| 3402 |
+
0xA5C00000A5D,
|
| 3403 |
+
0xA6600000A76,
|
| 3404 |
+
0xA8100000A84,
|
| 3405 |
+
0xA8500000A8E,
|
| 3406 |
+
0xA8F00000A92,
|
| 3407 |
+
0xA9300000AA9,
|
| 3408 |
+
0xAAA00000AB1,
|
| 3409 |
+
0xAB200000AB4,
|
| 3410 |
+
0xAB500000ABA,
|
| 3411 |
+
0xABC00000AC6,
|
| 3412 |
+
0xAC700000ACA,
|
| 3413 |
+
0xACB00000ACE,
|
| 3414 |
+
0xAD000000AD1,
|
| 3415 |
+
0xAE000000AE4,
|
| 3416 |
+
0xAE600000AF0,
|
| 3417 |
+
0xAF900000B00,
|
| 3418 |
+
0xB0100000B04,
|
| 3419 |
+
0xB0500000B0D,
|
| 3420 |
+
0xB0F00000B11,
|
| 3421 |
+
0xB1300000B29,
|
| 3422 |
+
0xB2A00000B31,
|
| 3423 |
+
0xB3200000B34,
|
| 3424 |
+
0xB3500000B3A,
|
| 3425 |
+
0xB3C00000B45,
|
| 3426 |
+
0xB4700000B49,
|
| 3427 |
+
0xB4B00000B4E,
|
| 3428 |
+
0xB5500000B58,
|
| 3429 |
+
0xB5F00000B64,
|
| 3430 |
+
0xB6600000B70,
|
| 3431 |
+
0xB7100000B72,
|
| 3432 |
+
0xB8200000B84,
|
| 3433 |
+
0xB8500000B8B,
|
| 3434 |
+
0xB8E00000B91,
|
| 3435 |
+
0xB9200000B96,
|
| 3436 |
+
0xB9900000B9B,
|
| 3437 |
+
0xB9C00000B9D,
|
| 3438 |
+
0xB9E00000BA0,
|
| 3439 |
+
0xBA300000BA5,
|
| 3440 |
+
0xBA800000BAB,
|
| 3441 |
+
0xBAE00000BBA,
|
| 3442 |
+
0xBBE00000BC3,
|
| 3443 |
+
0xBC600000BC9,
|
| 3444 |
+
0xBCA00000BCE,
|
| 3445 |
+
0xBD000000BD1,
|
| 3446 |
+
0xBD700000BD8,
|
| 3447 |
+
0xBE600000BF0,
|
| 3448 |
+
0xC0000000C0D,
|
| 3449 |
+
0xC0E00000C11,
|
| 3450 |
+
0xC1200000C29,
|
| 3451 |
+
0xC2A00000C3A,
|
| 3452 |
+
0xC3C00000C45,
|
| 3453 |
+
0xC4600000C49,
|
| 3454 |
+
0xC4A00000C4E,
|
| 3455 |
+
0xC5500000C57,
|
| 3456 |
+
0xC5800000C5B,
|
| 3457 |
+
0xC5D00000C5E,
|
| 3458 |
+
0xC6000000C64,
|
| 3459 |
+
0xC6600000C70,
|
| 3460 |
+
0xC8000000C84,
|
| 3461 |
+
0xC8500000C8D,
|
| 3462 |
+
0xC8E00000C91,
|
| 3463 |
+
0xC9200000CA9,
|
| 3464 |
+
0xCAA00000CB4,
|
| 3465 |
+
0xCB500000CBA,
|
| 3466 |
+
0xCBC00000CC5,
|
| 3467 |
+
0xCC600000CC9,
|
| 3468 |
+
0xCCA00000CCE,
|
| 3469 |
+
0xCD500000CD7,
|
| 3470 |
+
0xCDD00000CDF,
|
| 3471 |
+
0xCE000000CE4,
|
| 3472 |
+
0xCE600000CF0,
|
| 3473 |
+
0xCF100000CF4,
|
| 3474 |
+
0xD0000000D0D,
|
| 3475 |
+
0xD0E00000D11,
|
| 3476 |
+
0xD1200000D45,
|
| 3477 |
+
0xD4600000D49,
|
| 3478 |
+
0xD4A00000D4F,
|
| 3479 |
+
0xD5400000D58,
|
| 3480 |
+
0xD5F00000D64,
|
| 3481 |
+
0xD6600000D70,
|
| 3482 |
+
0xD7A00000D80,
|
| 3483 |
+
0xD8100000D84,
|
| 3484 |
+
0xD8500000D97,
|
| 3485 |
+
0xD9A00000DB2,
|
| 3486 |
+
0xDB300000DBC,
|
| 3487 |
+
0xDBD00000DBE,
|
| 3488 |
+
0xDC000000DC7,
|
| 3489 |
+
0xDCA00000DCB,
|
| 3490 |
+
0xDCF00000DD5,
|
| 3491 |
+
0xDD600000DD7,
|
| 3492 |
+
0xDD800000DE0,
|
| 3493 |
+
0xDE600000DF0,
|
| 3494 |
+
0xDF200000DF4,
|
| 3495 |
+
0xE0100000E33,
|
| 3496 |
+
0xE3400000E3B,
|
| 3497 |
+
0xE4000000E4F,
|
| 3498 |
+
0xE5000000E5A,
|
| 3499 |
+
0xE8100000E83,
|
| 3500 |
+
0xE8400000E85,
|
| 3501 |
+
0xE8600000E8B,
|
| 3502 |
+
0xE8C00000EA4,
|
| 3503 |
+
0xEA500000EA6,
|
| 3504 |
+
0xEA700000EB3,
|
| 3505 |
+
0xEB400000EBE,
|
| 3506 |
+
0xEC000000EC5,
|
| 3507 |
+
0xEC600000EC7,
|
| 3508 |
+
0xEC800000ECF,
|
| 3509 |
+
0xED000000EDA,
|
| 3510 |
+
0xEDE00000EE0,
|
| 3511 |
+
0xF0000000F01,
|
| 3512 |
+
0xF0B00000F0C,
|
| 3513 |
+
0xF1800000F1A,
|
| 3514 |
+
0xF2000000F2A,
|
| 3515 |
+
0xF3500000F36,
|
| 3516 |
+
0xF3700000F38,
|
| 3517 |
+
0xF3900000F3A,
|
| 3518 |
+
0xF3E00000F43,
|
| 3519 |
+
0xF4400000F48,
|
| 3520 |
+
0xF4900000F4D,
|
| 3521 |
+
0xF4E00000F52,
|
| 3522 |
+
0xF5300000F57,
|
| 3523 |
+
0xF5800000F5C,
|
| 3524 |
+
0xF5D00000F69,
|
| 3525 |
+
0xF6A00000F6D,
|
| 3526 |
+
0xF7100000F73,
|
| 3527 |
+
0xF7400000F75,
|
| 3528 |
+
0xF7A00000F81,
|
| 3529 |
+
0xF8200000F85,
|
| 3530 |
+
0xF8600000F93,
|
| 3531 |
+
0xF9400000F98,
|
| 3532 |
+
0xF9900000F9D,
|
| 3533 |
+
0xF9E00000FA2,
|
| 3534 |
+
0xFA300000FA7,
|
| 3535 |
+
0xFA800000FAC,
|
| 3536 |
+
0xFAD00000FB9,
|
| 3537 |
+
0xFBA00000FBD,
|
| 3538 |
+
0xFC600000FC7,
|
| 3539 |
+
0x10000000104A,
|
| 3540 |
+
0x10500000109E,
|
| 3541 |
+
0x10D0000010FB,
|
| 3542 |
+
0x10FD00001100,
|
| 3543 |
+
0x120000001249,
|
| 3544 |
+
0x124A0000124E,
|
| 3545 |
+
0x125000001257,
|
| 3546 |
+
0x125800001259,
|
| 3547 |
+
0x125A0000125E,
|
| 3548 |
+
0x126000001289,
|
| 3549 |
+
0x128A0000128E,
|
| 3550 |
+
0x1290000012B1,
|
| 3551 |
+
0x12B2000012B6,
|
| 3552 |
+
0x12B8000012BF,
|
| 3553 |
+
0x12C0000012C1,
|
| 3554 |
+
0x12C2000012C6,
|
| 3555 |
+
0x12C8000012D7,
|
| 3556 |
+
0x12D800001311,
|
| 3557 |
+
0x131200001316,
|
| 3558 |
+
0x13180000135B,
|
| 3559 |
+
0x135D00001360,
|
| 3560 |
+
0x138000001390,
|
| 3561 |
+
0x13A0000013F6,
|
| 3562 |
+
0x14010000166D,
|
| 3563 |
+
0x166F00001680,
|
| 3564 |
+
0x16810000169B,
|
| 3565 |
+
0x16A0000016EB,
|
| 3566 |
+
0x16F1000016F9,
|
| 3567 |
+
0x170000001716,
|
| 3568 |
+
0x171F00001735,
|
| 3569 |
+
0x174000001754,
|
| 3570 |
+
0x17600000176D,
|
| 3571 |
+
0x176E00001771,
|
| 3572 |
+
0x177200001774,
|
| 3573 |
+
0x1780000017B4,
|
| 3574 |
+
0x17B6000017D4,
|
| 3575 |
+
0x17D7000017D8,
|
| 3576 |
+
0x17DC000017DE,
|
| 3577 |
+
0x17E0000017EA,
|
| 3578 |
+
0x18100000181A,
|
| 3579 |
+
0x182000001879,
|
| 3580 |
+
0x1880000018AB,
|
| 3581 |
+
0x18B0000018F6,
|
| 3582 |
+
0x19000000191F,
|
| 3583 |
+
0x19200000192C,
|
| 3584 |
+
0x19300000193C,
|
| 3585 |
+
0x19460000196E,
|
| 3586 |
+
0x197000001975,
|
| 3587 |
+
0x1980000019AC,
|
| 3588 |
+
0x19B0000019CA,
|
| 3589 |
+
0x19D0000019DA,
|
| 3590 |
+
0x1A0000001A1C,
|
| 3591 |
+
0x1A2000001A5F,
|
| 3592 |
+
0x1A6000001A7D,
|
| 3593 |
+
0x1A7F00001A8A,
|
| 3594 |
+
0x1A9000001A9A,
|
| 3595 |
+
0x1AA700001AA8,
|
| 3596 |
+
0x1AB000001ABE,
|
| 3597 |
+
0x1ABF00001ACF,
|
| 3598 |
+
0x1B0000001B4D,
|
| 3599 |
+
0x1B5000001B5A,
|
| 3600 |
+
0x1B6B00001B74,
|
| 3601 |
+
0x1B8000001BF4,
|
| 3602 |
+
0x1C0000001C38,
|
| 3603 |
+
0x1C4000001C4A,
|
| 3604 |
+
0x1C4D00001C7E,
|
| 3605 |
+
0x1C8A00001C8B,
|
| 3606 |
+
0x1CD000001CD3,
|
| 3607 |
+
0x1CD400001CFB,
|
| 3608 |
+
0x1D0000001D2C,
|
| 3609 |
+
0x1D2F00001D30,
|
| 3610 |
+
0x1D3B00001D3C,
|
| 3611 |
+
0x1D4E00001D4F,
|
| 3612 |
+
0x1D6B00001D78,
|
| 3613 |
+
0x1D7900001D9B,
|
| 3614 |
+
0x1DC000001E00,
|
| 3615 |
+
0x1E0100001E02,
|
| 3616 |
+
0x1E0300001E04,
|
| 3617 |
+
0x1E0500001E06,
|
| 3618 |
+
0x1E0700001E08,
|
| 3619 |
+
0x1E0900001E0A,
|
| 3620 |
+
0x1E0B00001E0C,
|
| 3621 |
+
0x1E0D00001E0E,
|
| 3622 |
+
0x1E0F00001E10,
|
| 3623 |
+
0x1E1100001E12,
|
| 3624 |
+
0x1E1300001E14,
|
| 3625 |
+
0x1E1500001E16,
|
| 3626 |
+
0x1E1700001E18,
|
| 3627 |
+
0x1E1900001E1A,
|
| 3628 |
+
0x1E1B00001E1C,
|
| 3629 |
+
0x1E1D00001E1E,
|
| 3630 |
+
0x1E1F00001E20,
|
| 3631 |
+
0x1E2100001E22,
|
| 3632 |
+
0x1E2300001E24,
|
| 3633 |
+
0x1E2500001E26,
|
| 3634 |
+
0x1E2700001E28,
|
| 3635 |
+
0x1E2900001E2A,
|
| 3636 |
+
0x1E2B00001E2C,
|
| 3637 |
+
0x1E2D00001E2E,
|
| 3638 |
+
0x1E2F00001E30,
|
| 3639 |
+
0x1E3100001E32,
|
| 3640 |
+
0x1E3300001E34,
|
| 3641 |
+
0x1E3500001E36,
|
| 3642 |
+
0x1E3700001E38,
|
| 3643 |
+
0x1E3900001E3A,
|
| 3644 |
+
0x1E3B00001E3C,
|
| 3645 |
+
0x1E3D00001E3E,
|
| 3646 |
+
0x1E3F00001E40,
|
| 3647 |
+
0x1E4100001E42,
|
| 3648 |
+
0x1E4300001E44,
|
| 3649 |
+
0x1E4500001E46,
|
| 3650 |
+
0x1E4700001E48,
|
| 3651 |
+
0x1E4900001E4A,
|
| 3652 |
+
0x1E4B00001E4C,
|
| 3653 |
+
0x1E4D00001E4E,
|
| 3654 |
+
0x1E4F00001E50,
|
| 3655 |
+
0x1E5100001E52,
|
| 3656 |
+
0x1E5300001E54,
|
| 3657 |
+
0x1E5500001E56,
|
| 3658 |
+
0x1E5700001E58,
|
| 3659 |
+
0x1E5900001E5A,
|
| 3660 |
+
0x1E5B00001E5C,
|
| 3661 |
+
0x1E5D00001E5E,
|
| 3662 |
+
0x1E5F00001E60,
|
| 3663 |
+
0x1E6100001E62,
|
| 3664 |
+
0x1E6300001E64,
|
| 3665 |
+
0x1E6500001E66,
|
| 3666 |
+
0x1E6700001E68,
|
| 3667 |
+
0x1E6900001E6A,
|
| 3668 |
+
0x1E6B00001E6C,
|
| 3669 |
+
0x1E6D00001E6E,
|
| 3670 |
+
0x1E6F00001E70,
|
| 3671 |
+
0x1E7100001E72,
|
| 3672 |
+
0x1E7300001E74,
|
| 3673 |
+
0x1E7500001E76,
|
| 3674 |
+
0x1E7700001E78,
|
| 3675 |
+
0x1E7900001E7A,
|
| 3676 |
+
0x1E7B00001E7C,
|
| 3677 |
+
0x1E7D00001E7E,
|
| 3678 |
+
0x1E7F00001E80,
|
| 3679 |
+
0x1E8100001E82,
|
| 3680 |
+
0x1E8300001E84,
|
| 3681 |
+
0x1E8500001E86,
|
| 3682 |
+
0x1E8700001E88,
|
| 3683 |
+
0x1E8900001E8A,
|
| 3684 |
+
0x1E8B00001E8C,
|
| 3685 |
+
0x1E8D00001E8E,
|
| 3686 |
+
0x1E8F00001E90,
|
| 3687 |
+
0x1E9100001E92,
|
| 3688 |
+
0x1E9300001E94,
|
| 3689 |
+
0x1E9500001E9A,
|
| 3690 |
+
0x1E9C00001E9E,
|
| 3691 |
+
0x1E9F00001EA0,
|
| 3692 |
+
0x1EA100001EA2,
|
| 3693 |
+
0x1EA300001EA4,
|
| 3694 |
+
0x1EA500001EA6,
|
| 3695 |
+
0x1EA700001EA8,
|
| 3696 |
+
0x1EA900001EAA,
|
| 3697 |
+
0x1EAB00001EAC,
|
| 3698 |
+
0x1EAD00001EAE,
|
| 3699 |
+
0x1EAF00001EB0,
|
| 3700 |
+
0x1EB100001EB2,
|
| 3701 |
+
0x1EB300001EB4,
|
| 3702 |
+
0x1EB500001EB6,
|
| 3703 |
+
0x1EB700001EB8,
|
| 3704 |
+
0x1EB900001EBA,
|
| 3705 |
+
0x1EBB00001EBC,
|
| 3706 |
+
0x1EBD00001EBE,
|
| 3707 |
+
0x1EBF00001EC0,
|
| 3708 |
+
0x1EC100001EC2,
|
| 3709 |
+
0x1EC300001EC4,
|
| 3710 |
+
0x1EC500001EC6,
|
| 3711 |
+
0x1EC700001EC8,
|
| 3712 |
+
0x1EC900001ECA,
|
| 3713 |
+
0x1ECB00001ECC,
|
| 3714 |
+
0x1ECD00001ECE,
|
| 3715 |
+
0x1ECF00001ED0,
|
| 3716 |
+
0x1ED100001ED2,
|
| 3717 |
+
0x1ED300001ED4,
|
| 3718 |
+
0x1ED500001ED6,
|
| 3719 |
+
0x1ED700001ED8,
|
| 3720 |
+
0x1ED900001EDA,
|
| 3721 |
+
0x1EDB00001EDC,
|
| 3722 |
+
0x1EDD00001EDE,
|
| 3723 |
+
0x1EDF00001EE0,
|
| 3724 |
+
0x1EE100001EE2,
|
| 3725 |
+
0x1EE300001EE4,
|
| 3726 |
+
0x1EE500001EE6,
|
| 3727 |
+
0x1EE700001EE8,
|
| 3728 |
+
0x1EE900001EEA,
|
| 3729 |
+
0x1EEB00001EEC,
|
| 3730 |
+
0x1EED00001EEE,
|
| 3731 |
+
0x1EEF00001EF0,
|
| 3732 |
+
0x1EF100001EF2,
|
| 3733 |
+
0x1EF300001EF4,
|
| 3734 |
+
0x1EF500001EF6,
|
| 3735 |
+
0x1EF700001EF8,
|
| 3736 |
+
0x1EF900001EFA,
|
| 3737 |
+
0x1EFB00001EFC,
|
| 3738 |
+
0x1EFD00001EFE,
|
| 3739 |
+
0x1EFF00001F08,
|
| 3740 |
+
0x1F1000001F16,
|
| 3741 |
+
0x1F2000001F28,
|
| 3742 |
+
0x1F3000001F38,
|
| 3743 |
+
0x1F4000001F46,
|
| 3744 |
+
0x1F5000001F58,
|
| 3745 |
+
0x1F6000001F68,
|
| 3746 |
+
0x1F7000001F71,
|
| 3747 |
+
0x1F7200001F73,
|
| 3748 |
+
0x1F7400001F75,
|
| 3749 |
+
0x1F7600001F77,
|
| 3750 |
+
0x1F7800001F79,
|
| 3751 |
+
0x1F7A00001F7B,
|
| 3752 |
+
0x1F7C00001F7D,
|
| 3753 |
+
0x1FB000001FB2,
|
| 3754 |
+
0x1FB600001FB7,
|
| 3755 |
+
0x1FC600001FC7,
|
| 3756 |
+
0x1FD000001FD3,
|
| 3757 |
+
0x1FD600001FD8,
|
| 3758 |
+
0x1FE000001FE3,
|
| 3759 |
+
0x1FE400001FE8,
|
| 3760 |
+
0x1FF600001FF7,
|
| 3761 |
+
0x214E0000214F,
|
| 3762 |
+
0x218400002185,
|
| 3763 |
+
0x2C3000002C60,
|
| 3764 |
+
0x2C6100002C62,
|
| 3765 |
+
0x2C6500002C67,
|
| 3766 |
+
0x2C6800002C69,
|
| 3767 |
+
0x2C6A00002C6B,
|
| 3768 |
+
0x2C6C00002C6D,
|
| 3769 |
+
0x2C7100002C72,
|
| 3770 |
+
0x2C7300002C75,
|
| 3771 |
+
0x2C7600002C7C,
|
| 3772 |
+
0x2C8100002C82,
|
| 3773 |
+
0x2C8300002C84,
|
| 3774 |
+
0x2C8500002C86,
|
| 3775 |
+
0x2C8700002C88,
|
| 3776 |
+
0x2C8900002C8A,
|
| 3777 |
+
0x2C8B00002C8C,
|
| 3778 |
+
0x2C8D00002C8E,
|
| 3779 |
+
0x2C8F00002C90,
|
| 3780 |
+
0x2C9100002C92,
|
| 3781 |
+
0x2C9300002C94,
|
| 3782 |
+
0x2C9500002C96,
|
| 3783 |
+
0x2C9700002C98,
|
| 3784 |
+
0x2C9900002C9A,
|
| 3785 |
+
0x2C9B00002C9C,
|
| 3786 |
+
0x2C9D00002C9E,
|
| 3787 |
+
0x2C9F00002CA0,
|
| 3788 |
+
0x2CA100002CA2,
|
| 3789 |
+
0x2CA300002CA4,
|
| 3790 |
+
0x2CA500002CA6,
|
| 3791 |
+
0x2CA700002CA8,
|
| 3792 |
+
0x2CA900002CAA,
|
| 3793 |
+
0x2CAB00002CAC,
|
| 3794 |
+
0x2CAD00002CAE,
|
| 3795 |
+
0x2CAF00002CB0,
|
| 3796 |
+
0x2CB100002CB2,
|
| 3797 |
+
0x2CB300002CB4,
|
| 3798 |
+
0x2CB500002CB6,
|
| 3799 |
+
0x2CB700002CB8,
|
| 3800 |
+
0x2CB900002CBA,
|
| 3801 |
+
0x2CBB00002CBC,
|
| 3802 |
+
0x2CBD00002CBE,
|
| 3803 |
+
0x2CBF00002CC0,
|
| 3804 |
+
0x2CC100002CC2,
|
| 3805 |
+
0x2CC300002CC4,
|
| 3806 |
+
0x2CC500002CC6,
|
| 3807 |
+
0x2CC700002CC8,
|
| 3808 |
+
0x2CC900002CCA,
|
| 3809 |
+
0x2CCB00002CCC,
|
| 3810 |
+
0x2CCD00002CCE,
|
| 3811 |
+
0x2CCF00002CD0,
|
| 3812 |
+
0x2CD100002CD2,
|
| 3813 |
+
0x2CD300002CD4,
|
| 3814 |
+
0x2CD500002CD6,
|
| 3815 |
+
0x2CD700002CD8,
|
| 3816 |
+
0x2CD900002CDA,
|
| 3817 |
+
0x2CDB00002CDC,
|
| 3818 |
+
0x2CDD00002CDE,
|
| 3819 |
+
0x2CDF00002CE0,
|
| 3820 |
+
0x2CE100002CE2,
|
| 3821 |
+
0x2CE300002CE5,
|
| 3822 |
+
0x2CEC00002CED,
|
| 3823 |
+
0x2CEE00002CF2,
|
| 3824 |
+
0x2CF300002CF4,
|
| 3825 |
+
0x2D0000002D26,
|
| 3826 |
+
0x2D2700002D28,
|
| 3827 |
+
0x2D2D00002D2E,
|
| 3828 |
+
0x2D3000002D68,
|
| 3829 |
+
0x2D7F00002D97,
|
| 3830 |
+
0x2DA000002DA7,
|
| 3831 |
+
0x2DA800002DAF,
|
| 3832 |
+
0x2DB000002DB7,
|
| 3833 |
+
0x2DB800002DBF,
|
| 3834 |
+
0x2DC000002DC7,
|
| 3835 |
+
0x2DC800002DCF,
|
| 3836 |
+
0x2DD000002DD7,
|
| 3837 |
+
0x2DD800002DDF,
|
| 3838 |
+
0x2DE000002E00,
|
| 3839 |
+
0x2E2F00002E30,
|
| 3840 |
+
0x300500003008,
|
| 3841 |
+
0x302A0000302E,
|
| 3842 |
+
0x303C0000303D,
|
| 3843 |
+
0x304100003097,
|
| 3844 |
+
0x30990000309B,
|
| 3845 |
+
0x309D0000309F,
|
| 3846 |
+
0x30A1000030FB,
|
| 3847 |
+
0x30FC000030FF,
|
| 3848 |
+
0x310500003130,
|
| 3849 |
+
0x31A0000031C0,
|
| 3850 |
+
0x31F000003200,
|
| 3851 |
+
0x340000004DC0,
|
| 3852 |
+
0x4E000000A48D,
|
| 3853 |
+
0xA4D00000A4FE,
|
| 3854 |
+
0xA5000000A60D,
|
| 3855 |
+
0xA6100000A62C,
|
| 3856 |
+
0xA6410000A642,
|
| 3857 |
+
0xA6430000A644,
|
| 3858 |
+
0xA6450000A646,
|
| 3859 |
+
0xA6470000A648,
|
| 3860 |
+
0xA6490000A64A,
|
| 3861 |
+
0xA64B0000A64C,
|
| 3862 |
+
0xA64D0000A64E,
|
| 3863 |
+
0xA64F0000A650,
|
| 3864 |
+
0xA6510000A652,
|
| 3865 |
+
0xA6530000A654,
|
| 3866 |
+
0xA6550000A656,
|
| 3867 |
+
0xA6570000A658,
|
| 3868 |
+
0xA6590000A65A,
|
| 3869 |
+
0xA65B0000A65C,
|
| 3870 |
+
0xA65D0000A65E,
|
| 3871 |
+
0xA65F0000A660,
|
| 3872 |
+
0xA6610000A662,
|
| 3873 |
+
0xA6630000A664,
|
| 3874 |
+
0xA6650000A666,
|
| 3875 |
+
0xA6670000A668,
|
| 3876 |
+
0xA6690000A66A,
|
| 3877 |
+
0xA66B0000A66C,
|
| 3878 |
+
0xA66D0000A670,
|
| 3879 |
+
0xA6740000A67E,
|
| 3880 |
+
0xA67F0000A680,
|
| 3881 |
+
0xA6810000A682,
|
| 3882 |
+
0xA6830000A684,
|
| 3883 |
+
0xA6850000A686,
|
| 3884 |
+
0xA6870000A688,
|
| 3885 |
+
0xA6890000A68A,
|
| 3886 |
+
0xA68B0000A68C,
|
| 3887 |
+
0xA68D0000A68E,
|
| 3888 |
+
0xA68F0000A690,
|
| 3889 |
+
0xA6910000A692,
|
| 3890 |
+
0xA6930000A694,
|
| 3891 |
+
0xA6950000A696,
|
| 3892 |
+
0xA6970000A698,
|
| 3893 |
+
0xA6990000A69A,
|
| 3894 |
+
0xA69B0000A69C,
|
| 3895 |
+
0xA69E0000A6E6,
|
| 3896 |
+
0xA6F00000A6F2,
|
| 3897 |
+
0xA7170000A720,
|
| 3898 |
+
0xA7230000A724,
|
| 3899 |
+
0xA7250000A726,
|
| 3900 |
+
0xA7270000A728,
|
| 3901 |
+
0xA7290000A72A,
|
| 3902 |
+
0xA72B0000A72C,
|
| 3903 |
+
0xA72D0000A72E,
|
| 3904 |
+
0xA72F0000A732,
|
| 3905 |
+
0xA7330000A734,
|
| 3906 |
+
0xA7350000A736,
|
| 3907 |
+
0xA7370000A738,
|
| 3908 |
+
0xA7390000A73A,
|
| 3909 |
+
0xA73B0000A73C,
|
| 3910 |
+
0xA73D0000A73E,
|
| 3911 |
+
0xA73F0000A740,
|
| 3912 |
+
0xA7410000A742,
|
| 3913 |
+
0xA7430000A744,
|
| 3914 |
+
0xA7450000A746,
|
| 3915 |
+
0xA7470000A748,
|
| 3916 |
+
0xA7490000A74A,
|
| 3917 |
+
0xA74B0000A74C,
|
| 3918 |
+
0xA74D0000A74E,
|
| 3919 |
+
0xA74F0000A750,
|
| 3920 |
+
0xA7510000A752,
|
| 3921 |
+
0xA7530000A754,
|
| 3922 |
+
0xA7550000A756,
|
| 3923 |
+
0xA7570000A758,
|
| 3924 |
+
0xA7590000A75A,
|
| 3925 |
+
0xA75B0000A75C,
|
| 3926 |
+
0xA75D0000A75E,
|
| 3927 |
+
0xA75F0000A760,
|
| 3928 |
+
0xA7610000A762,
|
| 3929 |
+
0xA7630000A764,
|
| 3930 |
+
0xA7650000A766,
|
| 3931 |
+
0xA7670000A768,
|
| 3932 |
+
0xA7690000A76A,
|
| 3933 |
+
0xA76B0000A76C,
|
| 3934 |
+
0xA76D0000A76E,
|
| 3935 |
+
0xA76F0000A770,
|
| 3936 |
+
0xA7710000A779,
|
| 3937 |
+
0xA77A0000A77B,
|
| 3938 |
+
0xA77C0000A77D,
|
| 3939 |
+
0xA77F0000A780,
|
| 3940 |
+
0xA7810000A782,
|
| 3941 |
+
0xA7830000A784,
|
| 3942 |
+
0xA7850000A786,
|
| 3943 |
+
0xA7870000A789,
|
| 3944 |
+
0xA78C0000A78D,
|
| 3945 |
+
0xA78E0000A790,
|
| 3946 |
+
0xA7910000A792,
|
| 3947 |
+
0xA7930000A796,
|
| 3948 |
+
0xA7970000A798,
|
| 3949 |
+
0xA7990000A79A,
|
| 3950 |
+
0xA79B0000A79C,
|
| 3951 |
+
0xA79D0000A79E,
|
| 3952 |
+
0xA79F0000A7A0,
|
| 3953 |
+
0xA7A10000A7A2,
|
| 3954 |
+
0xA7A30000A7A4,
|
| 3955 |
+
0xA7A50000A7A6,
|
| 3956 |
+
0xA7A70000A7A8,
|
| 3957 |
+
0xA7A90000A7AA,
|
| 3958 |
+
0xA7AF0000A7B0,
|
| 3959 |
+
0xA7B50000A7B6,
|
| 3960 |
+
0xA7B70000A7B8,
|
| 3961 |
+
0xA7B90000A7BA,
|
| 3962 |
+
0xA7BB0000A7BC,
|
| 3963 |
+
0xA7BD0000A7BE,
|
| 3964 |
+
0xA7BF0000A7C0,
|
| 3965 |
+
0xA7C10000A7C2,
|
| 3966 |
+
0xA7C30000A7C4,
|
| 3967 |
+
0xA7C80000A7C9,
|
| 3968 |
+
0xA7CA0000A7CB,
|
| 3969 |
+
0xA7CD0000A7CE,
|
| 3970 |
+
0xA7D10000A7D2,
|
| 3971 |
+
0xA7D30000A7D4,
|
| 3972 |
+
0xA7D50000A7D6,
|
| 3973 |
+
0xA7D70000A7D8,
|
| 3974 |
+
0xA7D90000A7DA,
|
| 3975 |
+
0xA7DB0000A7DC,
|
| 3976 |
+
0xA7F60000A7F8,
|
| 3977 |
+
0xA7FA0000A828,
|
| 3978 |
+
0xA82C0000A82D,
|
| 3979 |
+
0xA8400000A874,
|
| 3980 |
+
0xA8800000A8C6,
|
| 3981 |
+
0xA8D00000A8DA,
|
| 3982 |
+
0xA8E00000A8F8,
|
| 3983 |
+
0xA8FB0000A8FC,
|
| 3984 |
+
0xA8FD0000A92E,
|
| 3985 |
+
0xA9300000A954,
|
| 3986 |
+
0xA9800000A9C1,
|
| 3987 |
+
0xA9CF0000A9DA,
|
| 3988 |
+
0xA9E00000A9FF,
|
| 3989 |
+
0xAA000000AA37,
|
| 3990 |
+
0xAA400000AA4E,
|
| 3991 |
+
0xAA500000AA5A,
|
| 3992 |
+
0xAA600000AA77,
|
| 3993 |
+
0xAA7A0000AAC3,
|
| 3994 |
+
0xAADB0000AADE,
|
| 3995 |
+
0xAAE00000AAF0,
|
| 3996 |
+
0xAAF20000AAF7,
|
| 3997 |
+
0xAB010000AB07,
|
| 3998 |
+
0xAB090000AB0F,
|
| 3999 |
+
0xAB110000AB17,
|
| 4000 |
+
0xAB200000AB27,
|
| 4001 |
+
0xAB280000AB2F,
|
| 4002 |
+
0xAB300000AB5B,
|
| 4003 |
+
0xAB600000AB69,
|
| 4004 |
+
0xABC00000ABEB,
|
| 4005 |
+
0xABEC0000ABEE,
|
| 4006 |
+
0xABF00000ABFA,
|
| 4007 |
+
0xAC000000D7A4,
|
| 4008 |
+
0xFA0E0000FA10,
|
| 4009 |
+
0xFA110000FA12,
|
| 4010 |
+
0xFA130000FA15,
|
| 4011 |
+
0xFA1F0000FA20,
|
| 4012 |
+
0xFA210000FA22,
|
| 4013 |
+
0xFA230000FA25,
|
| 4014 |
+
0xFA270000FA2A,
|
| 4015 |
+
0xFB1E0000FB1F,
|
| 4016 |
+
0xFE200000FE30,
|
| 4017 |
+
0xFE730000FE74,
|
| 4018 |
+
0x100000001000C,
|
| 4019 |
+
0x1000D00010027,
|
| 4020 |
+
0x100280001003B,
|
| 4021 |
+
0x1003C0001003E,
|
| 4022 |
+
0x1003F0001004E,
|
| 4023 |
+
0x100500001005E,
|
| 4024 |
+
0x10080000100FB,
|
| 4025 |
+
0x101FD000101FE,
|
| 4026 |
+
0x102800001029D,
|
| 4027 |
+
0x102A0000102D1,
|
| 4028 |
+
0x102E0000102E1,
|
| 4029 |
+
0x1030000010320,
|
| 4030 |
+
0x1032D00010341,
|
| 4031 |
+
0x103420001034A,
|
| 4032 |
+
0x103500001037B,
|
| 4033 |
+
0x103800001039E,
|
| 4034 |
+
0x103A0000103C4,
|
| 4035 |
+
0x103C8000103D0,
|
| 4036 |
+
0x104280001049E,
|
| 4037 |
+
0x104A0000104AA,
|
| 4038 |
+
0x104D8000104FC,
|
| 4039 |
+
0x1050000010528,
|
| 4040 |
+
0x1053000010564,
|
| 4041 |
+
0x10597000105A2,
|
| 4042 |
+
0x105A3000105B2,
|
| 4043 |
+
0x105B3000105BA,
|
| 4044 |
+
0x105BB000105BD,
|
| 4045 |
+
0x105C0000105F4,
|
| 4046 |
+
0x1060000010737,
|
| 4047 |
+
0x1074000010756,
|
| 4048 |
+
0x1076000010768,
|
| 4049 |
+
0x1078000010781,
|
| 4050 |
+
0x1080000010806,
|
| 4051 |
+
0x1080800010809,
|
| 4052 |
+
0x1080A00010836,
|
| 4053 |
+
0x1083700010839,
|
| 4054 |
+
0x1083C0001083D,
|
| 4055 |
+
0x1083F00010856,
|
| 4056 |
+
0x1086000010877,
|
| 4057 |
+
0x108800001089F,
|
| 4058 |
+
0x108E0000108F3,
|
| 4059 |
+
0x108F4000108F6,
|
| 4060 |
+
0x1090000010916,
|
| 4061 |
+
0x109200001093A,
|
| 4062 |
+
0x10980000109B8,
|
| 4063 |
+
0x109BE000109C0,
|
| 4064 |
+
0x10A0000010A04,
|
| 4065 |
+
0x10A0500010A07,
|
| 4066 |
+
0x10A0C00010A14,
|
| 4067 |
+
0x10A1500010A18,
|
| 4068 |
+
0x10A1900010A36,
|
| 4069 |
+
0x10A3800010A3B,
|
| 4070 |
+
0x10A3F00010A40,
|
| 4071 |
+
0x10A6000010A7D,
|
| 4072 |
+
0x10A8000010A9D,
|
| 4073 |
+
0x10AC000010AC8,
|
| 4074 |
+
0x10AC900010AE7,
|
| 4075 |
+
0x10B0000010B36,
|
| 4076 |
+
0x10B4000010B56,
|
| 4077 |
+
0x10B6000010B73,
|
| 4078 |
+
0x10B8000010B92,
|
| 4079 |
+
0x10C0000010C49,
|
| 4080 |
+
0x10CC000010CF3,
|
| 4081 |
+
0x10D0000010D28,
|
| 4082 |
+
0x10D3000010D3A,
|
| 4083 |
+
0x10D4000010D50,
|
| 4084 |
+
0x10D6900010D6E,
|
| 4085 |
+
0x10D6F00010D86,
|
| 4086 |
+
0x10E8000010EAA,
|
| 4087 |
+
0x10EAB00010EAD,
|
| 4088 |
+
0x10EB000010EB2,
|
| 4089 |
+
0x10EC200010EC5,
|
| 4090 |
+
0x10EFC00010F1D,
|
| 4091 |
+
0x10F2700010F28,
|
| 4092 |
+
0x10F3000010F51,
|
| 4093 |
+
0x10F7000010F86,
|
| 4094 |
+
0x10FB000010FC5,
|
| 4095 |
+
0x10FE000010FF7,
|
| 4096 |
+
0x1100000011047,
|
| 4097 |
+
0x1106600011076,
|
| 4098 |
+
0x1107F000110BB,
|
| 4099 |
+
0x110C2000110C3,
|
| 4100 |
+
0x110D0000110E9,
|
| 4101 |
+
0x110F0000110FA,
|
| 4102 |
+
0x1110000011135,
|
| 4103 |
+
0x1113600011140,
|
| 4104 |
+
0x1114400011148,
|
| 4105 |
+
0x1115000011174,
|
| 4106 |
+
0x1117600011177,
|
| 4107 |
+
0x11180000111C5,
|
| 4108 |
+
0x111C9000111CD,
|
| 4109 |
+
0x111CE000111DB,
|
| 4110 |
+
0x111DC000111DD,
|
| 4111 |
+
0x1120000011212,
|
| 4112 |
+
0x1121300011238,
|
| 4113 |
+
0x1123E00011242,
|
| 4114 |
+
0x1128000011287,
|
| 4115 |
+
0x1128800011289,
|
| 4116 |
+
0x1128A0001128E,
|
| 4117 |
+
0x1128F0001129E,
|
| 4118 |
+
0x1129F000112A9,
|
| 4119 |
+
0x112B0000112EB,
|
| 4120 |
+
0x112F0000112FA,
|
| 4121 |
+
0x1130000011304,
|
| 4122 |
+
0x113050001130D,
|
| 4123 |
+
0x1130F00011311,
|
| 4124 |
+
0x1131300011329,
|
| 4125 |
+
0x1132A00011331,
|
| 4126 |
+
0x1133200011334,
|
| 4127 |
+
0x113350001133A,
|
| 4128 |
+
0x1133B00011345,
|
| 4129 |
+
0x1134700011349,
|
| 4130 |
+
0x1134B0001134E,
|
| 4131 |
+
0x1135000011351,
|
| 4132 |
+
0x1135700011358,
|
| 4133 |
+
0x1135D00011364,
|
| 4134 |
+
0x113660001136D,
|
| 4135 |
+
0x1137000011375,
|
| 4136 |
+
0x113800001138A,
|
| 4137 |
+
0x1138B0001138C,
|
| 4138 |
+
0x1138E0001138F,
|
| 4139 |
+
0x11390000113B6,
|
| 4140 |
+
0x113B7000113C1,
|
| 4141 |
+
0x113C2000113C3,
|
| 4142 |
+
0x113C5000113C6,
|
| 4143 |
+
0x113C7000113CB,
|
| 4144 |
+
0x113CC000113D4,
|
| 4145 |
+
0x113E1000113E3,
|
| 4146 |
+
0x114000001144B,
|
| 4147 |
+
0x114500001145A,
|
| 4148 |
+
0x1145E00011462,
|
| 4149 |
+
0x11480000114C6,
|
| 4150 |
+
0x114C7000114C8,
|
| 4151 |
+
0x114D0000114DA,
|
| 4152 |
+
0x11580000115B6,
|
| 4153 |
+
0x115B8000115C1,
|
| 4154 |
+
0x115D8000115DE,
|
| 4155 |
+
0x1160000011641,
|
| 4156 |
+
0x1164400011645,
|
| 4157 |
+
0x116500001165A,
|
| 4158 |
+
0x11680000116B9,
|
| 4159 |
+
0x116C0000116CA,
|
| 4160 |
+
0x116D0000116E4,
|
| 4161 |
+
0x117000001171B,
|
| 4162 |
+
0x1171D0001172C,
|
| 4163 |
+
0x117300001173A,
|
| 4164 |
+
0x1174000011747,
|
| 4165 |
+
0x118000001183B,
|
| 4166 |
+
0x118C0000118EA,
|
| 4167 |
+
0x118FF00011907,
|
| 4168 |
+
0x119090001190A,
|
| 4169 |
+
0x1190C00011914,
|
| 4170 |
+
0x1191500011917,
|
| 4171 |
+
0x1191800011936,
|
| 4172 |
+
0x1193700011939,
|
| 4173 |
+
0x1193B00011944,
|
| 4174 |
+
0x119500001195A,
|
| 4175 |
+
0x119A0000119A8,
|
| 4176 |
+
0x119AA000119D8,
|
| 4177 |
+
0x119DA000119E2,
|
| 4178 |
+
0x119E3000119E5,
|
| 4179 |
+
0x11A0000011A3F,
|
| 4180 |
+
0x11A4700011A48,
|
| 4181 |
+
0x11A5000011A9A,
|
| 4182 |
+
0x11A9D00011A9E,
|
| 4183 |
+
0x11AB000011AF9,
|
| 4184 |
+
0x11BC000011BE1,
|
| 4185 |
+
0x11BF000011BFA,
|
| 4186 |
+
0x11C0000011C09,
|
| 4187 |
+
0x11C0A00011C37,
|
| 4188 |
+
0x11C3800011C41,
|
| 4189 |
+
0x11C5000011C5A,
|
| 4190 |
+
0x11C7200011C90,
|
| 4191 |
+
0x11C9200011CA8,
|
| 4192 |
+
0x11CA900011CB7,
|
| 4193 |
+
0x11D0000011D07,
|
| 4194 |
+
0x11D0800011D0A,
|
| 4195 |
+
0x11D0B00011D37,
|
| 4196 |
+
0x11D3A00011D3B,
|
| 4197 |
+
0x11D3C00011D3E,
|
| 4198 |
+
0x11D3F00011D48,
|
| 4199 |
+
0x11D5000011D5A,
|
| 4200 |
+
0x11D6000011D66,
|
| 4201 |
+
0x11D6700011D69,
|
| 4202 |
+
0x11D6A00011D8F,
|
| 4203 |
+
0x11D9000011D92,
|
| 4204 |
+
0x11D9300011D99,
|
| 4205 |
+
0x11DA000011DAA,
|
| 4206 |
+
0x11EE000011EF7,
|
| 4207 |
+
0x11F0000011F11,
|
| 4208 |
+
0x11F1200011F3B,
|
| 4209 |
+
0x11F3E00011F43,
|
| 4210 |
+
0x11F5000011F5B,
|
| 4211 |
+
0x11FB000011FB1,
|
| 4212 |
+
0x120000001239A,
|
| 4213 |
+
0x1248000012544,
|
| 4214 |
+
0x12F9000012FF1,
|
| 4215 |
+
0x1300000013430,
|
| 4216 |
+
0x1344000013456,
|
| 4217 |
+
0x13460000143FB,
|
| 4218 |
+
0x1440000014647,
|
| 4219 |
+
0x161000001613A,
|
| 4220 |
+
0x1680000016A39,
|
| 4221 |
+
0x16A4000016A5F,
|
| 4222 |
+
0x16A6000016A6A,
|
| 4223 |
+
0x16A7000016ABF,
|
| 4224 |
+
0x16AC000016ACA,
|
| 4225 |
+
0x16AD000016AEE,
|
| 4226 |
+
0x16AF000016AF5,
|
| 4227 |
+
0x16B0000016B37,
|
| 4228 |
+
0x16B4000016B44,
|
| 4229 |
+
0x16B5000016B5A,
|
| 4230 |
+
0x16B6300016B78,
|
| 4231 |
+
0x16B7D00016B90,
|
| 4232 |
+
0x16D4000016D6D,
|
| 4233 |
+
0x16D7000016D7A,
|
| 4234 |
+
0x16E6000016E80,
|
| 4235 |
+
0x16F0000016F4B,
|
| 4236 |
+
0x16F4F00016F88,
|
| 4237 |
+
0x16F8F00016FA0,
|
| 4238 |
+
0x16FE000016FE2,
|
| 4239 |
+
0x16FE300016FE5,
|
| 4240 |
+
0x16FF000016FF2,
|
| 4241 |
+
0x17000000187F8,
|
| 4242 |
+
0x1880000018CD6,
|
| 4243 |
+
0x18CFF00018D09,
|
| 4244 |
+
0x1AFF00001AFF4,
|
| 4245 |
+
0x1AFF50001AFFC,
|
| 4246 |
+
0x1AFFD0001AFFF,
|
| 4247 |
+
0x1B0000001B123,
|
| 4248 |
+
0x1B1320001B133,
|
| 4249 |
+
0x1B1500001B153,
|
| 4250 |
+
0x1B1550001B156,
|
| 4251 |
+
0x1B1640001B168,
|
| 4252 |
+
0x1B1700001B2FC,
|
| 4253 |
+
0x1BC000001BC6B,
|
| 4254 |
+
0x1BC700001BC7D,
|
| 4255 |
+
0x1BC800001BC89,
|
| 4256 |
+
0x1BC900001BC9A,
|
| 4257 |
+
0x1BC9D0001BC9F,
|
| 4258 |
+
0x1CCF00001CCFA,
|
| 4259 |
+
0x1CF000001CF2E,
|
| 4260 |
+
0x1CF300001CF47,
|
| 4261 |
+
0x1DA000001DA37,
|
| 4262 |
+
0x1DA3B0001DA6D,
|
| 4263 |
+
0x1DA750001DA76,
|
| 4264 |
+
0x1DA840001DA85,
|
| 4265 |
+
0x1DA9B0001DAA0,
|
| 4266 |
+
0x1DAA10001DAB0,
|
| 4267 |
+
0x1DF000001DF1F,
|
| 4268 |
+
0x1DF250001DF2B,
|
| 4269 |
+
0x1E0000001E007,
|
| 4270 |
+
0x1E0080001E019,
|
| 4271 |
+
0x1E01B0001E022,
|
| 4272 |
+
0x1E0230001E025,
|
| 4273 |
+
0x1E0260001E02B,
|
| 4274 |
+
0x1E08F0001E090,
|
| 4275 |
+
0x1E1000001E12D,
|
| 4276 |
+
0x1E1300001E13E,
|
| 4277 |
+
0x1E1400001E14A,
|
| 4278 |
+
0x1E14E0001E14F,
|
| 4279 |
+
0x1E2900001E2AF,
|
| 4280 |
+
0x1E2C00001E2FA,
|
| 4281 |
+
0x1E4D00001E4FA,
|
| 4282 |
+
0x1E5D00001E5FB,
|
| 4283 |
+
0x1E7E00001E7E7,
|
| 4284 |
+
0x1E7E80001E7EC,
|
| 4285 |
+
0x1E7ED0001E7EF,
|
| 4286 |
+
0x1E7F00001E7FF,
|
| 4287 |
+
0x1E8000001E8C5,
|
| 4288 |
+
0x1E8D00001E8D7,
|
| 4289 |
+
0x1E9220001E94C,
|
| 4290 |
+
0x1E9500001E95A,
|
| 4291 |
+
0x200000002A6E0,
|
| 4292 |
+
0x2A7000002B73A,
|
| 4293 |
+
0x2B7400002B81E,
|
| 4294 |
+
0x2B8200002CEA2,
|
| 4295 |
+
0x2CEB00002EBE1,
|
| 4296 |
+
0x2EBF00002EE5E,
|
| 4297 |
+
0x300000003134B,
|
| 4298 |
+
0x31350000323B0,
|
| 4299 |
+
),
|
| 4300 |
+
"CONTEXTJ": (0x200C0000200E,),
|
| 4301 |
+
"CONTEXTO": (
|
| 4302 |
+
0xB7000000B8,
|
| 4303 |
+
0x37500000376,
|
| 4304 |
+
0x5F3000005F5,
|
| 4305 |
+
0x6600000066A,
|
| 4306 |
+
0x6F0000006FA,
|
| 4307 |
+
0x30FB000030FC,
|
| 4308 |
+
),
|
| 4309 |
+
}
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/intranges.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Given a list of integers, made up of (hopefully) a small number of long runs
|
| 3 |
+
of consecutive integers, compute a representation of the form
|
| 4 |
+
((start1, end1), (start2, end2) ...). Then answer the question "was x present
|
| 5 |
+
in the original list?" in time O(log(# runs)).
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import bisect
|
| 9 |
+
from typing import List, Tuple
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def intranges_from_list(list_: List[int]) -> Tuple[int, ...]:
|
| 13 |
+
"""Represent a list of integers as a sequence of ranges:
|
| 14 |
+
((start_0, end_0), (start_1, end_1), ...), such that the original
|
| 15 |
+
integers are exactly those x such that start_i <= x < end_i for some i.
|
| 16 |
+
|
| 17 |
+
Ranges are encoded as single integers (start << 32 | end), not as tuples.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
sorted_list = sorted(list_)
|
| 21 |
+
ranges = []
|
| 22 |
+
last_write = -1
|
| 23 |
+
for i in range(len(sorted_list)):
|
| 24 |
+
if i + 1 < len(sorted_list):
|
| 25 |
+
if sorted_list[i] == sorted_list[i + 1] - 1:
|
| 26 |
+
continue
|
| 27 |
+
current_range = sorted_list[last_write + 1 : i + 1]
|
| 28 |
+
ranges.append(_encode_range(current_range[0], current_range[-1] + 1))
|
| 29 |
+
last_write = i
|
| 30 |
+
|
| 31 |
+
return tuple(ranges)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _encode_range(start: int, end: int) -> int:
|
| 35 |
+
return (start << 32) | end
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _decode_range(r: int) -> Tuple[int, int]:
|
| 39 |
+
return (r >> 32), (r & ((1 << 32) - 1))
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def intranges_contain(int_: int, ranges: Tuple[int, ...]) -> bool:
|
| 43 |
+
"""Determine if `int_` falls into one of the ranges in `ranges`."""
|
| 44 |
+
tuple_ = _encode_range(int_, 0)
|
| 45 |
+
pos = bisect.bisect_left(ranges, tuple_)
|
| 46 |
+
# we could be immediately ahead of a tuple (start, end)
|
| 47 |
+
# with start < int_ <= end
|
| 48 |
+
if pos > 0:
|
| 49 |
+
left, right = _decode_range(ranges[pos - 1])
|
| 50 |
+
if left <= int_ < right:
|
| 51 |
+
return True
|
| 52 |
+
# or we could be immediately behind a tuple (int_, end)
|
| 53 |
+
if pos < len(ranges):
|
| 54 |
+
left, _ = _decode_range(ranges[pos])
|
| 55 |
+
if left == int_:
|
| 56 |
+
return True
|
| 57 |
+
return False
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/package_data.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__version__ = "3.11"
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/py.typed
ADDED
|
File without changes
|
miniconda3/envs/ladir/lib/python3.10/site-packages/idna/uts46data.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/LICENSE.txt
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This package is a modified version of cpython's ipaddress module.
|
| 2 |
+
It is therefore distributed under the PSF license, as follows:
|
| 3 |
+
|
| 4 |
+
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
|
| 5 |
+
--------------------------------------------
|
| 6 |
+
|
| 7 |
+
1. This LICENSE AGREEMENT is between the Python Software Foundation
|
| 8 |
+
("PSF"), and the Individual or Organization ("Licensee") accessing and
|
| 9 |
+
otherwise using this software ("Python") in source or binary form and
|
| 10 |
+
its associated documentation.
|
| 11 |
+
|
| 12 |
+
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
| 13 |
+
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
|
| 14 |
+
analyze, test, perform and/or display publicly, prepare derivative works,
|
| 15 |
+
distribute, and otherwise use Python alone or in any derivative version,
|
| 16 |
+
provided, however, that PSF's License Agreement and PSF's notice of copyright,
|
| 17 |
+
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
| 18 |
+
2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are
|
| 19 |
+
retained in Python alone or in any derivative version prepared by Licensee.
|
| 20 |
+
|
| 21 |
+
3. In the event Licensee prepares a derivative work that is based on
|
| 22 |
+
or incorporates Python or any part thereof, and wants to make
|
| 23 |
+
the derivative work available to others as provided herein, then
|
| 24 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 25 |
+
the changes made to Python.
|
| 26 |
+
|
| 27 |
+
4. PSF is making Python available to Licensee on an "AS IS"
|
| 28 |
+
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 29 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
|
| 30 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 31 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
|
| 32 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 33 |
+
|
| 34 |
+
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
| 35 |
+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
| 36 |
+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
|
| 37 |
+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 38 |
+
|
| 39 |
+
6. This License Agreement will automatically terminate upon a material
|
| 40 |
+
breach of its terms and conditions.
|
| 41 |
+
|
| 42 |
+
7. Nothing in this License Agreement shall be deemed to create any
|
| 43 |
+
relationship of agency, partnership, or joint venture between PSF and
|
| 44 |
+
Licensee. This License Agreement does not grant permission to use PSF
|
| 45 |
+
trademarks or trade name in a trademark sense to endorse or promote
|
| 46 |
+
products or services of Licensee, or any third party.
|
| 47 |
+
|
| 48 |
+
8. By copying, installing or otherwise using Python, Licensee
|
| 49 |
+
agrees to be bound by the terms and conditions of this License
|
| 50 |
+
Agreement.
|
miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/METADATA
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: ipaddress
|
| 3 |
+
Version: 1.0.23
|
| 4 |
+
Summary: IPv4/IPv6 manipulation library
|
| 5 |
+
Home-page: https://github.com/phihag/ipaddress
|
| 6 |
+
Author: Philipp Hagemeister
|
| 7 |
+
Author-email: phihag@phihag.de
|
| 8 |
+
License: Python Software Foundation License
|
| 9 |
+
Platform: UNKNOWN
|
| 10 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 11 |
+
Classifier: Intended Audience :: Developers
|
| 12 |
+
Classifier: Natural Language :: English
|
| 13 |
+
Classifier: License :: OSI Approved :: Python Software Foundation License
|
| 14 |
+
Classifier: Programming Language :: Python
|
| 15 |
+
Classifier: Programming Language :: Python :: 2.6
|
| 16 |
+
Classifier: Programming Language :: Python :: 2.7
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.2
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.3
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.4
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.5
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.6
|
| 22 |
+
|
| 23 |
+
Port of the 3.3+ ipaddress module to 2.6, 2.7, 3.2
|
| 24 |
+
|
| 25 |
+
|
miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/RECORD
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/ipaddress.cpython-310.pyc,,
|
| 2 |
+
ipaddress-1.0.23.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
ipaddress-1.0.23.dist-info/LICENSE.txt,sha256=OGdUGetKeexhY5bXDxJUs6Qz-3CI-z9MybbAvNzsYWI,2573
|
| 4 |
+
ipaddress-1.0.23.dist-info/METADATA,sha256=b9Im8p_GYagfjF7EHTTyy1euB_3lPfKsHxdWOFIDfDg,923
|
| 5 |
+
ipaddress-1.0.23.dist-info/RECORD,,
|
| 6 |
+
ipaddress-1.0.23.dist-info/WHEEL,sha256=J3CsTk7Mf2JNUyhImI-mjX-fmI4oDjyiXgWT4qgZiCE,110
|
| 7 |
+
ipaddress-1.0.23.dist-info/top_level.txt,sha256=2eNV5koVDCuB7hG17Yfh-lkL6iQnSpnQcr9cmsEx2DU,10
|
| 8 |
+
ipaddress.py,sha256=-0RmurI31XgAaN20WCi0zrcuoat90nNA70_6yGlx2PU,79875
|
miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.31.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py2-none-any
|
| 5 |
+
Tag: py3-none-any
|
| 6 |
+
|
miniconda3/envs/ladir/lib/python3.10/site-packages/ipaddress-1.0.23.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ipaddress
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
miniconda3/envs/ladir/lib/python3.10/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 |
+
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/RECORD
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/WHEEL,sha256=_2ozNFCLWc93bK4WKHCO-eDUENDlo-dgc9cU3qokYO4,82
|
| 5 |
+
jinja2-3.1.6.dist-info/entry_points.txt,sha256=OL85gYU1eD8cuPlikifFngXpeBjaxl6rIJ8KkC_3r-I,58
|
| 6 |
+
jinja2-3.1.6.dist-info/licenses/LICENSE.txt,sha256=O0nc7kEF6ze6wQ-vG-JgQI_oXSUrjp3y4JefweCUQ3s,1475
|
| 7 |
+
jinja2/__init__.py,sha256=xxepO9i7DHsqkQrgBEduLtfoz2QCuT6_gbL4XSN1hbU,1928
|
| 8 |
+
jinja2/__pycache__/__init__.cpython-310.pyc,,
|
| 9 |
+
jinja2/__pycache__/_identifier.cpython-310.pyc,,
|
| 10 |
+
jinja2/__pycache__/async_utils.cpython-310.pyc,,
|
| 11 |
+
jinja2/__pycache__/bccache.cpython-310.pyc,,
|
| 12 |
+
jinja2/__pycache__/compiler.cpython-310.pyc,,
|
| 13 |
+
jinja2/__pycache__/constants.cpython-310.pyc,,
|
| 14 |
+
jinja2/__pycache__/debug.cpython-310.pyc,,
|
| 15 |
+
jinja2/__pycache__/defaults.cpython-310.pyc,,
|
| 16 |
+
jinja2/__pycache__/environment.cpython-310.pyc,,
|
| 17 |
+
jinja2/__pycache__/exceptions.cpython-310.pyc,,
|
| 18 |
+
jinja2/__pycache__/ext.cpython-310.pyc,,
|
| 19 |
+
jinja2/__pycache__/filters.cpython-310.pyc,,
|
| 20 |
+
jinja2/__pycache__/idtracking.cpython-310.pyc,,
|
| 21 |
+
jinja2/__pycache__/lexer.cpython-310.pyc,,
|
| 22 |
+
jinja2/__pycache__/loaders.cpython-310.pyc,,
|
| 23 |
+
jinja2/__pycache__/meta.cpython-310.pyc,,
|
| 24 |
+
jinja2/__pycache__/nativetypes.cpython-310.pyc,,
|
| 25 |
+
jinja2/__pycache__/nodes.cpython-310.pyc,,
|
| 26 |
+
jinja2/__pycache__/optimizer.cpython-310.pyc,,
|
| 27 |
+
jinja2/__pycache__/parser.cpython-310.pyc,,
|
| 28 |
+
jinja2/__pycache__/runtime.cpython-310.pyc,,
|
| 29 |
+
jinja2/__pycache__/sandbox.cpython-310.pyc,,
|
| 30 |
+
jinja2/__pycache__/tests.cpython-310.pyc,,
|
| 31 |
+
jinja2/__pycache__/utils.cpython-310.pyc,,
|
| 32 |
+
jinja2/__pycache__/visitor.cpython-310.pyc,,
|
| 33 |
+
jinja2/_identifier.py,sha256=_zYctNKzRqlk_murTNlzrju1FFJL7Va_Ijqqd7ii2lU,1958
|
| 34 |
+
jinja2/async_utils.py,sha256=vK-PdsuorOMnWSnEkT3iUJRIkTnYgO2T6MnGxDgHI5o,2834
|
| 35 |
+
jinja2/bccache.py,sha256=gh0qs9rulnXo0PhX5jTJy2UHzI8wFnQ63o_vw7nhzRg,14061
|
| 36 |
+
jinja2/compiler.py,sha256=9RpCQl5X88BHllJiPsHPh295Hh0uApvwFJNQuutULeM,74131
|
| 37 |
+
jinja2/constants.py,sha256=GMoFydBF_kdpaRKPoM5cl5MviquVRLVyZtfp5-16jg0,1433
|
| 38 |
+
jinja2/debug.py,sha256=CnHqCDHd-BVGvti_8ZsTolnXNhA3ECsY-6n_2pwU8Hw,6297
|
| 39 |
+
jinja2/defaults.py,sha256=boBcSw78h-lp20YbaXSJsqkAI2uN_mD_TtCydpeq5wU,1267
|
| 40 |
+
jinja2/environment.py,sha256=9nhrP7Ch-NbGX00wvyr4yy-uhNHq2OCc60ggGrni_fk,61513
|
| 41 |
+
jinja2/exceptions.py,sha256=ioHeHrWwCWNaXX1inHmHVblvc4haO7AXsjCp3GfWvx0,5071
|
| 42 |
+
jinja2/ext.py,sha256=5PF5eHfh8mXAIxXHHRB2xXbXohi8pE3nHSOxa66uS7E,31875
|
| 43 |
+
jinja2/filters.py,sha256=PQ_Egd9n9jSgtnGQYyF4K5j2nYwhUIulhPnyimkdr-k,55212
|
| 44 |
+
jinja2/idtracking.py,sha256=-ll5lIp73pML3ErUYiIJj7tdmWxcH_IlDv3yA_hiZYo,10555
|
| 45 |
+
jinja2/lexer.py,sha256=LYiYio6br-Tep9nPcupWXsPEtjluw3p1mU-lNBVRUfk,29786
|
| 46 |
+
jinja2/loaders.py,sha256=wIrnxjvcbqh5VwW28NSkfotiDq8qNCxIOSFbGUiSLB4,24055
|
| 47 |
+
jinja2/meta.py,sha256=OTDPkaFvU2Hgvx-6akz7154F8BIWaRmvJcBFvwopHww,4397
|
| 48 |
+
jinja2/nativetypes.py,sha256=7GIGALVJgdyL80oZJdQUaUfwSt5q2lSSZbXt0dNf_M4,4210
|
| 49 |
+
jinja2/nodes.py,sha256=m1Duzcr6qhZI8JQ6VyJgUNinjAf5bQzijSmDnMsvUx8,34579
|
| 50 |
+
jinja2/optimizer.py,sha256=rJnCRlQ7pZsEEmMhsQDgC_pKyDHxP5TPS6zVPGsgcu8,1651
|
| 51 |
+
jinja2/parser.py,sha256=lLOFy3sEmHc5IaEHRiH1sQVnId2moUQzhyeJZTtdY30,40383
|
| 52 |
+
jinja2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 53 |
+
jinja2/runtime.py,sha256=gDk-GvdriJXqgsGbHgrcKTP0Yp6zPXzhzrIpCFH3jAU,34249
|
| 54 |
+
jinja2/sandbox.py,sha256=Mw2aitlY2I8la7FYhcX2YG9BtUYcLnD0Gh3d29cDWrY,15009
|
| 55 |
+
jinja2/tests.py,sha256=VLsBhVFnWg-PxSBz1MhRnNWgP1ovXk3neO1FLQMeC9Q,5926
|
| 56 |
+
jinja2/utils.py,sha256=rRp3o9e7ZKS4fyrWRbELyLcpuGVTFcnooaOa1qx_FIk,24129
|
| 57 |
+
jinja2/visitor.py,sha256=EcnL1PIwf_4RVCOMxsRNuR8AXHbS1qfAdMOE2ngKJz4,3557
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2-3.1.6.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: flit 3.11.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
miniconda3/envs/ladir/lib/python3.10/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 |
+
|
miniconda3/envs/ladir/lib/python3.10/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.
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Jinja is a template engine written in pure Python. It provides a
|
| 2 |
+
non-XML syntax that supports inline expressions and an optional
|
| 3 |
+
sandboxed environment.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from .bccache import BytecodeCache as BytecodeCache
|
| 7 |
+
from .bccache import FileSystemBytecodeCache as FileSystemBytecodeCache
|
| 8 |
+
from .bccache import MemcachedBytecodeCache as MemcachedBytecodeCache
|
| 9 |
+
from .environment import Environment as Environment
|
| 10 |
+
from .environment import Template as Template
|
| 11 |
+
from .exceptions import TemplateAssertionError as TemplateAssertionError
|
| 12 |
+
from .exceptions import TemplateError as TemplateError
|
| 13 |
+
from .exceptions import TemplateNotFound as TemplateNotFound
|
| 14 |
+
from .exceptions import TemplateRuntimeError as TemplateRuntimeError
|
| 15 |
+
from .exceptions import TemplatesNotFound as TemplatesNotFound
|
| 16 |
+
from .exceptions import TemplateSyntaxError as TemplateSyntaxError
|
| 17 |
+
from .exceptions import UndefinedError as UndefinedError
|
| 18 |
+
from .loaders import BaseLoader as BaseLoader
|
| 19 |
+
from .loaders import ChoiceLoader as ChoiceLoader
|
| 20 |
+
from .loaders import DictLoader as DictLoader
|
| 21 |
+
from .loaders import FileSystemLoader as FileSystemLoader
|
| 22 |
+
from .loaders import FunctionLoader as FunctionLoader
|
| 23 |
+
from .loaders import ModuleLoader as ModuleLoader
|
| 24 |
+
from .loaders import PackageLoader as PackageLoader
|
| 25 |
+
from .loaders import PrefixLoader as PrefixLoader
|
| 26 |
+
from .runtime import ChainableUndefined as ChainableUndefined
|
| 27 |
+
from .runtime import DebugUndefined as DebugUndefined
|
| 28 |
+
from .runtime import make_logging_undefined as make_logging_undefined
|
| 29 |
+
from .runtime import StrictUndefined as StrictUndefined
|
| 30 |
+
from .runtime import Undefined as Undefined
|
| 31 |
+
from .utils import clear_caches as clear_caches
|
| 32 |
+
from .utils import is_undefined as is_undefined
|
| 33 |
+
from .utils import pass_context as pass_context
|
| 34 |
+
from .utils import pass_environment as pass_environment
|
| 35 |
+
from .utils import pass_eval_context as pass_eval_context
|
| 36 |
+
from .utils import select_autoescape as select_autoescape
|
| 37 |
+
|
| 38 |
+
__version__ = "3.1.6"
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/_identifier.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
# generated by scripts/generate_identifier_pattern.py
|
| 4 |
+
pattern = re.compile(
|
| 5 |
+
r"[\w·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-ٰٟۖ-ۜ۟-۪ۤۧۨ-ܑۭܰ-݊ަ-ް߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛࣓-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣঁ-ঃ়া-ৄেৈো-্ৗৢৣ৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑੰੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣஂா-ூெ-ைொ-்ௗఀ-ఄా-ౄె-ైొ-్ౕౖౢౣಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣංඃ්ා-ුූෘ-ෟෲෳัิ-ฺ็-๎ັິ-ູົຼ່-ໍ༹༘༙༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏႚ-ႝ፝-፟ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝᠋-᠍ᢅᢆᢩᤠ-ᤫᤰ-᤻ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼᪰-᪽ᬀ-ᬄ᬴-᭄᭫-᭳ᮀ-ᮂᮡ-ᮭ᯦-᯳ᰤ-᰷᳐-᳔᳒-᳨᳭ᳲ-᳴᳷-᳹᷀-᷹᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰℘℮⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣠-꣱ꣿꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀ꧥꨩ-ꨶꩃꩌꩍꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭ﬞ︀-️︠-︯︳︴﹍-﹏_𐇽𐋠𐍶-𐍺𐨁-𐨃𐨅𐨆𐨌-𐨏𐨸-𐨿𐨺𐫦𐫥𐴤-𐽆𐴧-𐽐𑀀-𑀂𑀸-𑁆𑁿-𑂂𑂰-𑂺𑄀-𑄂𑄧-𑄴𑅅𑅆𑅳𑆀-𑆂𑆳-𑇀𑇉-𑇌𑈬-𑈷𑈾𑋟-𑋪𑌀-𑌃𑌻𑌼𑌾-𑍄𑍇𑍈𑍋-𑍍𑍗𑍢𑍣𑍦-𑍬𑍰-𑍴𑐵-𑑆𑑞𑒰-𑓃𑖯-𑖵𑖸-𑗀𑗜𑗝𑘰-𑙀𑚫-𑚷𑜝-𑜫𑠬-𑠺𑨁-𑨊𑨳-𑨹𑨻-𑨾𑩇𑩑-𑩛𑪊-𑪙𑰯-𑰶𑰸-𑰿𑲒-𑲧𑲩-𑲶𑴱-𑴶𑴺𑴼𑴽𑴿-𑵅𑵇𑶊-𑶎𑶐𑶑𑶓-𑶗𑻳-𑻶𖫰-𖫴𖬰-𖬶𖽑-𖽾𖾏-𖾒𛲝𛲞𝅥-𝅩𝅭-𝅲𝅻-𝆂𝆅-𝆋𝆪-𝆭𝉂-𝉄𝨀-𝨶𝨻-𝩬𝩵𝪄𝪛-𝪟𝪡-𝪯𞀀-𞀆𞀈-𞀘𞀛-𞀡𞀣𞀤𞀦-𞣐𞀪-𞣖𞥄-𞥊󠄀-󠇯]+" # noqa: B950
|
| 6 |
+
)
|
miniconda3/envs/ladir/lib/python3.10/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)]
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/bccache.py
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The optional bytecode cache system. This is useful if you have very
|
| 2 |
+
complex template situations and the compilation of all those templates
|
| 3 |
+
slows down your application too much.
|
| 4 |
+
|
| 5 |
+
Situations where this is useful are often forking web applications that
|
| 6 |
+
are initialized on the first request.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import errno
|
| 10 |
+
import fnmatch
|
| 11 |
+
import marshal
|
| 12 |
+
import os
|
| 13 |
+
import pickle
|
| 14 |
+
import stat
|
| 15 |
+
import sys
|
| 16 |
+
import tempfile
|
| 17 |
+
import typing as t
|
| 18 |
+
from hashlib import sha1
|
| 19 |
+
from io import BytesIO
|
| 20 |
+
from types import CodeType
|
| 21 |
+
|
| 22 |
+
if t.TYPE_CHECKING:
|
| 23 |
+
import typing_extensions as te
|
| 24 |
+
|
| 25 |
+
from .environment import Environment
|
| 26 |
+
|
| 27 |
+
class _MemcachedClient(te.Protocol):
|
| 28 |
+
def get(self, key: str) -> bytes: ...
|
| 29 |
+
|
| 30 |
+
def set(
|
| 31 |
+
self, key: str, value: bytes, timeout: t.Optional[int] = None
|
| 32 |
+
) -> None: ...
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
bc_version = 5
|
| 36 |
+
# Magic bytes to identify Jinja bytecode cache files. Contains the
|
| 37 |
+
# Python major and minor version to avoid loading incompatible bytecode
|
| 38 |
+
# if a project upgrades its Python version.
|
| 39 |
+
bc_magic = (
|
| 40 |
+
b"j2"
|
| 41 |
+
+ pickle.dumps(bc_version, 2)
|
| 42 |
+
+ pickle.dumps((sys.version_info[0] << 24) | sys.version_info[1], 2)
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Bucket:
|
| 47 |
+
"""Buckets are used to store the bytecode for one template. It's created
|
| 48 |
+
and initialized by the bytecode cache and passed to the loading functions.
|
| 49 |
+
|
| 50 |
+
The buckets get an internal checksum from the cache assigned and use this
|
| 51 |
+
to automatically reject outdated cache material. Individual bytecode
|
| 52 |
+
cache subclasses don't have to care about cache invalidation.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def __init__(self, environment: "Environment", key: str, checksum: str) -> None:
|
| 56 |
+
self.environment = environment
|
| 57 |
+
self.key = key
|
| 58 |
+
self.checksum = checksum
|
| 59 |
+
self.reset()
|
| 60 |
+
|
| 61 |
+
def reset(self) -> None:
|
| 62 |
+
"""Resets the bucket (unloads the bytecode)."""
|
| 63 |
+
self.code: t.Optional[CodeType] = None
|
| 64 |
+
|
| 65 |
+
def load_bytecode(self, f: t.BinaryIO) -> None:
|
| 66 |
+
"""Loads bytecode from a file or file like object."""
|
| 67 |
+
# make sure the magic header is correct
|
| 68 |
+
magic = f.read(len(bc_magic))
|
| 69 |
+
if magic != bc_magic:
|
| 70 |
+
self.reset()
|
| 71 |
+
return
|
| 72 |
+
# the source code of the file changed, we need to reload
|
| 73 |
+
checksum = pickle.load(f)
|
| 74 |
+
if self.checksum != checksum:
|
| 75 |
+
self.reset()
|
| 76 |
+
return
|
| 77 |
+
# if marshal_load fails then we need to reload
|
| 78 |
+
try:
|
| 79 |
+
self.code = marshal.load(f)
|
| 80 |
+
except (EOFError, ValueError, TypeError):
|
| 81 |
+
self.reset()
|
| 82 |
+
return
|
| 83 |
+
|
| 84 |
+
def write_bytecode(self, f: t.IO[bytes]) -> None:
|
| 85 |
+
"""Dump the bytecode into the file or file like object passed."""
|
| 86 |
+
if self.code is None:
|
| 87 |
+
raise TypeError("can't write empty bucket")
|
| 88 |
+
f.write(bc_magic)
|
| 89 |
+
pickle.dump(self.checksum, f, 2)
|
| 90 |
+
marshal.dump(self.code, f)
|
| 91 |
+
|
| 92 |
+
def bytecode_from_string(self, string: bytes) -> None:
|
| 93 |
+
"""Load bytecode from bytes."""
|
| 94 |
+
self.load_bytecode(BytesIO(string))
|
| 95 |
+
|
| 96 |
+
def bytecode_to_string(self) -> bytes:
|
| 97 |
+
"""Return the bytecode as bytes."""
|
| 98 |
+
out = BytesIO()
|
| 99 |
+
self.write_bytecode(out)
|
| 100 |
+
return out.getvalue()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class BytecodeCache:
|
| 104 |
+
"""To implement your own bytecode cache you have to subclass this class
|
| 105 |
+
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
|
| 106 |
+
these methods are passed a :class:`~jinja2.bccache.Bucket`.
|
| 107 |
+
|
| 108 |
+
A very basic bytecode cache that saves the bytecode on the file system::
|
| 109 |
+
|
| 110 |
+
from os import path
|
| 111 |
+
|
| 112 |
+
class MyCache(BytecodeCache):
|
| 113 |
+
|
| 114 |
+
def __init__(self, directory):
|
| 115 |
+
self.directory = directory
|
| 116 |
+
|
| 117 |
+
def load_bytecode(self, bucket):
|
| 118 |
+
filename = path.join(self.directory, bucket.key)
|
| 119 |
+
if path.exists(filename):
|
| 120 |
+
with open(filename, 'rb') as f:
|
| 121 |
+
bucket.load_bytecode(f)
|
| 122 |
+
|
| 123 |
+
def dump_bytecode(self, bucket):
|
| 124 |
+
filename = path.join(self.directory, bucket.key)
|
| 125 |
+
with open(filename, 'wb') as f:
|
| 126 |
+
bucket.write_bytecode(f)
|
| 127 |
+
|
| 128 |
+
A more advanced version of a filesystem based bytecode cache is part of
|
| 129 |
+
Jinja.
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
def load_bytecode(self, bucket: Bucket) -> None:
|
| 133 |
+
"""Subclasses have to override this method to load bytecode into a
|
| 134 |
+
bucket. If they are not able to find code in the cache for the
|
| 135 |
+
bucket, it must not do anything.
|
| 136 |
+
"""
|
| 137 |
+
raise NotImplementedError()
|
| 138 |
+
|
| 139 |
+
def dump_bytecode(self, bucket: Bucket) -> None:
|
| 140 |
+
"""Subclasses have to override this method to write the bytecode
|
| 141 |
+
from a bucket back to the cache. If it unable to do so it must not
|
| 142 |
+
fail silently but raise an exception.
|
| 143 |
+
"""
|
| 144 |
+
raise NotImplementedError()
|
| 145 |
+
|
| 146 |
+
def clear(self) -> None:
|
| 147 |
+
"""Clears the cache. This method is not used by Jinja but should be
|
| 148 |
+
implemented to allow applications to clear the bytecode cache used
|
| 149 |
+
by a particular environment.
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
def get_cache_key(
|
| 153 |
+
self, name: str, filename: t.Optional[t.Union[str]] = None
|
| 154 |
+
) -> str:
|
| 155 |
+
"""Returns the unique hash key for this template name."""
|
| 156 |
+
hash = sha1(name.encode("utf-8"))
|
| 157 |
+
|
| 158 |
+
if filename is not None:
|
| 159 |
+
hash.update(f"|{filename}".encode())
|
| 160 |
+
|
| 161 |
+
return hash.hexdigest()
|
| 162 |
+
|
| 163 |
+
def get_source_checksum(self, source: str) -> str:
|
| 164 |
+
"""Returns a checksum for the source."""
|
| 165 |
+
return sha1(source.encode("utf-8")).hexdigest()
|
| 166 |
+
|
| 167 |
+
def get_bucket(
|
| 168 |
+
self,
|
| 169 |
+
environment: "Environment",
|
| 170 |
+
name: str,
|
| 171 |
+
filename: t.Optional[str],
|
| 172 |
+
source: str,
|
| 173 |
+
) -> Bucket:
|
| 174 |
+
"""Return a cache bucket for the given template. All arguments are
|
| 175 |
+
mandatory but filename may be `None`.
|
| 176 |
+
"""
|
| 177 |
+
key = self.get_cache_key(name, filename)
|
| 178 |
+
checksum = self.get_source_checksum(source)
|
| 179 |
+
bucket = Bucket(environment, key, checksum)
|
| 180 |
+
self.load_bytecode(bucket)
|
| 181 |
+
return bucket
|
| 182 |
+
|
| 183 |
+
def set_bucket(self, bucket: Bucket) -> None:
|
| 184 |
+
"""Put the bucket into the cache."""
|
| 185 |
+
self.dump_bytecode(bucket)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class FileSystemBytecodeCache(BytecodeCache):
|
| 189 |
+
"""A bytecode cache that stores bytecode on the filesystem. It accepts
|
| 190 |
+
two arguments: The directory where the cache items are stored and a
|
| 191 |
+
pattern string that is used to build the filename.
|
| 192 |
+
|
| 193 |
+
If no directory is specified a default cache directory is selected. On
|
| 194 |
+
Windows the user's temp directory is used, on UNIX systems a directory
|
| 195 |
+
is created for the user in the system temp directory.
|
| 196 |
+
|
| 197 |
+
The pattern can be used to have multiple separate caches operate on the
|
| 198 |
+
same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``
|
| 199 |
+
is replaced with the cache key.
|
| 200 |
+
|
| 201 |
+
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
|
| 202 |
+
|
| 203 |
+
This bytecode cache supports clearing of the cache using the clear method.
|
| 204 |
+
"""
|
| 205 |
+
|
| 206 |
+
def __init__(
|
| 207 |
+
self, directory: t.Optional[str] = None, pattern: str = "__jinja2_%s.cache"
|
| 208 |
+
) -> None:
|
| 209 |
+
if directory is None:
|
| 210 |
+
directory = self._get_default_cache_dir()
|
| 211 |
+
self.directory = directory
|
| 212 |
+
self.pattern = pattern
|
| 213 |
+
|
| 214 |
+
def _get_default_cache_dir(self) -> str:
|
| 215 |
+
def _unsafe_dir() -> "te.NoReturn":
|
| 216 |
+
raise RuntimeError(
|
| 217 |
+
"Cannot determine safe temp directory. You "
|
| 218 |
+
"need to explicitly provide one."
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
tmpdir = tempfile.gettempdir()
|
| 222 |
+
|
| 223 |
+
# On windows the temporary directory is used specific unless
|
| 224 |
+
# explicitly forced otherwise. We can just use that.
|
| 225 |
+
if os.name == "nt":
|
| 226 |
+
return tmpdir
|
| 227 |
+
if not hasattr(os, "getuid"):
|
| 228 |
+
_unsafe_dir()
|
| 229 |
+
|
| 230 |
+
dirname = f"_jinja2-cache-{os.getuid()}"
|
| 231 |
+
actual_dir = os.path.join(tmpdir, dirname)
|
| 232 |
+
|
| 233 |
+
try:
|
| 234 |
+
os.mkdir(actual_dir, stat.S_IRWXU)
|
| 235 |
+
except OSError as e:
|
| 236 |
+
if e.errno != errno.EEXIST:
|
| 237 |
+
raise
|
| 238 |
+
try:
|
| 239 |
+
os.chmod(actual_dir, stat.S_IRWXU)
|
| 240 |
+
actual_dir_stat = os.lstat(actual_dir)
|
| 241 |
+
if (
|
| 242 |
+
actual_dir_stat.st_uid != os.getuid()
|
| 243 |
+
or not stat.S_ISDIR(actual_dir_stat.st_mode)
|
| 244 |
+
or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU
|
| 245 |
+
):
|
| 246 |
+
_unsafe_dir()
|
| 247 |
+
except OSError as e:
|
| 248 |
+
if e.errno != errno.EEXIST:
|
| 249 |
+
raise
|
| 250 |
+
|
| 251 |
+
actual_dir_stat = os.lstat(actual_dir)
|
| 252 |
+
if (
|
| 253 |
+
actual_dir_stat.st_uid != os.getuid()
|
| 254 |
+
or not stat.S_ISDIR(actual_dir_stat.st_mode)
|
| 255 |
+
or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU
|
| 256 |
+
):
|
| 257 |
+
_unsafe_dir()
|
| 258 |
+
|
| 259 |
+
return actual_dir
|
| 260 |
+
|
| 261 |
+
def _get_cache_filename(self, bucket: Bucket) -> str:
|
| 262 |
+
return os.path.join(self.directory, self.pattern % (bucket.key,))
|
| 263 |
+
|
| 264 |
+
def load_bytecode(self, bucket: Bucket) -> None:
|
| 265 |
+
filename = self._get_cache_filename(bucket)
|
| 266 |
+
|
| 267 |
+
# Don't test for existence before opening the file, since the
|
| 268 |
+
# file could disappear after the test before the open.
|
| 269 |
+
try:
|
| 270 |
+
f = open(filename, "rb")
|
| 271 |
+
except (FileNotFoundError, IsADirectoryError, PermissionError):
|
| 272 |
+
# PermissionError can occur on Windows when an operation is
|
| 273 |
+
# in progress, such as calling clear().
|
| 274 |
+
return
|
| 275 |
+
|
| 276 |
+
with f:
|
| 277 |
+
bucket.load_bytecode(f)
|
| 278 |
+
|
| 279 |
+
def dump_bytecode(self, bucket: Bucket) -> None:
|
| 280 |
+
# Write to a temporary file, then rename to the real name after
|
| 281 |
+
# writing. This avoids another process reading the file before
|
| 282 |
+
# it is fully written.
|
| 283 |
+
name = self._get_cache_filename(bucket)
|
| 284 |
+
f = tempfile.NamedTemporaryFile(
|
| 285 |
+
mode="wb",
|
| 286 |
+
dir=os.path.dirname(name),
|
| 287 |
+
prefix=os.path.basename(name),
|
| 288 |
+
suffix=".tmp",
|
| 289 |
+
delete=False,
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
def remove_silent() -> None:
|
| 293 |
+
try:
|
| 294 |
+
os.remove(f.name)
|
| 295 |
+
except OSError:
|
| 296 |
+
# Another process may have called clear(). On Windows,
|
| 297 |
+
# another program may be holding the file open.
|
| 298 |
+
pass
|
| 299 |
+
|
| 300 |
+
try:
|
| 301 |
+
with f:
|
| 302 |
+
bucket.write_bytecode(f)
|
| 303 |
+
except BaseException:
|
| 304 |
+
remove_silent()
|
| 305 |
+
raise
|
| 306 |
+
|
| 307 |
+
try:
|
| 308 |
+
os.replace(f.name, name)
|
| 309 |
+
except OSError:
|
| 310 |
+
# Another process may have called clear(). On Windows,
|
| 311 |
+
# another program may be holding the file open.
|
| 312 |
+
remove_silent()
|
| 313 |
+
except BaseException:
|
| 314 |
+
remove_silent()
|
| 315 |
+
raise
|
| 316 |
+
|
| 317 |
+
def clear(self) -> None:
|
| 318 |
+
# imported lazily here because google app-engine doesn't support
|
| 319 |
+
# write access on the file system and the function does not exist
|
| 320 |
+
# normally.
|
| 321 |
+
from os import remove
|
| 322 |
+
|
| 323 |
+
files = fnmatch.filter(os.listdir(self.directory), self.pattern % ("*",))
|
| 324 |
+
for filename in files:
|
| 325 |
+
try:
|
| 326 |
+
remove(os.path.join(self.directory, filename))
|
| 327 |
+
except OSError:
|
| 328 |
+
pass
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class MemcachedBytecodeCache(BytecodeCache):
|
| 332 |
+
"""This class implements a bytecode cache that uses a memcache cache for
|
| 333 |
+
storing the information. It does not enforce a specific memcache library
|
| 334 |
+
(tummy's memcache or cmemcache) but will accept any class that provides
|
| 335 |
+
the minimal interface required.
|
| 336 |
+
|
| 337 |
+
Libraries compatible with this class:
|
| 338 |
+
|
| 339 |
+
- `cachelib <https://github.com/pallets/cachelib>`_
|
| 340 |
+
- `python-memcached <https://pypi.org/project/python-memcached/>`_
|
| 341 |
+
|
| 342 |
+
(Unfortunately the django cache interface is not compatible because it
|
| 343 |
+
does not support storing binary data, only text. You can however pass
|
| 344 |
+
the underlying cache client to the bytecode cache which is available
|
| 345 |
+
as `django.core.cache.cache._client`.)
|
| 346 |
+
|
| 347 |
+
The minimal interface for the client passed to the constructor is this:
|
| 348 |
+
|
| 349 |
+
.. class:: MinimalClientInterface
|
| 350 |
+
|
| 351 |
+
.. method:: set(key, value[, timeout])
|
| 352 |
+
|
| 353 |
+
Stores the bytecode in the cache. `value` is a string and
|
| 354 |
+
`timeout` the timeout of the key. If timeout is not provided
|
| 355 |
+
a default timeout or no timeout should be assumed, if it's
|
| 356 |
+
provided it's an integer with the number of seconds the cache
|
| 357 |
+
item should exist.
|
| 358 |
+
|
| 359 |
+
.. method:: get(key)
|
| 360 |
+
|
| 361 |
+
Returns the value for the cache key. If the item does not
|
| 362 |
+
exist in the cache the return value must be `None`.
|
| 363 |
+
|
| 364 |
+
The other arguments to the constructor are the prefix for all keys that
|
| 365 |
+
is added before the actual cache key and the timeout for the bytecode in
|
| 366 |
+
the cache system. We recommend a high (or no) timeout.
|
| 367 |
+
|
| 368 |
+
This bytecode cache does not support clearing of used items in the cache.
|
| 369 |
+
The clear method is a no-operation function.
|
| 370 |
+
|
| 371 |
+
.. versionadded:: 2.7
|
| 372 |
+
Added support for ignoring memcache errors through the
|
| 373 |
+
`ignore_memcache_errors` parameter.
|
| 374 |
+
"""
|
| 375 |
+
|
| 376 |
+
def __init__(
|
| 377 |
+
self,
|
| 378 |
+
client: "_MemcachedClient",
|
| 379 |
+
prefix: str = "jinja2/bytecode/",
|
| 380 |
+
timeout: t.Optional[int] = None,
|
| 381 |
+
ignore_memcache_errors: bool = True,
|
| 382 |
+
):
|
| 383 |
+
self.client = client
|
| 384 |
+
self.prefix = prefix
|
| 385 |
+
self.timeout = timeout
|
| 386 |
+
self.ignore_memcache_errors = ignore_memcache_errors
|
| 387 |
+
|
| 388 |
+
def load_bytecode(self, bucket: Bucket) -> None:
|
| 389 |
+
try:
|
| 390 |
+
code = self.client.get(self.prefix + bucket.key)
|
| 391 |
+
except Exception:
|
| 392 |
+
if not self.ignore_memcache_errors:
|
| 393 |
+
raise
|
| 394 |
+
else:
|
| 395 |
+
bucket.bytecode_from_string(code)
|
| 396 |
+
|
| 397 |
+
def dump_bytecode(self, bucket: Bucket) -> None:
|
| 398 |
+
key = self.prefix + bucket.key
|
| 399 |
+
value = bucket.bytecode_to_string()
|
| 400 |
+
|
| 401 |
+
try:
|
| 402 |
+
if self.timeout is not None:
|
| 403 |
+
self.client.set(key, value, self.timeout)
|
| 404 |
+
else:
|
| 405 |
+
self.client.set(key, value)
|
| 406 |
+
except Exception:
|
| 407 |
+
if not self.ignore_memcache_errors:
|
| 408 |
+
raise
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/compiler.py
ADDED
|
@@ -0,0 +1,1998 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Compiles nodes from the parser into Python code."""
|
| 2 |
+
|
| 3 |
+
import typing as t
|
| 4 |
+
from contextlib import contextmanager
|
| 5 |
+
from functools import update_wrapper
|
| 6 |
+
from io import StringIO
|
| 7 |
+
from itertools import chain
|
| 8 |
+
from keyword import iskeyword as is_python_keyword
|
| 9 |
+
|
| 10 |
+
from markupsafe import escape
|
| 11 |
+
from markupsafe import Markup
|
| 12 |
+
|
| 13 |
+
from . import nodes
|
| 14 |
+
from .exceptions import TemplateAssertionError
|
| 15 |
+
from .idtracking import Symbols
|
| 16 |
+
from .idtracking import VAR_LOAD_ALIAS
|
| 17 |
+
from .idtracking import VAR_LOAD_PARAMETER
|
| 18 |
+
from .idtracking import VAR_LOAD_RESOLVE
|
| 19 |
+
from .idtracking import VAR_LOAD_UNDEFINED
|
| 20 |
+
from .nodes import EvalContext
|
| 21 |
+
from .optimizer import Optimizer
|
| 22 |
+
from .utils import _PassArg
|
| 23 |
+
from .utils import concat
|
| 24 |
+
from .visitor import NodeVisitor
|
| 25 |
+
|
| 26 |
+
if t.TYPE_CHECKING:
|
| 27 |
+
import typing_extensions as te
|
| 28 |
+
|
| 29 |
+
from .environment import Environment
|
| 30 |
+
|
| 31 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 32 |
+
|
| 33 |
+
operators = {
|
| 34 |
+
"eq": "==",
|
| 35 |
+
"ne": "!=",
|
| 36 |
+
"gt": ">",
|
| 37 |
+
"gteq": ">=",
|
| 38 |
+
"lt": "<",
|
| 39 |
+
"lteq": "<=",
|
| 40 |
+
"in": "in",
|
| 41 |
+
"notin": "not in",
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def optimizeconst(f: F) -> F:
|
| 46 |
+
def new_func(
|
| 47 |
+
self: "CodeGenerator", node: nodes.Expr, frame: "Frame", **kwargs: t.Any
|
| 48 |
+
) -> t.Any:
|
| 49 |
+
# Only optimize if the frame is not volatile
|
| 50 |
+
if self.optimizer is not None and not frame.eval_ctx.volatile:
|
| 51 |
+
new_node = self.optimizer.visit(node, frame.eval_ctx)
|
| 52 |
+
|
| 53 |
+
if new_node != node:
|
| 54 |
+
return self.visit(new_node, frame)
|
| 55 |
+
|
| 56 |
+
return f(self, node, frame, **kwargs)
|
| 57 |
+
|
| 58 |
+
return update_wrapper(new_func, f) # type: ignore[return-value]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _make_binop(op: str) -> t.Callable[["CodeGenerator", nodes.BinExpr, "Frame"], None]:
|
| 62 |
+
@optimizeconst
|
| 63 |
+
def visitor(self: "CodeGenerator", node: nodes.BinExpr, frame: Frame) -> None:
|
| 64 |
+
if (
|
| 65 |
+
self.environment.sandboxed and op in self.environment.intercepted_binops # type: ignore
|
| 66 |
+
):
|
| 67 |
+
self.write(f"environment.call_binop(context, {op!r}, ")
|
| 68 |
+
self.visit(node.left, frame)
|
| 69 |
+
self.write(", ")
|
| 70 |
+
self.visit(node.right, frame)
|
| 71 |
+
else:
|
| 72 |
+
self.write("(")
|
| 73 |
+
self.visit(node.left, frame)
|
| 74 |
+
self.write(f" {op} ")
|
| 75 |
+
self.visit(node.right, frame)
|
| 76 |
+
|
| 77 |
+
self.write(")")
|
| 78 |
+
|
| 79 |
+
return visitor
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _make_unop(
|
| 83 |
+
op: str,
|
| 84 |
+
) -> t.Callable[["CodeGenerator", nodes.UnaryExpr, "Frame"], None]:
|
| 85 |
+
@optimizeconst
|
| 86 |
+
def visitor(self: "CodeGenerator", node: nodes.UnaryExpr, frame: Frame) -> None:
|
| 87 |
+
if (
|
| 88 |
+
self.environment.sandboxed and op in self.environment.intercepted_unops # type: ignore
|
| 89 |
+
):
|
| 90 |
+
self.write(f"environment.call_unop(context, {op!r}, ")
|
| 91 |
+
self.visit(node.node, frame)
|
| 92 |
+
else:
|
| 93 |
+
self.write("(" + op)
|
| 94 |
+
self.visit(node.node, frame)
|
| 95 |
+
|
| 96 |
+
self.write(")")
|
| 97 |
+
|
| 98 |
+
return visitor
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def generate(
|
| 102 |
+
node: nodes.Template,
|
| 103 |
+
environment: "Environment",
|
| 104 |
+
name: t.Optional[str],
|
| 105 |
+
filename: t.Optional[str],
|
| 106 |
+
stream: t.Optional[t.TextIO] = None,
|
| 107 |
+
defer_init: bool = False,
|
| 108 |
+
optimized: bool = True,
|
| 109 |
+
) -> t.Optional[str]:
|
| 110 |
+
"""Generate the python source for a node tree."""
|
| 111 |
+
if not isinstance(node, nodes.Template):
|
| 112 |
+
raise TypeError("Can't compile non template nodes")
|
| 113 |
+
|
| 114 |
+
generator = environment.code_generator_class(
|
| 115 |
+
environment, name, filename, stream, defer_init, optimized
|
| 116 |
+
)
|
| 117 |
+
generator.visit(node)
|
| 118 |
+
|
| 119 |
+
if stream is None:
|
| 120 |
+
return generator.stream.getvalue() # type: ignore
|
| 121 |
+
|
| 122 |
+
return None
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def has_safe_repr(value: t.Any) -> bool:
|
| 126 |
+
"""Does the node have a safe representation?"""
|
| 127 |
+
if value is None or value is NotImplemented or value is Ellipsis:
|
| 128 |
+
return True
|
| 129 |
+
|
| 130 |
+
if type(value) in {bool, int, float, complex, range, str, Markup}:
|
| 131 |
+
return True
|
| 132 |
+
|
| 133 |
+
if type(value) in {tuple, list, set, frozenset}:
|
| 134 |
+
return all(has_safe_repr(v) for v in value)
|
| 135 |
+
|
| 136 |
+
if type(value) is dict: # noqa E721
|
| 137 |
+
return all(has_safe_repr(k) and has_safe_repr(v) for k, v in value.items())
|
| 138 |
+
|
| 139 |
+
return False
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def find_undeclared(
|
| 143 |
+
nodes: t.Iterable[nodes.Node], names: t.Iterable[str]
|
| 144 |
+
) -> t.Set[str]:
|
| 145 |
+
"""Check if the names passed are accessed undeclared. The return value
|
| 146 |
+
is a set of all the undeclared names from the sequence of names found.
|
| 147 |
+
"""
|
| 148 |
+
visitor = UndeclaredNameVisitor(names)
|
| 149 |
+
try:
|
| 150 |
+
for node in nodes:
|
| 151 |
+
visitor.visit(node)
|
| 152 |
+
except VisitorExit:
|
| 153 |
+
pass
|
| 154 |
+
return visitor.undeclared
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
class MacroRef:
|
| 158 |
+
def __init__(self, node: t.Union[nodes.Macro, nodes.CallBlock]) -> None:
|
| 159 |
+
self.node = node
|
| 160 |
+
self.accesses_caller = False
|
| 161 |
+
self.accesses_kwargs = False
|
| 162 |
+
self.accesses_varargs = False
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class Frame:
|
| 166 |
+
"""Holds compile time information for us."""
|
| 167 |
+
|
| 168 |
+
def __init__(
|
| 169 |
+
self,
|
| 170 |
+
eval_ctx: EvalContext,
|
| 171 |
+
parent: t.Optional["Frame"] = None,
|
| 172 |
+
level: t.Optional[int] = None,
|
| 173 |
+
) -> None:
|
| 174 |
+
self.eval_ctx = eval_ctx
|
| 175 |
+
|
| 176 |
+
# the parent of this frame
|
| 177 |
+
self.parent = parent
|
| 178 |
+
|
| 179 |
+
if parent is None:
|
| 180 |
+
self.symbols = Symbols(level=level)
|
| 181 |
+
|
| 182 |
+
# in some dynamic inheritance situations the compiler needs to add
|
| 183 |
+
# write tests around output statements.
|
| 184 |
+
self.require_output_check = False
|
| 185 |
+
|
| 186 |
+
# inside some tags we are using a buffer rather than yield statements.
|
| 187 |
+
# this for example affects {% filter %} or {% macro %}. If a frame
|
| 188 |
+
# is buffered this variable points to the name of the list used as
|
| 189 |
+
# buffer.
|
| 190 |
+
self.buffer: t.Optional[str] = None
|
| 191 |
+
|
| 192 |
+
# the name of the block we're in, otherwise None.
|
| 193 |
+
self.block: t.Optional[str] = None
|
| 194 |
+
|
| 195 |
+
else:
|
| 196 |
+
self.symbols = Symbols(parent.symbols, level=level)
|
| 197 |
+
self.require_output_check = parent.require_output_check
|
| 198 |
+
self.buffer = parent.buffer
|
| 199 |
+
self.block = parent.block
|
| 200 |
+
|
| 201 |
+
# a toplevel frame is the root + soft frames such as if conditions.
|
| 202 |
+
self.toplevel = False
|
| 203 |
+
|
| 204 |
+
# the root frame is basically just the outermost frame, so no if
|
| 205 |
+
# conditions. This information is used to optimize inheritance
|
| 206 |
+
# situations.
|
| 207 |
+
self.rootlevel = False
|
| 208 |
+
|
| 209 |
+
# variables set inside of loops and blocks should not affect outer frames,
|
| 210 |
+
# but they still needs to be kept track of as part of the active context.
|
| 211 |
+
self.loop_frame = False
|
| 212 |
+
self.block_frame = False
|
| 213 |
+
|
| 214 |
+
# track whether the frame is being used in an if-statement or conditional
|
| 215 |
+
# expression as it determines which errors should be raised during runtime
|
| 216 |
+
# or compile time.
|
| 217 |
+
self.soft_frame = False
|
| 218 |
+
|
| 219 |
+
def copy(self) -> "te.Self":
|
| 220 |
+
"""Create a copy of the current one."""
|
| 221 |
+
rv = object.__new__(self.__class__)
|
| 222 |
+
rv.__dict__.update(self.__dict__)
|
| 223 |
+
rv.symbols = self.symbols.copy()
|
| 224 |
+
return rv
|
| 225 |
+
|
| 226 |
+
def inner(self, isolated: bool = False) -> "Frame":
|
| 227 |
+
"""Return an inner frame."""
|
| 228 |
+
if isolated:
|
| 229 |
+
return Frame(self.eval_ctx, level=self.symbols.level + 1)
|
| 230 |
+
return Frame(self.eval_ctx, self)
|
| 231 |
+
|
| 232 |
+
def soft(self) -> "te.Self":
|
| 233 |
+
"""Return a soft frame. A soft frame may not be modified as
|
| 234 |
+
standalone thing as it shares the resources with the frame it
|
| 235 |
+
was created of, but it's not a rootlevel frame any longer.
|
| 236 |
+
|
| 237 |
+
This is only used to implement if-statements and conditional
|
| 238 |
+
expressions.
|
| 239 |
+
"""
|
| 240 |
+
rv = self.copy()
|
| 241 |
+
rv.rootlevel = False
|
| 242 |
+
rv.soft_frame = True
|
| 243 |
+
return rv
|
| 244 |
+
|
| 245 |
+
__copy__ = copy
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class VisitorExit(RuntimeError):
|
| 249 |
+
"""Exception used by the `UndeclaredNameVisitor` to signal a stop."""
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
class DependencyFinderVisitor(NodeVisitor):
|
| 253 |
+
"""A visitor that collects filter and test calls."""
|
| 254 |
+
|
| 255 |
+
def __init__(self) -> None:
|
| 256 |
+
self.filters: t.Set[str] = set()
|
| 257 |
+
self.tests: t.Set[str] = set()
|
| 258 |
+
|
| 259 |
+
def visit_Filter(self, node: nodes.Filter) -> None:
|
| 260 |
+
self.generic_visit(node)
|
| 261 |
+
self.filters.add(node.name)
|
| 262 |
+
|
| 263 |
+
def visit_Test(self, node: nodes.Test) -> None:
|
| 264 |
+
self.generic_visit(node)
|
| 265 |
+
self.tests.add(node.name)
|
| 266 |
+
|
| 267 |
+
def visit_Block(self, node: nodes.Block) -> None:
|
| 268 |
+
"""Stop visiting at blocks."""
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
class UndeclaredNameVisitor(NodeVisitor):
|
| 272 |
+
"""A visitor that checks if a name is accessed without being
|
| 273 |
+
declared. This is different from the frame visitor as it will
|
| 274 |
+
not stop at closure frames.
|
| 275 |
+
"""
|
| 276 |
+
|
| 277 |
+
def __init__(self, names: t.Iterable[str]) -> None:
|
| 278 |
+
self.names = set(names)
|
| 279 |
+
self.undeclared: t.Set[str] = set()
|
| 280 |
+
|
| 281 |
+
def visit_Name(self, node: nodes.Name) -> None:
|
| 282 |
+
if node.ctx == "load" and node.name in self.names:
|
| 283 |
+
self.undeclared.add(node.name)
|
| 284 |
+
if self.undeclared == self.names:
|
| 285 |
+
raise VisitorExit()
|
| 286 |
+
else:
|
| 287 |
+
self.names.discard(node.name)
|
| 288 |
+
|
| 289 |
+
def visit_Block(self, node: nodes.Block) -> None:
|
| 290 |
+
"""Stop visiting a blocks."""
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
class CompilerExit(Exception):
|
| 294 |
+
"""Raised if the compiler encountered a situation where it just
|
| 295 |
+
doesn't make sense to further process the code. Any block that
|
| 296 |
+
raises such an exception is not further processed.
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class CodeGenerator(NodeVisitor):
|
| 301 |
+
def __init__(
|
| 302 |
+
self,
|
| 303 |
+
environment: "Environment",
|
| 304 |
+
name: t.Optional[str],
|
| 305 |
+
filename: t.Optional[str],
|
| 306 |
+
stream: t.Optional[t.TextIO] = None,
|
| 307 |
+
defer_init: bool = False,
|
| 308 |
+
optimized: bool = True,
|
| 309 |
+
) -> None:
|
| 310 |
+
if stream is None:
|
| 311 |
+
stream = StringIO()
|
| 312 |
+
self.environment = environment
|
| 313 |
+
self.name = name
|
| 314 |
+
self.filename = filename
|
| 315 |
+
self.stream = stream
|
| 316 |
+
self.created_block_context = False
|
| 317 |
+
self.defer_init = defer_init
|
| 318 |
+
self.optimizer: t.Optional[Optimizer] = None
|
| 319 |
+
|
| 320 |
+
if optimized:
|
| 321 |
+
self.optimizer = Optimizer(environment)
|
| 322 |
+
|
| 323 |
+
# aliases for imports
|
| 324 |
+
self.import_aliases: t.Dict[str, str] = {}
|
| 325 |
+
|
| 326 |
+
# a registry for all blocks. Because blocks are moved out
|
| 327 |
+
# into the global python scope they are registered here
|
| 328 |
+
self.blocks: t.Dict[str, nodes.Block] = {}
|
| 329 |
+
|
| 330 |
+
# the number of extends statements so far
|
| 331 |
+
self.extends_so_far = 0
|
| 332 |
+
|
| 333 |
+
# some templates have a rootlevel extends. In this case we
|
| 334 |
+
# can safely assume that we're a child template and do some
|
| 335 |
+
# more optimizations.
|
| 336 |
+
self.has_known_extends = False
|
| 337 |
+
|
| 338 |
+
# the current line number
|
| 339 |
+
self.code_lineno = 1
|
| 340 |
+
|
| 341 |
+
# registry of all filters and tests (global, not block local)
|
| 342 |
+
self.tests: t.Dict[str, str] = {}
|
| 343 |
+
self.filters: t.Dict[str, str] = {}
|
| 344 |
+
|
| 345 |
+
# the debug information
|
| 346 |
+
self.debug_info: t.List[t.Tuple[int, int]] = []
|
| 347 |
+
self._write_debug_info: t.Optional[int] = None
|
| 348 |
+
|
| 349 |
+
# the number of new lines before the next write()
|
| 350 |
+
self._new_lines = 0
|
| 351 |
+
|
| 352 |
+
# the line number of the last written statement
|
| 353 |
+
self._last_line = 0
|
| 354 |
+
|
| 355 |
+
# true if nothing was written so far.
|
| 356 |
+
self._first_write = True
|
| 357 |
+
|
| 358 |
+
# used by the `temporary_identifier` method to get new
|
| 359 |
+
# unique, temporary identifier
|
| 360 |
+
self._last_identifier = 0
|
| 361 |
+
|
| 362 |
+
# the current indentation
|
| 363 |
+
self._indentation = 0
|
| 364 |
+
|
| 365 |
+
# Tracks toplevel assignments
|
| 366 |
+
self._assign_stack: t.List[t.Set[str]] = []
|
| 367 |
+
|
| 368 |
+
# Tracks parameter definition blocks
|
| 369 |
+
self._param_def_block: t.List[t.Set[str]] = []
|
| 370 |
+
|
| 371 |
+
# Tracks the current context.
|
| 372 |
+
self._context_reference_stack = ["context"]
|
| 373 |
+
|
| 374 |
+
@property
|
| 375 |
+
def optimized(self) -> bool:
|
| 376 |
+
return self.optimizer is not None
|
| 377 |
+
|
| 378 |
+
# -- Various compilation helpers
|
| 379 |
+
|
| 380 |
+
def fail(self, msg: str, lineno: int) -> "te.NoReturn":
|
| 381 |
+
"""Fail with a :exc:`TemplateAssertionError`."""
|
| 382 |
+
raise TemplateAssertionError(msg, lineno, self.name, self.filename)
|
| 383 |
+
|
| 384 |
+
def temporary_identifier(self) -> str:
|
| 385 |
+
"""Get a new unique identifier."""
|
| 386 |
+
self._last_identifier += 1
|
| 387 |
+
return f"t_{self._last_identifier}"
|
| 388 |
+
|
| 389 |
+
def buffer(self, frame: Frame) -> None:
|
| 390 |
+
"""Enable buffering for the frame from that point onwards."""
|
| 391 |
+
frame.buffer = self.temporary_identifier()
|
| 392 |
+
self.writeline(f"{frame.buffer} = []")
|
| 393 |
+
|
| 394 |
+
def return_buffer_contents(
|
| 395 |
+
self, frame: Frame, force_unescaped: bool = False
|
| 396 |
+
) -> None:
|
| 397 |
+
"""Return the buffer contents of the frame."""
|
| 398 |
+
if not force_unescaped:
|
| 399 |
+
if frame.eval_ctx.volatile:
|
| 400 |
+
self.writeline("if context.eval_ctx.autoescape:")
|
| 401 |
+
self.indent()
|
| 402 |
+
self.writeline(f"return Markup(concat({frame.buffer}))")
|
| 403 |
+
self.outdent()
|
| 404 |
+
self.writeline("else:")
|
| 405 |
+
self.indent()
|
| 406 |
+
self.writeline(f"return concat({frame.buffer})")
|
| 407 |
+
self.outdent()
|
| 408 |
+
return
|
| 409 |
+
elif frame.eval_ctx.autoescape:
|
| 410 |
+
self.writeline(f"return Markup(concat({frame.buffer}))")
|
| 411 |
+
return
|
| 412 |
+
self.writeline(f"return concat({frame.buffer})")
|
| 413 |
+
|
| 414 |
+
def indent(self) -> None:
|
| 415 |
+
"""Indent by one."""
|
| 416 |
+
self._indentation += 1
|
| 417 |
+
|
| 418 |
+
def outdent(self, step: int = 1) -> None:
|
| 419 |
+
"""Outdent by step."""
|
| 420 |
+
self._indentation -= step
|
| 421 |
+
|
| 422 |
+
def start_write(self, frame: Frame, node: t.Optional[nodes.Node] = None) -> None:
|
| 423 |
+
"""Yield or write into the frame buffer."""
|
| 424 |
+
if frame.buffer is None:
|
| 425 |
+
self.writeline("yield ", node)
|
| 426 |
+
else:
|
| 427 |
+
self.writeline(f"{frame.buffer}.append(", node)
|
| 428 |
+
|
| 429 |
+
def end_write(self, frame: Frame) -> None:
|
| 430 |
+
"""End the writing process started by `start_write`."""
|
| 431 |
+
if frame.buffer is not None:
|
| 432 |
+
self.write(")")
|
| 433 |
+
|
| 434 |
+
def simple_write(
|
| 435 |
+
self, s: str, frame: Frame, node: t.Optional[nodes.Node] = None
|
| 436 |
+
) -> None:
|
| 437 |
+
"""Simple shortcut for start_write + write + end_write."""
|
| 438 |
+
self.start_write(frame, node)
|
| 439 |
+
self.write(s)
|
| 440 |
+
self.end_write(frame)
|
| 441 |
+
|
| 442 |
+
def blockvisit(self, nodes: t.Iterable[nodes.Node], frame: Frame) -> None:
|
| 443 |
+
"""Visit a list of nodes as block in a frame. If the current frame
|
| 444 |
+
is no buffer a dummy ``if 0: yield None`` is written automatically.
|
| 445 |
+
"""
|
| 446 |
+
try:
|
| 447 |
+
self.writeline("pass")
|
| 448 |
+
for node in nodes:
|
| 449 |
+
self.visit(node, frame)
|
| 450 |
+
except CompilerExit:
|
| 451 |
+
pass
|
| 452 |
+
|
| 453 |
+
def write(self, x: str) -> None:
|
| 454 |
+
"""Write a string into the output stream."""
|
| 455 |
+
if self._new_lines:
|
| 456 |
+
if not self._first_write:
|
| 457 |
+
self.stream.write("\n" * self._new_lines)
|
| 458 |
+
self.code_lineno += self._new_lines
|
| 459 |
+
if self._write_debug_info is not None:
|
| 460 |
+
self.debug_info.append((self._write_debug_info, self.code_lineno))
|
| 461 |
+
self._write_debug_info = None
|
| 462 |
+
self._first_write = False
|
| 463 |
+
self.stream.write(" " * self._indentation)
|
| 464 |
+
self._new_lines = 0
|
| 465 |
+
self.stream.write(x)
|
| 466 |
+
|
| 467 |
+
def writeline(
|
| 468 |
+
self, x: str, node: t.Optional[nodes.Node] = None, extra: int = 0
|
| 469 |
+
) -> None:
|
| 470 |
+
"""Combination of newline and write."""
|
| 471 |
+
self.newline(node, extra)
|
| 472 |
+
self.write(x)
|
| 473 |
+
|
| 474 |
+
def newline(self, node: t.Optional[nodes.Node] = None, extra: int = 0) -> None:
|
| 475 |
+
"""Add one or more newlines before the next write."""
|
| 476 |
+
self._new_lines = max(self._new_lines, 1 + extra)
|
| 477 |
+
if node is not None and node.lineno != self._last_line:
|
| 478 |
+
self._write_debug_info = node.lineno
|
| 479 |
+
self._last_line = node.lineno
|
| 480 |
+
|
| 481 |
+
def signature(
|
| 482 |
+
self,
|
| 483 |
+
node: t.Union[nodes.Call, nodes.Filter, nodes.Test],
|
| 484 |
+
frame: Frame,
|
| 485 |
+
extra_kwargs: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 486 |
+
) -> None:
|
| 487 |
+
"""Writes a function call to the stream for the current node.
|
| 488 |
+
A leading comma is added automatically. The extra keyword
|
| 489 |
+
arguments may not include python keywords otherwise a syntax
|
| 490 |
+
error could occur. The extra keyword arguments should be given
|
| 491 |
+
as python dict.
|
| 492 |
+
"""
|
| 493 |
+
# if any of the given keyword arguments is a python keyword
|
| 494 |
+
# we have to make sure that no invalid call is created.
|
| 495 |
+
kwarg_workaround = any(
|
| 496 |
+
is_python_keyword(t.cast(str, k))
|
| 497 |
+
for k in chain((x.key for x in node.kwargs), extra_kwargs or ())
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
for arg in node.args:
|
| 501 |
+
self.write(", ")
|
| 502 |
+
self.visit(arg, frame)
|
| 503 |
+
|
| 504 |
+
if not kwarg_workaround:
|
| 505 |
+
for kwarg in node.kwargs:
|
| 506 |
+
self.write(", ")
|
| 507 |
+
self.visit(kwarg, frame)
|
| 508 |
+
if extra_kwargs is not None:
|
| 509 |
+
for key, value in extra_kwargs.items():
|
| 510 |
+
self.write(f", {key}={value}")
|
| 511 |
+
if node.dyn_args:
|
| 512 |
+
self.write(", *")
|
| 513 |
+
self.visit(node.dyn_args, frame)
|
| 514 |
+
|
| 515 |
+
if kwarg_workaround:
|
| 516 |
+
if node.dyn_kwargs is not None:
|
| 517 |
+
self.write(", **dict({")
|
| 518 |
+
else:
|
| 519 |
+
self.write(", **{")
|
| 520 |
+
for kwarg in node.kwargs:
|
| 521 |
+
self.write(f"{kwarg.key!r}: ")
|
| 522 |
+
self.visit(kwarg.value, frame)
|
| 523 |
+
self.write(", ")
|
| 524 |
+
if extra_kwargs is not None:
|
| 525 |
+
for key, value in extra_kwargs.items():
|
| 526 |
+
self.write(f"{key!r}: {value}, ")
|
| 527 |
+
if node.dyn_kwargs is not None:
|
| 528 |
+
self.write("}, **")
|
| 529 |
+
self.visit(node.dyn_kwargs, frame)
|
| 530 |
+
self.write(")")
|
| 531 |
+
else:
|
| 532 |
+
self.write("}")
|
| 533 |
+
|
| 534 |
+
elif node.dyn_kwargs is not None:
|
| 535 |
+
self.write(", **")
|
| 536 |
+
self.visit(node.dyn_kwargs, frame)
|
| 537 |
+
|
| 538 |
+
def pull_dependencies(self, nodes: t.Iterable[nodes.Node]) -> None:
|
| 539 |
+
"""Find all filter and test names used in the template and
|
| 540 |
+
assign them to variables in the compiled namespace. Checking
|
| 541 |
+
that the names are registered with the environment is done when
|
| 542 |
+
compiling the Filter and Test nodes. If the node is in an If or
|
| 543 |
+
CondExpr node, the check is done at runtime instead.
|
| 544 |
+
|
| 545 |
+
.. versionchanged:: 3.0
|
| 546 |
+
Filters and tests in If and CondExpr nodes are checked at
|
| 547 |
+
runtime instead of compile time.
|
| 548 |
+
"""
|
| 549 |
+
visitor = DependencyFinderVisitor()
|
| 550 |
+
|
| 551 |
+
for node in nodes:
|
| 552 |
+
visitor.visit(node)
|
| 553 |
+
|
| 554 |
+
for id_map, names, dependency in (
|
| 555 |
+
(self.filters, visitor.filters, "filters"),
|
| 556 |
+
(
|
| 557 |
+
self.tests,
|
| 558 |
+
visitor.tests,
|
| 559 |
+
"tests",
|
| 560 |
+
),
|
| 561 |
+
):
|
| 562 |
+
for name in sorted(names):
|
| 563 |
+
if name not in id_map:
|
| 564 |
+
id_map[name] = self.temporary_identifier()
|
| 565 |
+
|
| 566 |
+
# add check during runtime that dependencies used inside of executed
|
| 567 |
+
# blocks are defined, as this step may be skipped during compile time
|
| 568 |
+
self.writeline("try:")
|
| 569 |
+
self.indent()
|
| 570 |
+
self.writeline(f"{id_map[name]} = environment.{dependency}[{name!r}]")
|
| 571 |
+
self.outdent()
|
| 572 |
+
self.writeline("except KeyError:")
|
| 573 |
+
self.indent()
|
| 574 |
+
self.writeline("@internalcode")
|
| 575 |
+
self.writeline(f"def {id_map[name]}(*unused):")
|
| 576 |
+
self.indent()
|
| 577 |
+
self.writeline(
|
| 578 |
+
f'raise TemplateRuntimeError("No {dependency[:-1]}'
|
| 579 |
+
f' named {name!r} found.")'
|
| 580 |
+
)
|
| 581 |
+
self.outdent()
|
| 582 |
+
self.outdent()
|
| 583 |
+
|
| 584 |
+
def enter_frame(self, frame: Frame) -> None:
|
| 585 |
+
undefs = []
|
| 586 |
+
for target, (action, param) in frame.symbols.loads.items():
|
| 587 |
+
if action == VAR_LOAD_PARAMETER:
|
| 588 |
+
pass
|
| 589 |
+
elif action == VAR_LOAD_RESOLVE:
|
| 590 |
+
self.writeline(f"{target} = {self.get_resolve_func()}({param!r})")
|
| 591 |
+
elif action == VAR_LOAD_ALIAS:
|
| 592 |
+
self.writeline(f"{target} = {param}")
|
| 593 |
+
elif action == VAR_LOAD_UNDEFINED:
|
| 594 |
+
undefs.append(target)
|
| 595 |
+
else:
|
| 596 |
+
raise NotImplementedError("unknown load instruction")
|
| 597 |
+
if undefs:
|
| 598 |
+
self.writeline(f"{' = '.join(undefs)} = missing")
|
| 599 |
+
|
| 600 |
+
def leave_frame(self, frame: Frame, with_python_scope: bool = False) -> None:
|
| 601 |
+
if not with_python_scope:
|
| 602 |
+
undefs = []
|
| 603 |
+
for target in frame.symbols.loads:
|
| 604 |
+
undefs.append(target)
|
| 605 |
+
if undefs:
|
| 606 |
+
self.writeline(f"{' = '.join(undefs)} = missing")
|
| 607 |
+
|
| 608 |
+
def choose_async(self, async_value: str = "async ", sync_value: str = "") -> str:
|
| 609 |
+
return async_value if self.environment.is_async else sync_value
|
| 610 |
+
|
| 611 |
+
def func(self, name: str) -> str:
|
| 612 |
+
return f"{self.choose_async()}def {name}"
|
| 613 |
+
|
| 614 |
+
def macro_body(
|
| 615 |
+
self, node: t.Union[nodes.Macro, nodes.CallBlock], frame: Frame
|
| 616 |
+
) -> t.Tuple[Frame, MacroRef]:
|
| 617 |
+
"""Dump the function def of a macro or call block."""
|
| 618 |
+
frame = frame.inner()
|
| 619 |
+
frame.symbols.analyze_node(node)
|
| 620 |
+
macro_ref = MacroRef(node)
|
| 621 |
+
|
| 622 |
+
explicit_caller = None
|
| 623 |
+
skip_special_params = set()
|
| 624 |
+
args = []
|
| 625 |
+
|
| 626 |
+
for idx, arg in enumerate(node.args):
|
| 627 |
+
if arg.name == "caller":
|
| 628 |
+
explicit_caller = idx
|
| 629 |
+
if arg.name in ("kwargs", "varargs"):
|
| 630 |
+
skip_special_params.add(arg.name)
|
| 631 |
+
args.append(frame.symbols.ref(arg.name))
|
| 632 |
+
|
| 633 |
+
undeclared = find_undeclared(node.body, ("caller", "kwargs", "varargs"))
|
| 634 |
+
|
| 635 |
+
if "caller" in undeclared:
|
| 636 |
+
# In older Jinja versions there was a bug that allowed caller
|
| 637 |
+
# to retain the special behavior even if it was mentioned in
|
| 638 |
+
# the argument list. However thankfully this was only really
|
| 639 |
+
# working if it was the last argument. So we are explicitly
|
| 640 |
+
# checking this now and error out if it is anywhere else in
|
| 641 |
+
# the argument list.
|
| 642 |
+
if explicit_caller is not None:
|
| 643 |
+
try:
|
| 644 |
+
node.defaults[explicit_caller - len(node.args)]
|
| 645 |
+
except IndexError:
|
| 646 |
+
self.fail(
|
| 647 |
+
"When defining macros or call blocks the "
|
| 648 |
+
'special "caller" argument must be omitted '
|
| 649 |
+
"or be given a default.",
|
| 650 |
+
node.lineno,
|
| 651 |
+
)
|
| 652 |
+
else:
|
| 653 |
+
args.append(frame.symbols.declare_parameter("caller"))
|
| 654 |
+
macro_ref.accesses_caller = True
|
| 655 |
+
if "kwargs" in undeclared and "kwargs" not in skip_special_params:
|
| 656 |
+
args.append(frame.symbols.declare_parameter("kwargs"))
|
| 657 |
+
macro_ref.accesses_kwargs = True
|
| 658 |
+
if "varargs" in undeclared and "varargs" not in skip_special_params:
|
| 659 |
+
args.append(frame.symbols.declare_parameter("varargs"))
|
| 660 |
+
macro_ref.accesses_varargs = True
|
| 661 |
+
|
| 662 |
+
# macros are delayed, they never require output checks
|
| 663 |
+
frame.require_output_check = False
|
| 664 |
+
frame.symbols.analyze_node(node)
|
| 665 |
+
self.writeline(f"{self.func('macro')}({', '.join(args)}):", node)
|
| 666 |
+
self.indent()
|
| 667 |
+
|
| 668 |
+
self.buffer(frame)
|
| 669 |
+
self.enter_frame(frame)
|
| 670 |
+
|
| 671 |
+
self.push_parameter_definitions(frame)
|
| 672 |
+
for idx, arg in enumerate(node.args):
|
| 673 |
+
ref = frame.symbols.ref(arg.name)
|
| 674 |
+
self.writeline(f"if {ref} is missing:")
|
| 675 |
+
self.indent()
|
| 676 |
+
try:
|
| 677 |
+
default = node.defaults[idx - len(node.args)]
|
| 678 |
+
except IndexError:
|
| 679 |
+
self.writeline(
|
| 680 |
+
f'{ref} = undefined("parameter {arg.name!r} was not provided",'
|
| 681 |
+
f" name={arg.name!r})"
|
| 682 |
+
)
|
| 683 |
+
else:
|
| 684 |
+
self.writeline(f"{ref} = ")
|
| 685 |
+
self.visit(default, frame)
|
| 686 |
+
self.mark_parameter_stored(ref)
|
| 687 |
+
self.outdent()
|
| 688 |
+
self.pop_parameter_definitions()
|
| 689 |
+
|
| 690 |
+
self.blockvisit(node.body, frame)
|
| 691 |
+
self.return_buffer_contents(frame, force_unescaped=True)
|
| 692 |
+
self.leave_frame(frame, with_python_scope=True)
|
| 693 |
+
self.outdent()
|
| 694 |
+
|
| 695 |
+
return frame, macro_ref
|
| 696 |
+
|
| 697 |
+
def macro_def(self, macro_ref: MacroRef, frame: Frame) -> None:
|
| 698 |
+
"""Dump the macro definition for the def created by macro_body."""
|
| 699 |
+
arg_tuple = ", ".join(repr(x.name) for x in macro_ref.node.args)
|
| 700 |
+
name = getattr(macro_ref.node, "name", None)
|
| 701 |
+
if len(macro_ref.node.args) == 1:
|
| 702 |
+
arg_tuple += ","
|
| 703 |
+
self.write(
|
| 704 |
+
f"Macro(environment, macro, {name!r}, ({arg_tuple}),"
|
| 705 |
+
f" {macro_ref.accesses_kwargs!r}, {macro_ref.accesses_varargs!r},"
|
| 706 |
+
f" {macro_ref.accesses_caller!r}, context.eval_ctx.autoescape)"
|
| 707 |
+
)
|
| 708 |
+
|
| 709 |
+
def position(self, node: nodes.Node) -> str:
|
| 710 |
+
"""Return a human readable position for the node."""
|
| 711 |
+
rv = f"line {node.lineno}"
|
| 712 |
+
if self.name is not None:
|
| 713 |
+
rv = f"{rv} in {self.name!r}"
|
| 714 |
+
return rv
|
| 715 |
+
|
| 716 |
+
def dump_local_context(self, frame: Frame) -> str:
|
| 717 |
+
items_kv = ", ".join(
|
| 718 |
+
f"{name!r}: {target}"
|
| 719 |
+
for name, target in frame.symbols.dump_stores().items()
|
| 720 |
+
)
|
| 721 |
+
return f"{{{items_kv}}}"
|
| 722 |
+
|
| 723 |
+
def write_commons(self) -> None:
|
| 724 |
+
"""Writes a common preamble that is used by root and block functions.
|
| 725 |
+
Primarily this sets up common local helpers and enforces a generator
|
| 726 |
+
through a dead branch.
|
| 727 |
+
"""
|
| 728 |
+
self.writeline("resolve = context.resolve_or_missing")
|
| 729 |
+
self.writeline("undefined = environment.undefined")
|
| 730 |
+
self.writeline("concat = environment.concat")
|
| 731 |
+
# always use the standard Undefined class for the implicit else of
|
| 732 |
+
# conditional expressions
|
| 733 |
+
self.writeline("cond_expr_undefined = Undefined")
|
| 734 |
+
self.writeline("if 0: yield None")
|
| 735 |
+
|
| 736 |
+
def push_parameter_definitions(self, frame: Frame) -> None:
|
| 737 |
+
"""Pushes all parameter targets from the given frame into a local
|
| 738 |
+
stack that permits tracking of yet to be assigned parameters. In
|
| 739 |
+
particular this enables the optimization from `visit_Name` to skip
|
| 740 |
+
undefined expressions for parameters in macros as macros can reference
|
| 741 |
+
otherwise unbound parameters.
|
| 742 |
+
"""
|
| 743 |
+
self._param_def_block.append(frame.symbols.dump_param_targets())
|
| 744 |
+
|
| 745 |
+
def pop_parameter_definitions(self) -> None:
|
| 746 |
+
"""Pops the current parameter definitions set."""
|
| 747 |
+
self._param_def_block.pop()
|
| 748 |
+
|
| 749 |
+
def mark_parameter_stored(self, target: str) -> None:
|
| 750 |
+
"""Marks a parameter in the current parameter definitions as stored.
|
| 751 |
+
This will skip the enforced undefined checks.
|
| 752 |
+
"""
|
| 753 |
+
if self._param_def_block:
|
| 754 |
+
self._param_def_block[-1].discard(target)
|
| 755 |
+
|
| 756 |
+
def push_context_reference(self, target: str) -> None:
|
| 757 |
+
self._context_reference_stack.append(target)
|
| 758 |
+
|
| 759 |
+
def pop_context_reference(self) -> None:
|
| 760 |
+
self._context_reference_stack.pop()
|
| 761 |
+
|
| 762 |
+
def get_context_ref(self) -> str:
|
| 763 |
+
return self._context_reference_stack[-1]
|
| 764 |
+
|
| 765 |
+
def get_resolve_func(self) -> str:
|
| 766 |
+
target = self._context_reference_stack[-1]
|
| 767 |
+
if target == "context":
|
| 768 |
+
return "resolve"
|
| 769 |
+
return f"{target}.resolve"
|
| 770 |
+
|
| 771 |
+
def derive_context(self, frame: Frame) -> str:
|
| 772 |
+
return f"{self.get_context_ref()}.derived({self.dump_local_context(frame)})"
|
| 773 |
+
|
| 774 |
+
def parameter_is_undeclared(self, target: str) -> bool:
|
| 775 |
+
"""Checks if a given target is an undeclared parameter."""
|
| 776 |
+
if not self._param_def_block:
|
| 777 |
+
return False
|
| 778 |
+
return target in self._param_def_block[-1]
|
| 779 |
+
|
| 780 |
+
def push_assign_tracking(self) -> None:
|
| 781 |
+
"""Pushes a new layer for assignment tracking."""
|
| 782 |
+
self._assign_stack.append(set())
|
| 783 |
+
|
| 784 |
+
def pop_assign_tracking(self, frame: Frame) -> None:
|
| 785 |
+
"""Pops the topmost level for assignment tracking and updates the
|
| 786 |
+
context variables if necessary.
|
| 787 |
+
"""
|
| 788 |
+
vars = self._assign_stack.pop()
|
| 789 |
+
if (
|
| 790 |
+
not frame.block_frame
|
| 791 |
+
and not frame.loop_frame
|
| 792 |
+
and not frame.toplevel
|
| 793 |
+
or not vars
|
| 794 |
+
):
|
| 795 |
+
return
|
| 796 |
+
public_names = [x for x in vars if x[:1] != "_"]
|
| 797 |
+
if len(vars) == 1:
|
| 798 |
+
name = next(iter(vars))
|
| 799 |
+
ref = frame.symbols.ref(name)
|
| 800 |
+
if frame.loop_frame:
|
| 801 |
+
self.writeline(f"_loop_vars[{name!r}] = {ref}")
|
| 802 |
+
return
|
| 803 |
+
if frame.block_frame:
|
| 804 |
+
self.writeline(f"_block_vars[{name!r}] = {ref}")
|
| 805 |
+
return
|
| 806 |
+
self.writeline(f"context.vars[{name!r}] = {ref}")
|
| 807 |
+
else:
|
| 808 |
+
if frame.loop_frame:
|
| 809 |
+
self.writeline("_loop_vars.update({")
|
| 810 |
+
elif frame.block_frame:
|
| 811 |
+
self.writeline("_block_vars.update({")
|
| 812 |
+
else:
|
| 813 |
+
self.writeline("context.vars.update({")
|
| 814 |
+
for idx, name in enumerate(sorted(vars)):
|
| 815 |
+
if idx:
|
| 816 |
+
self.write(", ")
|
| 817 |
+
ref = frame.symbols.ref(name)
|
| 818 |
+
self.write(f"{name!r}: {ref}")
|
| 819 |
+
self.write("})")
|
| 820 |
+
if not frame.block_frame and not frame.loop_frame and public_names:
|
| 821 |
+
if len(public_names) == 1:
|
| 822 |
+
self.writeline(f"context.exported_vars.add({public_names[0]!r})")
|
| 823 |
+
else:
|
| 824 |
+
names_str = ", ".join(map(repr, sorted(public_names)))
|
| 825 |
+
self.writeline(f"context.exported_vars.update(({names_str}))")
|
| 826 |
+
|
| 827 |
+
# -- Statement Visitors
|
| 828 |
+
|
| 829 |
+
def visit_Template(
|
| 830 |
+
self, node: nodes.Template, frame: t.Optional[Frame] = None
|
| 831 |
+
) -> None:
|
| 832 |
+
assert frame is None, "no root frame allowed"
|
| 833 |
+
eval_ctx = EvalContext(self.environment, self.name)
|
| 834 |
+
|
| 835 |
+
from .runtime import async_exported
|
| 836 |
+
from .runtime import exported
|
| 837 |
+
|
| 838 |
+
if self.environment.is_async:
|
| 839 |
+
exported_names = sorted(exported + async_exported)
|
| 840 |
+
else:
|
| 841 |
+
exported_names = sorted(exported)
|
| 842 |
+
|
| 843 |
+
self.writeline("from jinja2.runtime import " + ", ".join(exported_names))
|
| 844 |
+
|
| 845 |
+
# if we want a deferred initialization we cannot move the
|
| 846 |
+
# environment into a local name
|
| 847 |
+
envenv = "" if self.defer_init else ", environment=environment"
|
| 848 |
+
|
| 849 |
+
# do we have an extends tag at all? If not, we can save some
|
| 850 |
+
# overhead by just not processing any inheritance code.
|
| 851 |
+
have_extends = node.find(nodes.Extends) is not None
|
| 852 |
+
|
| 853 |
+
# find all blocks
|
| 854 |
+
for block in node.find_all(nodes.Block):
|
| 855 |
+
if block.name in self.blocks:
|
| 856 |
+
self.fail(f"block {block.name!r} defined twice", block.lineno)
|
| 857 |
+
self.blocks[block.name] = block
|
| 858 |
+
|
| 859 |
+
# find all imports and import them
|
| 860 |
+
for import_ in node.find_all(nodes.ImportedName):
|
| 861 |
+
if import_.importname not in self.import_aliases:
|
| 862 |
+
imp = import_.importname
|
| 863 |
+
self.import_aliases[imp] = alias = self.temporary_identifier()
|
| 864 |
+
if "." in imp:
|
| 865 |
+
module, obj = imp.rsplit(".", 1)
|
| 866 |
+
self.writeline(f"from {module} import {obj} as {alias}")
|
| 867 |
+
else:
|
| 868 |
+
self.writeline(f"import {imp} as {alias}")
|
| 869 |
+
|
| 870 |
+
# add the load name
|
| 871 |
+
self.writeline(f"name = {self.name!r}")
|
| 872 |
+
|
| 873 |
+
# generate the root render function.
|
| 874 |
+
self.writeline(
|
| 875 |
+
f"{self.func('root')}(context, missing=missing{envenv}):", extra=1
|
| 876 |
+
)
|
| 877 |
+
self.indent()
|
| 878 |
+
self.write_commons()
|
| 879 |
+
|
| 880 |
+
# process the root
|
| 881 |
+
frame = Frame(eval_ctx)
|
| 882 |
+
if "self" in find_undeclared(node.body, ("self",)):
|
| 883 |
+
ref = frame.symbols.declare_parameter("self")
|
| 884 |
+
self.writeline(f"{ref} = TemplateReference(context)")
|
| 885 |
+
frame.symbols.analyze_node(node)
|
| 886 |
+
frame.toplevel = frame.rootlevel = True
|
| 887 |
+
frame.require_output_check = have_extends and not self.has_known_extends
|
| 888 |
+
if have_extends:
|
| 889 |
+
self.writeline("parent_template = None")
|
| 890 |
+
self.enter_frame(frame)
|
| 891 |
+
self.pull_dependencies(node.body)
|
| 892 |
+
self.blockvisit(node.body, frame)
|
| 893 |
+
self.leave_frame(frame, with_python_scope=True)
|
| 894 |
+
self.outdent()
|
| 895 |
+
|
| 896 |
+
# make sure that the parent root is called.
|
| 897 |
+
if have_extends:
|
| 898 |
+
if not self.has_known_extends:
|
| 899 |
+
self.indent()
|
| 900 |
+
self.writeline("if parent_template is not None:")
|
| 901 |
+
self.indent()
|
| 902 |
+
if not self.environment.is_async:
|
| 903 |
+
self.writeline("yield from parent_template.root_render_func(context)")
|
| 904 |
+
else:
|
| 905 |
+
self.writeline("agen = parent_template.root_render_func(context)")
|
| 906 |
+
self.writeline("try:")
|
| 907 |
+
self.indent()
|
| 908 |
+
self.writeline("async for event in agen:")
|
| 909 |
+
self.indent()
|
| 910 |
+
self.writeline("yield event")
|
| 911 |
+
self.outdent()
|
| 912 |
+
self.outdent()
|
| 913 |
+
self.writeline("finally: await agen.aclose()")
|
| 914 |
+
self.outdent(1 + (not self.has_known_extends))
|
| 915 |
+
|
| 916 |
+
# at this point we now have the blocks collected and can visit them too.
|
| 917 |
+
for name, block in self.blocks.items():
|
| 918 |
+
self.writeline(
|
| 919 |
+
f"{self.func('block_' + name)}(context, missing=missing{envenv}):",
|
| 920 |
+
block,
|
| 921 |
+
1,
|
| 922 |
+
)
|
| 923 |
+
self.indent()
|
| 924 |
+
self.write_commons()
|
| 925 |
+
# It's important that we do not make this frame a child of the
|
| 926 |
+
# toplevel template. This would cause a variety of
|
| 927 |
+
# interesting issues with identifier tracking.
|
| 928 |
+
block_frame = Frame(eval_ctx)
|
| 929 |
+
block_frame.block_frame = True
|
| 930 |
+
undeclared = find_undeclared(block.body, ("self", "super"))
|
| 931 |
+
if "self" in undeclared:
|
| 932 |
+
ref = block_frame.symbols.declare_parameter("self")
|
| 933 |
+
self.writeline(f"{ref} = TemplateReference(context)")
|
| 934 |
+
if "super" in undeclared:
|
| 935 |
+
ref = block_frame.symbols.declare_parameter("super")
|
| 936 |
+
self.writeline(f"{ref} = context.super({name!r}, block_{name})")
|
| 937 |
+
block_frame.symbols.analyze_node(block)
|
| 938 |
+
block_frame.block = name
|
| 939 |
+
self.writeline("_block_vars = {}")
|
| 940 |
+
self.enter_frame(block_frame)
|
| 941 |
+
self.pull_dependencies(block.body)
|
| 942 |
+
self.blockvisit(block.body, block_frame)
|
| 943 |
+
self.leave_frame(block_frame, with_python_scope=True)
|
| 944 |
+
self.outdent()
|
| 945 |
+
|
| 946 |
+
blocks_kv_str = ", ".join(f"{x!r}: block_{x}" for x in self.blocks)
|
| 947 |
+
self.writeline(f"blocks = {{{blocks_kv_str}}}", extra=1)
|
| 948 |
+
debug_kv_str = "&".join(f"{k}={v}" for k, v in self.debug_info)
|
| 949 |
+
self.writeline(f"debug_info = {debug_kv_str!r}")
|
| 950 |
+
|
| 951 |
+
def visit_Block(self, node: nodes.Block, frame: Frame) -> None:
|
| 952 |
+
"""Call a block and register it for the template."""
|
| 953 |
+
level = 0
|
| 954 |
+
if frame.toplevel:
|
| 955 |
+
# if we know that we are a child template, there is no need to
|
| 956 |
+
# check if we are one
|
| 957 |
+
if self.has_known_extends:
|
| 958 |
+
return
|
| 959 |
+
if self.extends_so_far > 0:
|
| 960 |
+
self.writeline("if parent_template is None:")
|
| 961 |
+
self.indent()
|
| 962 |
+
level += 1
|
| 963 |
+
|
| 964 |
+
if node.scoped:
|
| 965 |
+
context = self.derive_context(frame)
|
| 966 |
+
else:
|
| 967 |
+
context = self.get_context_ref()
|
| 968 |
+
|
| 969 |
+
if node.required:
|
| 970 |
+
self.writeline(f"if len(context.blocks[{node.name!r}]) <= 1:", node)
|
| 971 |
+
self.indent()
|
| 972 |
+
self.writeline(
|
| 973 |
+
f'raise TemplateRuntimeError("Required block {node.name!r} not found")',
|
| 974 |
+
node,
|
| 975 |
+
)
|
| 976 |
+
self.outdent()
|
| 977 |
+
|
| 978 |
+
if not self.environment.is_async and frame.buffer is None:
|
| 979 |
+
self.writeline(
|
| 980 |
+
f"yield from context.blocks[{node.name!r}][0]({context})", node
|
| 981 |
+
)
|
| 982 |
+
else:
|
| 983 |
+
self.writeline(f"gen = context.blocks[{node.name!r}][0]({context})")
|
| 984 |
+
self.writeline("try:")
|
| 985 |
+
self.indent()
|
| 986 |
+
self.writeline(
|
| 987 |
+
f"{self.choose_async()}for event in gen:",
|
| 988 |
+
node,
|
| 989 |
+
)
|
| 990 |
+
self.indent()
|
| 991 |
+
self.simple_write("event", frame)
|
| 992 |
+
self.outdent()
|
| 993 |
+
self.outdent()
|
| 994 |
+
self.writeline(
|
| 995 |
+
f"finally: {self.choose_async('await gen.aclose()', 'gen.close()')}"
|
| 996 |
+
)
|
| 997 |
+
|
| 998 |
+
self.outdent(level)
|
| 999 |
+
|
| 1000 |
+
def visit_Extends(self, node: nodes.Extends, frame: Frame) -> None:
|
| 1001 |
+
"""Calls the extender."""
|
| 1002 |
+
if not frame.toplevel:
|
| 1003 |
+
self.fail("cannot use extend from a non top-level scope", node.lineno)
|
| 1004 |
+
|
| 1005 |
+
# if the number of extends statements in general is zero so
|
| 1006 |
+
# far, we don't have to add a check if something extended
|
| 1007 |
+
# the template before this one.
|
| 1008 |
+
if self.extends_so_far > 0:
|
| 1009 |
+
# if we have a known extends we just add a template runtime
|
| 1010 |
+
# error into the generated code. We could catch that at compile
|
| 1011 |
+
# time too, but i welcome it not to confuse users by throwing the
|
| 1012 |
+
# same error at different times just "because we can".
|
| 1013 |
+
if not self.has_known_extends:
|
| 1014 |
+
self.writeline("if parent_template is not None:")
|
| 1015 |
+
self.indent()
|
| 1016 |
+
self.writeline('raise TemplateRuntimeError("extended multiple times")')
|
| 1017 |
+
|
| 1018 |
+
# if we have a known extends already we don't need that code here
|
| 1019 |
+
# as we know that the template execution will end here.
|
| 1020 |
+
if self.has_known_extends:
|
| 1021 |
+
raise CompilerExit()
|
| 1022 |
+
else:
|
| 1023 |
+
self.outdent()
|
| 1024 |
+
|
| 1025 |
+
self.writeline("parent_template = environment.get_template(", node)
|
| 1026 |
+
self.visit(node.template, frame)
|
| 1027 |
+
self.write(f", {self.name!r})")
|
| 1028 |
+
self.writeline("for name, parent_block in parent_template.blocks.items():")
|
| 1029 |
+
self.indent()
|
| 1030 |
+
self.writeline("context.blocks.setdefault(name, []).append(parent_block)")
|
| 1031 |
+
self.outdent()
|
| 1032 |
+
|
| 1033 |
+
# if this extends statement was in the root level we can take
|
| 1034 |
+
# advantage of that information and simplify the generated code
|
| 1035 |
+
# in the top level from this point onwards
|
| 1036 |
+
if frame.rootlevel:
|
| 1037 |
+
self.has_known_extends = True
|
| 1038 |
+
|
| 1039 |
+
# and now we have one more
|
| 1040 |
+
self.extends_so_far += 1
|
| 1041 |
+
|
| 1042 |
+
def visit_Include(self, node: nodes.Include, frame: Frame) -> None:
|
| 1043 |
+
"""Handles includes."""
|
| 1044 |
+
if node.ignore_missing:
|
| 1045 |
+
self.writeline("try:")
|
| 1046 |
+
self.indent()
|
| 1047 |
+
|
| 1048 |
+
func_name = "get_or_select_template"
|
| 1049 |
+
if isinstance(node.template, nodes.Const):
|
| 1050 |
+
if isinstance(node.template.value, str):
|
| 1051 |
+
func_name = "get_template"
|
| 1052 |
+
elif isinstance(node.template.value, (tuple, list)):
|
| 1053 |
+
func_name = "select_template"
|
| 1054 |
+
elif isinstance(node.template, (nodes.Tuple, nodes.List)):
|
| 1055 |
+
func_name = "select_template"
|
| 1056 |
+
|
| 1057 |
+
self.writeline(f"template = environment.{func_name}(", node)
|
| 1058 |
+
self.visit(node.template, frame)
|
| 1059 |
+
self.write(f", {self.name!r})")
|
| 1060 |
+
if node.ignore_missing:
|
| 1061 |
+
self.outdent()
|
| 1062 |
+
self.writeline("except TemplateNotFound:")
|
| 1063 |
+
self.indent()
|
| 1064 |
+
self.writeline("pass")
|
| 1065 |
+
self.outdent()
|
| 1066 |
+
self.writeline("else:")
|
| 1067 |
+
self.indent()
|
| 1068 |
+
|
| 1069 |
+
def loop_body() -> None:
|
| 1070 |
+
self.indent()
|
| 1071 |
+
self.simple_write("event", frame)
|
| 1072 |
+
self.outdent()
|
| 1073 |
+
|
| 1074 |
+
if node.with_context:
|
| 1075 |
+
self.writeline(
|
| 1076 |
+
f"gen = template.root_render_func("
|
| 1077 |
+
"template.new_context(context.get_all(), True,"
|
| 1078 |
+
f" {self.dump_local_context(frame)}))"
|
| 1079 |
+
)
|
| 1080 |
+
self.writeline("try:")
|
| 1081 |
+
self.indent()
|
| 1082 |
+
self.writeline(f"{self.choose_async()}for event in gen:")
|
| 1083 |
+
loop_body()
|
| 1084 |
+
self.outdent()
|
| 1085 |
+
self.writeline(
|
| 1086 |
+
f"finally: {self.choose_async('await gen.aclose()', 'gen.close()')}"
|
| 1087 |
+
)
|
| 1088 |
+
elif self.environment.is_async:
|
| 1089 |
+
self.writeline(
|
| 1090 |
+
"for event in (await template._get_default_module_async())"
|
| 1091 |
+
"._body_stream:"
|
| 1092 |
+
)
|
| 1093 |
+
loop_body()
|
| 1094 |
+
else:
|
| 1095 |
+
self.writeline("yield from template._get_default_module()._body_stream")
|
| 1096 |
+
|
| 1097 |
+
if node.ignore_missing:
|
| 1098 |
+
self.outdent()
|
| 1099 |
+
|
| 1100 |
+
def _import_common(
|
| 1101 |
+
self, node: t.Union[nodes.Import, nodes.FromImport], frame: Frame
|
| 1102 |
+
) -> None:
|
| 1103 |
+
self.write(f"{self.choose_async('await ')}environment.get_template(")
|
| 1104 |
+
self.visit(node.template, frame)
|
| 1105 |
+
self.write(f", {self.name!r}).")
|
| 1106 |
+
|
| 1107 |
+
if node.with_context:
|
| 1108 |
+
f_name = f"make_module{self.choose_async('_async')}"
|
| 1109 |
+
self.write(
|
| 1110 |
+
f"{f_name}(context.get_all(), True, {self.dump_local_context(frame)})"
|
| 1111 |
+
)
|
| 1112 |
+
else:
|
| 1113 |
+
self.write(f"_get_default_module{self.choose_async('_async')}(context)")
|
| 1114 |
+
|
| 1115 |
+
def visit_Import(self, node: nodes.Import, frame: Frame) -> None:
|
| 1116 |
+
"""Visit regular imports."""
|
| 1117 |
+
self.writeline(f"{frame.symbols.ref(node.target)} = ", node)
|
| 1118 |
+
if frame.toplevel:
|
| 1119 |
+
self.write(f"context.vars[{node.target!r}] = ")
|
| 1120 |
+
|
| 1121 |
+
self._import_common(node, frame)
|
| 1122 |
+
|
| 1123 |
+
if frame.toplevel and not node.target.startswith("_"):
|
| 1124 |
+
self.writeline(f"context.exported_vars.discard({node.target!r})")
|
| 1125 |
+
|
| 1126 |
+
def visit_FromImport(self, node: nodes.FromImport, frame: Frame) -> None:
|
| 1127 |
+
"""Visit named imports."""
|
| 1128 |
+
self.newline(node)
|
| 1129 |
+
self.write("included_template = ")
|
| 1130 |
+
self._import_common(node, frame)
|
| 1131 |
+
var_names = []
|
| 1132 |
+
discarded_names = []
|
| 1133 |
+
for name in node.names:
|
| 1134 |
+
if isinstance(name, tuple):
|
| 1135 |
+
name, alias = name
|
| 1136 |
+
else:
|
| 1137 |
+
alias = name
|
| 1138 |
+
self.writeline(
|
| 1139 |
+
f"{frame.symbols.ref(alias)} ="
|
| 1140 |
+
f" getattr(included_template, {name!r}, missing)"
|
| 1141 |
+
)
|
| 1142 |
+
self.writeline(f"if {frame.symbols.ref(alias)} is missing:")
|
| 1143 |
+
self.indent()
|
| 1144 |
+
# The position will contain the template name, and will be formatted
|
| 1145 |
+
# into a string that will be compiled into an f-string. Curly braces
|
| 1146 |
+
# in the name must be replaced with escapes so that they will not be
|
| 1147 |
+
# executed as part of the f-string.
|
| 1148 |
+
position = self.position(node).replace("{", "{{").replace("}", "}}")
|
| 1149 |
+
message = (
|
| 1150 |
+
"the template {included_template.__name__!r}"
|
| 1151 |
+
f" (imported on {position})"
|
| 1152 |
+
f" does not export the requested name {name!r}"
|
| 1153 |
+
)
|
| 1154 |
+
self.writeline(
|
| 1155 |
+
f"{frame.symbols.ref(alias)} = undefined(f{message!r}, name={name!r})"
|
| 1156 |
+
)
|
| 1157 |
+
self.outdent()
|
| 1158 |
+
if frame.toplevel:
|
| 1159 |
+
var_names.append(alias)
|
| 1160 |
+
if not alias.startswith("_"):
|
| 1161 |
+
discarded_names.append(alias)
|
| 1162 |
+
|
| 1163 |
+
if var_names:
|
| 1164 |
+
if len(var_names) == 1:
|
| 1165 |
+
name = var_names[0]
|
| 1166 |
+
self.writeline(f"context.vars[{name!r}] = {frame.symbols.ref(name)}")
|
| 1167 |
+
else:
|
| 1168 |
+
names_kv = ", ".join(
|
| 1169 |
+
f"{name!r}: {frame.symbols.ref(name)}" for name in var_names
|
| 1170 |
+
)
|
| 1171 |
+
self.writeline(f"context.vars.update({{{names_kv}}})")
|
| 1172 |
+
if discarded_names:
|
| 1173 |
+
if len(discarded_names) == 1:
|
| 1174 |
+
self.writeline(f"context.exported_vars.discard({discarded_names[0]!r})")
|
| 1175 |
+
else:
|
| 1176 |
+
names_str = ", ".join(map(repr, discarded_names))
|
| 1177 |
+
self.writeline(
|
| 1178 |
+
f"context.exported_vars.difference_update(({names_str}))"
|
| 1179 |
+
)
|
| 1180 |
+
|
| 1181 |
+
def visit_For(self, node: nodes.For, frame: Frame) -> None:
|
| 1182 |
+
loop_frame = frame.inner()
|
| 1183 |
+
loop_frame.loop_frame = True
|
| 1184 |
+
test_frame = frame.inner()
|
| 1185 |
+
else_frame = frame.inner()
|
| 1186 |
+
|
| 1187 |
+
# try to figure out if we have an extended loop. An extended loop
|
| 1188 |
+
# is necessary if the loop is in recursive mode if the special loop
|
| 1189 |
+
# variable is accessed in the body if the body is a scoped block.
|
| 1190 |
+
extended_loop = (
|
| 1191 |
+
node.recursive
|
| 1192 |
+
or "loop"
|
| 1193 |
+
in find_undeclared(node.iter_child_nodes(only=("body",)), ("loop",))
|
| 1194 |
+
or any(block.scoped for block in node.find_all(nodes.Block))
|
| 1195 |
+
)
|
| 1196 |
+
|
| 1197 |
+
loop_ref = None
|
| 1198 |
+
if extended_loop:
|
| 1199 |
+
loop_ref = loop_frame.symbols.declare_parameter("loop")
|
| 1200 |
+
|
| 1201 |
+
loop_frame.symbols.analyze_node(node, for_branch="body")
|
| 1202 |
+
if node.else_:
|
| 1203 |
+
else_frame.symbols.analyze_node(node, for_branch="else")
|
| 1204 |
+
|
| 1205 |
+
if node.test:
|
| 1206 |
+
loop_filter_func = self.temporary_identifier()
|
| 1207 |
+
test_frame.symbols.analyze_node(node, for_branch="test")
|
| 1208 |
+
self.writeline(f"{self.func(loop_filter_func)}(fiter):", node.test)
|
| 1209 |
+
self.indent()
|
| 1210 |
+
self.enter_frame(test_frame)
|
| 1211 |
+
self.writeline(self.choose_async("async for ", "for "))
|
| 1212 |
+
self.visit(node.target, loop_frame)
|
| 1213 |
+
self.write(" in ")
|
| 1214 |
+
self.write(self.choose_async("auto_aiter(fiter)", "fiter"))
|
| 1215 |
+
self.write(":")
|
| 1216 |
+
self.indent()
|
| 1217 |
+
self.writeline("if ", node.test)
|
| 1218 |
+
self.visit(node.test, test_frame)
|
| 1219 |
+
self.write(":")
|
| 1220 |
+
self.indent()
|
| 1221 |
+
self.writeline("yield ")
|
| 1222 |
+
self.visit(node.target, loop_frame)
|
| 1223 |
+
self.outdent(3)
|
| 1224 |
+
self.leave_frame(test_frame, with_python_scope=True)
|
| 1225 |
+
|
| 1226 |
+
# if we don't have an recursive loop we have to find the shadowed
|
| 1227 |
+
# variables at that point. Because loops can be nested but the loop
|
| 1228 |
+
# variable is a special one we have to enforce aliasing for it.
|
| 1229 |
+
if node.recursive:
|
| 1230 |
+
self.writeline(
|
| 1231 |
+
f"{self.func('loop')}(reciter, loop_render_func, depth=0):", node
|
| 1232 |
+
)
|
| 1233 |
+
self.indent()
|
| 1234 |
+
self.buffer(loop_frame)
|
| 1235 |
+
|
| 1236 |
+
# Use the same buffer for the else frame
|
| 1237 |
+
else_frame.buffer = loop_frame.buffer
|
| 1238 |
+
|
| 1239 |
+
# make sure the loop variable is a special one and raise a template
|
| 1240 |
+
# assertion error if a loop tries to write to loop
|
| 1241 |
+
if extended_loop:
|
| 1242 |
+
self.writeline(f"{loop_ref} = missing")
|
| 1243 |
+
|
| 1244 |
+
for name in node.find_all(nodes.Name):
|
| 1245 |
+
if name.ctx == "store" and name.name == "loop":
|
| 1246 |
+
self.fail(
|
| 1247 |
+
"Can't assign to special loop variable in for-loop target",
|
| 1248 |
+
name.lineno,
|
| 1249 |
+
)
|
| 1250 |
+
|
| 1251 |
+
if node.else_:
|
| 1252 |
+
iteration_indicator = self.temporary_identifier()
|
| 1253 |
+
self.writeline(f"{iteration_indicator} = 1")
|
| 1254 |
+
|
| 1255 |
+
self.writeline(self.choose_async("async for ", "for "), node)
|
| 1256 |
+
self.visit(node.target, loop_frame)
|
| 1257 |
+
if extended_loop:
|
| 1258 |
+
self.write(f", {loop_ref} in {self.choose_async('Async')}LoopContext(")
|
| 1259 |
+
else:
|
| 1260 |
+
self.write(" in ")
|
| 1261 |
+
|
| 1262 |
+
if node.test:
|
| 1263 |
+
self.write(f"{loop_filter_func}(")
|
| 1264 |
+
if node.recursive:
|
| 1265 |
+
self.write("reciter")
|
| 1266 |
+
else:
|
| 1267 |
+
if self.environment.is_async and not extended_loop:
|
| 1268 |
+
self.write("auto_aiter(")
|
| 1269 |
+
self.visit(node.iter, frame)
|
| 1270 |
+
if self.environment.is_async and not extended_loop:
|
| 1271 |
+
self.write(")")
|
| 1272 |
+
if node.test:
|
| 1273 |
+
self.write(")")
|
| 1274 |
+
|
| 1275 |
+
if node.recursive:
|
| 1276 |
+
self.write(", undefined, loop_render_func, depth):")
|
| 1277 |
+
else:
|
| 1278 |
+
self.write(", undefined):" if extended_loop else ":")
|
| 1279 |
+
|
| 1280 |
+
self.indent()
|
| 1281 |
+
self.enter_frame(loop_frame)
|
| 1282 |
+
|
| 1283 |
+
self.writeline("_loop_vars = {}")
|
| 1284 |
+
self.blockvisit(node.body, loop_frame)
|
| 1285 |
+
if node.else_:
|
| 1286 |
+
self.writeline(f"{iteration_indicator} = 0")
|
| 1287 |
+
self.outdent()
|
| 1288 |
+
self.leave_frame(
|
| 1289 |
+
loop_frame, with_python_scope=node.recursive and not node.else_
|
| 1290 |
+
)
|
| 1291 |
+
|
| 1292 |
+
if node.else_:
|
| 1293 |
+
self.writeline(f"if {iteration_indicator}:")
|
| 1294 |
+
self.indent()
|
| 1295 |
+
self.enter_frame(else_frame)
|
| 1296 |
+
self.blockvisit(node.else_, else_frame)
|
| 1297 |
+
self.leave_frame(else_frame)
|
| 1298 |
+
self.outdent()
|
| 1299 |
+
|
| 1300 |
+
# if the node was recursive we have to return the buffer contents
|
| 1301 |
+
# and start the iteration code
|
| 1302 |
+
if node.recursive:
|
| 1303 |
+
self.return_buffer_contents(loop_frame)
|
| 1304 |
+
self.outdent()
|
| 1305 |
+
self.start_write(frame, node)
|
| 1306 |
+
self.write(f"{self.choose_async('await ')}loop(")
|
| 1307 |
+
if self.environment.is_async:
|
| 1308 |
+
self.write("auto_aiter(")
|
| 1309 |
+
self.visit(node.iter, frame)
|
| 1310 |
+
if self.environment.is_async:
|
| 1311 |
+
self.write(")")
|
| 1312 |
+
self.write(", loop)")
|
| 1313 |
+
self.end_write(frame)
|
| 1314 |
+
|
| 1315 |
+
# at the end of the iteration, clear any assignments made in the
|
| 1316 |
+
# loop from the top level
|
| 1317 |
+
if self._assign_stack:
|
| 1318 |
+
self._assign_stack[-1].difference_update(loop_frame.symbols.stores)
|
| 1319 |
+
|
| 1320 |
+
def visit_If(self, node: nodes.If, frame: Frame) -> None:
|
| 1321 |
+
if_frame = frame.soft()
|
| 1322 |
+
self.writeline("if ", node)
|
| 1323 |
+
self.visit(node.test, if_frame)
|
| 1324 |
+
self.write(":")
|
| 1325 |
+
self.indent()
|
| 1326 |
+
self.blockvisit(node.body, if_frame)
|
| 1327 |
+
self.outdent()
|
| 1328 |
+
for elif_ in node.elif_:
|
| 1329 |
+
self.writeline("elif ", elif_)
|
| 1330 |
+
self.visit(elif_.test, if_frame)
|
| 1331 |
+
self.write(":")
|
| 1332 |
+
self.indent()
|
| 1333 |
+
self.blockvisit(elif_.body, if_frame)
|
| 1334 |
+
self.outdent()
|
| 1335 |
+
if node.else_:
|
| 1336 |
+
self.writeline("else:")
|
| 1337 |
+
self.indent()
|
| 1338 |
+
self.blockvisit(node.else_, if_frame)
|
| 1339 |
+
self.outdent()
|
| 1340 |
+
|
| 1341 |
+
def visit_Macro(self, node: nodes.Macro, frame: Frame) -> None:
|
| 1342 |
+
macro_frame, macro_ref = self.macro_body(node, frame)
|
| 1343 |
+
self.newline()
|
| 1344 |
+
if frame.toplevel:
|
| 1345 |
+
if not node.name.startswith("_"):
|
| 1346 |
+
self.write(f"context.exported_vars.add({node.name!r})")
|
| 1347 |
+
self.writeline(f"context.vars[{node.name!r}] = ")
|
| 1348 |
+
self.write(f"{frame.symbols.ref(node.name)} = ")
|
| 1349 |
+
self.macro_def(macro_ref, macro_frame)
|
| 1350 |
+
|
| 1351 |
+
def visit_CallBlock(self, node: nodes.CallBlock, frame: Frame) -> None:
|
| 1352 |
+
call_frame, macro_ref = self.macro_body(node, frame)
|
| 1353 |
+
self.writeline("caller = ")
|
| 1354 |
+
self.macro_def(macro_ref, call_frame)
|
| 1355 |
+
self.start_write(frame, node)
|
| 1356 |
+
self.visit_Call(node.call, frame, forward_caller=True)
|
| 1357 |
+
self.end_write(frame)
|
| 1358 |
+
|
| 1359 |
+
def visit_FilterBlock(self, node: nodes.FilterBlock, frame: Frame) -> None:
|
| 1360 |
+
filter_frame = frame.inner()
|
| 1361 |
+
filter_frame.symbols.analyze_node(node)
|
| 1362 |
+
self.enter_frame(filter_frame)
|
| 1363 |
+
self.buffer(filter_frame)
|
| 1364 |
+
self.blockvisit(node.body, filter_frame)
|
| 1365 |
+
self.start_write(frame, node)
|
| 1366 |
+
self.visit_Filter(node.filter, filter_frame)
|
| 1367 |
+
self.end_write(frame)
|
| 1368 |
+
self.leave_frame(filter_frame)
|
| 1369 |
+
|
| 1370 |
+
def visit_With(self, node: nodes.With, frame: Frame) -> None:
|
| 1371 |
+
with_frame = frame.inner()
|
| 1372 |
+
with_frame.symbols.analyze_node(node)
|
| 1373 |
+
self.enter_frame(with_frame)
|
| 1374 |
+
for target, expr in zip(node.targets, node.values):
|
| 1375 |
+
self.newline()
|
| 1376 |
+
self.visit(target, with_frame)
|
| 1377 |
+
self.write(" = ")
|
| 1378 |
+
self.visit(expr, frame)
|
| 1379 |
+
self.blockvisit(node.body, with_frame)
|
| 1380 |
+
self.leave_frame(with_frame)
|
| 1381 |
+
|
| 1382 |
+
def visit_ExprStmt(self, node: nodes.ExprStmt, frame: Frame) -> None:
|
| 1383 |
+
self.newline(node)
|
| 1384 |
+
self.visit(node.node, frame)
|
| 1385 |
+
|
| 1386 |
+
class _FinalizeInfo(t.NamedTuple):
|
| 1387 |
+
const: t.Optional[t.Callable[..., str]]
|
| 1388 |
+
src: t.Optional[str]
|
| 1389 |
+
|
| 1390 |
+
@staticmethod
|
| 1391 |
+
def _default_finalize(value: t.Any) -> t.Any:
|
| 1392 |
+
"""The default finalize function if the environment isn't
|
| 1393 |
+
configured with one. Or, if the environment has one, this is
|
| 1394 |
+
called on that function's output for constants.
|
| 1395 |
+
"""
|
| 1396 |
+
return str(value)
|
| 1397 |
+
|
| 1398 |
+
_finalize: t.Optional[_FinalizeInfo] = None
|
| 1399 |
+
|
| 1400 |
+
def _make_finalize(self) -> _FinalizeInfo:
|
| 1401 |
+
"""Build the finalize function to be used on constants and at
|
| 1402 |
+
runtime. Cached so it's only created once for all output nodes.
|
| 1403 |
+
|
| 1404 |
+
Returns a ``namedtuple`` with the following attributes:
|
| 1405 |
+
|
| 1406 |
+
``const``
|
| 1407 |
+
A function to finalize constant data at compile time.
|
| 1408 |
+
|
| 1409 |
+
``src``
|
| 1410 |
+
Source code to output around nodes to be evaluated at
|
| 1411 |
+
runtime.
|
| 1412 |
+
"""
|
| 1413 |
+
if self._finalize is not None:
|
| 1414 |
+
return self._finalize
|
| 1415 |
+
|
| 1416 |
+
finalize: t.Optional[t.Callable[..., t.Any]]
|
| 1417 |
+
finalize = default = self._default_finalize
|
| 1418 |
+
src = None
|
| 1419 |
+
|
| 1420 |
+
if self.environment.finalize:
|
| 1421 |
+
src = "environment.finalize("
|
| 1422 |
+
env_finalize = self.environment.finalize
|
| 1423 |
+
pass_arg = {
|
| 1424 |
+
_PassArg.context: "context",
|
| 1425 |
+
_PassArg.eval_context: "context.eval_ctx",
|
| 1426 |
+
_PassArg.environment: "environment",
|
| 1427 |
+
}.get(
|
| 1428 |
+
_PassArg.from_obj(env_finalize) # type: ignore
|
| 1429 |
+
)
|
| 1430 |
+
finalize = None
|
| 1431 |
+
|
| 1432 |
+
if pass_arg is None:
|
| 1433 |
+
|
| 1434 |
+
def finalize(value: t.Any) -> t.Any: # noqa: F811
|
| 1435 |
+
return default(env_finalize(value))
|
| 1436 |
+
|
| 1437 |
+
else:
|
| 1438 |
+
src = f"{src}{pass_arg}, "
|
| 1439 |
+
|
| 1440 |
+
if pass_arg == "environment":
|
| 1441 |
+
|
| 1442 |
+
def finalize(value: t.Any) -> t.Any: # noqa: F811
|
| 1443 |
+
return default(env_finalize(self.environment, value))
|
| 1444 |
+
|
| 1445 |
+
self._finalize = self._FinalizeInfo(finalize, src)
|
| 1446 |
+
return self._finalize
|
| 1447 |
+
|
| 1448 |
+
def _output_const_repr(self, group: t.Iterable[t.Any]) -> str:
|
| 1449 |
+
"""Given a group of constant values converted from ``Output``
|
| 1450 |
+
child nodes, produce a string to write to the template module
|
| 1451 |
+
source.
|
| 1452 |
+
"""
|
| 1453 |
+
return repr(concat(group))
|
| 1454 |
+
|
| 1455 |
+
def _output_child_to_const(
|
| 1456 |
+
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
|
| 1457 |
+
) -> str:
|
| 1458 |
+
"""Try to optimize a child of an ``Output`` node by trying to
|
| 1459 |
+
convert it to constant, finalized data at compile time.
|
| 1460 |
+
|
| 1461 |
+
If :exc:`Impossible` is raised, the node is not constant and
|
| 1462 |
+
will be evaluated at runtime. Any other exception will also be
|
| 1463 |
+
evaluated at runtime for easier debugging.
|
| 1464 |
+
"""
|
| 1465 |
+
const = node.as_const(frame.eval_ctx)
|
| 1466 |
+
|
| 1467 |
+
if frame.eval_ctx.autoescape:
|
| 1468 |
+
const = escape(const)
|
| 1469 |
+
|
| 1470 |
+
# Template data doesn't go through finalize.
|
| 1471 |
+
if isinstance(node, nodes.TemplateData):
|
| 1472 |
+
return str(const)
|
| 1473 |
+
|
| 1474 |
+
return finalize.const(const) # type: ignore
|
| 1475 |
+
|
| 1476 |
+
def _output_child_pre(
|
| 1477 |
+
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
|
| 1478 |
+
) -> None:
|
| 1479 |
+
"""Output extra source code before visiting a child of an
|
| 1480 |
+
``Output`` node.
|
| 1481 |
+
"""
|
| 1482 |
+
if frame.eval_ctx.volatile:
|
| 1483 |
+
self.write("(escape if context.eval_ctx.autoescape else str)(")
|
| 1484 |
+
elif frame.eval_ctx.autoescape:
|
| 1485 |
+
self.write("escape(")
|
| 1486 |
+
else:
|
| 1487 |
+
self.write("str(")
|
| 1488 |
+
|
| 1489 |
+
if finalize.src is not None:
|
| 1490 |
+
self.write(finalize.src)
|
| 1491 |
+
|
| 1492 |
+
def _output_child_post(
|
| 1493 |
+
self, node: nodes.Expr, frame: Frame, finalize: _FinalizeInfo
|
| 1494 |
+
) -> None:
|
| 1495 |
+
"""Output extra source code after visiting a child of an
|
| 1496 |
+
``Output`` node.
|
| 1497 |
+
"""
|
| 1498 |
+
self.write(")")
|
| 1499 |
+
|
| 1500 |
+
if finalize.src is not None:
|
| 1501 |
+
self.write(")")
|
| 1502 |
+
|
| 1503 |
+
def visit_Output(self, node: nodes.Output, frame: Frame) -> None:
|
| 1504 |
+
# If an extends is active, don't render outside a block.
|
| 1505 |
+
if frame.require_output_check:
|
| 1506 |
+
# A top-level extends is known to exist at compile time.
|
| 1507 |
+
if self.has_known_extends:
|
| 1508 |
+
return
|
| 1509 |
+
|
| 1510 |
+
self.writeline("if parent_template is None:")
|
| 1511 |
+
self.indent()
|
| 1512 |
+
|
| 1513 |
+
finalize = self._make_finalize()
|
| 1514 |
+
body: t.List[t.Union[t.List[t.Any], nodes.Expr]] = []
|
| 1515 |
+
|
| 1516 |
+
# Evaluate constants at compile time if possible. Each item in
|
| 1517 |
+
# body will be either a list of static data or a node to be
|
| 1518 |
+
# evaluated at runtime.
|
| 1519 |
+
for child in node.nodes:
|
| 1520 |
+
try:
|
| 1521 |
+
if not (
|
| 1522 |
+
# If the finalize function requires runtime context,
|
| 1523 |
+
# constants can't be evaluated at compile time.
|
| 1524 |
+
finalize.const
|
| 1525 |
+
# Unless it's basic template data that won't be
|
| 1526 |
+
# finalized anyway.
|
| 1527 |
+
or isinstance(child, nodes.TemplateData)
|
| 1528 |
+
):
|
| 1529 |
+
raise nodes.Impossible()
|
| 1530 |
+
|
| 1531 |
+
const = self._output_child_to_const(child, frame, finalize)
|
| 1532 |
+
except (nodes.Impossible, Exception):
|
| 1533 |
+
# The node was not constant and needs to be evaluated at
|
| 1534 |
+
# runtime. Or another error was raised, which is easier
|
| 1535 |
+
# to debug at runtime.
|
| 1536 |
+
body.append(child)
|
| 1537 |
+
continue
|
| 1538 |
+
|
| 1539 |
+
if body and isinstance(body[-1], list):
|
| 1540 |
+
body[-1].append(const)
|
| 1541 |
+
else:
|
| 1542 |
+
body.append([const])
|
| 1543 |
+
|
| 1544 |
+
if frame.buffer is not None:
|
| 1545 |
+
if len(body) == 1:
|
| 1546 |
+
self.writeline(f"{frame.buffer}.append(")
|
| 1547 |
+
else:
|
| 1548 |
+
self.writeline(f"{frame.buffer}.extend((")
|
| 1549 |
+
|
| 1550 |
+
self.indent()
|
| 1551 |
+
|
| 1552 |
+
for item in body:
|
| 1553 |
+
if isinstance(item, list):
|
| 1554 |
+
# A group of constant data to join and output.
|
| 1555 |
+
val = self._output_const_repr(item)
|
| 1556 |
+
|
| 1557 |
+
if frame.buffer is None:
|
| 1558 |
+
self.writeline("yield " + val)
|
| 1559 |
+
else:
|
| 1560 |
+
self.writeline(val + ",")
|
| 1561 |
+
else:
|
| 1562 |
+
if frame.buffer is None:
|
| 1563 |
+
self.writeline("yield ", item)
|
| 1564 |
+
else:
|
| 1565 |
+
self.newline(item)
|
| 1566 |
+
|
| 1567 |
+
# A node to be evaluated at runtime.
|
| 1568 |
+
self._output_child_pre(item, frame, finalize)
|
| 1569 |
+
self.visit(item, frame)
|
| 1570 |
+
self._output_child_post(item, frame, finalize)
|
| 1571 |
+
|
| 1572 |
+
if frame.buffer is not None:
|
| 1573 |
+
self.write(",")
|
| 1574 |
+
|
| 1575 |
+
if frame.buffer is not None:
|
| 1576 |
+
self.outdent()
|
| 1577 |
+
self.writeline(")" if len(body) == 1 else "))")
|
| 1578 |
+
|
| 1579 |
+
if frame.require_output_check:
|
| 1580 |
+
self.outdent()
|
| 1581 |
+
|
| 1582 |
+
def visit_Assign(self, node: nodes.Assign, frame: Frame) -> None:
|
| 1583 |
+
self.push_assign_tracking()
|
| 1584 |
+
|
| 1585 |
+
# ``a.b`` is allowed for assignment, and is parsed as an NSRef. However,
|
| 1586 |
+
# it is only valid if it references a Namespace object. Emit a check for
|
| 1587 |
+
# that for each ref here, before assignment code is emitted. This can't
|
| 1588 |
+
# be done in visit_NSRef as the ref could be in the middle of a tuple.
|
| 1589 |
+
seen_refs: t.Set[str] = set()
|
| 1590 |
+
|
| 1591 |
+
for nsref in node.find_all(nodes.NSRef):
|
| 1592 |
+
if nsref.name in seen_refs:
|
| 1593 |
+
# Only emit the check for each reference once, in case the same
|
| 1594 |
+
# ref is used multiple times in a tuple, `ns.a, ns.b = c, d`.
|
| 1595 |
+
continue
|
| 1596 |
+
|
| 1597 |
+
seen_refs.add(nsref.name)
|
| 1598 |
+
ref = frame.symbols.ref(nsref.name)
|
| 1599 |
+
self.writeline(f"if not isinstance({ref}, Namespace):")
|
| 1600 |
+
self.indent()
|
| 1601 |
+
self.writeline(
|
| 1602 |
+
"raise TemplateRuntimeError"
|
| 1603 |
+
'("cannot assign attribute on non-namespace object")'
|
| 1604 |
+
)
|
| 1605 |
+
self.outdent()
|
| 1606 |
+
|
| 1607 |
+
self.newline(node)
|
| 1608 |
+
self.visit(node.target, frame)
|
| 1609 |
+
self.write(" = ")
|
| 1610 |
+
self.visit(node.node, frame)
|
| 1611 |
+
self.pop_assign_tracking(frame)
|
| 1612 |
+
|
| 1613 |
+
def visit_AssignBlock(self, node: nodes.AssignBlock, frame: Frame) -> None:
|
| 1614 |
+
self.push_assign_tracking()
|
| 1615 |
+
block_frame = frame.inner()
|
| 1616 |
+
# This is a special case. Since a set block always captures we
|
| 1617 |
+
# will disable output checks. This way one can use set blocks
|
| 1618 |
+
# toplevel even in extended templates.
|
| 1619 |
+
block_frame.require_output_check = False
|
| 1620 |
+
block_frame.symbols.analyze_node(node)
|
| 1621 |
+
self.enter_frame(block_frame)
|
| 1622 |
+
self.buffer(block_frame)
|
| 1623 |
+
self.blockvisit(node.body, block_frame)
|
| 1624 |
+
self.newline(node)
|
| 1625 |
+
self.visit(node.target, frame)
|
| 1626 |
+
self.write(" = (Markup if context.eval_ctx.autoescape else identity)(")
|
| 1627 |
+
if node.filter is not None:
|
| 1628 |
+
self.visit_Filter(node.filter, block_frame)
|
| 1629 |
+
else:
|
| 1630 |
+
self.write(f"concat({block_frame.buffer})")
|
| 1631 |
+
self.write(")")
|
| 1632 |
+
self.pop_assign_tracking(frame)
|
| 1633 |
+
self.leave_frame(block_frame)
|
| 1634 |
+
|
| 1635 |
+
# -- Expression Visitors
|
| 1636 |
+
|
| 1637 |
+
def visit_Name(self, node: nodes.Name, frame: Frame) -> None:
|
| 1638 |
+
if node.ctx == "store" and (
|
| 1639 |
+
frame.toplevel or frame.loop_frame or frame.block_frame
|
| 1640 |
+
):
|
| 1641 |
+
if self._assign_stack:
|
| 1642 |
+
self._assign_stack[-1].add(node.name)
|
| 1643 |
+
ref = frame.symbols.ref(node.name)
|
| 1644 |
+
|
| 1645 |
+
# If we are looking up a variable we might have to deal with the
|
| 1646 |
+
# case where it's undefined. We can skip that case if the load
|
| 1647 |
+
# instruction indicates a parameter which are always defined.
|
| 1648 |
+
if node.ctx == "load":
|
| 1649 |
+
load = frame.symbols.find_load(ref)
|
| 1650 |
+
if not (
|
| 1651 |
+
load is not None
|
| 1652 |
+
and load[0] == VAR_LOAD_PARAMETER
|
| 1653 |
+
and not self.parameter_is_undeclared(ref)
|
| 1654 |
+
):
|
| 1655 |
+
self.write(
|
| 1656 |
+
f"(undefined(name={node.name!r}) if {ref} is missing else {ref})"
|
| 1657 |
+
)
|
| 1658 |
+
return
|
| 1659 |
+
|
| 1660 |
+
self.write(ref)
|
| 1661 |
+
|
| 1662 |
+
def visit_NSRef(self, node: nodes.NSRef, frame: Frame) -> None:
|
| 1663 |
+
# NSRef is a dotted assignment target a.b=c, but uses a[b]=c internally.
|
| 1664 |
+
# visit_Assign emits code to validate that each ref is to a Namespace
|
| 1665 |
+
# object only. That can't be emitted here as the ref could be in the
|
| 1666 |
+
# middle of a tuple assignment.
|
| 1667 |
+
ref = frame.symbols.ref(node.name)
|
| 1668 |
+
self.writeline(f"{ref}[{node.attr!r}]")
|
| 1669 |
+
|
| 1670 |
+
def visit_Const(self, node: nodes.Const, frame: Frame) -> None:
|
| 1671 |
+
val = node.as_const(frame.eval_ctx)
|
| 1672 |
+
if isinstance(val, float):
|
| 1673 |
+
self.write(str(val))
|
| 1674 |
+
else:
|
| 1675 |
+
self.write(repr(val))
|
| 1676 |
+
|
| 1677 |
+
def visit_TemplateData(self, node: nodes.TemplateData, frame: Frame) -> None:
|
| 1678 |
+
try:
|
| 1679 |
+
self.write(repr(node.as_const(frame.eval_ctx)))
|
| 1680 |
+
except nodes.Impossible:
|
| 1681 |
+
self.write(
|
| 1682 |
+
f"(Markup if context.eval_ctx.autoescape else identity)({node.data!r})"
|
| 1683 |
+
)
|
| 1684 |
+
|
| 1685 |
+
def visit_Tuple(self, node: nodes.Tuple, frame: Frame) -> None:
|
| 1686 |
+
self.write("(")
|
| 1687 |
+
idx = -1
|
| 1688 |
+
for idx, item in enumerate(node.items):
|
| 1689 |
+
if idx:
|
| 1690 |
+
self.write(", ")
|
| 1691 |
+
self.visit(item, frame)
|
| 1692 |
+
self.write(",)" if idx == 0 else ")")
|
| 1693 |
+
|
| 1694 |
+
def visit_List(self, node: nodes.List, frame: Frame) -> None:
|
| 1695 |
+
self.write("[")
|
| 1696 |
+
for idx, item in enumerate(node.items):
|
| 1697 |
+
if idx:
|
| 1698 |
+
self.write(", ")
|
| 1699 |
+
self.visit(item, frame)
|
| 1700 |
+
self.write("]")
|
| 1701 |
+
|
| 1702 |
+
def visit_Dict(self, node: nodes.Dict, frame: Frame) -> None:
|
| 1703 |
+
self.write("{")
|
| 1704 |
+
for idx, item in enumerate(node.items):
|
| 1705 |
+
if idx:
|
| 1706 |
+
self.write(", ")
|
| 1707 |
+
self.visit(item.key, frame)
|
| 1708 |
+
self.write(": ")
|
| 1709 |
+
self.visit(item.value, frame)
|
| 1710 |
+
self.write("}")
|
| 1711 |
+
|
| 1712 |
+
visit_Add = _make_binop("+")
|
| 1713 |
+
visit_Sub = _make_binop("-")
|
| 1714 |
+
visit_Mul = _make_binop("*")
|
| 1715 |
+
visit_Div = _make_binop("/")
|
| 1716 |
+
visit_FloorDiv = _make_binop("//")
|
| 1717 |
+
visit_Pow = _make_binop("**")
|
| 1718 |
+
visit_Mod = _make_binop("%")
|
| 1719 |
+
visit_And = _make_binop("and")
|
| 1720 |
+
visit_Or = _make_binop("or")
|
| 1721 |
+
visit_Pos = _make_unop("+")
|
| 1722 |
+
visit_Neg = _make_unop("-")
|
| 1723 |
+
visit_Not = _make_unop("not ")
|
| 1724 |
+
|
| 1725 |
+
@optimizeconst
|
| 1726 |
+
def visit_Concat(self, node: nodes.Concat, frame: Frame) -> None:
|
| 1727 |
+
if frame.eval_ctx.volatile:
|
| 1728 |
+
func_name = "(markup_join if context.eval_ctx.volatile else str_join)"
|
| 1729 |
+
elif frame.eval_ctx.autoescape:
|
| 1730 |
+
func_name = "markup_join"
|
| 1731 |
+
else:
|
| 1732 |
+
func_name = "str_join"
|
| 1733 |
+
self.write(f"{func_name}((")
|
| 1734 |
+
for arg in node.nodes:
|
| 1735 |
+
self.visit(arg, frame)
|
| 1736 |
+
self.write(", ")
|
| 1737 |
+
self.write("))")
|
| 1738 |
+
|
| 1739 |
+
@optimizeconst
|
| 1740 |
+
def visit_Compare(self, node: nodes.Compare, frame: Frame) -> None:
|
| 1741 |
+
self.write("(")
|
| 1742 |
+
self.visit(node.expr, frame)
|
| 1743 |
+
for op in node.ops:
|
| 1744 |
+
self.visit(op, frame)
|
| 1745 |
+
self.write(")")
|
| 1746 |
+
|
| 1747 |
+
def visit_Operand(self, node: nodes.Operand, frame: Frame) -> None:
|
| 1748 |
+
self.write(f" {operators[node.op]} ")
|
| 1749 |
+
self.visit(node.expr, frame)
|
| 1750 |
+
|
| 1751 |
+
@optimizeconst
|
| 1752 |
+
def visit_Getattr(self, node: nodes.Getattr, frame: Frame) -> None:
|
| 1753 |
+
if self.environment.is_async:
|
| 1754 |
+
self.write("(await auto_await(")
|
| 1755 |
+
|
| 1756 |
+
self.write("environment.getattr(")
|
| 1757 |
+
self.visit(node.node, frame)
|
| 1758 |
+
self.write(f", {node.attr!r})")
|
| 1759 |
+
|
| 1760 |
+
if self.environment.is_async:
|
| 1761 |
+
self.write("))")
|
| 1762 |
+
|
| 1763 |
+
@optimizeconst
|
| 1764 |
+
def visit_Getitem(self, node: nodes.Getitem, frame: Frame) -> None:
|
| 1765 |
+
# slices bypass the environment getitem method.
|
| 1766 |
+
if isinstance(node.arg, nodes.Slice):
|
| 1767 |
+
self.visit(node.node, frame)
|
| 1768 |
+
self.write("[")
|
| 1769 |
+
self.visit(node.arg, frame)
|
| 1770 |
+
self.write("]")
|
| 1771 |
+
else:
|
| 1772 |
+
if self.environment.is_async:
|
| 1773 |
+
self.write("(await auto_await(")
|
| 1774 |
+
|
| 1775 |
+
self.write("environment.getitem(")
|
| 1776 |
+
self.visit(node.node, frame)
|
| 1777 |
+
self.write(", ")
|
| 1778 |
+
self.visit(node.arg, frame)
|
| 1779 |
+
self.write(")")
|
| 1780 |
+
|
| 1781 |
+
if self.environment.is_async:
|
| 1782 |
+
self.write("))")
|
| 1783 |
+
|
| 1784 |
+
def visit_Slice(self, node: nodes.Slice, frame: Frame) -> None:
|
| 1785 |
+
if node.start is not None:
|
| 1786 |
+
self.visit(node.start, frame)
|
| 1787 |
+
self.write(":")
|
| 1788 |
+
if node.stop is not None:
|
| 1789 |
+
self.visit(node.stop, frame)
|
| 1790 |
+
if node.step is not None:
|
| 1791 |
+
self.write(":")
|
| 1792 |
+
self.visit(node.step, frame)
|
| 1793 |
+
|
| 1794 |
+
@contextmanager
|
| 1795 |
+
def _filter_test_common(
|
| 1796 |
+
self, node: t.Union[nodes.Filter, nodes.Test], frame: Frame, is_filter: bool
|
| 1797 |
+
) -> t.Iterator[None]:
|
| 1798 |
+
if self.environment.is_async:
|
| 1799 |
+
self.write("(await auto_await(")
|
| 1800 |
+
|
| 1801 |
+
if is_filter:
|
| 1802 |
+
self.write(f"{self.filters[node.name]}(")
|
| 1803 |
+
func = self.environment.filters.get(node.name)
|
| 1804 |
+
else:
|
| 1805 |
+
self.write(f"{self.tests[node.name]}(")
|
| 1806 |
+
func = self.environment.tests.get(node.name)
|
| 1807 |
+
|
| 1808 |
+
# When inside an If or CondExpr frame, allow the filter to be
|
| 1809 |
+
# undefined at compile time and only raise an error if it's
|
| 1810 |
+
# actually called at runtime. See pull_dependencies.
|
| 1811 |
+
if func is None and not frame.soft_frame:
|
| 1812 |
+
type_name = "filter" if is_filter else "test"
|
| 1813 |
+
self.fail(f"No {type_name} named {node.name!r}.", node.lineno)
|
| 1814 |
+
|
| 1815 |
+
pass_arg = {
|
| 1816 |
+
_PassArg.context: "context",
|
| 1817 |
+
_PassArg.eval_context: "context.eval_ctx",
|
| 1818 |
+
_PassArg.environment: "environment",
|
| 1819 |
+
}.get(
|
| 1820 |
+
_PassArg.from_obj(func) # type: ignore
|
| 1821 |
+
)
|
| 1822 |
+
|
| 1823 |
+
if pass_arg is not None:
|
| 1824 |
+
self.write(f"{pass_arg}, ")
|
| 1825 |
+
|
| 1826 |
+
# Back to the visitor function to handle visiting the target of
|
| 1827 |
+
# the filter or test.
|
| 1828 |
+
yield
|
| 1829 |
+
|
| 1830 |
+
self.signature(node, frame)
|
| 1831 |
+
self.write(")")
|
| 1832 |
+
|
| 1833 |
+
if self.environment.is_async:
|
| 1834 |
+
self.write("))")
|
| 1835 |
+
|
| 1836 |
+
@optimizeconst
|
| 1837 |
+
def visit_Filter(self, node: nodes.Filter, frame: Frame) -> None:
|
| 1838 |
+
with self._filter_test_common(node, frame, True):
|
| 1839 |
+
# if the filter node is None we are inside a filter block
|
| 1840 |
+
# and want to write to the current buffer
|
| 1841 |
+
if node.node is not None:
|
| 1842 |
+
self.visit(node.node, frame)
|
| 1843 |
+
elif frame.eval_ctx.volatile:
|
| 1844 |
+
self.write(
|
| 1845 |
+
f"(Markup(concat({frame.buffer}))"
|
| 1846 |
+
f" if context.eval_ctx.autoescape else concat({frame.buffer}))"
|
| 1847 |
+
)
|
| 1848 |
+
elif frame.eval_ctx.autoescape:
|
| 1849 |
+
self.write(f"Markup(concat({frame.buffer}))")
|
| 1850 |
+
else:
|
| 1851 |
+
self.write(f"concat({frame.buffer})")
|
| 1852 |
+
|
| 1853 |
+
@optimizeconst
|
| 1854 |
+
def visit_Test(self, node: nodes.Test, frame: Frame) -> None:
|
| 1855 |
+
with self._filter_test_common(node, frame, False):
|
| 1856 |
+
self.visit(node.node, frame)
|
| 1857 |
+
|
| 1858 |
+
@optimizeconst
|
| 1859 |
+
def visit_CondExpr(self, node: nodes.CondExpr, frame: Frame) -> None:
|
| 1860 |
+
frame = frame.soft()
|
| 1861 |
+
|
| 1862 |
+
def write_expr2() -> None:
|
| 1863 |
+
if node.expr2 is not None:
|
| 1864 |
+
self.visit(node.expr2, frame)
|
| 1865 |
+
return
|
| 1866 |
+
|
| 1867 |
+
self.write(
|
| 1868 |
+
f'cond_expr_undefined("the inline if-expression on'
|
| 1869 |
+
f" {self.position(node)} evaluated to false and no else"
|
| 1870 |
+
f' section was defined.")'
|
| 1871 |
+
)
|
| 1872 |
+
|
| 1873 |
+
self.write("(")
|
| 1874 |
+
self.visit(node.expr1, frame)
|
| 1875 |
+
self.write(" if ")
|
| 1876 |
+
self.visit(node.test, frame)
|
| 1877 |
+
self.write(" else ")
|
| 1878 |
+
write_expr2()
|
| 1879 |
+
self.write(")")
|
| 1880 |
+
|
| 1881 |
+
@optimizeconst
|
| 1882 |
+
def visit_Call(
|
| 1883 |
+
self, node: nodes.Call, frame: Frame, forward_caller: bool = False
|
| 1884 |
+
) -> None:
|
| 1885 |
+
if self.environment.is_async:
|
| 1886 |
+
self.write("(await auto_await(")
|
| 1887 |
+
if self.environment.sandboxed:
|
| 1888 |
+
self.write("environment.call(context, ")
|
| 1889 |
+
else:
|
| 1890 |
+
self.write("context.call(")
|
| 1891 |
+
self.visit(node.node, frame)
|
| 1892 |
+
extra_kwargs = {"caller": "caller"} if forward_caller else None
|
| 1893 |
+
loop_kwargs = {"_loop_vars": "_loop_vars"} if frame.loop_frame else {}
|
| 1894 |
+
block_kwargs = {"_block_vars": "_block_vars"} if frame.block_frame else {}
|
| 1895 |
+
if extra_kwargs:
|
| 1896 |
+
extra_kwargs.update(loop_kwargs, **block_kwargs)
|
| 1897 |
+
elif loop_kwargs or block_kwargs:
|
| 1898 |
+
extra_kwargs = dict(loop_kwargs, **block_kwargs)
|
| 1899 |
+
self.signature(node, frame, extra_kwargs)
|
| 1900 |
+
self.write(")")
|
| 1901 |
+
if self.environment.is_async:
|
| 1902 |
+
self.write("))")
|
| 1903 |
+
|
| 1904 |
+
def visit_Keyword(self, node: nodes.Keyword, frame: Frame) -> None:
|
| 1905 |
+
self.write(node.key + "=")
|
| 1906 |
+
self.visit(node.value, frame)
|
| 1907 |
+
|
| 1908 |
+
# -- Unused nodes for extensions
|
| 1909 |
+
|
| 1910 |
+
def visit_MarkSafe(self, node: nodes.MarkSafe, frame: Frame) -> None:
|
| 1911 |
+
self.write("Markup(")
|
| 1912 |
+
self.visit(node.expr, frame)
|
| 1913 |
+
self.write(")")
|
| 1914 |
+
|
| 1915 |
+
def visit_MarkSafeIfAutoescape(
|
| 1916 |
+
self, node: nodes.MarkSafeIfAutoescape, frame: Frame
|
| 1917 |
+
) -> None:
|
| 1918 |
+
self.write("(Markup if context.eval_ctx.autoescape else identity)(")
|
| 1919 |
+
self.visit(node.expr, frame)
|
| 1920 |
+
self.write(")")
|
| 1921 |
+
|
| 1922 |
+
def visit_EnvironmentAttribute(
|
| 1923 |
+
self, node: nodes.EnvironmentAttribute, frame: Frame
|
| 1924 |
+
) -> None:
|
| 1925 |
+
self.write("environment." + node.name)
|
| 1926 |
+
|
| 1927 |
+
def visit_ExtensionAttribute(
|
| 1928 |
+
self, node: nodes.ExtensionAttribute, frame: Frame
|
| 1929 |
+
) -> None:
|
| 1930 |
+
self.write(f"environment.extensions[{node.identifier!r}].{node.name}")
|
| 1931 |
+
|
| 1932 |
+
def visit_ImportedName(self, node: nodes.ImportedName, frame: Frame) -> None:
|
| 1933 |
+
self.write(self.import_aliases[node.importname])
|
| 1934 |
+
|
| 1935 |
+
def visit_InternalName(self, node: nodes.InternalName, frame: Frame) -> None:
|
| 1936 |
+
self.write(node.name)
|
| 1937 |
+
|
| 1938 |
+
def visit_ContextReference(
|
| 1939 |
+
self, node: nodes.ContextReference, frame: Frame
|
| 1940 |
+
) -> None:
|
| 1941 |
+
self.write("context")
|
| 1942 |
+
|
| 1943 |
+
def visit_DerivedContextReference(
|
| 1944 |
+
self, node: nodes.DerivedContextReference, frame: Frame
|
| 1945 |
+
) -> None:
|
| 1946 |
+
self.write(self.derive_context(frame))
|
| 1947 |
+
|
| 1948 |
+
def visit_Continue(self, node: nodes.Continue, frame: Frame) -> None:
|
| 1949 |
+
self.writeline("continue", node)
|
| 1950 |
+
|
| 1951 |
+
def visit_Break(self, node: nodes.Break, frame: Frame) -> None:
|
| 1952 |
+
self.writeline("break", node)
|
| 1953 |
+
|
| 1954 |
+
def visit_Scope(self, node: nodes.Scope, frame: Frame) -> None:
|
| 1955 |
+
scope_frame = frame.inner()
|
| 1956 |
+
scope_frame.symbols.analyze_node(node)
|
| 1957 |
+
self.enter_frame(scope_frame)
|
| 1958 |
+
self.blockvisit(node.body, scope_frame)
|
| 1959 |
+
self.leave_frame(scope_frame)
|
| 1960 |
+
|
| 1961 |
+
def visit_OverlayScope(self, node: nodes.OverlayScope, frame: Frame) -> None:
|
| 1962 |
+
ctx = self.temporary_identifier()
|
| 1963 |
+
self.writeline(f"{ctx} = {self.derive_context(frame)}")
|
| 1964 |
+
self.writeline(f"{ctx}.vars = ")
|
| 1965 |
+
self.visit(node.context, frame)
|
| 1966 |
+
self.push_context_reference(ctx)
|
| 1967 |
+
|
| 1968 |
+
scope_frame = frame.inner(isolated=True)
|
| 1969 |
+
scope_frame.symbols.analyze_node(node)
|
| 1970 |
+
self.enter_frame(scope_frame)
|
| 1971 |
+
self.blockvisit(node.body, scope_frame)
|
| 1972 |
+
self.leave_frame(scope_frame)
|
| 1973 |
+
self.pop_context_reference()
|
| 1974 |
+
|
| 1975 |
+
def visit_EvalContextModifier(
|
| 1976 |
+
self, node: nodes.EvalContextModifier, frame: Frame
|
| 1977 |
+
) -> None:
|
| 1978 |
+
for keyword in node.options:
|
| 1979 |
+
self.writeline(f"context.eval_ctx.{keyword.key} = ")
|
| 1980 |
+
self.visit(keyword.value, frame)
|
| 1981 |
+
try:
|
| 1982 |
+
val = keyword.value.as_const(frame.eval_ctx)
|
| 1983 |
+
except nodes.Impossible:
|
| 1984 |
+
frame.eval_ctx.volatile = True
|
| 1985 |
+
else:
|
| 1986 |
+
setattr(frame.eval_ctx, keyword.key, val)
|
| 1987 |
+
|
| 1988 |
+
def visit_ScopedEvalContextModifier(
|
| 1989 |
+
self, node: nodes.ScopedEvalContextModifier, frame: Frame
|
| 1990 |
+
) -> None:
|
| 1991 |
+
old_ctx_name = self.temporary_identifier()
|
| 1992 |
+
saved_ctx = frame.eval_ctx.save()
|
| 1993 |
+
self.writeline(f"{old_ctx_name} = context.eval_ctx.save()")
|
| 1994 |
+
self.visit_EvalContextModifier(node, frame)
|
| 1995 |
+
for child in node.body:
|
| 1996 |
+
self.visit(child, frame)
|
| 1997 |
+
frame.eval_ctx.revert(saved_ctx)
|
| 1998 |
+
self.writeline(f"context.eval_ctx.revert({old_ctx_name})")
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/constants.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#: list of lorem ipsum words used by the lipsum() helper function
|
| 2 |
+
LOREM_IPSUM_WORDS = """\
|
| 3 |
+
a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at
|
| 4 |
+
auctor augue bibendum blandit class commodo condimentum congue consectetuer
|
| 5 |
+
consequat conubia convallis cras cubilia cum curabitur curae cursus dapibus
|
| 6 |
+
diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend
|
| 7 |
+
elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames
|
| 8 |
+
faucibus felis fermentum feugiat fringilla fusce gravida habitant habitasse hac
|
| 9 |
+
hendrerit hymenaeos iaculis id imperdiet in inceptos integer interdum ipsum
|
| 10 |
+
justo lacinia lacus laoreet lectus leo libero ligula litora lobortis lorem
|
| 11 |
+
luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie
|
| 12 |
+
mollis montes morbi mus nam nascetur natoque nec neque netus nibh nisi nisl non
|
| 13 |
+
nonummy nostra nulla nullam nunc odio orci ornare parturient pede pellentesque
|
| 14 |
+
penatibus per pharetra phasellus placerat platea porta porttitor posuere
|
| 15 |
+
potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus
|
| 16 |
+
ridiculus risus rutrum sagittis sapien scelerisque sed sem semper senectus sit
|
| 17 |
+
sociis sociosqu sodales sollicitudin suscipit suspendisse taciti tellus tempor
|
| 18 |
+
tempus tincidunt torquent tortor tristique turpis ullamcorper ultrices
|
| 19 |
+
ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus
|
| 20 |
+
viverra volutpat vulputate"""
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/debug.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import typing as t
|
| 3 |
+
from types import CodeType
|
| 4 |
+
from types import TracebackType
|
| 5 |
+
|
| 6 |
+
from .exceptions import TemplateSyntaxError
|
| 7 |
+
from .utils import internal_code
|
| 8 |
+
from .utils import missing
|
| 9 |
+
|
| 10 |
+
if t.TYPE_CHECKING:
|
| 11 |
+
from .runtime import Context
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def rewrite_traceback_stack(source: t.Optional[str] = None) -> BaseException:
|
| 15 |
+
"""Rewrite the current exception to replace any tracebacks from
|
| 16 |
+
within compiled template code with tracebacks that look like they
|
| 17 |
+
came from the template source.
|
| 18 |
+
|
| 19 |
+
This must be called within an ``except`` block.
|
| 20 |
+
|
| 21 |
+
:param source: For ``TemplateSyntaxError``, the original source if
|
| 22 |
+
known.
|
| 23 |
+
:return: The original exception with the rewritten traceback.
|
| 24 |
+
"""
|
| 25 |
+
_, exc_value, tb = sys.exc_info()
|
| 26 |
+
exc_value = t.cast(BaseException, exc_value)
|
| 27 |
+
tb = t.cast(TracebackType, tb)
|
| 28 |
+
|
| 29 |
+
if isinstance(exc_value, TemplateSyntaxError) and not exc_value.translated:
|
| 30 |
+
exc_value.translated = True
|
| 31 |
+
exc_value.source = source
|
| 32 |
+
# Remove the old traceback, otherwise the frames from the
|
| 33 |
+
# compiler still show up.
|
| 34 |
+
exc_value.with_traceback(None)
|
| 35 |
+
# Outside of runtime, so the frame isn't executing template
|
| 36 |
+
# code, but it still needs to point at the template.
|
| 37 |
+
tb = fake_traceback(
|
| 38 |
+
exc_value, None, exc_value.filename or "<unknown>", exc_value.lineno
|
| 39 |
+
)
|
| 40 |
+
else:
|
| 41 |
+
# Skip the frame for the render function.
|
| 42 |
+
tb = tb.tb_next
|
| 43 |
+
|
| 44 |
+
stack = []
|
| 45 |
+
|
| 46 |
+
# Build the stack of traceback object, replacing any in template
|
| 47 |
+
# code with the source file and line information.
|
| 48 |
+
while tb is not None:
|
| 49 |
+
# Skip frames decorated with @internalcode. These are internal
|
| 50 |
+
# calls that aren't useful in template debugging output.
|
| 51 |
+
if tb.tb_frame.f_code in internal_code:
|
| 52 |
+
tb = tb.tb_next
|
| 53 |
+
continue
|
| 54 |
+
|
| 55 |
+
template = tb.tb_frame.f_globals.get("__jinja_template__")
|
| 56 |
+
|
| 57 |
+
if template is not None:
|
| 58 |
+
lineno = template.get_corresponding_lineno(tb.tb_lineno)
|
| 59 |
+
fake_tb = fake_traceback(exc_value, tb, template.filename, lineno)
|
| 60 |
+
stack.append(fake_tb)
|
| 61 |
+
else:
|
| 62 |
+
stack.append(tb)
|
| 63 |
+
|
| 64 |
+
tb = tb.tb_next
|
| 65 |
+
|
| 66 |
+
tb_next = None
|
| 67 |
+
|
| 68 |
+
# Assign tb_next in reverse to avoid circular references.
|
| 69 |
+
for tb in reversed(stack):
|
| 70 |
+
tb.tb_next = tb_next
|
| 71 |
+
tb_next = tb
|
| 72 |
+
|
| 73 |
+
return exc_value.with_traceback(tb_next)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def fake_traceback( # type: ignore
|
| 77 |
+
exc_value: BaseException, tb: t.Optional[TracebackType], filename: str, lineno: int
|
| 78 |
+
) -> TracebackType:
|
| 79 |
+
"""Produce a new traceback object that looks like it came from the
|
| 80 |
+
template source instead of the compiled code. The filename, line
|
| 81 |
+
number, and location name will point to the template, and the local
|
| 82 |
+
variables will be the current template context.
|
| 83 |
+
|
| 84 |
+
:param exc_value: The original exception to be re-raised to create
|
| 85 |
+
the new traceback.
|
| 86 |
+
:param tb: The original traceback to get the local variables and
|
| 87 |
+
code info from.
|
| 88 |
+
:param filename: The template filename.
|
| 89 |
+
:param lineno: The line number in the template source.
|
| 90 |
+
"""
|
| 91 |
+
if tb is not None:
|
| 92 |
+
# Replace the real locals with the context that would be
|
| 93 |
+
# available at that point in the template.
|
| 94 |
+
locals = get_template_locals(tb.tb_frame.f_locals)
|
| 95 |
+
locals.pop("__jinja_exception__", None)
|
| 96 |
+
else:
|
| 97 |
+
locals = {}
|
| 98 |
+
|
| 99 |
+
globals = {
|
| 100 |
+
"__name__": filename,
|
| 101 |
+
"__file__": filename,
|
| 102 |
+
"__jinja_exception__": exc_value,
|
| 103 |
+
}
|
| 104 |
+
# Raise an exception at the correct line number.
|
| 105 |
+
code: CodeType = compile(
|
| 106 |
+
"\n" * (lineno - 1) + "raise __jinja_exception__", filename, "exec"
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
# Build a new code object that points to the template file and
|
| 110 |
+
# replaces the location with a block name.
|
| 111 |
+
location = "template"
|
| 112 |
+
|
| 113 |
+
if tb is not None:
|
| 114 |
+
function = tb.tb_frame.f_code.co_name
|
| 115 |
+
|
| 116 |
+
if function == "root":
|
| 117 |
+
location = "top-level template code"
|
| 118 |
+
elif function.startswith("block_"):
|
| 119 |
+
location = f"block {function[6:]!r}"
|
| 120 |
+
|
| 121 |
+
if sys.version_info >= (3, 8):
|
| 122 |
+
code = code.replace(co_name=location)
|
| 123 |
+
else:
|
| 124 |
+
code = CodeType(
|
| 125 |
+
code.co_argcount,
|
| 126 |
+
code.co_kwonlyargcount,
|
| 127 |
+
code.co_nlocals,
|
| 128 |
+
code.co_stacksize,
|
| 129 |
+
code.co_flags,
|
| 130 |
+
code.co_code,
|
| 131 |
+
code.co_consts,
|
| 132 |
+
code.co_names,
|
| 133 |
+
code.co_varnames,
|
| 134 |
+
code.co_filename,
|
| 135 |
+
location,
|
| 136 |
+
code.co_firstlineno,
|
| 137 |
+
code.co_lnotab,
|
| 138 |
+
code.co_freevars,
|
| 139 |
+
code.co_cellvars,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# Execute the new code, which is guaranteed to raise, and return
|
| 143 |
+
# the new traceback without this frame.
|
| 144 |
+
try:
|
| 145 |
+
exec(code, globals, locals)
|
| 146 |
+
except BaseException:
|
| 147 |
+
return sys.exc_info()[2].tb_next # type: ignore
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def get_template_locals(real_locals: t.Mapping[str, t.Any]) -> t.Dict[str, t.Any]:
|
| 151 |
+
"""Based on the runtime locals, get the context that would be
|
| 152 |
+
available at that point in the template.
|
| 153 |
+
"""
|
| 154 |
+
# Start with the current template context.
|
| 155 |
+
ctx: t.Optional[Context] = real_locals.get("context")
|
| 156 |
+
|
| 157 |
+
if ctx is not None:
|
| 158 |
+
data: t.Dict[str, t.Any] = ctx.get_all().copy()
|
| 159 |
+
else:
|
| 160 |
+
data = {}
|
| 161 |
+
|
| 162 |
+
# Might be in a derived context that only sets local variables
|
| 163 |
+
# rather than pushing a context. Local variables follow the scheme
|
| 164 |
+
# l_depth_name. Find the highest-depth local that has a value for
|
| 165 |
+
# each name.
|
| 166 |
+
local_overrides: t.Dict[str, t.Tuple[int, t.Any]] = {}
|
| 167 |
+
|
| 168 |
+
for name, value in real_locals.items():
|
| 169 |
+
if not name.startswith("l_") or value is missing:
|
| 170 |
+
# Not a template variable, or no longer relevant.
|
| 171 |
+
continue
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
_, depth_str, name = name.split("_", 2)
|
| 175 |
+
depth = int(depth_str)
|
| 176 |
+
except ValueError:
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
cur_depth = local_overrides.get(name, (-1,))[0]
|
| 180 |
+
|
| 181 |
+
if cur_depth < depth:
|
| 182 |
+
local_overrides[name] = (depth, value)
|
| 183 |
+
|
| 184 |
+
# Modify the context with any derived context.
|
| 185 |
+
for name, (_, value) in local_overrides.items():
|
| 186 |
+
if value is missing:
|
| 187 |
+
data.pop(name, None)
|
| 188 |
+
else:
|
| 189 |
+
data[name] = value
|
| 190 |
+
|
| 191 |
+
return data
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/defaults.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
|
| 3 |
+
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
|
| 4 |
+
from .tests import TESTS as DEFAULT_TESTS # noqa: F401
|
| 5 |
+
from .utils import Cycler
|
| 6 |
+
from .utils import generate_lorem_ipsum
|
| 7 |
+
from .utils import Joiner
|
| 8 |
+
from .utils import Namespace
|
| 9 |
+
|
| 10 |
+
if t.TYPE_CHECKING:
|
| 11 |
+
import typing_extensions as te
|
| 12 |
+
|
| 13 |
+
# defaults for the parser / lexer
|
| 14 |
+
BLOCK_START_STRING = "{%"
|
| 15 |
+
BLOCK_END_STRING = "%}"
|
| 16 |
+
VARIABLE_START_STRING = "{{"
|
| 17 |
+
VARIABLE_END_STRING = "}}"
|
| 18 |
+
COMMENT_START_STRING = "{#"
|
| 19 |
+
COMMENT_END_STRING = "#}"
|
| 20 |
+
LINE_STATEMENT_PREFIX: t.Optional[str] = None
|
| 21 |
+
LINE_COMMENT_PREFIX: t.Optional[str] = None
|
| 22 |
+
TRIM_BLOCKS = False
|
| 23 |
+
LSTRIP_BLOCKS = False
|
| 24 |
+
NEWLINE_SEQUENCE: "te.Literal['\\n', '\\r\\n', '\\r']" = "\n"
|
| 25 |
+
KEEP_TRAILING_NEWLINE = False
|
| 26 |
+
|
| 27 |
+
# default filters, tests and namespace
|
| 28 |
+
|
| 29 |
+
DEFAULT_NAMESPACE = {
|
| 30 |
+
"range": range,
|
| 31 |
+
"dict": dict,
|
| 32 |
+
"lipsum": generate_lorem_ipsum,
|
| 33 |
+
"cycler": Cycler,
|
| 34 |
+
"joiner": Joiner,
|
| 35 |
+
"namespace": Namespace,
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# default policies
|
| 39 |
+
DEFAULT_POLICIES: t.Dict[str, t.Any] = {
|
| 40 |
+
"compiler.ascii_str": True,
|
| 41 |
+
"urlize.rel": "noopener",
|
| 42 |
+
"urlize.target": None,
|
| 43 |
+
"urlize.extra_schemes": None,
|
| 44 |
+
"truncate.leeway": 5,
|
| 45 |
+
"json.dumps_function": None,
|
| 46 |
+
"json.dumps_kwargs": {"sort_keys": True},
|
| 47 |
+
"ext.i18n.trimmed": False,
|
| 48 |
+
}
|
miniconda3/envs/ladir/lib/python3.10/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
|
miniconda3/envs/ladir/lib/python3.10/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 |
+
"""
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/ext.py
ADDED
|
@@ -0,0 +1,870 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
| 1 |
+
"""Extension API for adding custom tags and behavior."""
|
| 2 |
+
|
| 3 |
+
import pprint
|
| 4 |
+
import re
|
| 5 |
+
import typing as t
|
| 6 |
+
|
| 7 |
+
from markupsafe import Markup
|
| 8 |
+
|
| 9 |
+
from . import defaults
|
| 10 |
+
from . import nodes
|
| 11 |
+
from .environment import Environment
|
| 12 |
+
from .exceptions import TemplateAssertionError
|
| 13 |
+
from .exceptions import TemplateSyntaxError
|
| 14 |
+
from .runtime import concat # type: ignore
|
| 15 |
+
from .runtime import Context
|
| 16 |
+
from .runtime import Undefined
|
| 17 |
+
from .utils import import_string
|
| 18 |
+
from .utils import pass_context
|
| 19 |
+
|
| 20 |
+
if t.TYPE_CHECKING:
|
| 21 |
+
import typing_extensions as te
|
| 22 |
+
|
| 23 |
+
from .lexer import Token
|
| 24 |
+
from .lexer import TokenStream
|
| 25 |
+
from .parser import Parser
|
| 26 |
+
|
| 27 |
+
class _TranslationsBasic(te.Protocol):
|
| 28 |
+
def gettext(self, message: str) -> str: ...
|
| 29 |
+
|
| 30 |
+
def ngettext(self, singular: str, plural: str, n: int) -> str:
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
class _TranslationsContext(_TranslationsBasic):
|
| 34 |
+
def pgettext(self, context: str, message: str) -> str: ...
|
| 35 |
+
|
| 36 |
+
def npgettext(
|
| 37 |
+
self, context: str, singular: str, plural: str, n: int
|
| 38 |
+
) -> str: ...
|
| 39 |
+
|
| 40 |
+
_SupportedTranslations = t.Union[_TranslationsBasic, _TranslationsContext]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# I18N functions available in Jinja templates. If the I18N library
|
| 44 |
+
# provides ugettext, it will be assigned to gettext.
|
| 45 |
+
GETTEXT_FUNCTIONS: t.Tuple[str, ...] = (
|
| 46 |
+
"_",
|
| 47 |
+
"gettext",
|
| 48 |
+
"ngettext",
|
| 49 |
+
"pgettext",
|
| 50 |
+
"npgettext",
|
| 51 |
+
)
|
| 52 |
+
_ws_re = re.compile(r"\s*\n\s*")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class Extension:
|
| 56 |
+
"""Extensions can be used to add extra functionality to the Jinja template
|
| 57 |
+
system at the parser level. Custom extensions are bound to an environment
|
| 58 |
+
but may not store environment specific data on `self`. The reason for
|
| 59 |
+
this is that an extension can be bound to another environment (for
|
| 60 |
+
overlays) by creating a copy and reassigning the `environment` attribute.
|
| 61 |
+
|
| 62 |
+
As extensions are created by the environment they cannot accept any
|
| 63 |
+
arguments for configuration. One may want to work around that by using
|
| 64 |
+
a factory function, but that is not possible as extensions are identified
|
| 65 |
+
by their import name. The correct way to configure the extension is
|
| 66 |
+
storing the configuration values on the environment. Because this way the
|
| 67 |
+
environment ends up acting as central configuration storage the
|
| 68 |
+
attributes may clash which is why extensions have to ensure that the names
|
| 69 |
+
they choose for configuration are not too generic. ``prefix`` for example
|
| 70 |
+
is a terrible name, ``fragment_cache_prefix`` on the other hand is a good
|
| 71 |
+
name as includes the name of the extension (fragment cache).
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
identifier: t.ClassVar[str]
|
| 75 |
+
|
| 76 |
+
def __init_subclass__(cls) -> None:
|
| 77 |
+
cls.identifier = f"{cls.__module__}.{cls.__name__}"
|
| 78 |
+
|
| 79 |
+
#: if this extension parses this is the list of tags it's listening to.
|
| 80 |
+
tags: t.Set[str] = set()
|
| 81 |
+
|
| 82 |
+
#: the priority of that extension. This is especially useful for
|
| 83 |
+
#: extensions that preprocess values. A lower value means higher
|
| 84 |
+
#: priority.
|
| 85 |
+
#:
|
| 86 |
+
#: .. versionadded:: 2.4
|
| 87 |
+
priority = 100
|
| 88 |
+
|
| 89 |
+
def __init__(self, environment: Environment) -> None:
|
| 90 |
+
self.environment = environment
|
| 91 |
+
|
| 92 |
+
def bind(self, environment: Environment) -> "te.Self":
|
| 93 |
+
"""Create a copy of this extension bound to another environment."""
|
| 94 |
+
rv = object.__new__(self.__class__)
|
| 95 |
+
rv.__dict__.update(self.__dict__)
|
| 96 |
+
rv.environment = environment
|
| 97 |
+
return rv
|
| 98 |
+
|
| 99 |
+
def preprocess(
|
| 100 |
+
self, source: str, name: t.Optional[str], filename: t.Optional[str] = None
|
| 101 |
+
) -> str:
|
| 102 |
+
"""This method is called before the actual lexing and can be used to
|
| 103 |
+
preprocess the source. The `filename` is optional. The return value
|
| 104 |
+
must be the preprocessed source.
|
| 105 |
+
"""
|
| 106 |
+
return source
|
| 107 |
+
|
| 108 |
+
def filter_stream(
|
| 109 |
+
self, stream: "TokenStream"
|
| 110 |
+
) -> t.Union["TokenStream", t.Iterable["Token"]]:
|
| 111 |
+
"""It's passed a :class:`~jinja2.lexer.TokenStream` that can be used
|
| 112 |
+
to filter tokens returned. This method has to return an iterable of
|
| 113 |
+
:class:`~jinja2.lexer.Token`\\s, but it doesn't have to return a
|
| 114 |
+
:class:`~jinja2.lexer.TokenStream`.
|
| 115 |
+
"""
|
| 116 |
+
return stream
|
| 117 |
+
|
| 118 |
+
def parse(self, parser: "Parser") -> t.Union[nodes.Node, t.List[nodes.Node]]:
|
| 119 |
+
"""If any of the :attr:`tags` matched this method is called with the
|
| 120 |
+
parser as first argument. The token the parser stream is pointing at
|
| 121 |
+
is the name token that matched. This method has to return one or a
|
| 122 |
+
list of multiple nodes.
|
| 123 |
+
"""
|
| 124 |
+
raise NotImplementedError()
|
| 125 |
+
|
| 126 |
+
def attr(
|
| 127 |
+
self, name: str, lineno: t.Optional[int] = None
|
| 128 |
+
) -> nodes.ExtensionAttribute:
|
| 129 |
+
"""Return an attribute node for the current extension. This is useful
|
| 130 |
+
to pass constants on extensions to generated template code.
|
| 131 |
+
|
| 132 |
+
::
|
| 133 |
+
|
| 134 |
+
self.attr('_my_attribute', lineno=lineno)
|
| 135 |
+
"""
|
| 136 |
+
return nodes.ExtensionAttribute(self.identifier, name, lineno=lineno)
|
| 137 |
+
|
| 138 |
+
def call_method(
|
| 139 |
+
self,
|
| 140 |
+
name: str,
|
| 141 |
+
args: t.Optional[t.List[nodes.Expr]] = None,
|
| 142 |
+
kwargs: t.Optional[t.List[nodes.Keyword]] = None,
|
| 143 |
+
dyn_args: t.Optional[nodes.Expr] = None,
|
| 144 |
+
dyn_kwargs: t.Optional[nodes.Expr] = None,
|
| 145 |
+
lineno: t.Optional[int] = None,
|
| 146 |
+
) -> nodes.Call:
|
| 147 |
+
"""Call a method of the extension. This is a shortcut for
|
| 148 |
+
:meth:`attr` + :class:`jinja2.nodes.Call`.
|
| 149 |
+
"""
|
| 150 |
+
if args is None:
|
| 151 |
+
args = []
|
| 152 |
+
if kwargs is None:
|
| 153 |
+
kwargs = []
|
| 154 |
+
return nodes.Call(
|
| 155 |
+
self.attr(name, lineno=lineno),
|
| 156 |
+
args,
|
| 157 |
+
kwargs,
|
| 158 |
+
dyn_args,
|
| 159 |
+
dyn_kwargs,
|
| 160 |
+
lineno=lineno,
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@pass_context
|
| 165 |
+
def _gettext_alias(
|
| 166 |
+
__context: Context, *args: t.Any, **kwargs: t.Any
|
| 167 |
+
) -> t.Union[t.Any, Undefined]:
|
| 168 |
+
return __context.call(__context.resolve("gettext"), *args, **kwargs)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _make_new_gettext(func: t.Callable[[str], str]) -> t.Callable[..., str]:
|
| 172 |
+
@pass_context
|
| 173 |
+
def gettext(__context: Context, __string: str, **variables: t.Any) -> str:
|
| 174 |
+
rv = __context.call(func, __string)
|
| 175 |
+
if __context.eval_ctx.autoescape:
|
| 176 |
+
rv = Markup(rv)
|
| 177 |
+
# Always treat as a format string, even if there are no
|
| 178 |
+
# variables. This makes translation strings more consistent
|
| 179 |
+
# and predictable. This requires escaping
|
| 180 |
+
return rv % variables # type: ignore
|
| 181 |
+
|
| 182 |
+
return gettext
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def _make_new_ngettext(func: t.Callable[[str, str, int], str]) -> t.Callable[..., str]:
|
| 186 |
+
@pass_context
|
| 187 |
+
def ngettext(
|
| 188 |
+
__context: Context,
|
| 189 |
+
__singular: str,
|
| 190 |
+
__plural: str,
|
| 191 |
+
__num: int,
|
| 192 |
+
**variables: t.Any,
|
| 193 |
+
) -> str:
|
| 194 |
+
variables.setdefault("num", __num)
|
| 195 |
+
rv = __context.call(func, __singular, __plural, __num)
|
| 196 |
+
if __context.eval_ctx.autoescape:
|
| 197 |
+
rv = Markup(rv)
|
| 198 |
+
# Always treat as a format string, see gettext comment above.
|
| 199 |
+
return rv % variables # type: ignore
|
| 200 |
+
|
| 201 |
+
return ngettext
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _make_new_pgettext(func: t.Callable[[str, str], str]) -> t.Callable[..., str]:
|
| 205 |
+
@pass_context
|
| 206 |
+
def pgettext(
|
| 207 |
+
__context: Context, __string_ctx: str, __string: str, **variables: t.Any
|
| 208 |
+
) -> str:
|
| 209 |
+
variables.setdefault("context", __string_ctx)
|
| 210 |
+
rv = __context.call(func, __string_ctx, __string)
|
| 211 |
+
|
| 212 |
+
if __context.eval_ctx.autoescape:
|
| 213 |
+
rv = Markup(rv)
|
| 214 |
+
|
| 215 |
+
# Always treat as a format string, see gettext comment above.
|
| 216 |
+
return rv % variables # type: ignore
|
| 217 |
+
|
| 218 |
+
return pgettext
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def _make_new_npgettext(
|
| 222 |
+
func: t.Callable[[str, str, str, int], str],
|
| 223 |
+
) -> t.Callable[..., str]:
|
| 224 |
+
@pass_context
|
| 225 |
+
def npgettext(
|
| 226 |
+
__context: Context,
|
| 227 |
+
__string_ctx: str,
|
| 228 |
+
__singular: str,
|
| 229 |
+
__plural: str,
|
| 230 |
+
__num: int,
|
| 231 |
+
**variables: t.Any,
|
| 232 |
+
) -> str:
|
| 233 |
+
variables.setdefault("context", __string_ctx)
|
| 234 |
+
variables.setdefault("num", __num)
|
| 235 |
+
rv = __context.call(func, __string_ctx, __singular, __plural, __num)
|
| 236 |
+
|
| 237 |
+
if __context.eval_ctx.autoescape:
|
| 238 |
+
rv = Markup(rv)
|
| 239 |
+
|
| 240 |
+
# Always treat as a format string, see gettext comment above.
|
| 241 |
+
return rv % variables # type: ignore
|
| 242 |
+
|
| 243 |
+
return npgettext
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class InternationalizationExtension(Extension):
|
| 247 |
+
"""This extension adds gettext support to Jinja."""
|
| 248 |
+
|
| 249 |
+
tags = {"trans"}
|
| 250 |
+
|
| 251 |
+
# TODO: the i18n extension is currently reevaluating values in a few
|
| 252 |
+
# situations. Take this example:
|
| 253 |
+
# {% trans count=something() %}{{ count }} foo{% pluralize
|
| 254 |
+
# %}{{ count }} fooss{% endtrans %}
|
| 255 |
+
# something is called twice here. One time for the gettext value and
|
| 256 |
+
# the other time for the n-parameter of the ngettext function.
|
| 257 |
+
|
| 258 |
+
def __init__(self, environment: Environment) -> None:
|
| 259 |
+
super().__init__(environment)
|
| 260 |
+
environment.globals["_"] = _gettext_alias
|
| 261 |
+
environment.extend(
|
| 262 |
+
install_gettext_translations=self._install,
|
| 263 |
+
install_null_translations=self._install_null,
|
| 264 |
+
install_gettext_callables=self._install_callables,
|
| 265 |
+
uninstall_gettext_translations=self._uninstall,
|
| 266 |
+
extract_translations=self._extract,
|
| 267 |
+
newstyle_gettext=False,
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
def _install(
|
| 271 |
+
self, translations: "_SupportedTranslations", newstyle: t.Optional[bool] = None
|
| 272 |
+
) -> None:
|
| 273 |
+
# ugettext and ungettext are preferred in case the I18N library
|
| 274 |
+
# is providing compatibility with older Python versions.
|
| 275 |
+
gettext = getattr(translations, "ugettext", None)
|
| 276 |
+
if gettext is None:
|
| 277 |
+
gettext = translations.gettext
|
| 278 |
+
ngettext = getattr(translations, "ungettext", None)
|
| 279 |
+
if ngettext is None:
|
| 280 |
+
ngettext = translations.ngettext
|
| 281 |
+
|
| 282 |
+
pgettext = getattr(translations, "pgettext", None)
|
| 283 |
+
npgettext = getattr(translations, "npgettext", None)
|
| 284 |
+
self._install_callables(
|
| 285 |
+
gettext, ngettext, newstyle=newstyle, pgettext=pgettext, npgettext=npgettext
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
def _install_null(self, newstyle: t.Optional[bool] = None) -> None:
|
| 289 |
+
import gettext
|
| 290 |
+
|
| 291 |
+
translations = gettext.NullTranslations()
|
| 292 |
+
|
| 293 |
+
if hasattr(translations, "pgettext"):
|
| 294 |
+
# Python < 3.8
|
| 295 |
+
pgettext = translations.pgettext
|
| 296 |
+
else:
|
| 297 |
+
|
| 298 |
+
def pgettext(c: str, s: str) -> str: # type: ignore[misc]
|
| 299 |
+
return s
|
| 300 |
+
|
| 301 |
+
if hasattr(translations, "npgettext"):
|
| 302 |
+
npgettext = translations.npgettext
|
| 303 |
+
else:
|
| 304 |
+
|
| 305 |
+
def npgettext(c: str, s: str, p: str, n: int) -> str: # type: ignore[misc]
|
| 306 |
+
return s if n == 1 else p
|
| 307 |
+
|
| 308 |
+
self._install_callables(
|
| 309 |
+
gettext=translations.gettext,
|
| 310 |
+
ngettext=translations.ngettext,
|
| 311 |
+
newstyle=newstyle,
|
| 312 |
+
pgettext=pgettext,
|
| 313 |
+
npgettext=npgettext,
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
def _install_callables(
|
| 317 |
+
self,
|
| 318 |
+
gettext: t.Callable[[str], str],
|
| 319 |
+
ngettext: t.Callable[[str, str, int], str],
|
| 320 |
+
newstyle: t.Optional[bool] = None,
|
| 321 |
+
pgettext: t.Optional[t.Callable[[str, str], str]] = None,
|
| 322 |
+
npgettext: t.Optional[t.Callable[[str, str, str, int], str]] = None,
|
| 323 |
+
) -> None:
|
| 324 |
+
if newstyle is not None:
|
| 325 |
+
self.environment.newstyle_gettext = newstyle # type: ignore
|
| 326 |
+
if self.environment.newstyle_gettext: # type: ignore
|
| 327 |
+
gettext = _make_new_gettext(gettext)
|
| 328 |
+
ngettext = _make_new_ngettext(ngettext)
|
| 329 |
+
|
| 330 |
+
if pgettext is not None:
|
| 331 |
+
pgettext = _make_new_pgettext(pgettext)
|
| 332 |
+
|
| 333 |
+
if npgettext is not None:
|
| 334 |
+
npgettext = _make_new_npgettext(npgettext)
|
| 335 |
+
|
| 336 |
+
self.environment.globals.update(
|
| 337 |
+
gettext=gettext, ngettext=ngettext, pgettext=pgettext, npgettext=npgettext
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
def _uninstall(self, translations: "_SupportedTranslations") -> None:
|
| 341 |
+
for key in ("gettext", "ngettext", "pgettext", "npgettext"):
|
| 342 |
+
self.environment.globals.pop(key, None)
|
| 343 |
+
|
| 344 |
+
def _extract(
|
| 345 |
+
self,
|
| 346 |
+
source: t.Union[str, nodes.Template],
|
| 347 |
+
gettext_functions: t.Sequence[str] = GETTEXT_FUNCTIONS,
|
| 348 |
+
) -> t.Iterator[
|
| 349 |
+
t.Tuple[int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]]]
|
| 350 |
+
]:
|
| 351 |
+
if isinstance(source, str):
|
| 352 |
+
source = self.environment.parse(source)
|
| 353 |
+
return extract_from_ast(source, gettext_functions)
|
| 354 |
+
|
| 355 |
+
def parse(self, parser: "Parser") -> t.Union[nodes.Node, t.List[nodes.Node]]:
|
| 356 |
+
"""Parse a translatable tag."""
|
| 357 |
+
lineno = next(parser.stream).lineno
|
| 358 |
+
|
| 359 |
+
context = None
|
| 360 |
+
context_token = parser.stream.next_if("string")
|
| 361 |
+
|
| 362 |
+
if context_token is not None:
|
| 363 |
+
context = context_token.value
|
| 364 |
+
|
| 365 |
+
# find all the variables referenced. Additionally a variable can be
|
| 366 |
+
# defined in the body of the trans block too, but this is checked at
|
| 367 |
+
# a later state.
|
| 368 |
+
plural_expr: t.Optional[nodes.Expr] = None
|
| 369 |
+
plural_expr_assignment: t.Optional[nodes.Assign] = None
|
| 370 |
+
num_called_num = False
|
| 371 |
+
variables: t.Dict[str, nodes.Expr] = {}
|
| 372 |
+
trimmed = None
|
| 373 |
+
while parser.stream.current.type != "block_end":
|
| 374 |
+
if variables:
|
| 375 |
+
parser.stream.expect("comma")
|
| 376 |
+
|
| 377 |
+
# skip colon for python compatibility
|
| 378 |
+
if parser.stream.skip_if("colon"):
|
| 379 |
+
break
|
| 380 |
+
|
| 381 |
+
token = parser.stream.expect("name")
|
| 382 |
+
if token.value in variables:
|
| 383 |
+
parser.fail(
|
| 384 |
+
f"translatable variable {token.value!r} defined twice.",
|
| 385 |
+
token.lineno,
|
| 386 |
+
exc=TemplateAssertionError,
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
# expressions
|
| 390 |
+
if parser.stream.current.type == "assign":
|
| 391 |
+
next(parser.stream)
|
| 392 |
+
variables[token.value] = var = parser.parse_expression()
|
| 393 |
+
elif trimmed is None and token.value in ("trimmed", "notrimmed"):
|
| 394 |
+
trimmed = token.value == "trimmed"
|
| 395 |
+
continue
|
| 396 |
+
else:
|
| 397 |
+
variables[token.value] = var = nodes.Name(token.value, "load")
|
| 398 |
+
|
| 399 |
+
if plural_expr is None:
|
| 400 |
+
if isinstance(var, nodes.Call):
|
| 401 |
+
plural_expr = nodes.Name("_trans", "load")
|
| 402 |
+
variables[token.value] = plural_expr
|
| 403 |
+
plural_expr_assignment = nodes.Assign(
|
| 404 |
+
nodes.Name("_trans", "store"), var
|
| 405 |
+
)
|
| 406 |
+
else:
|
| 407 |
+
plural_expr = var
|
| 408 |
+
num_called_num = token.value == "num"
|
| 409 |
+
|
| 410 |
+
parser.stream.expect("block_end")
|
| 411 |
+
|
| 412 |
+
plural = None
|
| 413 |
+
have_plural = False
|
| 414 |
+
referenced = set()
|
| 415 |
+
|
| 416 |
+
# now parse until endtrans or pluralize
|
| 417 |
+
singular_names, singular = self._parse_block(parser, True)
|
| 418 |
+
if singular_names:
|
| 419 |
+
referenced.update(singular_names)
|
| 420 |
+
if plural_expr is None:
|
| 421 |
+
plural_expr = nodes.Name(singular_names[0], "load")
|
| 422 |
+
num_called_num = singular_names[0] == "num"
|
| 423 |
+
|
| 424 |
+
# if we have a pluralize block, we parse that too
|
| 425 |
+
if parser.stream.current.test("name:pluralize"):
|
| 426 |
+
have_plural = True
|
| 427 |
+
next(parser.stream)
|
| 428 |
+
if parser.stream.current.type != "block_end":
|
| 429 |
+
token = parser.stream.expect("name")
|
| 430 |
+
if token.value not in variables:
|
| 431 |
+
parser.fail(
|
| 432 |
+
f"unknown variable {token.value!r} for pluralization",
|
| 433 |
+
token.lineno,
|
| 434 |
+
exc=TemplateAssertionError,
|
| 435 |
+
)
|
| 436 |
+
plural_expr = variables[token.value]
|
| 437 |
+
num_called_num = token.value == "num"
|
| 438 |
+
parser.stream.expect("block_end")
|
| 439 |
+
plural_names, plural = self._parse_block(parser, False)
|
| 440 |
+
next(parser.stream)
|
| 441 |
+
referenced.update(plural_names)
|
| 442 |
+
else:
|
| 443 |
+
next(parser.stream)
|
| 444 |
+
|
| 445 |
+
# register free names as simple name expressions
|
| 446 |
+
for name in referenced:
|
| 447 |
+
if name not in variables:
|
| 448 |
+
variables[name] = nodes.Name(name, "load")
|
| 449 |
+
|
| 450 |
+
if not have_plural:
|
| 451 |
+
plural_expr = None
|
| 452 |
+
elif plural_expr is None:
|
| 453 |
+
parser.fail("pluralize without variables", lineno)
|
| 454 |
+
|
| 455 |
+
if trimmed is None:
|
| 456 |
+
trimmed = self.environment.policies["ext.i18n.trimmed"]
|
| 457 |
+
if trimmed:
|
| 458 |
+
singular = self._trim_whitespace(singular)
|
| 459 |
+
if plural:
|
| 460 |
+
plural = self._trim_whitespace(plural)
|
| 461 |
+
|
| 462 |
+
node = self._make_node(
|
| 463 |
+
singular,
|
| 464 |
+
plural,
|
| 465 |
+
context,
|
| 466 |
+
variables,
|
| 467 |
+
plural_expr,
|
| 468 |
+
bool(referenced),
|
| 469 |
+
num_called_num and have_plural,
|
| 470 |
+
)
|
| 471 |
+
node.set_lineno(lineno)
|
| 472 |
+
if plural_expr_assignment is not None:
|
| 473 |
+
return [plural_expr_assignment, node]
|
| 474 |
+
else:
|
| 475 |
+
return node
|
| 476 |
+
|
| 477 |
+
def _trim_whitespace(self, string: str, _ws_re: t.Pattern[str] = _ws_re) -> str:
|
| 478 |
+
return _ws_re.sub(" ", string.strip())
|
| 479 |
+
|
| 480 |
+
def _parse_block(
|
| 481 |
+
self, parser: "Parser", allow_pluralize: bool
|
| 482 |
+
) -> t.Tuple[t.List[str], str]:
|
| 483 |
+
"""Parse until the next block tag with a given name."""
|
| 484 |
+
referenced = []
|
| 485 |
+
buf = []
|
| 486 |
+
|
| 487 |
+
while True:
|
| 488 |
+
if parser.stream.current.type == "data":
|
| 489 |
+
buf.append(parser.stream.current.value.replace("%", "%%"))
|
| 490 |
+
next(parser.stream)
|
| 491 |
+
elif parser.stream.current.type == "variable_begin":
|
| 492 |
+
next(parser.stream)
|
| 493 |
+
name = parser.stream.expect("name").value
|
| 494 |
+
referenced.append(name)
|
| 495 |
+
buf.append(f"%({name})s")
|
| 496 |
+
parser.stream.expect("variable_end")
|
| 497 |
+
elif parser.stream.current.type == "block_begin":
|
| 498 |
+
next(parser.stream)
|
| 499 |
+
block_name = (
|
| 500 |
+
parser.stream.current.value
|
| 501 |
+
if parser.stream.current.type == "name"
|
| 502 |
+
else None
|
| 503 |
+
)
|
| 504 |
+
if block_name == "endtrans":
|
| 505 |
+
break
|
| 506 |
+
elif block_name == "pluralize":
|
| 507 |
+
if allow_pluralize:
|
| 508 |
+
break
|
| 509 |
+
parser.fail(
|
| 510 |
+
"a translatable section can have only one pluralize section"
|
| 511 |
+
)
|
| 512 |
+
elif block_name == "trans":
|
| 513 |
+
parser.fail(
|
| 514 |
+
"trans blocks can't be nested; did you mean `endtrans`?"
|
| 515 |
+
)
|
| 516 |
+
parser.fail(
|
| 517 |
+
f"control structures in translatable sections are not allowed; "
|
| 518 |
+
f"saw `{block_name}`"
|
| 519 |
+
)
|
| 520 |
+
elif parser.stream.eos:
|
| 521 |
+
parser.fail("unclosed translation block")
|
| 522 |
+
else:
|
| 523 |
+
raise RuntimeError("internal parser error")
|
| 524 |
+
|
| 525 |
+
return referenced, concat(buf)
|
| 526 |
+
|
| 527 |
+
def _make_node(
|
| 528 |
+
self,
|
| 529 |
+
singular: str,
|
| 530 |
+
plural: t.Optional[str],
|
| 531 |
+
context: t.Optional[str],
|
| 532 |
+
variables: t.Dict[str, nodes.Expr],
|
| 533 |
+
plural_expr: t.Optional[nodes.Expr],
|
| 534 |
+
vars_referenced: bool,
|
| 535 |
+
num_called_num: bool,
|
| 536 |
+
) -> nodes.Output:
|
| 537 |
+
"""Generates a useful node from the data provided."""
|
| 538 |
+
newstyle = self.environment.newstyle_gettext # type: ignore
|
| 539 |
+
node: nodes.Expr
|
| 540 |
+
|
| 541 |
+
# no variables referenced? no need to escape for old style
|
| 542 |
+
# gettext invocations only if there are vars.
|
| 543 |
+
if not vars_referenced and not newstyle:
|
| 544 |
+
singular = singular.replace("%%", "%")
|
| 545 |
+
if plural:
|
| 546 |
+
plural = plural.replace("%%", "%")
|
| 547 |
+
|
| 548 |
+
func_name = "gettext"
|
| 549 |
+
func_args: t.List[nodes.Expr] = [nodes.Const(singular)]
|
| 550 |
+
|
| 551 |
+
if context is not None:
|
| 552 |
+
func_args.insert(0, nodes.Const(context))
|
| 553 |
+
func_name = f"p{func_name}"
|
| 554 |
+
|
| 555 |
+
if plural_expr is not None:
|
| 556 |
+
func_name = f"n{func_name}"
|
| 557 |
+
func_args.extend((nodes.Const(plural), plural_expr))
|
| 558 |
+
|
| 559 |
+
node = nodes.Call(nodes.Name(func_name, "load"), func_args, [], None, None)
|
| 560 |
+
|
| 561 |
+
# in case newstyle gettext is used, the method is powerful
|
| 562 |
+
# enough to handle the variable expansion and autoescape
|
| 563 |
+
# handling itself
|
| 564 |
+
if newstyle:
|
| 565 |
+
for key, value in variables.items():
|
| 566 |
+
# the function adds that later anyways in case num was
|
| 567 |
+
# called num, so just skip it.
|
| 568 |
+
if num_called_num and key == "num":
|
| 569 |
+
continue
|
| 570 |
+
node.kwargs.append(nodes.Keyword(key, value))
|
| 571 |
+
|
| 572 |
+
# otherwise do that here
|
| 573 |
+
else:
|
| 574 |
+
# mark the return value as safe if we are in an
|
| 575 |
+
# environment with autoescaping turned on
|
| 576 |
+
node = nodes.MarkSafeIfAutoescape(node)
|
| 577 |
+
if variables:
|
| 578 |
+
node = nodes.Mod(
|
| 579 |
+
node,
|
| 580 |
+
nodes.Dict(
|
| 581 |
+
[
|
| 582 |
+
nodes.Pair(nodes.Const(key), value)
|
| 583 |
+
for key, value in variables.items()
|
| 584 |
+
]
|
| 585 |
+
),
|
| 586 |
+
)
|
| 587 |
+
return nodes.Output([node])
|
| 588 |
+
|
| 589 |
+
|
| 590 |
+
class ExprStmtExtension(Extension):
|
| 591 |
+
"""Adds a `do` tag to Jinja that works like the print statement just
|
| 592 |
+
that it doesn't print the return value.
|
| 593 |
+
"""
|
| 594 |
+
|
| 595 |
+
tags = {"do"}
|
| 596 |
+
|
| 597 |
+
def parse(self, parser: "Parser") -> nodes.ExprStmt:
|
| 598 |
+
node = nodes.ExprStmt(lineno=next(parser.stream).lineno)
|
| 599 |
+
node.node = parser.parse_tuple()
|
| 600 |
+
return node
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
class LoopControlExtension(Extension):
|
| 604 |
+
"""Adds break and continue to the template engine."""
|
| 605 |
+
|
| 606 |
+
tags = {"break", "continue"}
|
| 607 |
+
|
| 608 |
+
def parse(self, parser: "Parser") -> t.Union[nodes.Break, nodes.Continue]:
|
| 609 |
+
token = next(parser.stream)
|
| 610 |
+
if token.value == "break":
|
| 611 |
+
return nodes.Break(lineno=token.lineno)
|
| 612 |
+
return nodes.Continue(lineno=token.lineno)
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
class DebugExtension(Extension):
|
| 616 |
+
"""A ``{% debug %}`` tag that dumps the available variables,
|
| 617 |
+
filters, and tests.
|
| 618 |
+
|
| 619 |
+
.. code-block:: html+jinja
|
| 620 |
+
|
| 621 |
+
<pre>{% debug %}</pre>
|
| 622 |
+
|
| 623 |
+
.. code-block:: text
|
| 624 |
+
|
| 625 |
+
{'context': {'cycler': <class 'jinja2.utils.Cycler'>,
|
| 626 |
+
...,
|
| 627 |
+
'namespace': <class 'jinja2.utils.Namespace'>},
|
| 628 |
+
'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
|
| 629 |
+
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
|
| 630 |
+
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
|
| 631 |
+
..., 'odd', 'sameas', 'sequence', 'string', 'undefined', 'upper']}
|
| 632 |
+
|
| 633 |
+
.. versionadded:: 2.11.0
|
| 634 |
+
"""
|
| 635 |
+
|
| 636 |
+
tags = {"debug"}
|
| 637 |
+
|
| 638 |
+
def parse(self, parser: "Parser") -> nodes.Output:
|
| 639 |
+
lineno = parser.stream.expect("name:debug").lineno
|
| 640 |
+
context = nodes.ContextReference()
|
| 641 |
+
result = self.call_method("_render", [context], lineno=lineno)
|
| 642 |
+
return nodes.Output([result], lineno=lineno)
|
| 643 |
+
|
| 644 |
+
def _render(self, context: Context) -> str:
|
| 645 |
+
result = {
|
| 646 |
+
"context": context.get_all(),
|
| 647 |
+
"filters": sorted(self.environment.filters.keys()),
|
| 648 |
+
"tests": sorted(self.environment.tests.keys()),
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
# Set the depth since the intent is to show the top few names.
|
| 652 |
+
return pprint.pformat(result, depth=3, compact=True)
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
def extract_from_ast(
|
| 656 |
+
ast: nodes.Template,
|
| 657 |
+
gettext_functions: t.Sequence[str] = GETTEXT_FUNCTIONS,
|
| 658 |
+
babel_style: bool = True,
|
| 659 |
+
) -> t.Iterator[
|
| 660 |
+
t.Tuple[int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]]]
|
| 661 |
+
]:
|
| 662 |
+
"""Extract localizable strings from the given template node. Per
|
| 663 |
+
default this function returns matches in babel style that means non string
|
| 664 |
+
parameters as well as keyword arguments are returned as `None`. This
|
| 665 |
+
allows Babel to figure out what you really meant if you are using
|
| 666 |
+
gettext functions that allow keyword arguments for placeholder expansion.
|
| 667 |
+
If you don't want that behavior set the `babel_style` parameter to `False`
|
| 668 |
+
which causes only strings to be returned and parameters are always stored
|
| 669 |
+
in tuples. As a consequence invalid gettext calls (calls without a single
|
| 670 |
+
string parameter or string parameters after non-string parameters) are
|
| 671 |
+
skipped.
|
| 672 |
+
|
| 673 |
+
This example explains the behavior:
|
| 674 |
+
|
| 675 |
+
>>> from jinja2 import Environment
|
| 676 |
+
>>> env = Environment()
|
| 677 |
+
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
|
| 678 |
+
>>> list(extract_from_ast(node))
|
| 679 |
+
[(1, '_', 'foo'), (1, '_', ()), (1, 'ngettext', ('foo', 'bar', None))]
|
| 680 |
+
>>> list(extract_from_ast(node, babel_style=False))
|
| 681 |
+
[(1, '_', ('foo',)), (1, 'ngettext', ('foo', 'bar'))]
|
| 682 |
+
|
| 683 |
+
For every string found this function yields a ``(lineno, function,
|
| 684 |
+
message)`` tuple, where:
|
| 685 |
+
|
| 686 |
+
* ``lineno`` is the number of the line on which the string was found,
|
| 687 |
+
* ``function`` is the name of the ``gettext`` function used (if the
|
| 688 |
+
string was extracted from embedded Python code), and
|
| 689 |
+
* ``message`` is the string, or a tuple of strings for functions
|
| 690 |
+
with multiple string arguments.
|
| 691 |
+
|
| 692 |
+
This extraction function operates on the AST and is because of that unable
|
| 693 |
+
to extract any comments. For comment support you have to use the babel
|
| 694 |
+
extraction interface or extract comments yourself.
|
| 695 |
+
"""
|
| 696 |
+
out: t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]]
|
| 697 |
+
|
| 698 |
+
for node in ast.find_all(nodes.Call):
|
| 699 |
+
if (
|
| 700 |
+
not isinstance(node.node, nodes.Name)
|
| 701 |
+
or node.node.name not in gettext_functions
|
| 702 |
+
):
|
| 703 |
+
continue
|
| 704 |
+
|
| 705 |
+
strings: t.List[t.Optional[str]] = []
|
| 706 |
+
|
| 707 |
+
for arg in node.args:
|
| 708 |
+
if isinstance(arg, nodes.Const) and isinstance(arg.value, str):
|
| 709 |
+
strings.append(arg.value)
|
| 710 |
+
else:
|
| 711 |
+
strings.append(None)
|
| 712 |
+
|
| 713 |
+
for _ in node.kwargs:
|
| 714 |
+
strings.append(None)
|
| 715 |
+
if node.dyn_args is not None:
|
| 716 |
+
strings.append(None)
|
| 717 |
+
if node.dyn_kwargs is not None:
|
| 718 |
+
strings.append(None)
|
| 719 |
+
|
| 720 |
+
if not babel_style:
|
| 721 |
+
out = tuple(x for x in strings if x is not None)
|
| 722 |
+
|
| 723 |
+
if not out:
|
| 724 |
+
continue
|
| 725 |
+
else:
|
| 726 |
+
if len(strings) == 1:
|
| 727 |
+
out = strings[0]
|
| 728 |
+
else:
|
| 729 |
+
out = tuple(strings)
|
| 730 |
+
|
| 731 |
+
yield node.lineno, node.node.name, out
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
class _CommentFinder:
|
| 735 |
+
"""Helper class to find comments in a token stream. Can only
|
| 736 |
+
find comments for gettext calls forwards. Once the comment
|
| 737 |
+
from line 4 is found, a comment for line 1 will not return a
|
| 738 |
+
usable value.
|
| 739 |
+
"""
|
| 740 |
+
|
| 741 |
+
def __init__(
|
| 742 |
+
self, tokens: t.Sequence[t.Tuple[int, str, str]], comment_tags: t.Sequence[str]
|
| 743 |
+
) -> None:
|
| 744 |
+
self.tokens = tokens
|
| 745 |
+
self.comment_tags = comment_tags
|
| 746 |
+
self.offset = 0
|
| 747 |
+
self.last_lineno = 0
|
| 748 |
+
|
| 749 |
+
def find_backwards(self, offset: int) -> t.List[str]:
|
| 750 |
+
try:
|
| 751 |
+
for _, token_type, token_value in reversed(
|
| 752 |
+
self.tokens[self.offset : offset]
|
| 753 |
+
):
|
| 754 |
+
if token_type in ("comment", "linecomment"):
|
| 755 |
+
try:
|
| 756 |
+
prefix, comment = token_value.split(None, 1)
|
| 757 |
+
except ValueError:
|
| 758 |
+
continue
|
| 759 |
+
if prefix in self.comment_tags:
|
| 760 |
+
return [comment.rstrip()]
|
| 761 |
+
return []
|
| 762 |
+
finally:
|
| 763 |
+
self.offset = offset
|
| 764 |
+
|
| 765 |
+
def find_comments(self, lineno: int) -> t.List[str]:
|
| 766 |
+
if not self.comment_tags or self.last_lineno > lineno:
|
| 767 |
+
return []
|
| 768 |
+
for idx, (token_lineno, _, _) in enumerate(self.tokens[self.offset :]):
|
| 769 |
+
if token_lineno > lineno:
|
| 770 |
+
return self.find_backwards(self.offset + idx)
|
| 771 |
+
return self.find_backwards(len(self.tokens))
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
def babel_extract(
|
| 775 |
+
fileobj: t.BinaryIO,
|
| 776 |
+
keywords: t.Sequence[str],
|
| 777 |
+
comment_tags: t.Sequence[str],
|
| 778 |
+
options: t.Dict[str, t.Any],
|
| 779 |
+
) -> t.Iterator[
|
| 780 |
+
t.Tuple[
|
| 781 |
+
int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]], t.List[str]
|
| 782 |
+
]
|
| 783 |
+
]:
|
| 784 |
+
"""Babel extraction method for Jinja templates.
|
| 785 |
+
|
| 786 |
+
.. versionchanged:: 2.3
|
| 787 |
+
Basic support for translation comments was added. If `comment_tags`
|
| 788 |
+
is now set to a list of keywords for extraction, the extractor will
|
| 789 |
+
try to find the best preceding comment that begins with one of the
|
| 790 |
+
keywords. For best results, make sure to not have more than one
|
| 791 |
+
gettext call in one line of code and the matching comment in the
|
| 792 |
+
same line or the line before.
|
| 793 |
+
|
| 794 |
+
.. versionchanged:: 2.5.1
|
| 795 |
+
The `newstyle_gettext` flag can be set to `True` to enable newstyle
|
| 796 |
+
gettext calls.
|
| 797 |
+
|
| 798 |
+
.. versionchanged:: 2.7
|
| 799 |
+
A `silent` option can now be provided. If set to `False` template
|
| 800 |
+
syntax errors are propagated instead of being ignored.
|
| 801 |
+
|
| 802 |
+
:param fileobj: the file-like object the messages should be extracted from
|
| 803 |
+
:param keywords: a list of keywords (i.e. function names) that should be
|
| 804 |
+
recognized as translation functions
|
| 805 |
+
:param comment_tags: a list of translator tags to search for and include
|
| 806 |
+
in the results.
|
| 807 |
+
:param options: a dictionary of additional options (optional)
|
| 808 |
+
:return: an iterator over ``(lineno, funcname, message, comments)`` tuples.
|
| 809 |
+
(comments will be empty currently)
|
| 810 |
+
"""
|
| 811 |
+
extensions: t.Dict[t.Type[Extension], None] = {}
|
| 812 |
+
|
| 813 |
+
for extension_name in options.get("extensions", "").split(","):
|
| 814 |
+
extension_name = extension_name.strip()
|
| 815 |
+
|
| 816 |
+
if not extension_name:
|
| 817 |
+
continue
|
| 818 |
+
|
| 819 |
+
extensions[import_string(extension_name)] = None
|
| 820 |
+
|
| 821 |
+
if InternationalizationExtension not in extensions:
|
| 822 |
+
extensions[InternationalizationExtension] = None
|
| 823 |
+
|
| 824 |
+
def getbool(options: t.Mapping[str, str], key: str, default: bool = False) -> bool:
|
| 825 |
+
return options.get(key, str(default)).lower() in {"1", "on", "yes", "true"}
|
| 826 |
+
|
| 827 |
+
silent = getbool(options, "silent", True)
|
| 828 |
+
environment = Environment(
|
| 829 |
+
options.get("block_start_string", defaults.BLOCK_START_STRING),
|
| 830 |
+
options.get("block_end_string", defaults.BLOCK_END_STRING),
|
| 831 |
+
options.get("variable_start_string", defaults.VARIABLE_START_STRING),
|
| 832 |
+
options.get("variable_end_string", defaults.VARIABLE_END_STRING),
|
| 833 |
+
options.get("comment_start_string", defaults.COMMENT_START_STRING),
|
| 834 |
+
options.get("comment_end_string", defaults.COMMENT_END_STRING),
|
| 835 |
+
options.get("line_statement_prefix") or defaults.LINE_STATEMENT_PREFIX,
|
| 836 |
+
options.get("line_comment_prefix") or defaults.LINE_COMMENT_PREFIX,
|
| 837 |
+
getbool(options, "trim_blocks", defaults.TRIM_BLOCKS),
|
| 838 |
+
getbool(options, "lstrip_blocks", defaults.LSTRIP_BLOCKS),
|
| 839 |
+
defaults.NEWLINE_SEQUENCE,
|
| 840 |
+
getbool(options, "keep_trailing_newline", defaults.KEEP_TRAILING_NEWLINE),
|
| 841 |
+
tuple(extensions),
|
| 842 |
+
cache_size=0,
|
| 843 |
+
auto_reload=False,
|
| 844 |
+
)
|
| 845 |
+
|
| 846 |
+
if getbool(options, "trimmed"):
|
| 847 |
+
environment.policies["ext.i18n.trimmed"] = True
|
| 848 |
+
if getbool(options, "newstyle_gettext"):
|
| 849 |
+
environment.newstyle_gettext = True # type: ignore
|
| 850 |
+
|
| 851 |
+
source = fileobj.read().decode(options.get("encoding", "utf-8"))
|
| 852 |
+
try:
|
| 853 |
+
node = environment.parse(source)
|
| 854 |
+
tokens = list(environment.lex(environment.preprocess(source)))
|
| 855 |
+
except TemplateSyntaxError:
|
| 856 |
+
if not silent:
|
| 857 |
+
raise
|
| 858 |
+
# skip templates with syntax errors
|
| 859 |
+
return
|
| 860 |
+
|
| 861 |
+
finder = _CommentFinder(tokens, comment_tags)
|
| 862 |
+
for lineno, func, message in extract_from_ast(node, keywords):
|
| 863 |
+
yield lineno, func, message, finder.find_comments(lineno)
|
| 864 |
+
|
| 865 |
+
|
| 866 |
+
#: nicer import names
|
| 867 |
+
i18n = InternationalizationExtension
|
| 868 |
+
do = ExprStmtExtension
|
| 869 |
+
loopcontrols = LoopControlExtension
|
| 870 |
+
debug = DebugExtension
|
miniconda3/envs/ladir/lib/python3.10/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 |
+
}
|
miniconda3/envs/ladir/lib/python3.10/site-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HECKING:
|
| 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."""
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/lexer.py
ADDED
|
@@ -0,0 +1,868 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Implements a Jinja / Python combination lexer. The ``Lexer`` class
|
| 2 |
+
is used to do some preprocessing. It filters out invalid operators like
|
| 3 |
+
the bitshift operators we don't allow in templates. It separates
|
| 4 |
+
template code and python code in expressions.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import re
|
| 8 |
+
import typing as t
|
| 9 |
+
from ast import literal_eval
|
| 10 |
+
from collections import deque
|
| 11 |
+
from sys import intern
|
| 12 |
+
|
| 13 |
+
from ._identifier import pattern as name_re
|
| 14 |
+
from .exceptions import TemplateSyntaxError
|
| 15 |
+
from .utils import LRUCache
|
| 16 |
+
|
| 17 |
+
if t.TYPE_CHECKING:
|
| 18 |
+
import typing_extensions as te
|
| 19 |
+
|
| 20 |
+
from .environment import Environment
|
| 21 |
+
|
| 22 |
+
# cache for the lexers. Exists in order to be able to have multiple
|
| 23 |
+
# environments with the same lexer
|
| 24 |
+
_lexer_cache: t.MutableMapping[t.Tuple, "Lexer"] = LRUCache(50) # type: ignore
|
| 25 |
+
|
| 26 |
+
# static regular expressions
|
| 27 |
+
whitespace_re = re.compile(r"\s+")
|
| 28 |
+
newline_re = re.compile(r"(\r\n|\r|\n)")
|
| 29 |
+
string_re = re.compile(
|
| 30 |
+
r"('([^'\\]*(?:\\.[^'\\]*)*)'" r'|"([^"\\]*(?:\\.[^"\\]*)*)")', re.S
|
| 31 |
+
)
|
| 32 |
+
integer_re = re.compile(
|
| 33 |
+
r"""
|
| 34 |
+
(
|
| 35 |
+
0b(_?[0-1])+ # binary
|
| 36 |
+
|
|
| 37 |
+
0o(_?[0-7])+ # octal
|
| 38 |
+
|
|
| 39 |
+
0x(_?[\da-f])+ # hex
|
| 40 |
+
|
|
| 41 |
+
[1-9](_?\d)* # decimal
|
| 42 |
+
|
|
| 43 |
+
0(_?0)* # decimal zero
|
| 44 |
+
)
|
| 45 |
+
""",
|
| 46 |
+
re.IGNORECASE | re.VERBOSE,
|
| 47 |
+
)
|
| 48 |
+
float_re = re.compile(
|
| 49 |
+
r"""
|
| 50 |
+
(?<!\.) # doesn't start with a .
|
| 51 |
+
(\d+_)*\d+ # digits, possibly _ separated
|
| 52 |
+
(
|
| 53 |
+
(\.(\d+_)*\d+)? # optional fractional part
|
| 54 |
+
e[+\-]?(\d+_)*\d+ # exponent part
|
| 55 |
+
|
|
| 56 |
+
\.(\d+_)*\d+ # required fractional part
|
| 57 |
+
)
|
| 58 |
+
""",
|
| 59 |
+
re.IGNORECASE | re.VERBOSE,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# internal the tokens and keep references to them
|
| 63 |
+
TOKEN_ADD = intern("add")
|
| 64 |
+
TOKEN_ASSIGN = intern("assign")
|
| 65 |
+
TOKEN_COLON = intern("colon")
|
| 66 |
+
TOKEN_COMMA = intern("comma")
|
| 67 |
+
TOKEN_DIV = intern("div")
|
| 68 |
+
TOKEN_DOT = intern("dot")
|
| 69 |
+
TOKEN_EQ = intern("eq")
|
| 70 |
+
TOKEN_FLOORDIV = intern("floordiv")
|
| 71 |
+
TOKEN_GT = intern("gt")
|
| 72 |
+
TOKEN_GTEQ = intern("gteq")
|
| 73 |
+
TOKEN_LBRACE = intern("lbrace")
|
| 74 |
+
TOKEN_LBRACKET = intern("lbracket")
|
| 75 |
+
TOKEN_LPAREN = intern("lparen")
|
| 76 |
+
TOKEN_LT = intern("lt")
|
| 77 |
+
TOKEN_LTEQ = intern("lteq")
|
| 78 |
+
TOKEN_MOD = intern("mod")
|
| 79 |
+
TOKEN_MUL = intern("mul")
|
| 80 |
+
TOKEN_NE = intern("ne")
|
| 81 |
+
TOKEN_PIPE = intern("pipe")
|
| 82 |
+
TOKEN_POW = intern("pow")
|
| 83 |
+
TOKEN_RBRACE = intern("rbrace")
|
| 84 |
+
TOKEN_RBRACKET = intern("rbracket")
|
| 85 |
+
TOKEN_RPAREN = intern("rparen")
|
| 86 |
+
TOKEN_SEMICOLON = intern("semicolon")
|
| 87 |
+
TOKEN_SUB = intern("sub")
|
| 88 |
+
TOKEN_TILDE = intern("tilde")
|
| 89 |
+
TOKEN_WHITESPACE = intern("whitespace")
|
| 90 |
+
TOKEN_FLOAT = intern("float")
|
| 91 |
+
TOKEN_INTEGER = intern("integer")
|
| 92 |
+
TOKEN_NAME = intern("name")
|
| 93 |
+
TOKEN_STRING = intern("string")
|
| 94 |
+
TOKEN_OPERATOR = intern("operator")
|
| 95 |
+
TOKEN_BLOCK_BEGIN = intern("block_begin")
|
| 96 |
+
TOKEN_BLOCK_END = intern("block_end")
|
| 97 |
+
TOKEN_VARIABLE_BEGIN = intern("variable_begin")
|
| 98 |
+
TOKEN_VARIABLE_END = intern("variable_end")
|
| 99 |
+
TOKEN_RAW_BEGIN = intern("raw_begin")
|
| 100 |
+
TOKEN_RAW_END = intern("raw_end")
|
| 101 |
+
TOKEN_COMMENT_BEGIN = intern("comment_begin")
|
| 102 |
+
TOKEN_COMMENT_END = intern("comment_end")
|
| 103 |
+
TOKEN_COMMENT = intern("comment")
|
| 104 |
+
TOKEN_LINESTATEMENT_BEGIN = intern("linestatement_begin")
|
| 105 |
+
TOKEN_LINESTATEMENT_END = intern("linestatement_end")
|
| 106 |
+
TOKEN_LINECOMMENT_BEGIN = intern("linecomment_begin")
|
| 107 |
+
TOKEN_LINECOMMENT_END = intern("linecomment_end")
|
| 108 |
+
TOKEN_LINECOMMENT = intern("linecomment")
|
| 109 |
+
TOKEN_DATA = intern("data")
|
| 110 |
+
TOKEN_INITIAL = intern("initial")
|
| 111 |
+
TOKEN_EOF = intern("eof")
|
| 112 |
+
|
| 113 |
+
# bind operators to token types
|
| 114 |
+
operators = {
|
| 115 |
+
"+": TOKEN_ADD,
|
| 116 |
+
"-": TOKEN_SUB,
|
| 117 |
+
"/": TOKEN_DIV,
|
| 118 |
+
"//": TOKEN_FLOORDIV,
|
| 119 |
+
"*": TOKEN_MUL,
|
| 120 |
+
"%": TOKEN_MOD,
|
| 121 |
+
"**": TOKEN_POW,
|
| 122 |
+
"~": TOKEN_TILDE,
|
| 123 |
+
"[": TOKEN_LBRACKET,
|
| 124 |
+
"]": TOKEN_RBRACKET,
|
| 125 |
+
"(": TOKEN_LPAREN,
|
| 126 |
+
")": TOKEN_RPAREN,
|
| 127 |
+
"{": TOKEN_LBRACE,
|
| 128 |
+
"}": TOKEN_RBRACE,
|
| 129 |
+
"==": TOKEN_EQ,
|
| 130 |
+
"!=": TOKEN_NE,
|
| 131 |
+
">": TOKEN_GT,
|
| 132 |
+
">=": TOKEN_GTEQ,
|
| 133 |
+
"<": TOKEN_LT,
|
| 134 |
+
"<=": TOKEN_LTEQ,
|
| 135 |
+
"=": TOKEN_ASSIGN,
|
| 136 |
+
".": TOKEN_DOT,
|
| 137 |
+
":": TOKEN_COLON,
|
| 138 |
+
"|": TOKEN_PIPE,
|
| 139 |
+
",": TOKEN_COMMA,
|
| 140 |
+
";": TOKEN_SEMICOLON,
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
reverse_operators = {v: k for k, v in operators.items()}
|
| 144 |
+
assert len(operators) == len(reverse_operators), "operators dropped"
|
| 145 |
+
operator_re = re.compile(
|
| 146 |
+
f"({'|'.join(re.escape(x) for x in sorted(operators, key=lambda x: -len(x)))})"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
ignored_tokens = frozenset(
|
| 150 |
+
[
|
| 151 |
+
TOKEN_COMMENT_BEGIN,
|
| 152 |
+
TOKEN_COMMENT,
|
| 153 |
+
TOKEN_COMMENT_END,
|
| 154 |
+
TOKEN_WHITESPACE,
|
| 155 |
+
TOKEN_LINECOMMENT_BEGIN,
|
| 156 |
+
TOKEN_LINECOMMENT_END,
|
| 157 |
+
TOKEN_LINECOMMENT,
|
| 158 |
+
]
|
| 159 |
+
)
|
| 160 |
+
ignore_if_empty = frozenset(
|
| 161 |
+
[TOKEN_WHITESPACE, TOKEN_DATA, TOKEN_COMMENT, TOKEN_LINECOMMENT]
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def _describe_token_type(token_type: str) -> str:
|
| 166 |
+
if token_type in reverse_operators:
|
| 167 |
+
return reverse_operators[token_type]
|
| 168 |
+
|
| 169 |
+
return {
|
| 170 |
+
TOKEN_COMMENT_BEGIN: "begin of comment",
|
| 171 |
+
TOKEN_COMMENT_END: "end of comment",
|
| 172 |
+
TOKEN_COMMENT: "comment",
|
| 173 |
+
TOKEN_LINECOMMENT: "comment",
|
| 174 |
+
TOKEN_BLOCK_BEGIN: "begin of statement block",
|
| 175 |
+
TOKEN_BLOCK_END: "end of statement block",
|
| 176 |
+
TOKEN_VARIABLE_BEGIN: "begin of print statement",
|
| 177 |
+
TOKEN_VARIABLE_END: "end of print statement",
|
| 178 |
+
TOKEN_LINESTATEMENT_BEGIN: "begin of line statement",
|
| 179 |
+
TOKEN_LINESTATEMENT_END: "end of line statement",
|
| 180 |
+
TOKEN_DATA: "template data / text",
|
| 181 |
+
TOKEN_EOF: "end of template",
|
| 182 |
+
}.get(token_type, token_type)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def describe_token(token: "Token") -> str:
|
| 186 |
+
"""Returns a description of the token."""
|
| 187 |
+
if token.type == TOKEN_NAME:
|
| 188 |
+
return token.value
|
| 189 |
+
|
| 190 |
+
return _describe_token_type(token.type)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def describe_token_expr(expr: str) -> str:
|
| 194 |
+
"""Like `describe_token` but for token expressions."""
|
| 195 |
+
if ":" in expr:
|
| 196 |
+
type, value = expr.split(":", 1)
|
| 197 |
+
|
| 198 |
+
if type == TOKEN_NAME:
|
| 199 |
+
return value
|
| 200 |
+
else:
|
| 201 |
+
type = expr
|
| 202 |
+
|
| 203 |
+
return _describe_token_type(type)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def count_newlines(value: str) -> int:
|
| 207 |
+
"""Count the number of newline characters in the string. This is
|
| 208 |
+
useful for extensions that filter a stream.
|
| 209 |
+
"""
|
| 210 |
+
return len(newline_re.findall(value))
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def compile_rules(environment: "Environment") -> t.List[t.Tuple[str, str]]:
|
| 214 |
+
"""Compiles all the rules from the environment into a list of rules."""
|
| 215 |
+
e = re.escape
|
| 216 |
+
rules = [
|
| 217 |
+
(
|
| 218 |
+
len(environment.comment_start_string),
|
| 219 |
+
TOKEN_COMMENT_BEGIN,
|
| 220 |
+
e(environment.comment_start_string),
|
| 221 |
+
),
|
| 222 |
+
(
|
| 223 |
+
len(environment.block_start_string),
|
| 224 |
+
TOKEN_BLOCK_BEGIN,
|
| 225 |
+
e(environment.block_start_string),
|
| 226 |
+
),
|
| 227 |
+
(
|
| 228 |
+
len(environment.variable_start_string),
|
| 229 |
+
TOKEN_VARIABLE_BEGIN,
|
| 230 |
+
e(environment.variable_start_string),
|
| 231 |
+
),
|
| 232 |
+
]
|
| 233 |
+
|
| 234 |
+
if environment.line_statement_prefix is not None:
|
| 235 |
+
rules.append(
|
| 236 |
+
(
|
| 237 |
+
len(environment.line_statement_prefix),
|
| 238 |
+
TOKEN_LINESTATEMENT_BEGIN,
|
| 239 |
+
r"^[ \t\v]*" + e(environment.line_statement_prefix),
|
| 240 |
+
)
|
| 241 |
+
)
|
| 242 |
+
if environment.line_comment_prefix is not None:
|
| 243 |
+
rules.append(
|
| 244 |
+
(
|
| 245 |
+
len(environment.line_comment_prefix),
|
| 246 |
+
TOKEN_LINECOMMENT_BEGIN,
|
| 247 |
+
r"(?:^|(?<=\S))[^\S\r\n]*" + e(environment.line_comment_prefix),
|
| 248 |
+
)
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
return [x[1:] for x in sorted(rules, reverse=True)]
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
class Failure:
|
| 255 |
+
"""Class that raises a `TemplateSyntaxError` if called.
|
| 256 |
+
Used by the `Lexer` to specify known errors.
|
| 257 |
+
"""
|
| 258 |
+
|
| 259 |
+
def __init__(
|
| 260 |
+
self, message: str, cls: t.Type[TemplateSyntaxError] = TemplateSyntaxError
|
| 261 |
+
) -> None:
|
| 262 |
+
self.message = message
|
| 263 |
+
self.error_class = cls
|
| 264 |
+
|
| 265 |
+
def __call__(self, lineno: int, filename: t.Optional[str]) -> "te.NoReturn":
|
| 266 |
+
raise self.error_class(self.message, lineno, filename)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
class Token(t.NamedTuple):
|
| 270 |
+
lineno: int
|
| 271 |
+
type: str
|
| 272 |
+
value: str
|
| 273 |
+
|
| 274 |
+
def __str__(self) -> str:
|
| 275 |
+
return describe_token(self)
|
| 276 |
+
|
| 277 |
+
def test(self, expr: str) -> bool:
|
| 278 |
+
"""Test a token against a token expression. This can either be a
|
| 279 |
+
token type or ``'token_type:token_value'``. This can only test
|
| 280 |
+
against string values and types.
|
| 281 |
+
"""
|
| 282 |
+
# here we do a regular string equality check as test_any is usually
|
| 283 |
+
# passed an iterable of not interned strings.
|
| 284 |
+
if self.type == expr:
|
| 285 |
+
return True
|
| 286 |
+
|
| 287 |
+
if ":" in expr:
|
| 288 |
+
return expr.split(":", 1) == [self.type, self.value]
|
| 289 |
+
|
| 290 |
+
return False
|
| 291 |
+
|
| 292 |
+
def test_any(self, *iterable: str) -> bool:
|
| 293 |
+
"""Test against multiple token expressions."""
|
| 294 |
+
return any(self.test(expr) for expr in iterable)
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class TokenStreamIterator:
|
| 298 |
+
"""The iterator for tokenstreams. Iterate over the stream
|
| 299 |
+
until the eof token is reached.
|
| 300 |
+
"""
|
| 301 |
+
|
| 302 |
+
def __init__(self, stream: "TokenStream") -> None:
|
| 303 |
+
self.stream = stream
|
| 304 |
+
|
| 305 |
+
def __iter__(self) -> "TokenStreamIterator":
|
| 306 |
+
return self
|
| 307 |
+
|
| 308 |
+
def __next__(self) -> Token:
|
| 309 |
+
token = self.stream.current
|
| 310 |
+
|
| 311 |
+
if token.type is TOKEN_EOF:
|
| 312 |
+
self.stream.close()
|
| 313 |
+
raise StopIteration
|
| 314 |
+
|
| 315 |
+
next(self.stream)
|
| 316 |
+
return token
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class TokenStream:
|
| 320 |
+
"""A token stream is an iterable that yields :class:`Token`\\s. The
|
| 321 |
+
parser however does not iterate over it but calls :meth:`next` to go
|
| 322 |
+
one token ahead. The current active token is stored as :attr:`current`.
|
| 323 |
+
"""
|
| 324 |
+
|
| 325 |
+
def __init__(
|
| 326 |
+
self,
|
| 327 |
+
generator: t.Iterable[Token],
|
| 328 |
+
name: t.Optional[str],
|
| 329 |
+
filename: t.Optional[str],
|
| 330 |
+
):
|
| 331 |
+
self._iter = iter(generator)
|
| 332 |
+
self._pushed: te.Deque[Token] = deque()
|
| 333 |
+
self.name = name
|
| 334 |
+
self.filename = filename
|
| 335 |
+
self.closed = False
|
| 336 |
+
self.current = Token(1, TOKEN_INITIAL, "")
|
| 337 |
+
next(self)
|
| 338 |
+
|
| 339 |
+
def __iter__(self) -> TokenStreamIterator:
|
| 340 |
+
return TokenStreamIterator(self)
|
| 341 |
+
|
| 342 |
+
def __bool__(self) -> bool:
|
| 343 |
+
return bool(self._pushed) or self.current.type is not TOKEN_EOF
|
| 344 |
+
|
| 345 |
+
@property
|
| 346 |
+
def eos(self) -> bool:
|
| 347 |
+
"""Are we at the end of the stream?"""
|
| 348 |
+
return not self
|
| 349 |
+
|
| 350 |
+
def push(self, token: Token) -> None:
|
| 351 |
+
"""Push a token back to the stream."""
|
| 352 |
+
self._pushed.append(token)
|
| 353 |
+
|
| 354 |
+
def look(self) -> Token:
|
| 355 |
+
"""Look at the next token."""
|
| 356 |
+
old_token = next(self)
|
| 357 |
+
result = self.current
|
| 358 |
+
self.push(result)
|
| 359 |
+
self.current = old_token
|
| 360 |
+
return result
|
| 361 |
+
|
| 362 |
+
def skip(self, n: int = 1) -> None:
|
| 363 |
+
"""Got n tokens ahead."""
|
| 364 |
+
for _ in range(n):
|
| 365 |
+
next(self)
|
| 366 |
+
|
| 367 |
+
def next_if(self, expr: str) -> t.Optional[Token]:
|
| 368 |
+
"""Perform the token test and return the token if it matched.
|
| 369 |
+
Otherwise the return value is `None`.
|
| 370 |
+
"""
|
| 371 |
+
if self.current.test(expr):
|
| 372 |
+
return next(self)
|
| 373 |
+
|
| 374 |
+
return None
|
| 375 |
+
|
| 376 |
+
def skip_if(self, expr: str) -> bool:
|
| 377 |
+
"""Like :meth:`next_if` but only returns `True` or `False`."""
|
| 378 |
+
return self.next_if(expr) is not None
|
| 379 |
+
|
| 380 |
+
def __next__(self) -> Token:
|
| 381 |
+
"""Go one token ahead and return the old one.
|
| 382 |
+
|
| 383 |
+
Use the built-in :func:`next` instead of calling this directly.
|
| 384 |
+
"""
|
| 385 |
+
rv = self.current
|
| 386 |
+
|
| 387 |
+
if self._pushed:
|
| 388 |
+
self.current = self._pushed.popleft()
|
| 389 |
+
elif self.current.type is not TOKEN_EOF:
|
| 390 |
+
try:
|
| 391 |
+
self.current = next(self._iter)
|
| 392 |
+
except StopIteration:
|
| 393 |
+
self.close()
|
| 394 |
+
|
| 395 |
+
return rv
|
| 396 |
+
|
| 397 |
+
def close(self) -> None:
|
| 398 |
+
"""Close the stream."""
|
| 399 |
+
self.current = Token(self.current.lineno, TOKEN_EOF, "")
|
| 400 |
+
self._iter = iter(())
|
| 401 |
+
self.closed = True
|
| 402 |
+
|
| 403 |
+
def expect(self, expr: str) -> Token:
|
| 404 |
+
"""Expect a given token type and return it. This accepts the same
|
| 405 |
+
argument as :meth:`jinja2.lexer.Token.test`.
|
| 406 |
+
"""
|
| 407 |
+
if not self.current.test(expr):
|
| 408 |
+
expr = describe_token_expr(expr)
|
| 409 |
+
|
| 410 |
+
if self.current.type is TOKEN_EOF:
|
| 411 |
+
raise TemplateSyntaxError(
|
| 412 |
+
f"unexpected end of template, expected {expr!r}.",
|
| 413 |
+
self.current.lineno,
|
| 414 |
+
self.name,
|
| 415 |
+
self.filename,
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
raise TemplateSyntaxError(
|
| 419 |
+
f"expected token {expr!r}, got {describe_token(self.current)!r}",
|
| 420 |
+
self.current.lineno,
|
| 421 |
+
self.name,
|
| 422 |
+
self.filename,
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
return next(self)
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
def get_lexer(environment: "Environment") -> "Lexer":
|
| 429 |
+
"""Return a lexer which is probably cached."""
|
| 430 |
+
key = (
|
| 431 |
+
environment.block_start_string,
|
| 432 |
+
environment.block_end_string,
|
| 433 |
+
environment.variable_start_string,
|
| 434 |
+
environment.variable_end_string,
|
| 435 |
+
environment.comment_start_string,
|
| 436 |
+
environment.comment_end_string,
|
| 437 |
+
environment.line_statement_prefix,
|
| 438 |
+
environment.line_comment_prefix,
|
| 439 |
+
environment.trim_blocks,
|
| 440 |
+
environment.lstrip_blocks,
|
| 441 |
+
environment.newline_sequence,
|
| 442 |
+
environment.keep_trailing_newline,
|
| 443 |
+
)
|
| 444 |
+
lexer = _lexer_cache.get(key)
|
| 445 |
+
|
| 446 |
+
if lexer is None:
|
| 447 |
+
_lexer_cache[key] = lexer = Lexer(environment)
|
| 448 |
+
|
| 449 |
+
return lexer
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
class OptionalLStrip(tuple): # type: ignore[type-arg]
|
| 453 |
+
"""A special tuple for marking a point in the state that can have
|
| 454 |
+
lstrip applied.
|
| 455 |
+
"""
|
| 456 |
+
|
| 457 |
+
__slots__ = ()
|
| 458 |
+
|
| 459 |
+
# Even though it looks like a no-op, creating instances fails
|
| 460 |
+
# without this.
|
| 461 |
+
def __new__(cls, *members, **kwargs): # type: ignore
|
| 462 |
+
return super().__new__(cls, members)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
class _Rule(t.NamedTuple):
|
| 466 |
+
pattern: t.Pattern[str]
|
| 467 |
+
tokens: t.Union[str, t.Tuple[str, ...], t.Tuple[Failure]]
|
| 468 |
+
command: t.Optional[str]
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
class Lexer:
|
| 472 |
+
"""Class that implements a lexer for a given environment. Automatically
|
| 473 |
+
created by the environment class, usually you don't have to do that.
|
| 474 |
+
|
| 475 |
+
Note that the lexer is not automatically bound to an environment.
|
| 476 |
+
Multiple environments can share the same lexer.
|
| 477 |
+
"""
|
| 478 |
+
|
| 479 |
+
def __init__(self, environment: "Environment") -> None:
|
| 480 |
+
# shortcuts
|
| 481 |
+
e = re.escape
|
| 482 |
+
|
| 483 |
+
def c(x: str) -> t.Pattern[str]:
|
| 484 |
+
return re.compile(x, re.M | re.S)
|
| 485 |
+
|
| 486 |
+
# lexing rules for tags
|
| 487 |
+
tag_rules: t.List[_Rule] = [
|
| 488 |
+
_Rule(whitespace_re, TOKEN_WHITESPACE, None),
|
| 489 |
+
_Rule(float_re, TOKEN_FLOAT, None),
|
| 490 |
+
_Rule(integer_re, TOKEN_INTEGER, None),
|
| 491 |
+
_Rule(name_re, TOKEN_NAME, None),
|
| 492 |
+
_Rule(string_re, TOKEN_STRING, None),
|
| 493 |
+
_Rule(operator_re, TOKEN_OPERATOR, None),
|
| 494 |
+
]
|
| 495 |
+
|
| 496 |
+
# assemble the root lexing rule. because "|" is ungreedy
|
| 497 |
+
# we have to sort by length so that the lexer continues working
|
| 498 |
+
# as expected when we have parsing rules like <% for block and
|
| 499 |
+
# <%= for variables. (if someone wants asp like syntax)
|
| 500 |
+
# variables are just part of the rules if variable processing
|
| 501 |
+
# is required.
|
| 502 |
+
root_tag_rules = compile_rules(environment)
|
| 503 |
+
|
| 504 |
+
block_start_re = e(environment.block_start_string)
|
| 505 |
+
block_end_re = e(environment.block_end_string)
|
| 506 |
+
comment_end_re = e(environment.comment_end_string)
|
| 507 |
+
variable_end_re = e(environment.variable_end_string)
|
| 508 |
+
|
| 509 |
+
# block suffix if trimming is enabled
|
| 510 |
+
block_suffix_re = "\\n?" if environment.trim_blocks else ""
|
| 511 |
+
|
| 512 |
+
self.lstrip_blocks = environment.lstrip_blocks
|
| 513 |
+
|
| 514 |
+
self.newline_sequence = environment.newline_sequence
|
| 515 |
+
self.keep_trailing_newline = environment.keep_trailing_newline
|
| 516 |
+
|
| 517 |
+
root_raw_re = (
|
| 518 |
+
rf"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*"
|
| 519 |
+
rf"(?:\-{block_end_re}\s*|{block_end_re}))"
|
| 520 |
+
)
|
| 521 |
+
root_parts_re = "|".join(
|
| 522 |
+
[root_raw_re] + [rf"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules]
|
| 523 |
+
)
|
| 524 |
+
|
| 525 |
+
# global lexing rules
|
| 526 |
+
self.rules: t.Dict[str, t.List[_Rule]] = {
|
| 527 |
+
"root": [
|
| 528 |
+
# directives
|
| 529 |
+
_Rule(
|
| 530 |
+
c(rf"(.*?)(?:{root_parts_re})"),
|
| 531 |
+
OptionalLStrip(TOKEN_DATA, "#bygroup"), # type: ignore
|
| 532 |
+
"#bygroup",
|
| 533 |
+
),
|
| 534 |
+
# data
|
| 535 |
+
_Rule(c(".+"), TOKEN_DATA, None),
|
| 536 |
+
],
|
| 537 |
+
# comments
|
| 538 |
+
TOKEN_COMMENT_BEGIN: [
|
| 539 |
+
_Rule(
|
| 540 |
+
c(
|
| 541 |
+
rf"(.*?)((?:\+{comment_end_re}|\-{comment_end_re}\s*"
|
| 542 |
+
rf"|{comment_end_re}{block_suffix_re}))"
|
| 543 |
+
),
|
| 544 |
+
(TOKEN_COMMENT, TOKEN_COMMENT_END),
|
| 545 |
+
"#pop",
|
| 546 |
+
),
|
| 547 |
+
_Rule(c(r"(.)"), (Failure("Missing end of comment tag"),), None),
|
| 548 |
+
],
|
| 549 |
+
# blocks
|
| 550 |
+
TOKEN_BLOCK_BEGIN: [
|
| 551 |
+
_Rule(
|
| 552 |
+
c(
|
| 553 |
+
rf"(?:\+{block_end_re}|\-{block_end_re}\s*"
|
| 554 |
+
rf"|{block_end_re}{block_suffix_re})"
|
| 555 |
+
),
|
| 556 |
+
TOKEN_BLOCK_END,
|
| 557 |
+
"#pop",
|
| 558 |
+
),
|
| 559 |
+
]
|
| 560 |
+
+ tag_rules,
|
| 561 |
+
# variables
|
| 562 |
+
TOKEN_VARIABLE_BEGIN: [
|
| 563 |
+
_Rule(
|
| 564 |
+
c(rf"\-{variable_end_re}\s*|{variable_end_re}"),
|
| 565 |
+
TOKEN_VARIABLE_END,
|
| 566 |
+
"#pop",
|
| 567 |
+
)
|
| 568 |
+
]
|
| 569 |
+
+ tag_rules,
|
| 570 |
+
# raw block
|
| 571 |
+
TOKEN_RAW_BEGIN: [
|
| 572 |
+
_Rule(
|
| 573 |
+
c(
|
| 574 |
+
rf"(.*?)((?:{block_start_re}(\-|\+|))\s*endraw\s*"
|
| 575 |
+
rf"(?:\+{block_end_re}|\-{block_end_re}\s*"
|
| 576 |
+
rf"|{block_end_re}{block_suffix_re}))"
|
| 577 |
+
),
|
| 578 |
+
OptionalLStrip(TOKEN_DATA, TOKEN_RAW_END), # type: ignore
|
| 579 |
+
"#pop",
|
| 580 |
+
),
|
| 581 |
+
_Rule(c(r"(.)"), (Failure("Missing end of raw directive"),), None),
|
| 582 |
+
],
|
| 583 |
+
# line statements
|
| 584 |
+
TOKEN_LINESTATEMENT_BEGIN: [
|
| 585 |
+
_Rule(c(r"\s*(\n|$)"), TOKEN_LINESTATEMENT_END, "#pop")
|
| 586 |
+
]
|
| 587 |
+
+ tag_rules,
|
| 588 |
+
# line comments
|
| 589 |
+
TOKEN_LINECOMMENT_BEGIN: [
|
| 590 |
+
_Rule(
|
| 591 |
+
c(r"(.*?)()(?=\n|$)"),
|
| 592 |
+
(TOKEN_LINECOMMENT, TOKEN_LINECOMMENT_END),
|
| 593 |
+
"#pop",
|
| 594 |
+
)
|
| 595 |
+
],
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
def _normalize_newlines(self, value: str) -> str:
|
| 599 |
+
"""Replace all newlines with the configured sequence in strings
|
| 600 |
+
and template data.
|
| 601 |
+
"""
|
| 602 |
+
return newline_re.sub(self.newline_sequence, value)
|
| 603 |
+
|
| 604 |
+
def tokenize(
|
| 605 |
+
self,
|
| 606 |
+
source: str,
|
| 607 |
+
name: t.Optional[str] = None,
|
| 608 |
+
filename: t.Optional[str] = None,
|
| 609 |
+
state: t.Optional[str] = None,
|
| 610 |
+
) -> TokenStream:
|
| 611 |
+
"""Calls tokeniter + tokenize and wraps it in a token stream."""
|
| 612 |
+
stream = self.tokeniter(source, name, filename, state)
|
| 613 |
+
return TokenStream(self.wrap(stream, name, filename), name, filename)
|
| 614 |
+
|
| 615 |
+
def wrap(
|
| 616 |
+
self,
|
| 617 |
+
stream: t.Iterable[t.Tuple[int, str, str]],
|
| 618 |
+
name: t.Optional[str] = None,
|
| 619 |
+
filename: t.Optional[str] = None,
|
| 620 |
+
) -> t.Iterator[Token]:
|
| 621 |
+
"""This is called with the stream as returned by `tokenize` and wraps
|
| 622 |
+
every token in a :class:`Token` and converts the value.
|
| 623 |
+
"""
|
| 624 |
+
for lineno, token, value_str in stream:
|
| 625 |
+
if token in ignored_tokens:
|
| 626 |
+
continue
|
| 627 |
+
|
| 628 |
+
value: t.Any = value_str
|
| 629 |
+
|
| 630 |
+
if token == TOKEN_LINESTATEMENT_BEGIN:
|
| 631 |
+
token = TOKEN_BLOCK_BEGIN
|
| 632 |
+
elif token == TOKEN_LINESTATEMENT_END:
|
| 633 |
+
token = TOKEN_BLOCK_END
|
| 634 |
+
# we are not interested in those tokens in the parser
|
| 635 |
+
elif token in (TOKEN_RAW_BEGIN, TOKEN_RAW_END):
|
| 636 |
+
continue
|
| 637 |
+
elif token == TOKEN_DATA:
|
| 638 |
+
value = self._normalize_newlines(value_str)
|
| 639 |
+
elif token == "keyword":
|
| 640 |
+
token = value_str
|
| 641 |
+
elif token == TOKEN_NAME:
|
| 642 |
+
value = value_str
|
| 643 |
+
|
| 644 |
+
if not value.isidentifier():
|
| 645 |
+
raise TemplateSyntaxError(
|
| 646 |
+
"Invalid character in identifier", lineno, name, filename
|
| 647 |
+
)
|
| 648 |
+
elif token == TOKEN_STRING:
|
| 649 |
+
# try to unescape string
|
| 650 |
+
try:
|
| 651 |
+
value = (
|
| 652 |
+
self._normalize_newlines(value_str[1:-1])
|
| 653 |
+
.encode("ascii", "backslashreplace")
|
| 654 |
+
.decode("unicode-escape")
|
| 655 |
+
)
|
| 656 |
+
except Exception as e:
|
| 657 |
+
msg = str(e).split(":")[-1].strip()
|
| 658 |
+
raise TemplateSyntaxError(msg, lineno, name, filename) from e
|
| 659 |
+
elif token == TOKEN_INTEGER:
|
| 660 |
+
value = int(value_str.replace("_", ""), 0)
|
| 661 |
+
elif token == TOKEN_FLOAT:
|
| 662 |
+
# remove all "_" first to support more Python versions
|
| 663 |
+
value = literal_eval(value_str.replace("_", ""))
|
| 664 |
+
elif token == TOKEN_OPERATOR:
|
| 665 |
+
token = operators[value_str]
|
| 666 |
+
|
| 667 |
+
yield Token(lineno, token, value)
|
| 668 |
+
|
| 669 |
+
def tokeniter(
|
| 670 |
+
self,
|
| 671 |
+
source: str,
|
| 672 |
+
name: t.Optional[str],
|
| 673 |
+
filename: t.Optional[str] = None,
|
| 674 |
+
state: t.Optional[str] = None,
|
| 675 |
+
) -> t.Iterator[t.Tuple[int, str, str]]:
|
| 676 |
+
"""This method tokenizes the text and returns the tokens in a
|
| 677 |
+
generator. Use this method if you just want to tokenize a template.
|
| 678 |
+
|
| 679 |
+
.. versionchanged:: 3.0
|
| 680 |
+
Only ``\\n``, ``\\r\\n`` and ``\\r`` are treated as line
|
| 681 |
+
breaks.
|
| 682 |
+
"""
|
| 683 |
+
lines = newline_re.split(source)[::2]
|
| 684 |
+
|
| 685 |
+
if not self.keep_trailing_newline and lines[-1] == "":
|
| 686 |
+
del lines[-1]
|
| 687 |
+
|
| 688 |
+
source = "\n".join(lines)
|
| 689 |
+
pos = 0
|
| 690 |
+
lineno = 1
|
| 691 |
+
stack = ["root"]
|
| 692 |
+
|
| 693 |
+
if state is not None and state != "root":
|
| 694 |
+
assert state in ("variable", "block"), "invalid state"
|
| 695 |
+
stack.append(state + "_begin")
|
| 696 |
+
|
| 697 |
+
statetokens = self.rules[stack[-1]]
|
| 698 |
+
source_length = len(source)
|
| 699 |
+
balancing_stack: t.List[str] = []
|
| 700 |
+
newlines_stripped = 0
|
| 701 |
+
line_starting = True
|
| 702 |
+
|
| 703 |
+
while True:
|
| 704 |
+
# tokenizer loop
|
| 705 |
+
for regex, tokens, new_state in statetokens:
|
| 706 |
+
m = regex.match(source, pos)
|
| 707 |
+
|
| 708 |
+
# if no match we try again with the next rule
|
| 709 |
+
if m is None:
|
| 710 |
+
continue
|
| 711 |
+
|
| 712 |
+
# we only match blocks and variables if braces / parentheses
|
| 713 |
+
# are balanced. continue parsing with the lower rule which
|
| 714 |
+
# is the operator rule. do this only if the end tags look
|
| 715 |
+
# like operators
|
| 716 |
+
if balancing_stack and tokens in (
|
| 717 |
+
TOKEN_VARIABLE_END,
|
| 718 |
+
TOKEN_BLOCK_END,
|
| 719 |
+
TOKEN_LINESTATEMENT_END,
|
| 720 |
+
):
|
| 721 |
+
continue
|
| 722 |
+
|
| 723 |
+
# tuples support more options
|
| 724 |
+
if isinstance(tokens, tuple):
|
| 725 |
+
groups: t.Sequence[str] = m.groups()
|
| 726 |
+
|
| 727 |
+
if isinstance(tokens, OptionalLStrip):
|
| 728 |
+
# Rule supports lstrip. Match will look like
|
| 729 |
+
# text, block type, whitespace control, type, control, ...
|
| 730 |
+
text = groups[0]
|
| 731 |
+
# Skipping the text and first type, every other group is the
|
| 732 |
+
# whitespace control for each type. One of the groups will be
|
| 733 |
+
# -, +, or empty string instead of None.
|
| 734 |
+
strip_sign = next(g for g in groups[2::2] if g is not None)
|
| 735 |
+
|
| 736 |
+
if strip_sign == "-":
|
| 737 |
+
# Strip all whitespace between the text and the tag.
|
| 738 |
+
stripped = text.rstrip()
|
| 739 |
+
newlines_stripped = text[len(stripped) :].count("\n")
|
| 740 |
+
groups = [stripped, *groups[1:]]
|
| 741 |
+
elif (
|
| 742 |
+
# Not marked for preserving whitespace.
|
| 743 |
+
strip_sign != "+"
|
| 744 |
+
# lstrip is enabled.
|
| 745 |
+
and self.lstrip_blocks
|
| 746 |
+
# Not a variable expression.
|
| 747 |
+
and not m.groupdict().get(TOKEN_VARIABLE_BEGIN)
|
| 748 |
+
):
|
| 749 |
+
# The start of text between the last newline and the tag.
|
| 750 |
+
l_pos = text.rfind("\n") + 1
|
| 751 |
+
|
| 752 |
+
if l_pos > 0 or line_starting:
|
| 753 |
+
# If there's only whitespace between the newline and the
|
| 754 |
+
# tag, strip it.
|
| 755 |
+
if whitespace_re.fullmatch(text, l_pos):
|
| 756 |
+
groups = [text[:l_pos], *groups[1:]]
|
| 757 |
+
|
| 758 |
+
for idx, token in enumerate(tokens):
|
| 759 |
+
# failure group
|
| 760 |
+
if isinstance(token, Failure):
|
| 761 |
+
raise token(lineno, filename)
|
| 762 |
+
# bygroup is a bit more complex, in that case we
|
| 763 |
+
# yield for the current token the first named
|
| 764 |
+
# group that matched
|
| 765 |
+
elif token == "#bygroup":
|
| 766 |
+
for key, value in m.groupdict().items():
|
| 767 |
+
if value is not None:
|
| 768 |
+
yield lineno, key, value
|
| 769 |
+
lineno += value.count("\n")
|
| 770 |
+
break
|
| 771 |
+
else:
|
| 772 |
+
raise RuntimeError(
|
| 773 |
+
f"{regex!r} wanted to resolve the token dynamically"
|
| 774 |
+
" but no group matched"
|
| 775 |
+
)
|
| 776 |
+
# normal group
|
| 777 |
+
else:
|
| 778 |
+
data = groups[idx]
|
| 779 |
+
|
| 780 |
+
if data or token not in ignore_if_empty:
|
| 781 |
+
yield lineno, token, data # type: ignore[misc]
|
| 782 |
+
|
| 783 |
+
lineno += data.count("\n") + newlines_stripped
|
| 784 |
+
newlines_stripped = 0
|
| 785 |
+
|
| 786 |
+
# strings as token just are yielded as it.
|
| 787 |
+
else:
|
| 788 |
+
data = m.group()
|
| 789 |
+
|
| 790 |
+
# update brace/parentheses balance
|
| 791 |
+
if tokens == TOKEN_OPERATOR:
|
| 792 |
+
if data == "{":
|
| 793 |
+
balancing_stack.append("}")
|
| 794 |
+
elif data == "(":
|
| 795 |
+
balancing_stack.append(")")
|
| 796 |
+
elif data == "[":
|
| 797 |
+
balancing_stack.append("]")
|
| 798 |
+
elif data in ("}", ")", "]"):
|
| 799 |
+
if not balancing_stack:
|
| 800 |
+
raise TemplateSyntaxError(
|
| 801 |
+
f"unexpected '{data}'", lineno, name, filename
|
| 802 |
+
)
|
| 803 |
+
|
| 804 |
+
expected_op = balancing_stack.pop()
|
| 805 |
+
|
| 806 |
+
if expected_op != data:
|
| 807 |
+
raise TemplateSyntaxError(
|
| 808 |
+
f"unexpected '{data}', expected '{expected_op}'",
|
| 809 |
+
lineno,
|
| 810 |
+
name,
|
| 811 |
+
filename,
|
| 812 |
+
)
|
| 813 |
+
|
| 814 |
+
# yield items
|
| 815 |
+
if data or tokens not in ignore_if_empty:
|
| 816 |
+
yield lineno, tokens, data
|
| 817 |
+
|
| 818 |
+
lineno += data.count("\n")
|
| 819 |
+
|
| 820 |
+
line_starting = m.group()[-1:] == "\n"
|
| 821 |
+
# fetch new position into new variable so that we can check
|
| 822 |
+
# if there is a internal parsing error which would result
|
| 823 |
+
# in an infinite loop
|
| 824 |
+
pos2 = m.end()
|
| 825 |
+
|
| 826 |
+
# handle state changes
|
| 827 |
+
if new_state is not None:
|
| 828 |
+
# remove the uppermost state
|
| 829 |
+
if new_state == "#pop":
|
| 830 |
+
stack.pop()
|
| 831 |
+
# resolve the new state by group checking
|
| 832 |
+
elif new_state == "#bygroup":
|
| 833 |
+
for key, value in m.groupdict().items():
|
| 834 |
+
if value is not None:
|
| 835 |
+
stack.append(key)
|
| 836 |
+
break
|
| 837 |
+
else:
|
| 838 |
+
raise RuntimeError(
|
| 839 |
+
f"{regex!r} wanted to resolve the new state dynamically"
|
| 840 |
+
f" but no group matched"
|
| 841 |
+
)
|
| 842 |
+
# direct state name given
|
| 843 |
+
else:
|
| 844 |
+
stack.append(new_state)
|
| 845 |
+
|
| 846 |
+
statetokens = self.rules[stack[-1]]
|
| 847 |
+
# we are still at the same position and no stack change.
|
| 848 |
+
# this means a loop without break condition, avoid that and
|
| 849 |
+
# raise error
|
| 850 |
+
elif pos2 == pos:
|
| 851 |
+
raise RuntimeError(
|
| 852 |
+
f"{regex!r} yielded empty string without stack change"
|
| 853 |
+
)
|
| 854 |
+
|
| 855 |
+
# publish new function and start again
|
| 856 |
+
pos = pos2
|
| 857 |
+
break
|
| 858 |
+
# if loop terminated without break we haven't found a single match
|
| 859 |
+
# either we are at the end of the file or we have a problem
|
| 860 |
+
else:
|
| 861 |
+
# end of text
|
| 862 |
+
if pos >= source_length:
|
| 863 |
+
return
|
| 864 |
+
|
| 865 |
+
# something went wrong
|
| 866 |
+
raise TemplateSyntaxError(
|
| 867 |
+
f"unexpected char {source[pos]!r} at {pos}", lineno, name, filename
|
| 868 |
+
)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/loaders.py
ADDED
|
@@ -0,0 +1,693 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""API and implementations for loading templates from different data
|
| 2 |
+
sources.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import importlib.util
|
| 6 |
+
import os
|
| 7 |
+
import posixpath
|
| 8 |
+
import sys
|
| 9 |
+
import typing as t
|
| 10 |
+
import weakref
|
| 11 |
+
import zipimport
|
| 12 |
+
from collections import abc
|
| 13 |
+
from hashlib import sha1
|
| 14 |
+
from importlib import import_module
|
| 15 |
+
from types import ModuleType
|
| 16 |
+
|
| 17 |
+
from .exceptions import TemplateNotFound
|
| 18 |
+
from .utils import internalcode
|
| 19 |
+
|
| 20 |
+
if t.TYPE_CHECKING:
|
| 21 |
+
from .environment import Environment
|
| 22 |
+
from .environment import Template
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def split_template_path(template: str) -> t.List[str]:
|
| 26 |
+
"""Split a path into segments and perform a sanity check. If it detects
|
| 27 |
+
'..' in the path it will raise a `TemplateNotFound` error.
|
| 28 |
+
"""
|
| 29 |
+
pieces = []
|
| 30 |
+
for piece in template.split("/"):
|
| 31 |
+
if (
|
| 32 |
+
os.path.sep in piece
|
| 33 |
+
or (os.path.altsep and os.path.altsep in piece)
|
| 34 |
+
or piece == os.path.pardir
|
| 35 |
+
):
|
| 36 |
+
raise TemplateNotFound(template)
|
| 37 |
+
elif piece and piece != ".":
|
| 38 |
+
pieces.append(piece)
|
| 39 |
+
return pieces
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class BaseLoader:
|
| 43 |
+
"""Baseclass for all loaders. Subclass this and override `get_source` to
|
| 44 |
+
implement a custom loading mechanism. The environment provides a
|
| 45 |
+
`get_template` method that calls the loader's `load` method to get the
|
| 46 |
+
:class:`Template` object.
|
| 47 |
+
|
| 48 |
+
A very basic example for a loader that looks up templates on the file
|
| 49 |
+
system could look like this::
|
| 50 |
+
|
| 51 |
+
from jinja2 import BaseLoader, TemplateNotFound
|
| 52 |
+
from os.path import join, exists, getmtime
|
| 53 |
+
|
| 54 |
+
class MyLoader(BaseLoader):
|
| 55 |
+
|
| 56 |
+
def __init__(self, path):
|
| 57 |
+
self.path = path
|
| 58 |
+
|
| 59 |
+
def get_source(self, environment, template):
|
| 60 |
+
path = join(self.path, template)
|
| 61 |
+
if not exists(path):
|
| 62 |
+
raise TemplateNotFound(template)
|
| 63 |
+
mtime = getmtime(path)
|
| 64 |
+
with open(path) as f:
|
| 65 |
+
source = f.read()
|
| 66 |
+
return source, path, lambda: mtime == getmtime(path)
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
#: if set to `False` it indicates that the loader cannot provide access
|
| 70 |
+
#: to the source of templates.
|
| 71 |
+
#:
|
| 72 |
+
#: .. versionadded:: 2.4
|
| 73 |
+
has_source_access = True
|
| 74 |
+
|
| 75 |
+
def get_source(
|
| 76 |
+
self, environment: "Environment", template: str
|
| 77 |
+
) -> t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]:
|
| 78 |
+
"""Get the template source, filename and reload helper for a template.
|
| 79 |
+
It's passed the environment and template name and has to return a
|
| 80 |
+
tuple in the form ``(source, filename, uptodate)`` or raise a
|
| 81 |
+
`TemplateNotFound` error if it can't locate the template.
|
| 82 |
+
|
| 83 |
+
The source part of the returned tuple must be the source of the
|
| 84 |
+
template as a string. The filename should be the name of the
|
| 85 |
+
file on the filesystem if it was loaded from there, otherwise
|
| 86 |
+
``None``. The filename is used by Python for the tracebacks
|
| 87 |
+
if no loader extension is used.
|
| 88 |
+
|
| 89 |
+
The last item in the tuple is the `uptodate` function. If auto
|
| 90 |
+
reloading is enabled it's always called to check if the template
|
| 91 |
+
changed. No arguments are passed so the function must store the
|
| 92 |
+
old state somewhere (for example in a closure). If it returns `False`
|
| 93 |
+
the template will be reloaded.
|
| 94 |
+
"""
|
| 95 |
+
if not self.has_source_access:
|
| 96 |
+
raise RuntimeError(
|
| 97 |
+
f"{type(self).__name__} cannot provide access to the source"
|
| 98 |
+
)
|
| 99 |
+
raise TemplateNotFound(template)
|
| 100 |
+
|
| 101 |
+
def list_templates(self) -> t.List[str]:
|
| 102 |
+
"""Iterates over all templates. If the loader does not support that
|
| 103 |
+
it should raise a :exc:`TypeError` which is the default behavior.
|
| 104 |
+
"""
|
| 105 |
+
raise TypeError("this loader cannot iterate over all templates")
|
| 106 |
+
|
| 107 |
+
@internalcode
|
| 108 |
+
def load(
|
| 109 |
+
self,
|
| 110 |
+
environment: "Environment",
|
| 111 |
+
name: str,
|
| 112 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 113 |
+
) -> "Template":
|
| 114 |
+
"""Loads a template. This method looks up the template in the cache
|
| 115 |
+
or loads one by calling :meth:`get_source`. Subclasses should not
|
| 116 |
+
override this method as loaders working on collections of other
|
| 117 |
+
loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`)
|
| 118 |
+
will not call this method but `get_source` directly.
|
| 119 |
+
"""
|
| 120 |
+
code = None
|
| 121 |
+
if globals is None:
|
| 122 |
+
globals = {}
|
| 123 |
+
|
| 124 |
+
# first we try to get the source for this template together
|
| 125 |
+
# with the filename and the uptodate function.
|
| 126 |
+
source, filename, uptodate = self.get_source(environment, name)
|
| 127 |
+
|
| 128 |
+
# try to load the code from the bytecode cache if there is a
|
| 129 |
+
# bytecode cache configured.
|
| 130 |
+
bcc = environment.bytecode_cache
|
| 131 |
+
if bcc is not None:
|
| 132 |
+
bucket = bcc.get_bucket(environment, name, filename, source)
|
| 133 |
+
code = bucket.code
|
| 134 |
+
|
| 135 |
+
# if we don't have code so far (not cached, no longer up to
|
| 136 |
+
# date) etc. we compile the template
|
| 137 |
+
if code is None:
|
| 138 |
+
code = environment.compile(source, name, filename)
|
| 139 |
+
|
| 140 |
+
# if the bytecode cache is available and the bucket doesn't
|
| 141 |
+
# have a code so far, we give the bucket the new code and put
|
| 142 |
+
# it back to the bytecode cache.
|
| 143 |
+
if bcc is not None and bucket.code is None:
|
| 144 |
+
bucket.code = code
|
| 145 |
+
bcc.set_bucket(bucket)
|
| 146 |
+
|
| 147 |
+
return environment.template_class.from_code(
|
| 148 |
+
environment, code, globals, uptodate
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
class FileSystemLoader(BaseLoader):
|
| 153 |
+
"""Load templates from a directory in the file system.
|
| 154 |
+
|
| 155 |
+
The path can be relative or absolute. Relative paths are relative to
|
| 156 |
+
the current working directory.
|
| 157 |
+
|
| 158 |
+
.. code-block:: python
|
| 159 |
+
|
| 160 |
+
loader = FileSystemLoader("templates")
|
| 161 |
+
|
| 162 |
+
A list of paths can be given. The directories will be searched in
|
| 163 |
+
order, stopping at the first matching template.
|
| 164 |
+
|
| 165 |
+
.. code-block:: python
|
| 166 |
+
|
| 167 |
+
loader = FileSystemLoader(["/override/templates", "/default/templates"])
|
| 168 |
+
|
| 169 |
+
:param searchpath: A path, or list of paths, to the directory that
|
| 170 |
+
contains the templates.
|
| 171 |
+
:param encoding: Use this encoding to read the text from template
|
| 172 |
+
files.
|
| 173 |
+
:param followlinks: Follow symbolic links in the path.
|
| 174 |
+
|
| 175 |
+
.. versionchanged:: 2.8
|
| 176 |
+
Added the ``followlinks`` parameter.
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
def __init__(
|
| 180 |
+
self,
|
| 181 |
+
searchpath: t.Union[
|
| 182 |
+
str, "os.PathLike[str]", t.Sequence[t.Union[str, "os.PathLike[str]"]]
|
| 183 |
+
],
|
| 184 |
+
encoding: str = "utf-8",
|
| 185 |
+
followlinks: bool = False,
|
| 186 |
+
) -> None:
|
| 187 |
+
if not isinstance(searchpath, abc.Iterable) or isinstance(searchpath, str):
|
| 188 |
+
searchpath = [searchpath]
|
| 189 |
+
|
| 190 |
+
self.searchpath = [os.fspath(p) for p in searchpath]
|
| 191 |
+
self.encoding = encoding
|
| 192 |
+
self.followlinks = followlinks
|
| 193 |
+
|
| 194 |
+
def get_source(
|
| 195 |
+
self, environment: "Environment", template: str
|
| 196 |
+
) -> t.Tuple[str, str, t.Callable[[], bool]]:
|
| 197 |
+
pieces = split_template_path(template)
|
| 198 |
+
|
| 199 |
+
for searchpath in self.searchpath:
|
| 200 |
+
# Use posixpath even on Windows to avoid "drive:" or UNC
|
| 201 |
+
# segments breaking out of the search directory.
|
| 202 |
+
filename = posixpath.join(searchpath, *pieces)
|
| 203 |
+
|
| 204 |
+
if os.path.isfile(filename):
|
| 205 |
+
break
|
| 206 |
+
else:
|
| 207 |
+
plural = "path" if len(self.searchpath) == 1 else "paths"
|
| 208 |
+
paths_str = ", ".join(repr(p) for p in self.searchpath)
|
| 209 |
+
raise TemplateNotFound(
|
| 210 |
+
template,
|
| 211 |
+
f"{template!r} not found in search {plural}: {paths_str}",
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
with open(filename, encoding=self.encoding) as f:
|
| 215 |
+
contents = f.read()
|
| 216 |
+
|
| 217 |
+
mtime = os.path.getmtime(filename)
|
| 218 |
+
|
| 219 |
+
def uptodate() -> bool:
|
| 220 |
+
try:
|
| 221 |
+
return os.path.getmtime(filename) == mtime
|
| 222 |
+
except OSError:
|
| 223 |
+
return False
|
| 224 |
+
|
| 225 |
+
# Use normpath to convert Windows altsep to sep.
|
| 226 |
+
return contents, os.path.normpath(filename), uptodate
|
| 227 |
+
|
| 228 |
+
def list_templates(self) -> t.List[str]:
|
| 229 |
+
found = set()
|
| 230 |
+
for searchpath in self.searchpath:
|
| 231 |
+
walk_dir = os.walk(searchpath, followlinks=self.followlinks)
|
| 232 |
+
for dirpath, _, filenames in walk_dir:
|
| 233 |
+
for filename in filenames:
|
| 234 |
+
template = (
|
| 235 |
+
os.path.join(dirpath, filename)[len(searchpath) :]
|
| 236 |
+
.strip(os.path.sep)
|
| 237 |
+
.replace(os.path.sep, "/")
|
| 238 |
+
)
|
| 239 |
+
if template[:2] == "./":
|
| 240 |
+
template = template[2:]
|
| 241 |
+
if template not in found:
|
| 242 |
+
found.add(template)
|
| 243 |
+
return sorted(found)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
if sys.version_info >= (3, 13):
|
| 247 |
+
|
| 248 |
+
def _get_zipimporter_files(z: t.Any) -> t.Dict[str, object]:
|
| 249 |
+
try:
|
| 250 |
+
get_files = z._get_files
|
| 251 |
+
except AttributeError as e:
|
| 252 |
+
raise TypeError(
|
| 253 |
+
"This zip import does not have the required"
|
| 254 |
+
" metadata to list templates."
|
| 255 |
+
) from e
|
| 256 |
+
return get_files()
|
| 257 |
+
else:
|
| 258 |
+
|
| 259 |
+
def _get_zipimporter_files(z: t.Any) -> t.Dict[str, object]:
|
| 260 |
+
try:
|
| 261 |
+
files = z._files
|
| 262 |
+
except AttributeError as e:
|
| 263 |
+
raise TypeError(
|
| 264 |
+
"This zip import does not have the required"
|
| 265 |
+
" metadata to list templates."
|
| 266 |
+
) from e
|
| 267 |
+
return files # type: ignore[no-any-return]
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
class PackageLoader(BaseLoader):
|
| 271 |
+
"""Load templates from a directory in a Python package.
|
| 272 |
+
|
| 273 |
+
:param package_name: Import name of the package that contains the
|
| 274 |
+
template directory.
|
| 275 |
+
:param package_path: Directory within the imported package that
|
| 276 |
+
contains the templates.
|
| 277 |
+
:param encoding: Encoding of template files.
|
| 278 |
+
|
| 279 |
+
The following example looks up templates in the ``pages`` directory
|
| 280 |
+
within the ``project.ui`` package.
|
| 281 |
+
|
| 282 |
+
.. code-block:: python
|
| 283 |
+
|
| 284 |
+
loader = PackageLoader("project.ui", "pages")
|
| 285 |
+
|
| 286 |
+
Only packages installed as directories (standard pip behavior) or
|
| 287 |
+
zip/egg files (less common) are supported. The Python API for
|
| 288 |
+
introspecting data in packages is too limited to support other
|
| 289 |
+
installation methods the way this loader requires.
|
| 290 |
+
|
| 291 |
+
There is limited support for :pep:`420` namespace packages. The
|
| 292 |
+
template directory is assumed to only be in one namespace
|
| 293 |
+
contributor. Zip files contributing to a namespace are not
|
| 294 |
+
supported.
|
| 295 |
+
|
| 296 |
+
.. versionchanged:: 3.0
|
| 297 |
+
No longer uses ``setuptools`` as a dependency.
|
| 298 |
+
|
| 299 |
+
.. versionchanged:: 3.0
|
| 300 |
+
Limited PEP 420 namespace package support.
|
| 301 |
+
"""
|
| 302 |
+
|
| 303 |
+
def __init__(
|
| 304 |
+
self,
|
| 305 |
+
package_name: str,
|
| 306 |
+
package_path: "str" = "templates",
|
| 307 |
+
encoding: str = "utf-8",
|
| 308 |
+
) -> None:
|
| 309 |
+
package_path = os.path.normpath(package_path).rstrip(os.path.sep)
|
| 310 |
+
|
| 311 |
+
# normpath preserves ".", which isn't valid in zip paths.
|
| 312 |
+
if package_path == os.path.curdir:
|
| 313 |
+
package_path = ""
|
| 314 |
+
elif package_path[:2] == os.path.curdir + os.path.sep:
|
| 315 |
+
package_path = package_path[2:]
|
| 316 |
+
|
| 317 |
+
self.package_path = package_path
|
| 318 |
+
self.package_name = package_name
|
| 319 |
+
self.encoding = encoding
|
| 320 |
+
|
| 321 |
+
# Make sure the package exists. This also makes namespace
|
| 322 |
+
# packages work, otherwise get_loader returns None.
|
| 323 |
+
import_module(package_name)
|
| 324 |
+
spec = importlib.util.find_spec(package_name)
|
| 325 |
+
assert spec is not None, "An import spec was not found for the package."
|
| 326 |
+
loader = spec.loader
|
| 327 |
+
assert loader is not None, "A loader was not found for the package."
|
| 328 |
+
self._loader = loader
|
| 329 |
+
self._archive = None
|
| 330 |
+
|
| 331 |
+
if isinstance(loader, zipimport.zipimporter):
|
| 332 |
+
self._archive = loader.archive
|
| 333 |
+
pkgdir = next(iter(spec.submodule_search_locations)) # type: ignore
|
| 334 |
+
template_root = os.path.join(pkgdir, package_path).rstrip(os.path.sep)
|
| 335 |
+
else:
|
| 336 |
+
roots: t.List[str] = []
|
| 337 |
+
|
| 338 |
+
# One element for regular packages, multiple for namespace
|
| 339 |
+
# packages, or None for single module file.
|
| 340 |
+
if spec.submodule_search_locations:
|
| 341 |
+
roots.extend(spec.submodule_search_locations)
|
| 342 |
+
# A single module file, use the parent directory instead.
|
| 343 |
+
elif spec.origin is not None:
|
| 344 |
+
roots.append(os.path.dirname(spec.origin))
|
| 345 |
+
|
| 346 |
+
if not roots:
|
| 347 |
+
raise ValueError(
|
| 348 |
+
f"The {package_name!r} package was not installed in a"
|
| 349 |
+
" way that PackageLoader understands."
|
| 350 |
+
)
|
| 351 |
+
|
| 352 |
+
for root in roots:
|
| 353 |
+
root = os.path.join(root, package_path)
|
| 354 |
+
|
| 355 |
+
if os.path.isdir(root):
|
| 356 |
+
template_root = root
|
| 357 |
+
break
|
| 358 |
+
else:
|
| 359 |
+
raise ValueError(
|
| 360 |
+
f"PackageLoader could not find a {package_path!r} directory"
|
| 361 |
+
f" in the {package_name!r} package."
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
self._template_root = template_root
|
| 365 |
+
|
| 366 |
+
def get_source(
|
| 367 |
+
self, environment: "Environment", template: str
|
| 368 |
+
) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]:
|
| 369 |
+
# Use posixpath even on Windows to avoid "drive:" or UNC
|
| 370 |
+
# segments breaking out of the search directory. Use normpath to
|
| 371 |
+
# convert Windows altsep to sep.
|
| 372 |
+
p = os.path.normpath(
|
| 373 |
+
posixpath.join(self._template_root, *split_template_path(template))
|
| 374 |
+
)
|
| 375 |
+
up_to_date: t.Optional[t.Callable[[], bool]]
|
| 376 |
+
|
| 377 |
+
if self._archive is None:
|
| 378 |
+
# Package is a directory.
|
| 379 |
+
if not os.path.isfile(p):
|
| 380 |
+
raise TemplateNotFound(template)
|
| 381 |
+
|
| 382 |
+
with open(p, "rb") as f:
|
| 383 |
+
source = f.read()
|
| 384 |
+
|
| 385 |
+
mtime = os.path.getmtime(p)
|
| 386 |
+
|
| 387 |
+
def up_to_date() -> bool:
|
| 388 |
+
return os.path.isfile(p) and os.path.getmtime(p) == mtime
|
| 389 |
+
|
| 390 |
+
else:
|
| 391 |
+
# Package is a zip file.
|
| 392 |
+
try:
|
| 393 |
+
source = self._loader.get_data(p) # type: ignore
|
| 394 |
+
except OSError as e:
|
| 395 |
+
raise TemplateNotFound(template) from e
|
| 396 |
+
|
| 397 |
+
# Could use the zip's mtime for all template mtimes, but
|
| 398 |
+
# would need to safely reload the module if it's out of
|
| 399 |
+
# date, so just report it as always current.
|
| 400 |
+
up_to_date = None
|
| 401 |
+
|
| 402 |
+
return source.decode(self.encoding), p, up_to_date
|
| 403 |
+
|
| 404 |
+
def list_templates(self) -> t.List[str]:
|
| 405 |
+
results: t.List[str] = []
|
| 406 |
+
|
| 407 |
+
if self._archive is None:
|
| 408 |
+
# Package is a directory.
|
| 409 |
+
offset = len(self._template_root)
|
| 410 |
+
|
| 411 |
+
for dirpath, _, filenames in os.walk(self._template_root):
|
| 412 |
+
dirpath = dirpath[offset:].lstrip(os.path.sep)
|
| 413 |
+
results.extend(
|
| 414 |
+
os.path.join(dirpath, name).replace(os.path.sep, "/")
|
| 415 |
+
for name in filenames
|
| 416 |
+
)
|
| 417 |
+
else:
|
| 418 |
+
files = _get_zipimporter_files(self._loader)
|
| 419 |
+
|
| 420 |
+
# Package is a zip file.
|
| 421 |
+
prefix = (
|
| 422 |
+
self._template_root[len(self._archive) :].lstrip(os.path.sep)
|
| 423 |
+
+ os.path.sep
|
| 424 |
+
)
|
| 425 |
+
offset = len(prefix)
|
| 426 |
+
|
| 427 |
+
for name in files:
|
| 428 |
+
# Find names under the templates directory that aren't directories.
|
| 429 |
+
if name.startswith(prefix) and name[-1] != os.path.sep:
|
| 430 |
+
results.append(name[offset:].replace(os.path.sep, "/"))
|
| 431 |
+
|
| 432 |
+
results.sort()
|
| 433 |
+
return results
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
class DictLoader(BaseLoader):
|
| 437 |
+
"""Loads a template from a Python dict mapping template names to
|
| 438 |
+
template source. This loader is useful for unittesting:
|
| 439 |
+
|
| 440 |
+
>>> loader = DictLoader({'index.html': 'source here'})
|
| 441 |
+
|
| 442 |
+
Because auto reloading is rarely useful this is disabled by default.
|
| 443 |
+
"""
|
| 444 |
+
|
| 445 |
+
def __init__(self, mapping: t.Mapping[str, str]) -> None:
|
| 446 |
+
self.mapping = mapping
|
| 447 |
+
|
| 448 |
+
def get_source(
|
| 449 |
+
self, environment: "Environment", template: str
|
| 450 |
+
) -> t.Tuple[str, None, t.Callable[[], bool]]:
|
| 451 |
+
if template in self.mapping:
|
| 452 |
+
source = self.mapping[template]
|
| 453 |
+
return source, None, lambda: source == self.mapping.get(template)
|
| 454 |
+
raise TemplateNotFound(template)
|
| 455 |
+
|
| 456 |
+
def list_templates(self) -> t.List[str]:
|
| 457 |
+
return sorted(self.mapping)
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
class FunctionLoader(BaseLoader):
|
| 461 |
+
"""A loader that is passed a function which does the loading. The
|
| 462 |
+
function receives the name of the template and has to return either
|
| 463 |
+
a string with the template source, a tuple in the form ``(source,
|
| 464 |
+
filename, uptodatefunc)`` or `None` if the template does not exist.
|
| 465 |
+
|
| 466 |
+
>>> def load_template(name):
|
| 467 |
+
... if name == 'index.html':
|
| 468 |
+
... return '...'
|
| 469 |
+
...
|
| 470 |
+
>>> loader = FunctionLoader(load_template)
|
| 471 |
+
|
| 472 |
+
The `uptodatefunc` is a function that is called if autoreload is enabled
|
| 473 |
+
and has to return `True` if the template is still up to date. For more
|
| 474 |
+
details have a look at :meth:`BaseLoader.get_source` which has the same
|
| 475 |
+
return value.
|
| 476 |
+
"""
|
| 477 |
+
|
| 478 |
+
def __init__(
|
| 479 |
+
self,
|
| 480 |
+
load_func: t.Callable[
|
| 481 |
+
[str],
|
| 482 |
+
t.Optional[
|
| 483 |
+
t.Union[
|
| 484 |
+
str, t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]
|
| 485 |
+
]
|
| 486 |
+
],
|
| 487 |
+
],
|
| 488 |
+
) -> None:
|
| 489 |
+
self.load_func = load_func
|
| 490 |
+
|
| 491 |
+
def get_source(
|
| 492 |
+
self, environment: "Environment", template: str
|
| 493 |
+
) -> t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]:
|
| 494 |
+
rv = self.load_func(template)
|
| 495 |
+
|
| 496 |
+
if rv is None:
|
| 497 |
+
raise TemplateNotFound(template)
|
| 498 |
+
|
| 499 |
+
if isinstance(rv, str):
|
| 500 |
+
return rv, None, None
|
| 501 |
+
|
| 502 |
+
return rv
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
class PrefixLoader(BaseLoader):
|
| 506 |
+
"""A loader that is passed a dict of loaders where each loader is bound
|
| 507 |
+
to a prefix. The prefix is delimited from the template by a slash per
|
| 508 |
+
default, which can be changed by setting the `delimiter` argument to
|
| 509 |
+
something else::
|
| 510 |
+
|
| 511 |
+
loader = PrefixLoader({
|
| 512 |
+
'app1': PackageLoader('mypackage.app1'),
|
| 513 |
+
'app2': PackageLoader('mypackage.app2')
|
| 514 |
+
})
|
| 515 |
+
|
| 516 |
+
By loading ``'app1/index.html'`` the file from the app1 package is loaded,
|
| 517 |
+
by loading ``'app2/index.html'`` the file from the second.
|
| 518 |
+
"""
|
| 519 |
+
|
| 520 |
+
def __init__(
|
| 521 |
+
self, mapping: t.Mapping[str, BaseLoader], delimiter: str = "/"
|
| 522 |
+
) -> None:
|
| 523 |
+
self.mapping = mapping
|
| 524 |
+
self.delimiter = delimiter
|
| 525 |
+
|
| 526 |
+
def get_loader(self, template: str) -> t.Tuple[BaseLoader, str]:
|
| 527 |
+
try:
|
| 528 |
+
prefix, name = template.split(self.delimiter, 1)
|
| 529 |
+
loader = self.mapping[prefix]
|
| 530 |
+
except (ValueError, KeyError) as e:
|
| 531 |
+
raise TemplateNotFound(template) from e
|
| 532 |
+
return loader, name
|
| 533 |
+
|
| 534 |
+
def get_source(
|
| 535 |
+
self, environment: "Environment", template: str
|
| 536 |
+
) -> t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]:
|
| 537 |
+
loader, name = self.get_loader(template)
|
| 538 |
+
try:
|
| 539 |
+
return loader.get_source(environment, name)
|
| 540 |
+
except TemplateNotFound as e:
|
| 541 |
+
# re-raise the exception with the correct filename here.
|
| 542 |
+
# (the one that includes the prefix)
|
| 543 |
+
raise TemplateNotFound(template) from e
|
| 544 |
+
|
| 545 |
+
@internalcode
|
| 546 |
+
def load(
|
| 547 |
+
self,
|
| 548 |
+
environment: "Environment",
|
| 549 |
+
name: str,
|
| 550 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 551 |
+
) -> "Template":
|
| 552 |
+
loader, local_name = self.get_loader(name)
|
| 553 |
+
try:
|
| 554 |
+
return loader.load(environment, local_name, globals)
|
| 555 |
+
except TemplateNotFound as e:
|
| 556 |
+
# re-raise the exception with the correct filename here.
|
| 557 |
+
# (the one that includes the prefix)
|
| 558 |
+
raise TemplateNotFound(name) from e
|
| 559 |
+
|
| 560 |
+
def list_templates(self) -> t.List[str]:
|
| 561 |
+
result = []
|
| 562 |
+
for prefix, loader in self.mapping.items():
|
| 563 |
+
for template in loader.list_templates():
|
| 564 |
+
result.append(prefix + self.delimiter + template)
|
| 565 |
+
return result
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
class ChoiceLoader(BaseLoader):
|
| 569 |
+
"""This loader works like the `PrefixLoader` just that no prefix is
|
| 570 |
+
specified. If a template could not be found by one loader the next one
|
| 571 |
+
is tried.
|
| 572 |
+
|
| 573 |
+
>>> loader = ChoiceLoader([
|
| 574 |
+
... FileSystemLoader('/path/to/user/templates'),
|
| 575 |
+
... FileSystemLoader('/path/to/system/templates')
|
| 576 |
+
... ])
|
| 577 |
+
|
| 578 |
+
This is useful if you want to allow users to override builtin templates
|
| 579 |
+
from a different location.
|
| 580 |
+
"""
|
| 581 |
+
|
| 582 |
+
def __init__(self, loaders: t.Sequence[BaseLoader]) -> None:
|
| 583 |
+
self.loaders = loaders
|
| 584 |
+
|
| 585 |
+
def get_source(
|
| 586 |
+
self, environment: "Environment", template: str
|
| 587 |
+
) -> t.Tuple[str, t.Optional[str], t.Optional[t.Callable[[], bool]]]:
|
| 588 |
+
for loader in self.loaders:
|
| 589 |
+
try:
|
| 590 |
+
return loader.get_source(environment, template)
|
| 591 |
+
except TemplateNotFound:
|
| 592 |
+
pass
|
| 593 |
+
raise TemplateNotFound(template)
|
| 594 |
+
|
| 595 |
+
@internalcode
|
| 596 |
+
def load(
|
| 597 |
+
self,
|
| 598 |
+
environment: "Environment",
|
| 599 |
+
name: str,
|
| 600 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 601 |
+
) -> "Template":
|
| 602 |
+
for loader in self.loaders:
|
| 603 |
+
try:
|
| 604 |
+
return loader.load(environment, name, globals)
|
| 605 |
+
except TemplateNotFound:
|
| 606 |
+
pass
|
| 607 |
+
raise TemplateNotFound(name)
|
| 608 |
+
|
| 609 |
+
def list_templates(self) -> t.List[str]:
|
| 610 |
+
found = set()
|
| 611 |
+
for loader in self.loaders:
|
| 612 |
+
found.update(loader.list_templates())
|
| 613 |
+
return sorted(found)
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
class _TemplateModule(ModuleType):
|
| 617 |
+
"""Like a normal module but with support for weak references"""
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
class ModuleLoader(BaseLoader):
|
| 621 |
+
"""This loader loads templates from precompiled templates.
|
| 622 |
+
|
| 623 |
+
Example usage:
|
| 624 |
+
|
| 625 |
+
>>> loader = ModuleLoader('/path/to/compiled/templates')
|
| 626 |
+
|
| 627 |
+
Templates can be precompiled with :meth:`Environment.compile_templates`.
|
| 628 |
+
"""
|
| 629 |
+
|
| 630 |
+
has_source_access = False
|
| 631 |
+
|
| 632 |
+
def __init__(
|
| 633 |
+
self,
|
| 634 |
+
path: t.Union[
|
| 635 |
+
str, "os.PathLike[str]", t.Sequence[t.Union[str, "os.PathLike[str]"]]
|
| 636 |
+
],
|
| 637 |
+
) -> None:
|
| 638 |
+
package_name = f"_jinja2_module_templates_{id(self):x}"
|
| 639 |
+
|
| 640 |
+
# create a fake module that looks for the templates in the
|
| 641 |
+
# path given.
|
| 642 |
+
mod = _TemplateModule(package_name)
|
| 643 |
+
|
| 644 |
+
if not isinstance(path, abc.Iterable) or isinstance(path, str):
|
| 645 |
+
path = [path]
|
| 646 |
+
|
| 647 |
+
mod.__path__ = [os.fspath(p) for p in path]
|
| 648 |
+
|
| 649 |
+
sys.modules[package_name] = weakref.proxy(
|
| 650 |
+
mod, lambda x: sys.modules.pop(package_name, None)
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
+
# the only strong reference, the sys.modules entry is weak
|
| 654 |
+
# so that the garbage collector can remove it once the
|
| 655 |
+
# loader that created it goes out of business.
|
| 656 |
+
self.module = mod
|
| 657 |
+
self.package_name = package_name
|
| 658 |
+
|
| 659 |
+
@staticmethod
|
| 660 |
+
def get_template_key(name: str) -> str:
|
| 661 |
+
return "tmpl_" + sha1(name.encode("utf-8")).hexdigest()
|
| 662 |
+
|
| 663 |
+
@staticmethod
|
| 664 |
+
def get_module_filename(name: str) -> str:
|
| 665 |
+
return ModuleLoader.get_template_key(name) + ".py"
|
| 666 |
+
|
| 667 |
+
@internalcode
|
| 668 |
+
def load(
|
| 669 |
+
self,
|
| 670 |
+
environment: "Environment",
|
| 671 |
+
name: str,
|
| 672 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 673 |
+
) -> "Template":
|
| 674 |
+
key = self.get_template_key(name)
|
| 675 |
+
module = f"{self.package_name}.{key}"
|
| 676 |
+
mod = getattr(self.module, module, None)
|
| 677 |
+
|
| 678 |
+
if mod is None:
|
| 679 |
+
try:
|
| 680 |
+
mod = __import__(module, None, None, ["root"])
|
| 681 |
+
except ImportError as e:
|
| 682 |
+
raise TemplateNotFound(name) from e
|
| 683 |
+
|
| 684 |
+
# remove the entry from sys.modules, we only want the attribute
|
| 685 |
+
# on the module object we have stored on the loader.
|
| 686 |
+
sys.modules.pop(module, None)
|
| 687 |
+
|
| 688 |
+
if globals is None:
|
| 689 |
+
globals = {}
|
| 690 |
+
|
| 691 |
+
return environment.template_class.from_module_dict(
|
| 692 |
+
environment, mod.__dict__, globals
|
| 693 |
+
)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/meta.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions that expose information about templates that might be
|
| 2 |
+
interesting for introspection.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import typing as t
|
| 6 |
+
|
| 7 |
+
from . import nodes
|
| 8 |
+
from .compiler import CodeGenerator
|
| 9 |
+
from .compiler import Frame
|
| 10 |
+
|
| 11 |
+
if t.TYPE_CHECKING:
|
| 12 |
+
from .environment import Environment
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TrackingCodeGenerator(CodeGenerator):
|
| 16 |
+
"""We abuse the code generator for introspection."""
|
| 17 |
+
|
| 18 |
+
def __init__(self, environment: "Environment") -> None:
|
| 19 |
+
super().__init__(environment, "<introspection>", "<introspection>")
|
| 20 |
+
self.undeclared_identifiers: t.Set[str] = set()
|
| 21 |
+
|
| 22 |
+
def write(self, x: str) -> None:
|
| 23 |
+
"""Don't write."""
|
| 24 |
+
|
| 25 |
+
def enter_frame(self, frame: Frame) -> None:
|
| 26 |
+
"""Remember all undeclared identifiers."""
|
| 27 |
+
super().enter_frame(frame)
|
| 28 |
+
|
| 29 |
+
for _, (action, param) in frame.symbols.loads.items():
|
| 30 |
+
if action == "resolve" and param not in self.environment.globals:
|
| 31 |
+
self.undeclared_identifiers.add(param)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def find_undeclared_variables(ast: nodes.Template) -> t.Set[str]:
|
| 35 |
+
"""Returns a set of all variables in the AST that will be looked up from
|
| 36 |
+
the context at runtime. Because at compile time it's not known which
|
| 37 |
+
variables will be used depending on the path the execution takes at
|
| 38 |
+
runtime, all variables are returned.
|
| 39 |
+
|
| 40 |
+
>>> from jinja2 import Environment, meta
|
| 41 |
+
>>> env = Environment()
|
| 42 |
+
>>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
|
| 43 |
+
>>> meta.find_undeclared_variables(ast) == {'bar'}
|
| 44 |
+
True
|
| 45 |
+
|
| 46 |
+
.. admonition:: Implementation
|
| 47 |
+
|
| 48 |
+
Internally the code generator is used for finding undeclared variables.
|
| 49 |
+
This is good to know because the code generator might raise a
|
| 50 |
+
:exc:`TemplateAssertionError` during compilation and as a matter of
|
| 51 |
+
fact this function can currently raise that exception as well.
|
| 52 |
+
"""
|
| 53 |
+
codegen = TrackingCodeGenerator(ast.environment) # type: ignore
|
| 54 |
+
codegen.visit(ast)
|
| 55 |
+
return codegen.undeclared_identifiers
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
_ref_types = (nodes.Extends, nodes.FromImport, nodes.Import, nodes.Include)
|
| 59 |
+
_RefType = t.Union[nodes.Extends, nodes.FromImport, nodes.Import, nodes.Include]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def find_referenced_templates(ast: nodes.Template) -> t.Iterator[t.Optional[str]]:
|
| 63 |
+
"""Finds all the referenced templates from the AST. This will return an
|
| 64 |
+
iterator over all the hardcoded template extensions, inclusions and
|
| 65 |
+
imports. If dynamic inheritance or inclusion is used, `None` will be
|
| 66 |
+
yielded.
|
| 67 |
+
|
| 68 |
+
>>> from jinja2 import Environment, meta
|
| 69 |
+
>>> env = Environment()
|
| 70 |
+
>>> ast = env.parse('{% extends "layout.html" %}{% include helper %}')
|
| 71 |
+
>>> list(meta.find_referenced_templates(ast))
|
| 72 |
+
['layout.html', None]
|
| 73 |
+
|
| 74 |
+
This function is useful for dependency tracking. For example if you want
|
| 75 |
+
to rebuild parts of the website after a layout template has changed.
|
| 76 |
+
"""
|
| 77 |
+
template_name: t.Any
|
| 78 |
+
|
| 79 |
+
for node in ast.find_all(_ref_types):
|
| 80 |
+
template: nodes.Expr = node.template # type: ignore
|
| 81 |
+
|
| 82 |
+
if not isinstance(template, nodes.Const):
|
| 83 |
+
# a tuple with some non consts in there
|
| 84 |
+
if isinstance(template, (nodes.Tuple, nodes.List)):
|
| 85 |
+
for template_name in template.items:
|
| 86 |
+
# something const, only yield the strings and ignore
|
| 87 |
+
# non-string consts that really just make no sense
|
| 88 |
+
if isinstance(template_name, nodes.Const):
|
| 89 |
+
if isinstance(template_name.value, str):
|
| 90 |
+
yield template_name.value
|
| 91 |
+
# something dynamic in there
|
| 92 |
+
else:
|
| 93 |
+
yield None
|
| 94 |
+
# something dynamic we don't know about here
|
| 95 |
+
else:
|
| 96 |
+
yield None
|
| 97 |
+
continue
|
| 98 |
+
# constant is a basestring, direct template name
|
| 99 |
+
if isinstance(template.value, str):
|
| 100 |
+
yield template.value
|
| 101 |
+
# a tuple or list (latter *should* not happen) made of consts,
|
| 102 |
+
# yield the consts that are strings. We could warn here for
|
| 103 |
+
# non string values
|
| 104 |
+
elif isinstance(node, nodes.Include) and isinstance(
|
| 105 |
+
template.value, (tuple, list)
|
| 106 |
+
):
|
| 107 |
+
for template_name in template.value:
|
| 108 |
+
if isinstance(template_name, str):
|
| 109 |
+
yield template_name
|
| 110 |
+
# something else we don't care about, we could warn here
|
| 111 |
+
else:
|
| 112 |
+
yield None
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/nativetypes.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
from ast import literal_eval
|
| 3 |
+
from ast import parse
|
| 4 |
+
from itertools import chain
|
| 5 |
+
from itertools import islice
|
| 6 |
+
from types import GeneratorType
|
| 7 |
+
|
| 8 |
+
from . import nodes
|
| 9 |
+
from .compiler import CodeGenerator
|
| 10 |
+
from .compiler import Frame
|
| 11 |
+
from .compiler import has_safe_repr
|
| 12 |
+
from .environment import Environment
|
| 13 |
+
from .environment import Template
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def native_concat(values: t.Iterable[t.Any]) -> t.Optional[t.Any]:
|
| 17 |
+
"""Return a native Python type from the list of compiled nodes. If
|
| 18 |
+
the result is a single node, its value is returned. Otherwise, the
|
| 19 |
+
nodes are concatenated as strings. If the result can be parsed with
|
| 20 |
+
:func:`ast.literal_eval`, the parsed value is returned. Otherwise,
|
| 21 |
+
the string is returned.
|
| 22 |
+
|
| 23 |
+
:param values: Iterable of outputs to concatenate.
|
| 24 |
+
"""
|
| 25 |
+
head = list(islice(values, 2))
|
| 26 |
+
|
| 27 |
+
if not head:
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
if len(head) == 1:
|
| 31 |
+
raw = head[0]
|
| 32 |
+
if not isinstance(raw, str):
|
| 33 |
+
return raw
|
| 34 |
+
else:
|
| 35 |
+
if isinstance(values, GeneratorType):
|
| 36 |
+
values = chain(head, values)
|
| 37 |
+
raw = "".join([str(v) for v in values])
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
return literal_eval(
|
| 41 |
+
# In Python 3.10+ ast.literal_eval removes leading spaces/tabs
|
| 42 |
+
# from the given string. For backwards compatibility we need to
|
| 43 |
+
# parse the string ourselves without removing leading spaces/tabs.
|
| 44 |
+
parse(raw, mode="eval")
|
| 45 |
+
)
|
| 46 |
+
except (ValueError, SyntaxError, MemoryError):
|
| 47 |
+
return raw
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class NativeCodeGenerator(CodeGenerator):
|
| 51 |
+
"""A code generator which renders Python types by not adding
|
| 52 |
+
``str()`` around output nodes.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
@staticmethod
|
| 56 |
+
def _default_finalize(value: t.Any) -> t.Any:
|
| 57 |
+
return value
|
| 58 |
+
|
| 59 |
+
def _output_const_repr(self, group: t.Iterable[t.Any]) -> str:
|
| 60 |
+
return repr("".join([str(v) for v in group]))
|
| 61 |
+
|
| 62 |
+
def _output_child_to_const(
|
| 63 |
+
self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
|
| 64 |
+
) -> t.Any:
|
| 65 |
+
const = node.as_const(frame.eval_ctx)
|
| 66 |
+
|
| 67 |
+
if not has_safe_repr(const):
|
| 68 |
+
raise nodes.Impossible()
|
| 69 |
+
|
| 70 |
+
if isinstance(node, nodes.TemplateData):
|
| 71 |
+
return const
|
| 72 |
+
|
| 73 |
+
return finalize.const(const) # type: ignore
|
| 74 |
+
|
| 75 |
+
def _output_child_pre(
|
| 76 |
+
self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
|
| 77 |
+
) -> None:
|
| 78 |
+
if finalize.src is not None:
|
| 79 |
+
self.write(finalize.src)
|
| 80 |
+
|
| 81 |
+
def _output_child_post(
|
| 82 |
+
self, node: nodes.Expr, frame: Frame, finalize: CodeGenerator._FinalizeInfo
|
| 83 |
+
) -> None:
|
| 84 |
+
if finalize.src is not None:
|
| 85 |
+
self.write(")")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class NativeEnvironment(Environment):
|
| 89 |
+
"""An environment that renders templates to native Python types."""
|
| 90 |
+
|
| 91 |
+
code_generator_class = NativeCodeGenerator
|
| 92 |
+
concat = staticmethod(native_concat) # type: ignore
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class NativeTemplate(Template):
|
| 96 |
+
environment_class = NativeEnvironment
|
| 97 |
+
|
| 98 |
+
def render(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
| 99 |
+
"""Render the template to produce a native Python type. If the
|
| 100 |
+
result is a single node, its value is returned. Otherwise, the
|
| 101 |
+
nodes are concatenated as strings. If the result can be parsed
|
| 102 |
+
with :func:`ast.literal_eval`, the parsed value is returned.
|
| 103 |
+
Otherwise, the string is returned.
|
| 104 |
+
"""
|
| 105 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
return self.environment_class.concat( # type: ignore
|
| 109 |
+
self.root_render_func(ctx)
|
| 110 |
+
)
|
| 111 |
+
except Exception:
|
| 112 |
+
return self.environment.handle_exception()
|
| 113 |
+
|
| 114 |
+
async def render_async(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
|
| 115 |
+
if not self.environment.is_async:
|
| 116 |
+
raise RuntimeError(
|
| 117 |
+
"The environment was not created with async mode enabled."
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
ctx = self.new_context(dict(*args, **kwargs))
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
return self.environment_class.concat( # type: ignore
|
| 124 |
+
[n async for n in self.root_render_func(ctx)] # type: ignore
|
| 125 |
+
)
|
| 126 |
+
except Exception:
|
| 127 |
+
return self.environment.handle_exception()
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
NativeEnvironment.template_class = NativeTemplate
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/nodes.py
ADDED
|
@@ -0,0 +1,1206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""AST nodes generated by the parser for the compiler. Also provides
|
| 2 |
+
some node tree helper functions used by the parser and compiler in order
|
| 3 |
+
to normalize nodes.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import inspect
|
| 7 |
+
import operator
|
| 8 |
+
import typing as t
|
| 9 |
+
from collections import deque
|
| 10 |
+
|
| 11 |
+
from markupsafe import Markup
|
| 12 |
+
|
| 13 |
+
from .utils import _PassArg
|
| 14 |
+
|
| 15 |
+
if t.TYPE_CHECKING:
|
| 16 |
+
import typing_extensions as te
|
| 17 |
+
|
| 18 |
+
from .environment import Environment
|
| 19 |
+
|
| 20 |
+
_NodeBound = t.TypeVar("_NodeBound", bound="Node")
|
| 21 |
+
|
| 22 |
+
_binop_to_func: t.Dict[str, t.Callable[[t.Any, t.Any], t.Any]] = {
|
| 23 |
+
"*": operator.mul,
|
| 24 |
+
"/": operator.truediv,
|
| 25 |
+
"//": operator.floordiv,
|
| 26 |
+
"**": operator.pow,
|
| 27 |
+
"%": operator.mod,
|
| 28 |
+
"+": operator.add,
|
| 29 |
+
"-": operator.sub,
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
_uaop_to_func: t.Dict[str, t.Callable[[t.Any], t.Any]] = {
|
| 33 |
+
"not": operator.not_,
|
| 34 |
+
"+": operator.pos,
|
| 35 |
+
"-": operator.neg,
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
_cmpop_to_func: t.Dict[str, t.Callable[[t.Any, t.Any], t.Any]] = {
|
| 39 |
+
"eq": operator.eq,
|
| 40 |
+
"ne": operator.ne,
|
| 41 |
+
"gt": operator.gt,
|
| 42 |
+
"gteq": operator.ge,
|
| 43 |
+
"lt": operator.lt,
|
| 44 |
+
"lteq": operator.le,
|
| 45 |
+
"in": lambda a, b: a in b,
|
| 46 |
+
"notin": lambda a, b: a not in b,
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class Impossible(Exception):
|
| 51 |
+
"""Raised if the node could not perform a requested action."""
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class NodeType(type):
|
| 55 |
+
"""A metaclass for nodes that handles the field and attribute
|
| 56 |
+
inheritance. fields and attributes from the parent class are
|
| 57 |
+
automatically forwarded to the child."""
|
| 58 |
+
|
| 59 |
+
def __new__(mcs, name, bases, d): # type: ignore
|
| 60 |
+
for attr in "fields", "attributes":
|
| 61 |
+
storage: t.List[t.Tuple[str, ...]] = []
|
| 62 |
+
storage.extend(getattr(bases[0] if bases else object, attr, ()))
|
| 63 |
+
storage.extend(d.get(attr, ()))
|
| 64 |
+
assert len(bases) <= 1, "multiple inheritance not allowed"
|
| 65 |
+
assert len(storage) == len(set(storage)), "layout conflict"
|
| 66 |
+
d[attr] = tuple(storage)
|
| 67 |
+
d.setdefault("abstract", False)
|
| 68 |
+
return type.__new__(mcs, name, bases, d)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class EvalContext:
|
| 72 |
+
"""Holds evaluation time information. Custom attributes can be attached
|
| 73 |
+
to it in extensions.
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
def __init__(
|
| 77 |
+
self, environment: "Environment", template_name: t.Optional[str] = None
|
| 78 |
+
) -> None:
|
| 79 |
+
self.environment = environment
|
| 80 |
+
if callable(environment.autoescape):
|
| 81 |
+
self.autoescape = environment.autoescape(template_name)
|
| 82 |
+
else:
|
| 83 |
+
self.autoescape = environment.autoescape
|
| 84 |
+
self.volatile = False
|
| 85 |
+
|
| 86 |
+
def save(self) -> t.Mapping[str, t.Any]:
|
| 87 |
+
return self.__dict__.copy()
|
| 88 |
+
|
| 89 |
+
def revert(self, old: t.Mapping[str, t.Any]) -> None:
|
| 90 |
+
self.__dict__.clear()
|
| 91 |
+
self.__dict__.update(old)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def get_eval_context(node: "Node", ctx: t.Optional[EvalContext]) -> EvalContext:
|
| 95 |
+
if ctx is None:
|
| 96 |
+
if node.environment is None:
|
| 97 |
+
raise RuntimeError(
|
| 98 |
+
"if no eval context is passed, the node must have an"
|
| 99 |
+
" attached environment."
|
| 100 |
+
)
|
| 101 |
+
return EvalContext(node.environment)
|
| 102 |
+
return ctx
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class Node(metaclass=NodeType):
|
| 106 |
+
"""Baseclass for all Jinja nodes. There are a number of nodes available
|
| 107 |
+
of different types. There are four major types:
|
| 108 |
+
|
| 109 |
+
- :class:`Stmt`: statements
|
| 110 |
+
- :class:`Expr`: expressions
|
| 111 |
+
- :class:`Helper`: helper nodes
|
| 112 |
+
- :class:`Template`: the outermost wrapper node
|
| 113 |
+
|
| 114 |
+
All nodes have fields and attributes. Fields may be other nodes, lists,
|
| 115 |
+
or arbitrary values. Fields are passed to the constructor as regular
|
| 116 |
+
positional arguments, attributes as keyword arguments. Each node has
|
| 117 |
+
two attributes: `lineno` (the line number of the node) and `environment`.
|
| 118 |
+
The `environment` attribute is set at the end of the parsing process for
|
| 119 |
+
all nodes automatically.
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
fields: t.Tuple[str, ...] = ()
|
| 123 |
+
attributes: t.Tuple[str, ...] = ("lineno", "environment")
|
| 124 |
+
abstract = True
|
| 125 |
+
|
| 126 |
+
lineno: int
|
| 127 |
+
environment: t.Optional["Environment"]
|
| 128 |
+
|
| 129 |
+
def __init__(self, *fields: t.Any, **attributes: t.Any) -> None:
|
| 130 |
+
if self.abstract:
|
| 131 |
+
raise TypeError("abstract nodes are not instantiable")
|
| 132 |
+
if fields:
|
| 133 |
+
if len(fields) != len(self.fields):
|
| 134 |
+
if not self.fields:
|
| 135 |
+
raise TypeError(f"{type(self).__name__!r} takes 0 arguments")
|
| 136 |
+
raise TypeError(
|
| 137 |
+
f"{type(self).__name__!r} takes 0 or {len(self.fields)}"
|
| 138 |
+
f" argument{'s' if len(self.fields) != 1 else ''}"
|
| 139 |
+
)
|
| 140 |
+
for name, arg in zip(self.fields, fields):
|
| 141 |
+
setattr(self, name, arg)
|
| 142 |
+
for attr in self.attributes:
|
| 143 |
+
setattr(self, attr, attributes.pop(attr, None))
|
| 144 |
+
if attributes:
|
| 145 |
+
raise TypeError(f"unknown attribute {next(iter(attributes))!r}")
|
| 146 |
+
|
| 147 |
+
def iter_fields(
|
| 148 |
+
self,
|
| 149 |
+
exclude: t.Optional[t.Container[str]] = None,
|
| 150 |
+
only: t.Optional[t.Container[str]] = None,
|
| 151 |
+
) -> t.Iterator[t.Tuple[str, t.Any]]:
|
| 152 |
+
"""This method iterates over all fields that are defined and yields
|
| 153 |
+
``(key, value)`` tuples. Per default all fields are returned, but
|
| 154 |
+
it's possible to limit that to some fields by providing the `only`
|
| 155 |
+
parameter or to exclude some using the `exclude` parameter. Both
|
| 156 |
+
should be sets or tuples of field names.
|
| 157 |
+
"""
|
| 158 |
+
for name in self.fields:
|
| 159 |
+
if (
|
| 160 |
+
(exclude is None and only is None)
|
| 161 |
+
or (exclude is not None and name not in exclude)
|
| 162 |
+
or (only is not None and name in only)
|
| 163 |
+
):
|
| 164 |
+
try:
|
| 165 |
+
yield name, getattr(self, name)
|
| 166 |
+
except AttributeError:
|
| 167 |
+
pass
|
| 168 |
+
|
| 169 |
+
def iter_child_nodes(
|
| 170 |
+
self,
|
| 171 |
+
exclude: t.Optional[t.Container[str]] = None,
|
| 172 |
+
only: t.Optional[t.Container[str]] = None,
|
| 173 |
+
) -> t.Iterator["Node"]:
|
| 174 |
+
"""Iterates over all direct child nodes of the node. This iterates
|
| 175 |
+
over all fields and yields the values of they are nodes. If the value
|
| 176 |
+
of a field is a list all the nodes in that list are returned.
|
| 177 |
+
"""
|
| 178 |
+
for _, item in self.iter_fields(exclude, only):
|
| 179 |
+
if isinstance(item, list):
|
| 180 |
+
for n in item:
|
| 181 |
+
if isinstance(n, Node):
|
| 182 |
+
yield n
|
| 183 |
+
elif isinstance(item, Node):
|
| 184 |
+
yield item
|
| 185 |
+
|
| 186 |
+
def find(self, node_type: t.Type[_NodeBound]) -> t.Optional[_NodeBound]:
|
| 187 |
+
"""Find the first node of a given type. If no such node exists the
|
| 188 |
+
return value is `None`.
|
| 189 |
+
"""
|
| 190 |
+
for result in self.find_all(node_type):
|
| 191 |
+
return result
|
| 192 |
+
|
| 193 |
+
return None
|
| 194 |
+
|
| 195 |
+
def find_all(
|
| 196 |
+
self, node_type: t.Union[t.Type[_NodeBound], t.Tuple[t.Type[_NodeBound], ...]]
|
| 197 |
+
) -> t.Iterator[_NodeBound]:
|
| 198 |
+
"""Find all the nodes of a given type. If the type is a tuple,
|
| 199 |
+
the check is performed for any of the tuple items.
|
| 200 |
+
"""
|
| 201 |
+
for child in self.iter_child_nodes():
|
| 202 |
+
if isinstance(child, node_type):
|
| 203 |
+
yield child # type: ignore
|
| 204 |
+
yield from child.find_all(node_type)
|
| 205 |
+
|
| 206 |
+
def set_ctx(self, ctx: str) -> "Node":
|
| 207 |
+
"""Reset the context of a node and all child nodes. Per default the
|
| 208 |
+
parser will all generate nodes that have a 'load' context as it's the
|
| 209 |
+
most common one. This method is used in the parser to set assignment
|
| 210 |
+
targets and other nodes to a store context.
|
| 211 |
+
"""
|
| 212 |
+
todo = deque([self])
|
| 213 |
+
while todo:
|
| 214 |
+
node = todo.popleft()
|
| 215 |
+
if "ctx" in node.fields:
|
| 216 |
+
node.ctx = ctx # type: ignore
|
| 217 |
+
todo.extend(node.iter_child_nodes())
|
| 218 |
+
return self
|
| 219 |
+
|
| 220 |
+
def set_lineno(self, lineno: int, override: bool = False) -> "Node":
|
| 221 |
+
"""Set the line numbers of the node and children."""
|
| 222 |
+
todo = deque([self])
|
| 223 |
+
while todo:
|
| 224 |
+
node = todo.popleft()
|
| 225 |
+
if "lineno" in node.attributes:
|
| 226 |
+
if node.lineno is None or override:
|
| 227 |
+
node.lineno = lineno
|
| 228 |
+
todo.extend(node.iter_child_nodes())
|
| 229 |
+
return self
|
| 230 |
+
|
| 231 |
+
def set_environment(self, environment: "Environment") -> "Node":
|
| 232 |
+
"""Set the environment for all nodes."""
|
| 233 |
+
todo = deque([self])
|
| 234 |
+
while todo:
|
| 235 |
+
node = todo.popleft()
|
| 236 |
+
node.environment = environment
|
| 237 |
+
todo.extend(node.iter_child_nodes())
|
| 238 |
+
return self
|
| 239 |
+
|
| 240 |
+
def __eq__(self, other: t.Any) -> bool:
|
| 241 |
+
if type(self) is not type(other):
|
| 242 |
+
return NotImplemented
|
| 243 |
+
|
| 244 |
+
return tuple(self.iter_fields()) == tuple(other.iter_fields())
|
| 245 |
+
|
| 246 |
+
__hash__ = object.__hash__
|
| 247 |
+
|
| 248 |
+
def __repr__(self) -> str:
|
| 249 |
+
args_str = ", ".join(f"{a}={getattr(self, a, None)!r}" for a in self.fields)
|
| 250 |
+
return f"{type(self).__name__}({args_str})"
|
| 251 |
+
|
| 252 |
+
def dump(self) -> str:
|
| 253 |
+
def _dump(node: t.Union[Node, t.Any]) -> None:
|
| 254 |
+
if not isinstance(node, Node):
|
| 255 |
+
buf.append(repr(node))
|
| 256 |
+
return
|
| 257 |
+
|
| 258 |
+
buf.append(f"nodes.{type(node).__name__}(")
|
| 259 |
+
if not node.fields:
|
| 260 |
+
buf.append(")")
|
| 261 |
+
return
|
| 262 |
+
for idx, field in enumerate(node.fields):
|
| 263 |
+
if idx:
|
| 264 |
+
buf.append(", ")
|
| 265 |
+
value = getattr(node, field)
|
| 266 |
+
if isinstance(value, list):
|
| 267 |
+
buf.append("[")
|
| 268 |
+
for idx, item in enumerate(value):
|
| 269 |
+
if idx:
|
| 270 |
+
buf.append(", ")
|
| 271 |
+
_dump(item)
|
| 272 |
+
buf.append("]")
|
| 273 |
+
else:
|
| 274 |
+
_dump(value)
|
| 275 |
+
buf.append(")")
|
| 276 |
+
|
| 277 |
+
buf: t.List[str] = []
|
| 278 |
+
_dump(self)
|
| 279 |
+
return "".join(buf)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class Stmt(Node):
|
| 283 |
+
"""Base node for all statements."""
|
| 284 |
+
|
| 285 |
+
abstract = True
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
class Helper(Node):
|
| 289 |
+
"""Nodes that exist in a specific context only."""
|
| 290 |
+
|
| 291 |
+
abstract = True
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
class Template(Node):
|
| 295 |
+
"""Node that represents a template. This must be the outermost node that
|
| 296 |
+
is passed to the compiler.
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
fields = ("body",)
|
| 300 |
+
body: t.List[Node]
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
class Output(Stmt):
|
| 304 |
+
"""A node that holds multiple expressions which are then printed out.
|
| 305 |
+
This is used both for the `print` statement and the regular template data.
|
| 306 |
+
"""
|
| 307 |
+
|
| 308 |
+
fields = ("nodes",)
|
| 309 |
+
nodes: t.List["Expr"]
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class Extends(Stmt):
|
| 313 |
+
"""Represents an extends statement."""
|
| 314 |
+
|
| 315 |
+
fields = ("template",)
|
| 316 |
+
template: "Expr"
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
class For(Stmt):
|
| 320 |
+
"""The for loop. `target` is the target for the iteration (usually a
|
| 321 |
+
:class:`Name` or :class:`Tuple`), `iter` the iterable. `body` is a list
|
| 322 |
+
of nodes that are used as loop-body, and `else_` a list of nodes for the
|
| 323 |
+
`else` block. If no else node exists it has to be an empty list.
|
| 324 |
+
|
| 325 |
+
For filtered nodes an expression can be stored as `test`, otherwise `None`.
|
| 326 |
+
"""
|
| 327 |
+
|
| 328 |
+
fields = ("target", "iter", "body", "else_", "test", "recursive")
|
| 329 |
+
target: Node
|
| 330 |
+
iter: Node
|
| 331 |
+
body: t.List[Node]
|
| 332 |
+
else_: t.List[Node]
|
| 333 |
+
test: t.Optional[Node]
|
| 334 |
+
recursive: bool
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
class If(Stmt):
|
| 338 |
+
"""If `test` is true, `body` is rendered, else `else_`."""
|
| 339 |
+
|
| 340 |
+
fields = ("test", "body", "elif_", "else_")
|
| 341 |
+
test: Node
|
| 342 |
+
body: t.List[Node]
|
| 343 |
+
elif_: t.List["If"]
|
| 344 |
+
else_: t.List[Node]
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
class Macro(Stmt):
|
| 348 |
+
"""A macro definition. `name` is the name of the macro, `args` a list of
|
| 349 |
+
arguments and `defaults` a list of defaults if there are any. `body` is
|
| 350 |
+
a list of nodes for the macro body.
|
| 351 |
+
"""
|
| 352 |
+
|
| 353 |
+
fields = ("name", "args", "defaults", "body")
|
| 354 |
+
name: str
|
| 355 |
+
args: t.List["Name"]
|
| 356 |
+
defaults: t.List["Expr"]
|
| 357 |
+
body: t.List[Node]
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
class CallBlock(Stmt):
|
| 361 |
+
"""Like a macro without a name but a call instead. `call` is called with
|
| 362 |
+
the unnamed macro as `caller` argument this node holds.
|
| 363 |
+
"""
|
| 364 |
+
|
| 365 |
+
fields = ("call", "args", "defaults", "body")
|
| 366 |
+
call: "Call"
|
| 367 |
+
args: t.List["Name"]
|
| 368 |
+
defaults: t.List["Expr"]
|
| 369 |
+
body: t.List[Node]
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
class FilterBlock(Stmt):
|
| 373 |
+
"""Node for filter sections."""
|
| 374 |
+
|
| 375 |
+
fields = ("body", "filter")
|
| 376 |
+
body: t.List[Node]
|
| 377 |
+
filter: "Filter"
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
class With(Stmt):
|
| 381 |
+
"""Specific node for with statements. In older versions of Jinja the
|
| 382 |
+
with statement was implemented on the base of the `Scope` node instead.
|
| 383 |
+
|
| 384 |
+
.. versionadded:: 2.9.3
|
| 385 |
+
"""
|
| 386 |
+
|
| 387 |
+
fields = ("targets", "values", "body")
|
| 388 |
+
targets: t.List["Expr"]
|
| 389 |
+
values: t.List["Expr"]
|
| 390 |
+
body: t.List[Node]
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class Block(Stmt):
|
| 394 |
+
"""A node that represents a block.
|
| 395 |
+
|
| 396 |
+
.. versionchanged:: 3.0.0
|
| 397 |
+
the `required` field was added.
|
| 398 |
+
"""
|
| 399 |
+
|
| 400 |
+
fields = ("name", "body", "scoped", "required")
|
| 401 |
+
name: str
|
| 402 |
+
body: t.List[Node]
|
| 403 |
+
scoped: bool
|
| 404 |
+
required: bool
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
class Include(Stmt):
|
| 408 |
+
"""A node that represents the include tag."""
|
| 409 |
+
|
| 410 |
+
fields = ("template", "with_context", "ignore_missing")
|
| 411 |
+
template: "Expr"
|
| 412 |
+
with_context: bool
|
| 413 |
+
ignore_missing: bool
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
class Import(Stmt):
|
| 417 |
+
"""A node that represents the import tag."""
|
| 418 |
+
|
| 419 |
+
fields = ("template", "target", "with_context")
|
| 420 |
+
template: "Expr"
|
| 421 |
+
target: str
|
| 422 |
+
with_context: bool
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
class FromImport(Stmt):
|
| 426 |
+
"""A node that represents the from import tag. It's important to not
|
| 427 |
+
pass unsafe names to the name attribute. The compiler translates the
|
| 428 |
+
attribute lookups directly into getattr calls and does *not* use the
|
| 429 |
+
subscript callback of the interface. As exported variables may not
|
| 430 |
+
start with double underscores (which the parser asserts) this is not a
|
| 431 |
+
problem for regular Jinja code, but if this node is used in an extension
|
| 432 |
+
extra care must be taken.
|
| 433 |
+
|
| 434 |
+
The list of names may contain tuples if aliases are wanted.
|
| 435 |
+
"""
|
| 436 |
+
|
| 437 |
+
fields = ("template", "names", "with_context")
|
| 438 |
+
template: "Expr"
|
| 439 |
+
names: t.List[t.Union[str, t.Tuple[str, str]]]
|
| 440 |
+
with_context: bool
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
class ExprStmt(Stmt):
|
| 444 |
+
"""A statement that evaluates an expression and discards the result."""
|
| 445 |
+
|
| 446 |
+
fields = ("node",)
|
| 447 |
+
node: Node
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
class Assign(Stmt):
|
| 451 |
+
"""Assigns an expression to a target."""
|
| 452 |
+
|
| 453 |
+
fields = ("target", "node")
|
| 454 |
+
target: "Expr"
|
| 455 |
+
node: Node
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
class AssignBlock(Stmt):
|
| 459 |
+
"""Assigns a block to a target."""
|
| 460 |
+
|
| 461 |
+
fields = ("target", "filter", "body")
|
| 462 |
+
target: "Expr"
|
| 463 |
+
filter: t.Optional["Filter"]
|
| 464 |
+
body: t.List[Node]
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
class Expr(Node):
|
| 468 |
+
"""Baseclass for all expressions."""
|
| 469 |
+
|
| 470 |
+
abstract = True
|
| 471 |
+
|
| 472 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 473 |
+
"""Return the value of the expression as constant or raise
|
| 474 |
+
:exc:`Impossible` if this was not possible.
|
| 475 |
+
|
| 476 |
+
An :class:`EvalContext` can be provided, if none is given
|
| 477 |
+
a default context is created which requires the nodes to have
|
| 478 |
+
an attached environment.
|
| 479 |
+
|
| 480 |
+
.. versionchanged:: 2.4
|
| 481 |
+
the `eval_ctx` parameter was added.
|
| 482 |
+
"""
|
| 483 |
+
raise Impossible()
|
| 484 |
+
|
| 485 |
+
def can_assign(self) -> bool:
|
| 486 |
+
"""Check if it's possible to assign something to this node."""
|
| 487 |
+
return False
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
class BinExpr(Expr):
|
| 491 |
+
"""Baseclass for all binary expressions."""
|
| 492 |
+
|
| 493 |
+
fields = ("left", "right")
|
| 494 |
+
left: Expr
|
| 495 |
+
right: Expr
|
| 496 |
+
operator: str
|
| 497 |
+
abstract = True
|
| 498 |
+
|
| 499 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 500 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 501 |
+
|
| 502 |
+
# intercepted operators cannot be folded at compile time
|
| 503 |
+
if (
|
| 504 |
+
eval_ctx.environment.sandboxed
|
| 505 |
+
and self.operator in eval_ctx.environment.intercepted_binops # type: ignore
|
| 506 |
+
):
|
| 507 |
+
raise Impossible()
|
| 508 |
+
f = _binop_to_func[self.operator]
|
| 509 |
+
try:
|
| 510 |
+
return f(self.left.as_const(eval_ctx), self.right.as_const(eval_ctx))
|
| 511 |
+
except Exception as e:
|
| 512 |
+
raise Impossible() from e
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
class UnaryExpr(Expr):
|
| 516 |
+
"""Baseclass for all unary expressions."""
|
| 517 |
+
|
| 518 |
+
fields = ("node",)
|
| 519 |
+
node: Expr
|
| 520 |
+
operator: str
|
| 521 |
+
abstract = True
|
| 522 |
+
|
| 523 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 524 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 525 |
+
|
| 526 |
+
# intercepted operators cannot be folded at compile time
|
| 527 |
+
if (
|
| 528 |
+
eval_ctx.environment.sandboxed
|
| 529 |
+
and self.operator in eval_ctx.environment.intercepted_unops # type: ignore
|
| 530 |
+
):
|
| 531 |
+
raise Impossible()
|
| 532 |
+
f = _uaop_to_func[self.operator]
|
| 533 |
+
try:
|
| 534 |
+
return f(self.node.as_const(eval_ctx))
|
| 535 |
+
except Exception as e:
|
| 536 |
+
raise Impossible() from e
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
class Name(Expr):
|
| 540 |
+
"""Looks up a name or stores a value in a name.
|
| 541 |
+
The `ctx` of the node can be one of the following values:
|
| 542 |
+
|
| 543 |
+
- `store`: store a value in the name
|
| 544 |
+
- `load`: load that name
|
| 545 |
+
- `param`: like `store` but if the name was defined as function parameter.
|
| 546 |
+
"""
|
| 547 |
+
|
| 548 |
+
fields = ("name", "ctx")
|
| 549 |
+
name: str
|
| 550 |
+
ctx: str
|
| 551 |
+
|
| 552 |
+
def can_assign(self) -> bool:
|
| 553 |
+
return self.name not in {"true", "false", "none", "True", "False", "None"}
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
class NSRef(Expr):
|
| 557 |
+
"""Reference to a namespace value assignment"""
|
| 558 |
+
|
| 559 |
+
fields = ("name", "attr")
|
| 560 |
+
name: str
|
| 561 |
+
attr: str
|
| 562 |
+
|
| 563 |
+
def can_assign(self) -> bool:
|
| 564 |
+
# We don't need any special checks here; NSRef assignments have a
|
| 565 |
+
# runtime check to ensure the target is a namespace object which will
|
| 566 |
+
# have been checked already as it is created using a normal assignment
|
| 567 |
+
# which goes through a `Name` node.
|
| 568 |
+
return True
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
class Literal(Expr):
|
| 572 |
+
"""Baseclass for literals."""
|
| 573 |
+
|
| 574 |
+
abstract = True
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
class Const(Literal):
|
| 578 |
+
"""All constant values. The parser will return this node for simple
|
| 579 |
+
constants such as ``42`` or ``"foo"`` but it can be used to store more
|
| 580 |
+
complex values such as lists too. Only constants with a safe
|
| 581 |
+
representation (objects where ``eval(repr(x)) == x`` is true).
|
| 582 |
+
"""
|
| 583 |
+
|
| 584 |
+
fields = ("value",)
|
| 585 |
+
value: t.Any
|
| 586 |
+
|
| 587 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 588 |
+
return self.value
|
| 589 |
+
|
| 590 |
+
@classmethod
|
| 591 |
+
def from_untrusted(
|
| 592 |
+
cls,
|
| 593 |
+
value: t.Any,
|
| 594 |
+
lineno: t.Optional[int] = None,
|
| 595 |
+
environment: "t.Optional[Environment]" = None,
|
| 596 |
+
) -> "Const":
|
| 597 |
+
"""Return a const object if the value is representable as
|
| 598 |
+
constant value in the generated code, otherwise it will raise
|
| 599 |
+
an `Impossible` exception.
|
| 600 |
+
"""
|
| 601 |
+
from .compiler import has_safe_repr
|
| 602 |
+
|
| 603 |
+
if not has_safe_repr(value):
|
| 604 |
+
raise Impossible()
|
| 605 |
+
return cls(value, lineno=lineno, environment=environment)
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
class TemplateData(Literal):
|
| 609 |
+
"""A constant template string."""
|
| 610 |
+
|
| 611 |
+
fields = ("data",)
|
| 612 |
+
data: str
|
| 613 |
+
|
| 614 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> str:
|
| 615 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 616 |
+
if eval_ctx.volatile:
|
| 617 |
+
raise Impossible()
|
| 618 |
+
if eval_ctx.autoescape:
|
| 619 |
+
return Markup(self.data)
|
| 620 |
+
return self.data
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
class Tuple(Literal):
|
| 624 |
+
"""For loop unpacking and some other things like multiple arguments
|
| 625 |
+
for subscripts. Like for :class:`Name` `ctx` specifies if the tuple
|
| 626 |
+
is used for loading the names or storing.
|
| 627 |
+
"""
|
| 628 |
+
|
| 629 |
+
fields = ("items", "ctx")
|
| 630 |
+
items: t.List[Expr]
|
| 631 |
+
ctx: str
|
| 632 |
+
|
| 633 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Tuple[t.Any, ...]:
|
| 634 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 635 |
+
return tuple(x.as_const(eval_ctx) for x in self.items)
|
| 636 |
+
|
| 637 |
+
def can_assign(self) -> bool:
|
| 638 |
+
for item in self.items:
|
| 639 |
+
if not item.can_assign():
|
| 640 |
+
return False
|
| 641 |
+
return True
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
class List(Literal):
|
| 645 |
+
"""Any list literal such as ``[1, 2, 3]``"""
|
| 646 |
+
|
| 647 |
+
fields = ("items",)
|
| 648 |
+
items: t.List[Expr]
|
| 649 |
+
|
| 650 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.List[t.Any]:
|
| 651 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 652 |
+
return [x.as_const(eval_ctx) for x in self.items]
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
class Dict(Literal):
|
| 656 |
+
"""Any dict literal such as ``{1: 2, 3: 4}``. The items must be a list of
|
| 657 |
+
:class:`Pair` nodes.
|
| 658 |
+
"""
|
| 659 |
+
|
| 660 |
+
fields = ("items",)
|
| 661 |
+
items: t.List["Pair"]
|
| 662 |
+
|
| 663 |
+
def as_const(
|
| 664 |
+
self, eval_ctx: t.Optional[EvalContext] = None
|
| 665 |
+
) -> t.Dict[t.Any, t.Any]:
|
| 666 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 667 |
+
return dict(x.as_const(eval_ctx) for x in self.items)
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
class Pair(Helper):
|
| 671 |
+
"""A key, value pair for dicts."""
|
| 672 |
+
|
| 673 |
+
fields = ("key", "value")
|
| 674 |
+
key: Expr
|
| 675 |
+
value: Expr
|
| 676 |
+
|
| 677 |
+
def as_const(
|
| 678 |
+
self, eval_ctx: t.Optional[EvalContext] = None
|
| 679 |
+
) -> t.Tuple[t.Any, t.Any]:
|
| 680 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 681 |
+
return self.key.as_const(eval_ctx), self.value.as_const(eval_ctx)
|
| 682 |
+
|
| 683 |
+
|
| 684 |
+
class Keyword(Helper):
|
| 685 |
+
"""A key, value pair for keyword arguments where key is a string."""
|
| 686 |
+
|
| 687 |
+
fields = ("key", "value")
|
| 688 |
+
key: str
|
| 689 |
+
value: Expr
|
| 690 |
+
|
| 691 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Tuple[str, t.Any]:
|
| 692 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 693 |
+
return self.key, self.value.as_const(eval_ctx)
|
| 694 |
+
|
| 695 |
+
|
| 696 |
+
class CondExpr(Expr):
|
| 697 |
+
"""A conditional expression (inline if expression). (``{{
|
| 698 |
+
foo if bar else baz }}``)
|
| 699 |
+
"""
|
| 700 |
+
|
| 701 |
+
fields = ("test", "expr1", "expr2")
|
| 702 |
+
test: Expr
|
| 703 |
+
expr1: Expr
|
| 704 |
+
expr2: t.Optional[Expr]
|
| 705 |
+
|
| 706 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 707 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 708 |
+
if self.test.as_const(eval_ctx):
|
| 709 |
+
return self.expr1.as_const(eval_ctx)
|
| 710 |
+
|
| 711 |
+
# if we evaluate to an undefined object, we better do that at runtime
|
| 712 |
+
if self.expr2 is None:
|
| 713 |
+
raise Impossible()
|
| 714 |
+
|
| 715 |
+
return self.expr2.as_const(eval_ctx)
|
| 716 |
+
|
| 717 |
+
|
| 718 |
+
def args_as_const(
|
| 719 |
+
node: t.Union["_FilterTestCommon", "Call"], eval_ctx: t.Optional[EvalContext]
|
| 720 |
+
) -> t.Tuple[t.List[t.Any], t.Dict[t.Any, t.Any]]:
|
| 721 |
+
args = [x.as_const(eval_ctx) for x in node.args]
|
| 722 |
+
kwargs = dict(x.as_const(eval_ctx) for x in node.kwargs)
|
| 723 |
+
|
| 724 |
+
if node.dyn_args is not None:
|
| 725 |
+
try:
|
| 726 |
+
args.extend(node.dyn_args.as_const(eval_ctx))
|
| 727 |
+
except Exception as e:
|
| 728 |
+
raise Impossible() from e
|
| 729 |
+
|
| 730 |
+
if node.dyn_kwargs is not None:
|
| 731 |
+
try:
|
| 732 |
+
kwargs.update(node.dyn_kwargs.as_const(eval_ctx))
|
| 733 |
+
except Exception as e:
|
| 734 |
+
raise Impossible() from e
|
| 735 |
+
|
| 736 |
+
return args, kwargs
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
class _FilterTestCommon(Expr):
|
| 740 |
+
fields = ("node", "name", "args", "kwargs", "dyn_args", "dyn_kwargs")
|
| 741 |
+
node: Expr
|
| 742 |
+
name: str
|
| 743 |
+
args: t.List[Expr]
|
| 744 |
+
kwargs: t.List[Pair]
|
| 745 |
+
dyn_args: t.Optional[Expr]
|
| 746 |
+
dyn_kwargs: t.Optional[Expr]
|
| 747 |
+
abstract = True
|
| 748 |
+
_is_filter = True
|
| 749 |
+
|
| 750 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 751 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 752 |
+
|
| 753 |
+
if eval_ctx.volatile:
|
| 754 |
+
raise Impossible()
|
| 755 |
+
|
| 756 |
+
if self._is_filter:
|
| 757 |
+
env_map = eval_ctx.environment.filters
|
| 758 |
+
else:
|
| 759 |
+
env_map = eval_ctx.environment.tests
|
| 760 |
+
|
| 761 |
+
func = env_map.get(self.name)
|
| 762 |
+
pass_arg = _PassArg.from_obj(func) # type: ignore
|
| 763 |
+
|
| 764 |
+
if func is None or pass_arg is _PassArg.context:
|
| 765 |
+
raise Impossible()
|
| 766 |
+
|
| 767 |
+
if eval_ctx.environment.is_async and (
|
| 768 |
+
getattr(func, "jinja_async_variant", False) is True
|
| 769 |
+
or inspect.iscoroutinefunction(func)
|
| 770 |
+
):
|
| 771 |
+
raise Impossible()
|
| 772 |
+
|
| 773 |
+
args, kwargs = args_as_const(self, eval_ctx)
|
| 774 |
+
args.insert(0, self.node.as_const(eval_ctx))
|
| 775 |
+
|
| 776 |
+
if pass_arg is _PassArg.eval_context:
|
| 777 |
+
args.insert(0, eval_ctx)
|
| 778 |
+
elif pass_arg is _PassArg.environment:
|
| 779 |
+
args.insert(0, eval_ctx.environment)
|
| 780 |
+
|
| 781 |
+
try:
|
| 782 |
+
return func(*args, **kwargs)
|
| 783 |
+
except Exception as e:
|
| 784 |
+
raise Impossible() from e
|
| 785 |
+
|
| 786 |
+
|
| 787 |
+
class Filter(_FilterTestCommon):
|
| 788 |
+
"""Apply a filter to an expression. ``name`` is the name of the
|
| 789 |
+
filter, the other fields are the same as :class:`Call`.
|
| 790 |
+
|
| 791 |
+
If ``node`` is ``None``, the filter is being used in a filter block
|
| 792 |
+
and is applied to the content of the block.
|
| 793 |
+
"""
|
| 794 |
+
|
| 795 |
+
node: t.Optional[Expr] # type: ignore
|
| 796 |
+
|
| 797 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 798 |
+
if self.node is None:
|
| 799 |
+
raise Impossible()
|
| 800 |
+
|
| 801 |
+
return super().as_const(eval_ctx=eval_ctx)
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
class Test(_FilterTestCommon):
|
| 805 |
+
"""Apply a test to an expression. ``name`` is the name of the test,
|
| 806 |
+
the other field are the same as :class:`Call`.
|
| 807 |
+
|
| 808 |
+
.. versionchanged:: 3.0
|
| 809 |
+
``as_const`` shares the same logic for filters and tests. Tests
|
| 810 |
+
check for volatile, async, and ``@pass_context`` etc.
|
| 811 |
+
decorators.
|
| 812 |
+
"""
|
| 813 |
+
|
| 814 |
+
_is_filter = False
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
class Call(Expr):
|
| 818 |
+
"""Calls an expression. `args` is a list of arguments, `kwargs` a list
|
| 819 |
+
of keyword arguments (list of :class:`Keyword` nodes), and `dyn_args`
|
| 820 |
+
and `dyn_kwargs` has to be either `None` or a node that is used as
|
| 821 |
+
node for dynamic positional (``*args``) or keyword (``**kwargs``)
|
| 822 |
+
arguments.
|
| 823 |
+
"""
|
| 824 |
+
|
| 825 |
+
fields = ("node", "args", "kwargs", "dyn_args", "dyn_kwargs")
|
| 826 |
+
node: Expr
|
| 827 |
+
args: t.List[Expr]
|
| 828 |
+
kwargs: t.List[Keyword]
|
| 829 |
+
dyn_args: t.Optional[Expr]
|
| 830 |
+
dyn_kwargs: t.Optional[Expr]
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
class Getitem(Expr):
|
| 834 |
+
"""Get an attribute or item from an expression and prefer the item."""
|
| 835 |
+
|
| 836 |
+
fields = ("node", "arg", "ctx")
|
| 837 |
+
node: Expr
|
| 838 |
+
arg: Expr
|
| 839 |
+
ctx: str
|
| 840 |
+
|
| 841 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 842 |
+
if self.ctx != "load":
|
| 843 |
+
raise Impossible()
|
| 844 |
+
|
| 845 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 846 |
+
|
| 847 |
+
try:
|
| 848 |
+
return eval_ctx.environment.getitem(
|
| 849 |
+
self.node.as_const(eval_ctx), self.arg.as_const(eval_ctx)
|
| 850 |
+
)
|
| 851 |
+
except Exception as e:
|
| 852 |
+
raise Impossible() from e
|
| 853 |
+
|
| 854 |
+
|
| 855 |
+
class Getattr(Expr):
|
| 856 |
+
"""Get an attribute or item from an expression that is a ascii-only
|
| 857 |
+
bytestring and prefer the attribute.
|
| 858 |
+
"""
|
| 859 |
+
|
| 860 |
+
fields = ("node", "attr", "ctx")
|
| 861 |
+
node: Expr
|
| 862 |
+
attr: str
|
| 863 |
+
ctx: str
|
| 864 |
+
|
| 865 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 866 |
+
if self.ctx != "load":
|
| 867 |
+
raise Impossible()
|
| 868 |
+
|
| 869 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 870 |
+
|
| 871 |
+
try:
|
| 872 |
+
return eval_ctx.environment.getattr(self.node.as_const(eval_ctx), self.attr)
|
| 873 |
+
except Exception as e:
|
| 874 |
+
raise Impossible() from e
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
class Slice(Expr):
|
| 878 |
+
"""Represents a slice object. This must only be used as argument for
|
| 879 |
+
:class:`Subscript`.
|
| 880 |
+
"""
|
| 881 |
+
|
| 882 |
+
fields = ("start", "stop", "step")
|
| 883 |
+
start: t.Optional[Expr]
|
| 884 |
+
stop: t.Optional[Expr]
|
| 885 |
+
step: t.Optional[Expr]
|
| 886 |
+
|
| 887 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> slice:
|
| 888 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 889 |
+
|
| 890 |
+
def const(obj: t.Optional[Expr]) -> t.Optional[t.Any]:
|
| 891 |
+
if obj is None:
|
| 892 |
+
return None
|
| 893 |
+
return obj.as_const(eval_ctx)
|
| 894 |
+
|
| 895 |
+
return slice(const(self.start), const(self.stop), const(self.step))
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
class Concat(Expr):
|
| 899 |
+
"""Concatenates the list of expressions provided after converting
|
| 900 |
+
them to strings.
|
| 901 |
+
"""
|
| 902 |
+
|
| 903 |
+
fields = ("nodes",)
|
| 904 |
+
nodes: t.List[Expr]
|
| 905 |
+
|
| 906 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> str:
|
| 907 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 908 |
+
return "".join(str(x.as_const(eval_ctx)) for x in self.nodes)
|
| 909 |
+
|
| 910 |
+
|
| 911 |
+
class Compare(Expr):
|
| 912 |
+
"""Compares an expression with some other expressions. `ops` must be a
|
| 913 |
+
list of :class:`Operand`\\s.
|
| 914 |
+
"""
|
| 915 |
+
|
| 916 |
+
fields = ("expr", "ops")
|
| 917 |
+
expr: Expr
|
| 918 |
+
ops: t.List["Operand"]
|
| 919 |
+
|
| 920 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 921 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 922 |
+
result = value = self.expr.as_const(eval_ctx)
|
| 923 |
+
|
| 924 |
+
try:
|
| 925 |
+
for op in self.ops:
|
| 926 |
+
new_value = op.expr.as_const(eval_ctx)
|
| 927 |
+
result = _cmpop_to_func[op.op](value, new_value)
|
| 928 |
+
|
| 929 |
+
if not result:
|
| 930 |
+
return False
|
| 931 |
+
|
| 932 |
+
value = new_value
|
| 933 |
+
except Exception as e:
|
| 934 |
+
raise Impossible() from e
|
| 935 |
+
|
| 936 |
+
return result
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
class Operand(Helper):
|
| 940 |
+
"""Holds an operator and an expression."""
|
| 941 |
+
|
| 942 |
+
fields = ("op", "expr")
|
| 943 |
+
op: str
|
| 944 |
+
expr: Expr
|
| 945 |
+
|
| 946 |
+
|
| 947 |
+
class Mul(BinExpr):
|
| 948 |
+
"""Multiplies the left with the right node."""
|
| 949 |
+
|
| 950 |
+
operator = "*"
|
| 951 |
+
|
| 952 |
+
|
| 953 |
+
class Div(BinExpr):
|
| 954 |
+
"""Divides the left by the right node."""
|
| 955 |
+
|
| 956 |
+
operator = "/"
|
| 957 |
+
|
| 958 |
+
|
| 959 |
+
class FloorDiv(BinExpr):
|
| 960 |
+
"""Divides the left by the right node and converts the
|
| 961 |
+
result into an integer by truncating.
|
| 962 |
+
"""
|
| 963 |
+
|
| 964 |
+
operator = "//"
|
| 965 |
+
|
| 966 |
+
|
| 967 |
+
class Add(BinExpr):
|
| 968 |
+
"""Add the left to the right node."""
|
| 969 |
+
|
| 970 |
+
operator = "+"
|
| 971 |
+
|
| 972 |
+
|
| 973 |
+
class Sub(BinExpr):
|
| 974 |
+
"""Subtract the right from the left node."""
|
| 975 |
+
|
| 976 |
+
operator = "-"
|
| 977 |
+
|
| 978 |
+
|
| 979 |
+
class Mod(BinExpr):
|
| 980 |
+
"""Left modulo right."""
|
| 981 |
+
|
| 982 |
+
operator = "%"
|
| 983 |
+
|
| 984 |
+
|
| 985 |
+
class Pow(BinExpr):
|
| 986 |
+
"""Left to the power of right."""
|
| 987 |
+
|
| 988 |
+
operator = "**"
|
| 989 |
+
|
| 990 |
+
|
| 991 |
+
class And(BinExpr):
|
| 992 |
+
"""Short circuited AND."""
|
| 993 |
+
|
| 994 |
+
operator = "and"
|
| 995 |
+
|
| 996 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 997 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 998 |
+
return self.left.as_const(eval_ctx) and self.right.as_const(eval_ctx)
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
class Or(BinExpr):
|
| 1002 |
+
"""Short circuited OR."""
|
| 1003 |
+
|
| 1004 |
+
operator = "or"
|
| 1005 |
+
|
| 1006 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> t.Any:
|
| 1007 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 1008 |
+
return self.left.as_const(eval_ctx) or self.right.as_const(eval_ctx)
|
| 1009 |
+
|
| 1010 |
+
|
| 1011 |
+
class Not(UnaryExpr):
|
| 1012 |
+
"""Negate the expression."""
|
| 1013 |
+
|
| 1014 |
+
operator = "not"
|
| 1015 |
+
|
| 1016 |
+
|
| 1017 |
+
class Neg(UnaryExpr):
|
| 1018 |
+
"""Make the expression negative."""
|
| 1019 |
+
|
| 1020 |
+
operator = "-"
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
class Pos(UnaryExpr):
|
| 1024 |
+
"""Make the expression positive (noop for most expressions)"""
|
| 1025 |
+
|
| 1026 |
+
operator = "+"
|
| 1027 |
+
|
| 1028 |
+
|
| 1029 |
+
# Helpers for extensions
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
class EnvironmentAttribute(Expr):
|
| 1033 |
+
"""Loads an attribute from the environment object. This is useful for
|
| 1034 |
+
extensions that want to call a callback stored on the environment.
|
| 1035 |
+
"""
|
| 1036 |
+
|
| 1037 |
+
fields = ("name",)
|
| 1038 |
+
name: str
|
| 1039 |
+
|
| 1040 |
+
|
| 1041 |
+
class ExtensionAttribute(Expr):
|
| 1042 |
+
"""Returns the attribute of an extension bound to the environment.
|
| 1043 |
+
The identifier is the identifier of the :class:`Extension`.
|
| 1044 |
+
|
| 1045 |
+
This node is usually constructed by calling the
|
| 1046 |
+
:meth:`~jinja2.ext.Extension.attr` method on an extension.
|
| 1047 |
+
"""
|
| 1048 |
+
|
| 1049 |
+
fields = ("identifier", "name")
|
| 1050 |
+
identifier: str
|
| 1051 |
+
name: str
|
| 1052 |
+
|
| 1053 |
+
|
| 1054 |
+
class ImportedName(Expr):
|
| 1055 |
+
"""If created with an import name the import name is returned on node
|
| 1056 |
+
access. For example ``ImportedName('cgi.escape')`` returns the `escape`
|
| 1057 |
+
function from the cgi module on evaluation. Imports are optimized by the
|
| 1058 |
+
compiler so there is no need to assign them to local variables.
|
| 1059 |
+
"""
|
| 1060 |
+
|
| 1061 |
+
fields = ("importname",)
|
| 1062 |
+
importname: str
|
| 1063 |
+
|
| 1064 |
+
|
| 1065 |
+
class InternalName(Expr):
|
| 1066 |
+
"""An internal name in the compiler. You cannot create these nodes
|
| 1067 |
+
yourself but the parser provides a
|
| 1068 |
+
:meth:`~jinja2.parser.Parser.free_identifier` method that creates
|
| 1069 |
+
a new identifier for you. This identifier is not available from the
|
| 1070 |
+
template and is not treated specially by the compiler.
|
| 1071 |
+
"""
|
| 1072 |
+
|
| 1073 |
+
fields = ("name",)
|
| 1074 |
+
name: str
|
| 1075 |
+
|
| 1076 |
+
def __init__(self) -> None:
|
| 1077 |
+
raise TypeError(
|
| 1078 |
+
"Can't create internal names. Use the "
|
| 1079 |
+
"`free_identifier` method on a parser."
|
| 1080 |
+
)
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
class MarkSafe(Expr):
|
| 1084 |
+
"""Mark the wrapped expression as safe (wrap it as `Markup`)."""
|
| 1085 |
+
|
| 1086 |
+
fields = ("expr",)
|
| 1087 |
+
expr: Expr
|
| 1088 |
+
|
| 1089 |
+
def as_const(self, eval_ctx: t.Optional[EvalContext] = None) -> Markup:
|
| 1090 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 1091 |
+
return Markup(self.expr.as_const(eval_ctx))
|
| 1092 |
+
|
| 1093 |
+
|
| 1094 |
+
class MarkSafeIfAutoescape(Expr):
|
| 1095 |
+
"""Mark the wrapped expression as safe (wrap it as `Markup`) but
|
| 1096 |
+
only if autoescaping is active.
|
| 1097 |
+
|
| 1098 |
+
.. versionadded:: 2.5
|
| 1099 |
+
"""
|
| 1100 |
+
|
| 1101 |
+
fields = ("expr",)
|
| 1102 |
+
expr: Expr
|
| 1103 |
+
|
| 1104 |
+
def as_const(
|
| 1105 |
+
self, eval_ctx: t.Optional[EvalContext] = None
|
| 1106 |
+
) -> t.Union[Markup, t.Any]:
|
| 1107 |
+
eval_ctx = get_eval_context(self, eval_ctx)
|
| 1108 |
+
if eval_ctx.volatile:
|
| 1109 |
+
raise Impossible()
|
| 1110 |
+
expr = self.expr.as_const(eval_ctx)
|
| 1111 |
+
if eval_ctx.autoescape:
|
| 1112 |
+
return Markup(expr)
|
| 1113 |
+
return expr
|
| 1114 |
+
|
| 1115 |
+
|
| 1116 |
+
class ContextReference(Expr):
|
| 1117 |
+
"""Returns the current template context. It can be used like a
|
| 1118 |
+
:class:`Name` node, with a ``'load'`` ctx and will return the
|
| 1119 |
+
current :class:`~jinja2.runtime.Context` object.
|
| 1120 |
+
|
| 1121 |
+
Here an example that assigns the current template name to a
|
| 1122 |
+
variable named `foo`::
|
| 1123 |
+
|
| 1124 |
+
Assign(Name('foo', ctx='store'),
|
| 1125 |
+
Getattr(ContextReference(), 'name'))
|
| 1126 |
+
|
| 1127 |
+
This is basically equivalent to using the
|
| 1128 |
+
:func:`~jinja2.pass_context` decorator when using the high-level
|
| 1129 |
+
API, which causes a reference to the context to be passed as the
|
| 1130 |
+
first argument to a function.
|
| 1131 |
+
"""
|
| 1132 |
+
|
| 1133 |
+
|
| 1134 |
+
class DerivedContextReference(Expr):
|
| 1135 |
+
"""Return the current template context including locals. Behaves
|
| 1136 |
+
exactly like :class:`ContextReference`, but includes local
|
| 1137 |
+
variables, such as from a ``for`` loop.
|
| 1138 |
+
|
| 1139 |
+
.. versionadded:: 2.11
|
| 1140 |
+
"""
|
| 1141 |
+
|
| 1142 |
+
|
| 1143 |
+
class Continue(Stmt):
|
| 1144 |
+
"""Continue a loop."""
|
| 1145 |
+
|
| 1146 |
+
|
| 1147 |
+
class Break(Stmt):
|
| 1148 |
+
"""Break a loop."""
|
| 1149 |
+
|
| 1150 |
+
|
| 1151 |
+
class Scope(Stmt):
|
| 1152 |
+
"""An artificial scope."""
|
| 1153 |
+
|
| 1154 |
+
fields = ("body",)
|
| 1155 |
+
body: t.List[Node]
|
| 1156 |
+
|
| 1157 |
+
|
| 1158 |
+
class OverlayScope(Stmt):
|
| 1159 |
+
"""An overlay scope for extensions. This is a largely unoptimized scope
|
| 1160 |
+
that however can be used to introduce completely arbitrary variables into
|
| 1161 |
+
a sub scope from a dictionary or dictionary like object. The `context`
|
| 1162 |
+
field has to evaluate to a dictionary object.
|
| 1163 |
+
|
| 1164 |
+
Example usage::
|
| 1165 |
+
|
| 1166 |
+
OverlayScope(context=self.call_method('get_context'),
|
| 1167 |
+
body=[...])
|
| 1168 |
+
|
| 1169 |
+
.. versionadded:: 2.10
|
| 1170 |
+
"""
|
| 1171 |
+
|
| 1172 |
+
fields = ("context", "body")
|
| 1173 |
+
context: Expr
|
| 1174 |
+
body: t.List[Node]
|
| 1175 |
+
|
| 1176 |
+
|
| 1177 |
+
class EvalContextModifier(Stmt):
|
| 1178 |
+
"""Modifies the eval context. For each option that should be modified,
|
| 1179 |
+
a :class:`Keyword` has to be added to the :attr:`options` list.
|
| 1180 |
+
|
| 1181 |
+
Example to change the `autoescape` setting::
|
| 1182 |
+
|
| 1183 |
+
EvalContextModifier(options=[Keyword('autoescape', Const(True))])
|
| 1184 |
+
"""
|
| 1185 |
+
|
| 1186 |
+
fields = ("options",)
|
| 1187 |
+
options: t.List[Keyword]
|
| 1188 |
+
|
| 1189 |
+
|
| 1190 |
+
class ScopedEvalContextModifier(EvalContextModifier):
|
| 1191 |
+
"""Modifies the eval context and reverts it later. Works exactly like
|
| 1192 |
+
:class:`EvalContextModifier` but will only modify the
|
| 1193 |
+
:class:`~jinja2.nodes.EvalContext` for nodes in the :attr:`body`.
|
| 1194 |
+
"""
|
| 1195 |
+
|
| 1196 |
+
fields = ("body",)
|
| 1197 |
+
body: t.List[Node]
|
| 1198 |
+
|
| 1199 |
+
|
| 1200 |
+
# make sure nobody creates custom nodes
|
| 1201 |
+
def _failing_new(*args: t.Any, **kwargs: t.Any) -> "te.NoReturn":
|
| 1202 |
+
raise TypeError("can't create custom node types")
|
| 1203 |
+
|
| 1204 |
+
|
| 1205 |
+
NodeType.__new__ = staticmethod(_failing_new) # type: ignore
|
| 1206 |
+
del _failing_new
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/optimizer.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The optimizer tries to constant fold expressions and modify the AST
|
| 2 |
+
in place so that it should be faster to evaluate.
|
| 3 |
+
|
| 4 |
+
Because the AST does not contain all the scoping information and the
|
| 5 |
+
compiler has to find that out, we cannot do all the optimizations we
|
| 6 |
+
want. For example, loop unrolling doesn't work because unrolled loops
|
| 7 |
+
would have a different scope. The solution would be a second syntax tree
|
| 8 |
+
that stored the scoping rules.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import typing as t
|
| 12 |
+
|
| 13 |
+
from . import nodes
|
| 14 |
+
from .visitor import NodeTransformer
|
| 15 |
+
|
| 16 |
+
if t.TYPE_CHECKING:
|
| 17 |
+
from .environment import Environment
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def optimize(node: nodes.Node, environment: "Environment") -> nodes.Node:
|
| 21 |
+
"""The context hint can be used to perform an static optimization
|
| 22 |
+
based on the context given."""
|
| 23 |
+
optimizer = Optimizer(environment)
|
| 24 |
+
return t.cast(nodes.Node, optimizer.visit(node))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Optimizer(NodeTransformer):
|
| 28 |
+
def __init__(self, environment: "t.Optional[Environment]") -> None:
|
| 29 |
+
self.environment = environment
|
| 30 |
+
|
| 31 |
+
def generic_visit(
|
| 32 |
+
self, node: nodes.Node, *args: t.Any, **kwargs: t.Any
|
| 33 |
+
) -> nodes.Node:
|
| 34 |
+
node = super().generic_visit(node, *args, **kwargs)
|
| 35 |
+
|
| 36 |
+
# Do constant folding. Some other nodes besides Expr have
|
| 37 |
+
# as_const, but folding them causes errors later on.
|
| 38 |
+
if isinstance(node, nodes.Expr):
|
| 39 |
+
try:
|
| 40 |
+
return nodes.Const.from_untrusted(
|
| 41 |
+
node.as_const(args[0] if args else None),
|
| 42 |
+
lineno=node.lineno,
|
| 43 |
+
environment=self.environment,
|
| 44 |
+
)
|
| 45 |
+
except nodes.Impossible:
|
| 46 |
+
pass
|
| 47 |
+
|
| 48 |
+
return node
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/parser.py
ADDED
|
@@ -0,0 +1,1049 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse tokens from the lexer into nodes for the compiler."""
|
| 2 |
+
|
| 3 |
+
import typing
|
| 4 |
+
import typing as t
|
| 5 |
+
|
| 6 |
+
from . import nodes
|
| 7 |
+
from .exceptions import TemplateAssertionError
|
| 8 |
+
from .exceptions import TemplateSyntaxError
|
| 9 |
+
from .lexer import describe_token
|
| 10 |
+
from .lexer import describe_token_expr
|
| 11 |
+
|
| 12 |
+
if t.TYPE_CHECKING:
|
| 13 |
+
import typing_extensions as te
|
| 14 |
+
|
| 15 |
+
from .environment import Environment
|
| 16 |
+
|
| 17 |
+
_ImportInclude = t.TypeVar("_ImportInclude", nodes.Import, nodes.Include)
|
| 18 |
+
_MacroCall = t.TypeVar("_MacroCall", nodes.Macro, nodes.CallBlock)
|
| 19 |
+
|
| 20 |
+
_statement_keywords = frozenset(
|
| 21 |
+
[
|
| 22 |
+
"for",
|
| 23 |
+
"if",
|
| 24 |
+
"block",
|
| 25 |
+
"extends",
|
| 26 |
+
"print",
|
| 27 |
+
"macro",
|
| 28 |
+
"include",
|
| 29 |
+
"from",
|
| 30 |
+
"import",
|
| 31 |
+
"set",
|
| 32 |
+
"with",
|
| 33 |
+
"autoescape",
|
| 34 |
+
]
|
| 35 |
+
)
|
| 36 |
+
_compare_operators = frozenset(["eq", "ne", "lt", "lteq", "gt", "gteq"])
|
| 37 |
+
|
| 38 |
+
_math_nodes: t.Dict[str, t.Type[nodes.Expr]] = {
|
| 39 |
+
"add": nodes.Add,
|
| 40 |
+
"sub": nodes.Sub,
|
| 41 |
+
"mul": nodes.Mul,
|
| 42 |
+
"div": nodes.Div,
|
| 43 |
+
"floordiv": nodes.FloorDiv,
|
| 44 |
+
"mod": nodes.Mod,
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class Parser:
|
| 49 |
+
"""This is the central parsing class Jinja uses. It's passed to
|
| 50 |
+
extensions and can be used to parse expressions or statements.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def __init__(
|
| 54 |
+
self,
|
| 55 |
+
environment: "Environment",
|
| 56 |
+
source: str,
|
| 57 |
+
name: t.Optional[str] = None,
|
| 58 |
+
filename: t.Optional[str] = None,
|
| 59 |
+
state: t.Optional[str] = None,
|
| 60 |
+
) -> None:
|
| 61 |
+
self.environment = environment
|
| 62 |
+
self.stream = environment._tokenize(source, name, filename, state)
|
| 63 |
+
self.name = name
|
| 64 |
+
self.filename = filename
|
| 65 |
+
self.closed = False
|
| 66 |
+
self.extensions: t.Dict[
|
| 67 |
+
str, t.Callable[[Parser], t.Union[nodes.Node, t.List[nodes.Node]]]
|
| 68 |
+
] = {}
|
| 69 |
+
for extension in environment.iter_extensions():
|
| 70 |
+
for tag in extension.tags:
|
| 71 |
+
self.extensions[tag] = extension.parse
|
| 72 |
+
self._last_identifier = 0
|
| 73 |
+
self._tag_stack: t.List[str] = []
|
| 74 |
+
self._end_token_stack: t.List[t.Tuple[str, ...]] = []
|
| 75 |
+
|
| 76 |
+
def fail(
|
| 77 |
+
self,
|
| 78 |
+
msg: str,
|
| 79 |
+
lineno: t.Optional[int] = None,
|
| 80 |
+
exc: t.Type[TemplateSyntaxError] = TemplateSyntaxError,
|
| 81 |
+
) -> "te.NoReturn":
|
| 82 |
+
"""Convenience method that raises `exc` with the message, passed
|
| 83 |
+
line number or last line number as well as the current name and
|
| 84 |
+
filename.
|
| 85 |
+
"""
|
| 86 |
+
if lineno is None:
|
| 87 |
+
lineno = self.stream.current.lineno
|
| 88 |
+
raise exc(msg, lineno, self.name, self.filename)
|
| 89 |
+
|
| 90 |
+
def _fail_ut_eof(
|
| 91 |
+
self,
|
| 92 |
+
name: t.Optional[str],
|
| 93 |
+
end_token_stack: t.List[t.Tuple[str, ...]],
|
| 94 |
+
lineno: t.Optional[int],
|
| 95 |
+
) -> "te.NoReturn":
|
| 96 |
+
expected: t.Set[str] = set()
|
| 97 |
+
for exprs in end_token_stack:
|
| 98 |
+
expected.update(map(describe_token_expr, exprs))
|
| 99 |
+
if end_token_stack:
|
| 100 |
+
currently_looking: t.Optional[str] = " or ".join(
|
| 101 |
+
map(repr, map(describe_token_expr, end_token_stack[-1]))
|
| 102 |
+
)
|
| 103 |
+
else:
|
| 104 |
+
currently_looking = None
|
| 105 |
+
|
| 106 |
+
if name is None:
|
| 107 |
+
message = ["Unexpected end of template."]
|
| 108 |
+
else:
|
| 109 |
+
message = [f"Encountered unknown tag {name!r}."]
|
| 110 |
+
|
| 111 |
+
if currently_looking:
|
| 112 |
+
if name is not None and name in expected:
|
| 113 |
+
message.append(
|
| 114 |
+
"You probably made a nesting mistake. Jinja is expecting this tag,"
|
| 115 |
+
f" but currently looking for {currently_looking}."
|
| 116 |
+
)
|
| 117 |
+
else:
|
| 118 |
+
message.append(
|
| 119 |
+
f"Jinja was looking for the following tags: {currently_looking}."
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
if self._tag_stack:
|
| 123 |
+
message.append(
|
| 124 |
+
"The innermost block that needs to be closed is"
|
| 125 |
+
f" {self._tag_stack[-1]!r}."
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
self.fail(" ".join(message), lineno)
|
| 129 |
+
|
| 130 |
+
def fail_unknown_tag(
|
| 131 |
+
self, name: str, lineno: t.Optional[int] = None
|
| 132 |
+
) -> "te.NoReturn":
|
| 133 |
+
"""Called if the parser encounters an unknown tag. Tries to fail
|
| 134 |
+
with a human readable error message that could help to identify
|
| 135 |
+
the problem.
|
| 136 |
+
"""
|
| 137 |
+
self._fail_ut_eof(name, self._end_token_stack, lineno)
|
| 138 |
+
|
| 139 |
+
def fail_eof(
|
| 140 |
+
self,
|
| 141 |
+
end_tokens: t.Optional[t.Tuple[str, ...]] = None,
|
| 142 |
+
lineno: t.Optional[int] = None,
|
| 143 |
+
) -> "te.NoReturn":
|
| 144 |
+
"""Like fail_unknown_tag but for end of template situations."""
|
| 145 |
+
stack = list(self._end_token_stack)
|
| 146 |
+
if end_tokens is not None:
|
| 147 |
+
stack.append(end_tokens)
|
| 148 |
+
self._fail_ut_eof(None, stack, lineno)
|
| 149 |
+
|
| 150 |
+
def is_tuple_end(
|
| 151 |
+
self, extra_end_rules: t.Optional[t.Tuple[str, ...]] = None
|
| 152 |
+
) -> bool:
|
| 153 |
+
"""Are we at the end of a tuple?"""
|
| 154 |
+
if self.stream.current.type in ("variable_end", "block_end", "rparen"):
|
| 155 |
+
return True
|
| 156 |
+
elif extra_end_rules is not None:
|
| 157 |
+
return self.stream.current.test_any(extra_end_rules) # type: ignore
|
| 158 |
+
return False
|
| 159 |
+
|
| 160 |
+
def free_identifier(self, lineno: t.Optional[int] = None) -> nodes.InternalName:
|
| 161 |
+
"""Return a new free identifier as :class:`~jinja2.nodes.InternalName`."""
|
| 162 |
+
self._last_identifier += 1
|
| 163 |
+
rv = object.__new__(nodes.InternalName)
|
| 164 |
+
nodes.Node.__init__(rv, f"fi{self._last_identifier}", lineno=lineno)
|
| 165 |
+
return rv
|
| 166 |
+
|
| 167 |
+
def parse_statement(self) -> t.Union[nodes.Node, t.List[nodes.Node]]:
|
| 168 |
+
"""Parse a single statement."""
|
| 169 |
+
token = self.stream.current
|
| 170 |
+
if token.type != "name":
|
| 171 |
+
self.fail("tag name expected", token.lineno)
|
| 172 |
+
self._tag_stack.append(token.value)
|
| 173 |
+
pop_tag = True
|
| 174 |
+
try:
|
| 175 |
+
if token.value in _statement_keywords:
|
| 176 |
+
f = getattr(self, f"parse_{self.stream.current.value}")
|
| 177 |
+
return f() # type: ignore
|
| 178 |
+
if token.value == "call":
|
| 179 |
+
return self.parse_call_block()
|
| 180 |
+
if token.value == "filter":
|
| 181 |
+
return self.parse_filter_block()
|
| 182 |
+
ext = self.extensions.get(token.value)
|
| 183 |
+
if ext is not None:
|
| 184 |
+
return ext(self)
|
| 185 |
+
|
| 186 |
+
# did not work out, remove the token we pushed by accident
|
| 187 |
+
# from the stack so that the unknown tag fail function can
|
| 188 |
+
# produce a proper error message.
|
| 189 |
+
self._tag_stack.pop()
|
| 190 |
+
pop_tag = False
|
| 191 |
+
self.fail_unknown_tag(token.value, token.lineno)
|
| 192 |
+
finally:
|
| 193 |
+
if pop_tag:
|
| 194 |
+
self._tag_stack.pop()
|
| 195 |
+
|
| 196 |
+
def parse_statements(
|
| 197 |
+
self, end_tokens: t.Tuple[str, ...], drop_needle: bool = False
|
| 198 |
+
) -> t.List[nodes.Node]:
|
| 199 |
+
"""Parse multiple statements into a list until one of the end tokens
|
| 200 |
+
is reached. This is used to parse the body of statements as it also
|
| 201 |
+
parses template data if appropriate. The parser checks first if the
|
| 202 |
+
current token is a colon and skips it if there is one. Then it checks
|
| 203 |
+
for the block end and parses until if one of the `end_tokens` is
|
| 204 |
+
reached. Per default the active token in the stream at the end of
|
| 205 |
+
the call is the matched end token. If this is not wanted `drop_needle`
|
| 206 |
+
can be set to `True` and the end token is removed.
|
| 207 |
+
"""
|
| 208 |
+
# the first token may be a colon for python compatibility
|
| 209 |
+
self.stream.skip_if("colon")
|
| 210 |
+
|
| 211 |
+
# in the future it would be possible to add whole code sections
|
| 212 |
+
# by adding some sort of end of statement token and parsing those here.
|
| 213 |
+
self.stream.expect("block_end")
|
| 214 |
+
result = self.subparse(end_tokens)
|
| 215 |
+
|
| 216 |
+
# we reached the end of the template too early, the subparser
|
| 217 |
+
# does not check for this, so we do that now
|
| 218 |
+
if self.stream.current.type == "eof":
|
| 219 |
+
self.fail_eof(end_tokens)
|
| 220 |
+
|
| 221 |
+
if drop_needle:
|
| 222 |
+
next(self.stream)
|
| 223 |
+
return result
|
| 224 |
+
|
| 225 |
+
def parse_set(self) -> t.Union[nodes.Assign, nodes.AssignBlock]:
|
| 226 |
+
"""Parse an assign statement."""
|
| 227 |
+
lineno = next(self.stream).lineno
|
| 228 |
+
target = self.parse_assign_target(with_namespace=True)
|
| 229 |
+
if self.stream.skip_if("assign"):
|
| 230 |
+
expr = self.parse_tuple()
|
| 231 |
+
return nodes.Assign(target, expr, lineno=lineno)
|
| 232 |
+
filter_node = self.parse_filter(None)
|
| 233 |
+
body = self.parse_statements(("name:endset",), drop_needle=True)
|
| 234 |
+
return nodes.AssignBlock(target, filter_node, body, lineno=lineno)
|
| 235 |
+
|
| 236 |
+
def parse_for(self) -> nodes.For:
|
| 237 |
+
"""Parse a for loop."""
|
| 238 |
+
lineno = self.stream.expect("name:for").lineno
|
| 239 |
+
target = self.parse_assign_target(extra_end_rules=("name:in",))
|
| 240 |
+
self.stream.expect("name:in")
|
| 241 |
+
iter = self.parse_tuple(
|
| 242 |
+
with_condexpr=False, extra_end_rules=("name:recursive",)
|
| 243 |
+
)
|
| 244 |
+
test = None
|
| 245 |
+
if self.stream.skip_if("name:if"):
|
| 246 |
+
test = self.parse_expression()
|
| 247 |
+
recursive = self.stream.skip_if("name:recursive")
|
| 248 |
+
body = self.parse_statements(("name:endfor", "name:else"))
|
| 249 |
+
if next(self.stream).value == "endfor":
|
| 250 |
+
else_ = []
|
| 251 |
+
else:
|
| 252 |
+
else_ = self.parse_statements(("name:endfor",), drop_needle=True)
|
| 253 |
+
return nodes.For(target, iter, body, else_, test, recursive, lineno=lineno)
|
| 254 |
+
|
| 255 |
+
def parse_if(self) -> nodes.If:
|
| 256 |
+
"""Parse an if construct."""
|
| 257 |
+
node = result = nodes.If(lineno=self.stream.expect("name:if").lineno)
|
| 258 |
+
while True:
|
| 259 |
+
node.test = self.parse_tuple(with_condexpr=False)
|
| 260 |
+
node.body = self.parse_statements(("name:elif", "name:else", "name:endif"))
|
| 261 |
+
node.elif_ = []
|
| 262 |
+
node.else_ = []
|
| 263 |
+
token = next(self.stream)
|
| 264 |
+
if token.test("name:elif"):
|
| 265 |
+
node = nodes.If(lineno=self.stream.current.lineno)
|
| 266 |
+
result.elif_.append(node)
|
| 267 |
+
continue
|
| 268 |
+
elif token.test("name:else"):
|
| 269 |
+
result.else_ = self.parse_statements(("name:endif",), drop_needle=True)
|
| 270 |
+
break
|
| 271 |
+
return result
|
| 272 |
+
|
| 273 |
+
def parse_with(self) -> nodes.With:
|
| 274 |
+
node = nodes.With(lineno=next(self.stream).lineno)
|
| 275 |
+
targets: t.List[nodes.Expr] = []
|
| 276 |
+
values: t.List[nodes.Expr] = []
|
| 277 |
+
while self.stream.current.type != "block_end":
|
| 278 |
+
if targets:
|
| 279 |
+
self.stream.expect("comma")
|
| 280 |
+
target = self.parse_assign_target()
|
| 281 |
+
target.set_ctx("param")
|
| 282 |
+
targets.append(target)
|
| 283 |
+
self.stream.expect("assign")
|
| 284 |
+
values.append(self.parse_expression())
|
| 285 |
+
node.targets = targets
|
| 286 |
+
node.values = values
|
| 287 |
+
node.body = self.parse_statements(("name:endwith",), drop_needle=True)
|
| 288 |
+
return node
|
| 289 |
+
|
| 290 |
+
def parse_autoescape(self) -> nodes.Scope:
|
| 291 |
+
node = nodes.ScopedEvalContextModifier(lineno=next(self.stream).lineno)
|
| 292 |
+
node.options = [nodes.Keyword("autoescape", self.parse_expression())]
|
| 293 |
+
node.body = self.parse_statements(("name:endautoescape",), drop_needle=True)
|
| 294 |
+
return nodes.Scope([node])
|
| 295 |
+
|
| 296 |
+
def parse_block(self) -> nodes.Block:
|
| 297 |
+
node = nodes.Block(lineno=next(self.stream).lineno)
|
| 298 |
+
node.name = self.stream.expect("name").value
|
| 299 |
+
node.scoped = self.stream.skip_if("name:scoped")
|
| 300 |
+
node.required = self.stream.skip_if("name:required")
|
| 301 |
+
|
| 302 |
+
# common problem people encounter when switching from django
|
| 303 |
+
# to jinja. we do not support hyphens in block names, so let's
|
| 304 |
+
# raise a nicer error message in that case.
|
| 305 |
+
if self.stream.current.type == "sub":
|
| 306 |
+
self.fail(
|
| 307 |
+
"Block names in Jinja have to be valid Python identifiers and may not"
|
| 308 |
+
" contain hyphens, use an underscore instead."
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
node.body = self.parse_statements(("name:endblock",), drop_needle=True)
|
| 312 |
+
|
| 313 |
+
# enforce that required blocks only contain whitespace or comments
|
| 314 |
+
# by asserting that the body, if not empty, is just TemplateData nodes
|
| 315 |
+
# with whitespace data
|
| 316 |
+
if node.required:
|
| 317 |
+
for body_node in node.body:
|
| 318 |
+
if not isinstance(body_node, nodes.Output) or any(
|
| 319 |
+
not isinstance(output_node, nodes.TemplateData)
|
| 320 |
+
or not output_node.data.isspace()
|
| 321 |
+
for output_node in body_node.nodes
|
| 322 |
+
):
|
| 323 |
+
self.fail("Required blocks can only contain comments or whitespace")
|
| 324 |
+
|
| 325 |
+
self.stream.skip_if("name:" + node.name)
|
| 326 |
+
return node
|
| 327 |
+
|
| 328 |
+
def parse_extends(self) -> nodes.Extends:
|
| 329 |
+
node = nodes.Extends(lineno=next(self.stream).lineno)
|
| 330 |
+
node.template = self.parse_expression()
|
| 331 |
+
return node
|
| 332 |
+
|
| 333 |
+
def parse_import_context(
|
| 334 |
+
self, node: _ImportInclude, default: bool
|
| 335 |
+
) -> _ImportInclude:
|
| 336 |
+
if self.stream.current.test_any(
|
| 337 |
+
"name:with", "name:without"
|
| 338 |
+
) and self.stream.look().test("name:context"):
|
| 339 |
+
node.with_context = next(self.stream).value == "with"
|
| 340 |
+
self.stream.skip()
|
| 341 |
+
else:
|
| 342 |
+
node.with_context = default
|
| 343 |
+
return node
|
| 344 |
+
|
| 345 |
+
def parse_include(self) -> nodes.Include:
|
| 346 |
+
node = nodes.Include(lineno=next(self.stream).lineno)
|
| 347 |
+
node.template = self.parse_expression()
|
| 348 |
+
if self.stream.current.test("name:ignore") and self.stream.look().test(
|
| 349 |
+
"name:missing"
|
| 350 |
+
):
|
| 351 |
+
node.ignore_missing = True
|
| 352 |
+
self.stream.skip(2)
|
| 353 |
+
else:
|
| 354 |
+
node.ignore_missing = False
|
| 355 |
+
return self.parse_import_context(node, True)
|
| 356 |
+
|
| 357 |
+
def parse_import(self) -> nodes.Import:
|
| 358 |
+
node = nodes.Import(lineno=next(self.stream).lineno)
|
| 359 |
+
node.template = self.parse_expression()
|
| 360 |
+
self.stream.expect("name:as")
|
| 361 |
+
node.target = self.parse_assign_target(name_only=True).name
|
| 362 |
+
return self.parse_import_context(node, False)
|
| 363 |
+
|
| 364 |
+
def parse_from(self) -> nodes.FromImport:
|
| 365 |
+
node = nodes.FromImport(lineno=next(self.stream).lineno)
|
| 366 |
+
node.template = self.parse_expression()
|
| 367 |
+
self.stream.expect("name:import")
|
| 368 |
+
node.names = []
|
| 369 |
+
|
| 370 |
+
def parse_context() -> bool:
|
| 371 |
+
if self.stream.current.value in {
|
| 372 |
+
"with",
|
| 373 |
+
"without",
|
| 374 |
+
} and self.stream.look().test("name:context"):
|
| 375 |
+
node.with_context = next(self.stream).value == "with"
|
| 376 |
+
self.stream.skip()
|
| 377 |
+
return True
|
| 378 |
+
return False
|
| 379 |
+
|
| 380 |
+
while True:
|
| 381 |
+
if node.names:
|
| 382 |
+
self.stream.expect("comma")
|
| 383 |
+
if self.stream.current.type == "name":
|
| 384 |
+
if parse_context():
|
| 385 |
+
break
|
| 386 |
+
target = self.parse_assign_target(name_only=True)
|
| 387 |
+
if target.name.startswith("_"):
|
| 388 |
+
self.fail(
|
| 389 |
+
"names starting with an underline can not be imported",
|
| 390 |
+
target.lineno,
|
| 391 |
+
exc=TemplateAssertionError,
|
| 392 |
+
)
|
| 393 |
+
if self.stream.skip_if("name:as"):
|
| 394 |
+
alias = self.parse_assign_target(name_only=True)
|
| 395 |
+
node.names.append((target.name, alias.name))
|
| 396 |
+
else:
|
| 397 |
+
node.names.append(target.name)
|
| 398 |
+
if parse_context() or self.stream.current.type != "comma":
|
| 399 |
+
break
|
| 400 |
+
else:
|
| 401 |
+
self.stream.expect("name")
|
| 402 |
+
if not hasattr(node, "with_context"):
|
| 403 |
+
node.with_context = False
|
| 404 |
+
return node
|
| 405 |
+
|
| 406 |
+
def parse_signature(self, node: _MacroCall) -> None:
|
| 407 |
+
args = node.args = []
|
| 408 |
+
defaults = node.defaults = []
|
| 409 |
+
self.stream.expect("lparen")
|
| 410 |
+
while self.stream.current.type != "rparen":
|
| 411 |
+
if args:
|
| 412 |
+
self.stream.expect("comma")
|
| 413 |
+
arg = self.parse_assign_target(name_only=True)
|
| 414 |
+
arg.set_ctx("param")
|
| 415 |
+
if self.stream.skip_if("assign"):
|
| 416 |
+
defaults.append(self.parse_expression())
|
| 417 |
+
elif defaults:
|
| 418 |
+
self.fail("non-default argument follows default argument")
|
| 419 |
+
args.append(arg)
|
| 420 |
+
self.stream.expect("rparen")
|
| 421 |
+
|
| 422 |
+
def parse_call_block(self) -> nodes.CallBlock:
|
| 423 |
+
node = nodes.CallBlock(lineno=next(self.stream).lineno)
|
| 424 |
+
if self.stream.current.type == "lparen":
|
| 425 |
+
self.parse_signature(node)
|
| 426 |
+
else:
|
| 427 |
+
node.args = []
|
| 428 |
+
node.defaults = []
|
| 429 |
+
|
| 430 |
+
call_node = self.parse_expression()
|
| 431 |
+
if not isinstance(call_node, nodes.Call):
|
| 432 |
+
self.fail("expected call", node.lineno)
|
| 433 |
+
node.call = call_node
|
| 434 |
+
node.body = self.parse_statements(("name:endcall",), drop_needle=True)
|
| 435 |
+
return node
|
| 436 |
+
|
| 437 |
+
def parse_filter_block(self) -> nodes.FilterBlock:
|
| 438 |
+
node = nodes.FilterBlock(lineno=next(self.stream).lineno)
|
| 439 |
+
node.filter = self.parse_filter(None, start_inline=True) # type: ignore
|
| 440 |
+
node.body = self.parse_statements(("name:endfilter",), drop_needle=True)
|
| 441 |
+
return node
|
| 442 |
+
|
| 443 |
+
def parse_macro(self) -> nodes.Macro:
|
| 444 |
+
node = nodes.Macro(lineno=next(self.stream).lineno)
|
| 445 |
+
node.name = self.parse_assign_target(name_only=True).name
|
| 446 |
+
self.parse_signature(node)
|
| 447 |
+
node.body = self.parse_statements(("name:endmacro",), drop_needle=True)
|
| 448 |
+
return node
|
| 449 |
+
|
| 450 |
+
def parse_print(self) -> nodes.Output:
|
| 451 |
+
node = nodes.Output(lineno=next(self.stream).lineno)
|
| 452 |
+
node.nodes = []
|
| 453 |
+
while self.stream.current.type != "block_end":
|
| 454 |
+
if node.nodes:
|
| 455 |
+
self.stream.expect("comma")
|
| 456 |
+
node.nodes.append(self.parse_expression())
|
| 457 |
+
return node
|
| 458 |
+
|
| 459 |
+
@typing.overload
|
| 460 |
+
def parse_assign_target(
|
| 461 |
+
self, with_tuple: bool = ..., name_only: "te.Literal[True]" = ...
|
| 462 |
+
) -> nodes.Name: ...
|
| 463 |
+
|
| 464 |
+
@typing.overload
|
| 465 |
+
def parse_assign_target(
|
| 466 |
+
self,
|
| 467 |
+
with_tuple: bool = True,
|
| 468 |
+
name_only: bool = False,
|
| 469 |
+
extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
|
| 470 |
+
with_namespace: bool = False,
|
| 471 |
+
) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]: ...
|
| 472 |
+
|
| 473 |
+
def parse_assign_target(
|
| 474 |
+
self,
|
| 475 |
+
with_tuple: bool = True,
|
| 476 |
+
name_only: bool = False,
|
| 477 |
+
extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
|
| 478 |
+
with_namespace: bool = False,
|
| 479 |
+
) -> t.Union[nodes.NSRef, nodes.Name, nodes.Tuple]:
|
| 480 |
+
"""Parse an assignment target. As Jinja allows assignments to
|
| 481 |
+
tuples, this function can parse all allowed assignment targets. Per
|
| 482 |
+
default assignments to tuples are parsed, that can be disable however
|
| 483 |
+
by setting `with_tuple` to `False`. If only assignments to names are
|
| 484 |
+
wanted `name_only` can be set to `True`. The `extra_end_rules`
|
| 485 |
+
parameter is forwarded to the tuple parsing function. If
|
| 486 |
+
`with_namespace` is enabled, a namespace assignment may be parsed.
|
| 487 |
+
"""
|
| 488 |
+
target: nodes.Expr
|
| 489 |
+
|
| 490 |
+
if name_only:
|
| 491 |
+
token = self.stream.expect("name")
|
| 492 |
+
target = nodes.Name(token.value, "store", lineno=token.lineno)
|
| 493 |
+
else:
|
| 494 |
+
if with_tuple:
|
| 495 |
+
target = self.parse_tuple(
|
| 496 |
+
simplified=True,
|
| 497 |
+
extra_end_rules=extra_end_rules,
|
| 498 |
+
with_namespace=with_namespace,
|
| 499 |
+
)
|
| 500 |
+
else:
|
| 501 |
+
target = self.parse_primary(with_namespace=with_namespace)
|
| 502 |
+
|
| 503 |
+
target.set_ctx("store")
|
| 504 |
+
|
| 505 |
+
if not target.can_assign():
|
| 506 |
+
self.fail(
|
| 507 |
+
f"can't assign to {type(target).__name__.lower()!r}", target.lineno
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
return target # type: ignore
|
| 511 |
+
|
| 512 |
+
def parse_expression(self, with_condexpr: bool = True) -> nodes.Expr:
|
| 513 |
+
"""Parse an expression. Per default all expressions are parsed, if
|
| 514 |
+
the optional `with_condexpr` parameter is set to `False` conditional
|
| 515 |
+
expressions are not parsed.
|
| 516 |
+
"""
|
| 517 |
+
if with_condexpr:
|
| 518 |
+
return self.parse_condexpr()
|
| 519 |
+
return self.parse_or()
|
| 520 |
+
|
| 521 |
+
def parse_condexpr(self) -> nodes.Expr:
|
| 522 |
+
lineno = self.stream.current.lineno
|
| 523 |
+
expr1 = self.parse_or()
|
| 524 |
+
expr3: t.Optional[nodes.Expr]
|
| 525 |
+
|
| 526 |
+
while self.stream.skip_if("name:if"):
|
| 527 |
+
expr2 = self.parse_or()
|
| 528 |
+
if self.stream.skip_if("name:else"):
|
| 529 |
+
expr3 = self.parse_condexpr()
|
| 530 |
+
else:
|
| 531 |
+
expr3 = None
|
| 532 |
+
expr1 = nodes.CondExpr(expr2, expr1, expr3, lineno=lineno)
|
| 533 |
+
lineno = self.stream.current.lineno
|
| 534 |
+
return expr1
|
| 535 |
+
|
| 536 |
+
def parse_or(self) -> nodes.Expr:
|
| 537 |
+
lineno = self.stream.current.lineno
|
| 538 |
+
left = self.parse_and()
|
| 539 |
+
while self.stream.skip_if("name:or"):
|
| 540 |
+
right = self.parse_and()
|
| 541 |
+
left = nodes.Or(left, right, lineno=lineno)
|
| 542 |
+
lineno = self.stream.current.lineno
|
| 543 |
+
return left
|
| 544 |
+
|
| 545 |
+
def parse_and(self) -> nodes.Expr:
|
| 546 |
+
lineno = self.stream.current.lineno
|
| 547 |
+
left = self.parse_not()
|
| 548 |
+
while self.stream.skip_if("name:and"):
|
| 549 |
+
right = self.parse_not()
|
| 550 |
+
left = nodes.And(left, right, lineno=lineno)
|
| 551 |
+
lineno = self.stream.current.lineno
|
| 552 |
+
return left
|
| 553 |
+
|
| 554 |
+
def parse_not(self) -> nodes.Expr:
|
| 555 |
+
if self.stream.current.test("name:not"):
|
| 556 |
+
lineno = next(self.stream).lineno
|
| 557 |
+
return nodes.Not(self.parse_not(), lineno=lineno)
|
| 558 |
+
return self.parse_compare()
|
| 559 |
+
|
| 560 |
+
def parse_compare(self) -> nodes.Expr:
|
| 561 |
+
lineno = self.stream.current.lineno
|
| 562 |
+
expr = self.parse_math1()
|
| 563 |
+
ops = []
|
| 564 |
+
while True:
|
| 565 |
+
token_type = self.stream.current.type
|
| 566 |
+
if token_type in _compare_operators:
|
| 567 |
+
next(self.stream)
|
| 568 |
+
ops.append(nodes.Operand(token_type, self.parse_math1()))
|
| 569 |
+
elif self.stream.skip_if("name:in"):
|
| 570 |
+
ops.append(nodes.Operand("in", self.parse_math1()))
|
| 571 |
+
elif self.stream.current.test("name:not") and self.stream.look().test(
|
| 572 |
+
"name:in"
|
| 573 |
+
):
|
| 574 |
+
self.stream.skip(2)
|
| 575 |
+
ops.append(nodes.Operand("notin", self.parse_math1()))
|
| 576 |
+
else:
|
| 577 |
+
break
|
| 578 |
+
lineno = self.stream.current.lineno
|
| 579 |
+
if not ops:
|
| 580 |
+
return expr
|
| 581 |
+
return nodes.Compare(expr, ops, lineno=lineno)
|
| 582 |
+
|
| 583 |
+
def parse_math1(self) -> nodes.Expr:
|
| 584 |
+
lineno = self.stream.current.lineno
|
| 585 |
+
left = self.parse_concat()
|
| 586 |
+
while self.stream.current.type in ("add", "sub"):
|
| 587 |
+
cls = _math_nodes[self.stream.current.type]
|
| 588 |
+
next(self.stream)
|
| 589 |
+
right = self.parse_concat()
|
| 590 |
+
left = cls(left, right, lineno=lineno)
|
| 591 |
+
lineno = self.stream.current.lineno
|
| 592 |
+
return left
|
| 593 |
+
|
| 594 |
+
def parse_concat(self) -> nodes.Expr:
|
| 595 |
+
lineno = self.stream.current.lineno
|
| 596 |
+
args = [self.parse_math2()]
|
| 597 |
+
while self.stream.current.type == "tilde":
|
| 598 |
+
next(self.stream)
|
| 599 |
+
args.append(self.parse_math2())
|
| 600 |
+
if len(args) == 1:
|
| 601 |
+
return args[0]
|
| 602 |
+
return nodes.Concat(args, lineno=lineno)
|
| 603 |
+
|
| 604 |
+
def parse_math2(self) -> nodes.Expr:
|
| 605 |
+
lineno = self.stream.current.lineno
|
| 606 |
+
left = self.parse_pow()
|
| 607 |
+
while self.stream.current.type in ("mul", "div", "floordiv", "mod"):
|
| 608 |
+
cls = _math_nodes[self.stream.current.type]
|
| 609 |
+
next(self.stream)
|
| 610 |
+
right = self.parse_pow()
|
| 611 |
+
left = cls(left, right, lineno=lineno)
|
| 612 |
+
lineno = self.stream.current.lineno
|
| 613 |
+
return left
|
| 614 |
+
|
| 615 |
+
def parse_pow(self) -> nodes.Expr:
|
| 616 |
+
lineno = self.stream.current.lineno
|
| 617 |
+
left = self.parse_unary()
|
| 618 |
+
while self.stream.current.type == "pow":
|
| 619 |
+
next(self.stream)
|
| 620 |
+
right = self.parse_unary()
|
| 621 |
+
left = nodes.Pow(left, right, lineno=lineno)
|
| 622 |
+
lineno = self.stream.current.lineno
|
| 623 |
+
return left
|
| 624 |
+
|
| 625 |
+
def parse_unary(self, with_filter: bool = True) -> nodes.Expr:
|
| 626 |
+
token_type = self.stream.current.type
|
| 627 |
+
lineno = self.stream.current.lineno
|
| 628 |
+
node: nodes.Expr
|
| 629 |
+
|
| 630 |
+
if token_type == "sub":
|
| 631 |
+
next(self.stream)
|
| 632 |
+
node = nodes.Neg(self.parse_unary(False), lineno=lineno)
|
| 633 |
+
elif token_type == "add":
|
| 634 |
+
next(self.stream)
|
| 635 |
+
node = nodes.Pos(self.parse_unary(False), lineno=lineno)
|
| 636 |
+
else:
|
| 637 |
+
node = self.parse_primary()
|
| 638 |
+
node = self.parse_postfix(node)
|
| 639 |
+
if with_filter:
|
| 640 |
+
node = self.parse_filter_expr(node)
|
| 641 |
+
return node
|
| 642 |
+
|
| 643 |
+
def parse_primary(self, with_namespace: bool = False) -> nodes.Expr:
|
| 644 |
+
"""Parse a name or literal value. If ``with_namespace`` is enabled, also
|
| 645 |
+
parse namespace attr refs, for use in assignments."""
|
| 646 |
+
token = self.stream.current
|
| 647 |
+
node: nodes.Expr
|
| 648 |
+
if token.type == "name":
|
| 649 |
+
next(self.stream)
|
| 650 |
+
if token.value in ("true", "false", "True", "False"):
|
| 651 |
+
node = nodes.Const(token.value in ("true", "True"), lineno=token.lineno)
|
| 652 |
+
elif token.value in ("none", "None"):
|
| 653 |
+
node = nodes.Const(None, lineno=token.lineno)
|
| 654 |
+
elif with_namespace and self.stream.current.type == "dot":
|
| 655 |
+
# If namespace attributes are allowed at this point, and the next
|
| 656 |
+
# token is a dot, produce a namespace reference.
|
| 657 |
+
next(self.stream)
|
| 658 |
+
attr = self.stream.expect("name")
|
| 659 |
+
node = nodes.NSRef(token.value, attr.value, lineno=token.lineno)
|
| 660 |
+
else:
|
| 661 |
+
node = nodes.Name(token.value, "load", lineno=token.lineno)
|
| 662 |
+
elif token.type == "string":
|
| 663 |
+
next(self.stream)
|
| 664 |
+
buf = [token.value]
|
| 665 |
+
lineno = token.lineno
|
| 666 |
+
while self.stream.current.type == "string":
|
| 667 |
+
buf.append(self.stream.current.value)
|
| 668 |
+
next(self.stream)
|
| 669 |
+
node = nodes.Const("".join(buf), lineno=lineno)
|
| 670 |
+
elif token.type in ("integer", "float"):
|
| 671 |
+
next(self.stream)
|
| 672 |
+
node = nodes.Const(token.value, lineno=token.lineno)
|
| 673 |
+
elif token.type == "lparen":
|
| 674 |
+
next(self.stream)
|
| 675 |
+
node = self.parse_tuple(explicit_parentheses=True)
|
| 676 |
+
self.stream.expect("rparen")
|
| 677 |
+
elif token.type == "lbracket":
|
| 678 |
+
node = self.parse_list()
|
| 679 |
+
elif token.type == "lbrace":
|
| 680 |
+
node = self.parse_dict()
|
| 681 |
+
else:
|
| 682 |
+
self.fail(f"unexpected {describe_token(token)!r}", token.lineno)
|
| 683 |
+
return node
|
| 684 |
+
|
| 685 |
+
def parse_tuple(
|
| 686 |
+
self,
|
| 687 |
+
simplified: bool = False,
|
| 688 |
+
with_condexpr: bool = True,
|
| 689 |
+
extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
|
| 690 |
+
explicit_parentheses: bool = False,
|
| 691 |
+
with_namespace: bool = False,
|
| 692 |
+
) -> t.Union[nodes.Tuple, nodes.Expr]:
|
| 693 |
+
"""Works like `parse_expression` but if multiple expressions are
|
| 694 |
+
delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
|
| 695 |
+
This method could also return a regular expression instead of a tuple
|
| 696 |
+
if no commas where found.
|
| 697 |
+
|
| 698 |
+
The default parsing mode is a full tuple. If `simplified` is `True`
|
| 699 |
+
only names and literals are parsed; ``with_namespace`` allows namespace
|
| 700 |
+
attr refs as well. The `no_condexpr` parameter is forwarded to
|
| 701 |
+
:meth:`parse_expression`.
|
| 702 |
+
|
| 703 |
+
Because tuples do not require delimiters and may end in a bogus comma
|
| 704 |
+
an extra hint is needed that marks the end of a tuple. For example
|
| 705 |
+
for loops support tuples between `for` and `in`. In that case the
|
| 706 |
+
`extra_end_rules` is set to ``['name:in']``.
|
| 707 |
+
|
| 708 |
+
`explicit_parentheses` is true if the parsing was triggered by an
|
| 709 |
+
expression in parentheses. This is used to figure out if an empty
|
| 710 |
+
tuple is a valid expression or not.
|
| 711 |
+
"""
|
| 712 |
+
lineno = self.stream.current.lineno
|
| 713 |
+
if simplified:
|
| 714 |
+
|
| 715 |
+
def parse() -> nodes.Expr:
|
| 716 |
+
return self.parse_primary(with_namespace=with_namespace)
|
| 717 |
+
|
| 718 |
+
else:
|
| 719 |
+
|
| 720 |
+
def parse() -> nodes.Expr:
|
| 721 |
+
return self.parse_expression(with_condexpr=with_condexpr)
|
| 722 |
+
|
| 723 |
+
args: t.List[nodes.Expr] = []
|
| 724 |
+
is_tuple = False
|
| 725 |
+
|
| 726 |
+
while True:
|
| 727 |
+
if args:
|
| 728 |
+
self.stream.expect("comma")
|
| 729 |
+
if self.is_tuple_end(extra_end_rules):
|
| 730 |
+
break
|
| 731 |
+
args.append(parse())
|
| 732 |
+
if self.stream.current.type == "comma":
|
| 733 |
+
is_tuple = True
|
| 734 |
+
else:
|
| 735 |
+
break
|
| 736 |
+
lineno = self.stream.current.lineno
|
| 737 |
+
|
| 738 |
+
if not is_tuple:
|
| 739 |
+
if args:
|
| 740 |
+
return args[0]
|
| 741 |
+
|
| 742 |
+
# if we don't have explicit parentheses, an empty tuple is
|
| 743 |
+
# not a valid expression. This would mean nothing (literally
|
| 744 |
+
# nothing) in the spot of an expression would be an empty
|
| 745 |
+
# tuple.
|
| 746 |
+
if not explicit_parentheses:
|
| 747 |
+
self.fail(
|
| 748 |
+
"Expected an expression,"
|
| 749 |
+
f" got {describe_token(self.stream.current)!r}"
|
| 750 |
+
)
|
| 751 |
+
|
| 752 |
+
return nodes.Tuple(args, "load", lineno=lineno)
|
| 753 |
+
|
| 754 |
+
def parse_list(self) -> nodes.List:
|
| 755 |
+
token = self.stream.expect("lbracket")
|
| 756 |
+
items: t.List[nodes.Expr] = []
|
| 757 |
+
while self.stream.current.type != "rbracket":
|
| 758 |
+
if items:
|
| 759 |
+
self.stream.expect("comma")
|
| 760 |
+
if self.stream.current.type == "rbracket":
|
| 761 |
+
break
|
| 762 |
+
items.append(self.parse_expression())
|
| 763 |
+
self.stream.expect("rbracket")
|
| 764 |
+
return nodes.List(items, lineno=token.lineno)
|
| 765 |
+
|
| 766 |
+
def parse_dict(self) -> nodes.Dict:
|
| 767 |
+
token = self.stream.expect("lbrace")
|
| 768 |
+
items: t.List[nodes.Pair] = []
|
| 769 |
+
while self.stream.current.type != "rbrace":
|
| 770 |
+
if items:
|
| 771 |
+
self.stream.expect("comma")
|
| 772 |
+
if self.stream.current.type == "rbrace":
|
| 773 |
+
break
|
| 774 |
+
key = self.parse_expression()
|
| 775 |
+
self.stream.expect("colon")
|
| 776 |
+
value = self.parse_expression()
|
| 777 |
+
items.append(nodes.Pair(key, value, lineno=key.lineno))
|
| 778 |
+
self.stream.expect("rbrace")
|
| 779 |
+
return nodes.Dict(items, lineno=token.lineno)
|
| 780 |
+
|
| 781 |
+
def parse_postfix(self, node: nodes.Expr) -> nodes.Expr:
|
| 782 |
+
while True:
|
| 783 |
+
token_type = self.stream.current.type
|
| 784 |
+
if token_type == "dot" or token_type == "lbracket":
|
| 785 |
+
node = self.parse_subscript(node)
|
| 786 |
+
# calls are valid both after postfix expressions (getattr
|
| 787 |
+
# and getitem) as well as filters and tests
|
| 788 |
+
elif token_type == "lparen":
|
| 789 |
+
node = self.parse_call(node)
|
| 790 |
+
else:
|
| 791 |
+
break
|
| 792 |
+
return node
|
| 793 |
+
|
| 794 |
+
def parse_filter_expr(self, node: nodes.Expr) -> nodes.Expr:
|
| 795 |
+
while True:
|
| 796 |
+
token_type = self.stream.current.type
|
| 797 |
+
if token_type == "pipe":
|
| 798 |
+
node = self.parse_filter(node) # type: ignore
|
| 799 |
+
elif token_type == "name" and self.stream.current.value == "is":
|
| 800 |
+
node = self.parse_test(node)
|
| 801 |
+
# calls are valid both after postfix expressions (getattr
|
| 802 |
+
# and getitem) as well as filters and tests
|
| 803 |
+
elif token_type == "lparen":
|
| 804 |
+
node = self.parse_call(node)
|
| 805 |
+
else:
|
| 806 |
+
break
|
| 807 |
+
return node
|
| 808 |
+
|
| 809 |
+
def parse_subscript(
|
| 810 |
+
self, node: nodes.Expr
|
| 811 |
+
) -> t.Union[nodes.Getattr, nodes.Getitem]:
|
| 812 |
+
token = next(self.stream)
|
| 813 |
+
arg: nodes.Expr
|
| 814 |
+
|
| 815 |
+
if token.type == "dot":
|
| 816 |
+
attr_token = self.stream.current
|
| 817 |
+
next(self.stream)
|
| 818 |
+
if attr_token.type == "name":
|
| 819 |
+
return nodes.Getattr(
|
| 820 |
+
node, attr_token.value, "load", lineno=token.lineno
|
| 821 |
+
)
|
| 822 |
+
elif attr_token.type != "integer":
|
| 823 |
+
self.fail("expected name or number", attr_token.lineno)
|
| 824 |
+
arg = nodes.Const(attr_token.value, lineno=attr_token.lineno)
|
| 825 |
+
return nodes.Getitem(node, arg, "load", lineno=token.lineno)
|
| 826 |
+
if token.type == "lbracket":
|
| 827 |
+
args: t.List[nodes.Expr] = []
|
| 828 |
+
while self.stream.current.type != "rbracket":
|
| 829 |
+
if args:
|
| 830 |
+
self.stream.expect("comma")
|
| 831 |
+
args.append(self.parse_subscribed())
|
| 832 |
+
self.stream.expect("rbracket")
|
| 833 |
+
if len(args) == 1:
|
| 834 |
+
arg = args[0]
|
| 835 |
+
else:
|
| 836 |
+
arg = nodes.Tuple(args, "load", lineno=token.lineno)
|
| 837 |
+
return nodes.Getitem(node, arg, "load", lineno=token.lineno)
|
| 838 |
+
self.fail("expected subscript expression", token.lineno)
|
| 839 |
+
|
| 840 |
+
def parse_subscribed(self) -> nodes.Expr:
|
| 841 |
+
lineno = self.stream.current.lineno
|
| 842 |
+
args: t.List[t.Optional[nodes.Expr]]
|
| 843 |
+
|
| 844 |
+
if self.stream.current.type == "colon":
|
| 845 |
+
next(self.stream)
|
| 846 |
+
args = [None]
|
| 847 |
+
else:
|
| 848 |
+
node = self.parse_expression()
|
| 849 |
+
if self.stream.current.type != "colon":
|
| 850 |
+
return node
|
| 851 |
+
next(self.stream)
|
| 852 |
+
args = [node]
|
| 853 |
+
|
| 854 |
+
if self.stream.current.type == "colon":
|
| 855 |
+
args.append(None)
|
| 856 |
+
elif self.stream.current.type not in ("rbracket", "comma"):
|
| 857 |
+
args.append(self.parse_expression())
|
| 858 |
+
else:
|
| 859 |
+
args.append(None)
|
| 860 |
+
|
| 861 |
+
if self.stream.current.type == "colon":
|
| 862 |
+
next(self.stream)
|
| 863 |
+
if self.stream.current.type not in ("rbracket", "comma"):
|
| 864 |
+
args.append(self.parse_expression())
|
| 865 |
+
else:
|
| 866 |
+
args.append(None)
|
| 867 |
+
else:
|
| 868 |
+
args.append(None)
|
| 869 |
+
|
| 870 |
+
return nodes.Slice(lineno=lineno, *args) # noqa: B026
|
| 871 |
+
|
| 872 |
+
def parse_call_args(
|
| 873 |
+
self,
|
| 874 |
+
) -> t.Tuple[
|
| 875 |
+
t.List[nodes.Expr],
|
| 876 |
+
t.List[nodes.Keyword],
|
| 877 |
+
t.Optional[nodes.Expr],
|
| 878 |
+
t.Optional[nodes.Expr],
|
| 879 |
+
]:
|
| 880 |
+
token = self.stream.expect("lparen")
|
| 881 |
+
args = []
|
| 882 |
+
kwargs = []
|
| 883 |
+
dyn_args = None
|
| 884 |
+
dyn_kwargs = None
|
| 885 |
+
require_comma = False
|
| 886 |
+
|
| 887 |
+
def ensure(expr: bool) -> None:
|
| 888 |
+
if not expr:
|
| 889 |
+
self.fail("invalid syntax for function call expression", token.lineno)
|
| 890 |
+
|
| 891 |
+
while self.stream.current.type != "rparen":
|
| 892 |
+
if require_comma:
|
| 893 |
+
self.stream.expect("comma")
|
| 894 |
+
|
| 895 |
+
# support for trailing comma
|
| 896 |
+
if self.stream.current.type == "rparen":
|
| 897 |
+
break
|
| 898 |
+
|
| 899 |
+
if self.stream.current.type == "mul":
|
| 900 |
+
ensure(dyn_args is None and dyn_kwargs is None)
|
| 901 |
+
next(self.stream)
|
| 902 |
+
dyn_args = self.parse_expression()
|
| 903 |
+
elif self.stream.current.type == "pow":
|
| 904 |
+
ensure(dyn_kwargs is None)
|
| 905 |
+
next(self.stream)
|
| 906 |
+
dyn_kwargs = self.parse_expression()
|
| 907 |
+
else:
|
| 908 |
+
if (
|
| 909 |
+
self.stream.current.type == "name"
|
| 910 |
+
and self.stream.look().type == "assign"
|
| 911 |
+
):
|
| 912 |
+
# Parsing a kwarg
|
| 913 |
+
ensure(dyn_kwargs is None)
|
| 914 |
+
key = self.stream.current.value
|
| 915 |
+
self.stream.skip(2)
|
| 916 |
+
value = self.parse_expression()
|
| 917 |
+
kwargs.append(nodes.Keyword(key, value, lineno=value.lineno))
|
| 918 |
+
else:
|
| 919 |
+
# Parsing an arg
|
| 920 |
+
ensure(dyn_args is None and dyn_kwargs is None and not kwargs)
|
| 921 |
+
args.append(self.parse_expression())
|
| 922 |
+
|
| 923 |
+
require_comma = True
|
| 924 |
+
|
| 925 |
+
self.stream.expect("rparen")
|
| 926 |
+
return args, kwargs, dyn_args, dyn_kwargs
|
| 927 |
+
|
| 928 |
+
def parse_call(self, node: nodes.Expr) -> nodes.Call:
|
| 929 |
+
# The lparen will be expected in parse_call_args, but the lineno
|
| 930 |
+
# needs to be recorded before the stream is advanced.
|
| 931 |
+
token = self.stream.current
|
| 932 |
+
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
|
| 933 |
+
return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno)
|
| 934 |
+
|
| 935 |
+
def parse_filter(
|
| 936 |
+
self, node: t.Optional[nodes.Expr], start_inline: bool = False
|
| 937 |
+
) -> t.Optional[nodes.Expr]:
|
| 938 |
+
while self.stream.current.type == "pipe" or start_inline:
|
| 939 |
+
if not start_inline:
|
| 940 |
+
next(self.stream)
|
| 941 |
+
token = self.stream.expect("name")
|
| 942 |
+
name = token.value
|
| 943 |
+
while self.stream.current.type == "dot":
|
| 944 |
+
next(self.stream)
|
| 945 |
+
name += "." + self.stream.expect("name").value
|
| 946 |
+
if self.stream.current.type == "lparen":
|
| 947 |
+
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
|
| 948 |
+
else:
|
| 949 |
+
args = []
|
| 950 |
+
kwargs = []
|
| 951 |
+
dyn_args = dyn_kwargs = None
|
| 952 |
+
node = nodes.Filter(
|
| 953 |
+
node, name, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno
|
| 954 |
+
)
|
| 955 |
+
start_inline = False
|
| 956 |
+
return node
|
| 957 |
+
|
| 958 |
+
def parse_test(self, node: nodes.Expr) -> nodes.Expr:
|
| 959 |
+
token = next(self.stream)
|
| 960 |
+
if self.stream.current.test("name:not"):
|
| 961 |
+
next(self.stream)
|
| 962 |
+
negated = True
|
| 963 |
+
else:
|
| 964 |
+
negated = False
|
| 965 |
+
name = self.stream.expect("name").value
|
| 966 |
+
while self.stream.current.type == "dot":
|
| 967 |
+
next(self.stream)
|
| 968 |
+
name += "." + self.stream.expect("name").value
|
| 969 |
+
dyn_args = dyn_kwargs = None
|
| 970 |
+
kwargs: t.List[nodes.Keyword] = []
|
| 971 |
+
if self.stream.current.type == "lparen":
|
| 972 |
+
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
|
| 973 |
+
elif self.stream.current.type in {
|
| 974 |
+
"name",
|
| 975 |
+
"string",
|
| 976 |
+
"integer",
|
| 977 |
+
"float",
|
| 978 |
+
"lparen",
|
| 979 |
+
"lbracket",
|
| 980 |
+
"lbrace",
|
| 981 |
+
} and not self.stream.current.test_any("name:else", "name:or", "name:and"):
|
| 982 |
+
if self.stream.current.test("name:is"):
|
| 983 |
+
self.fail("You cannot chain multiple tests with is")
|
| 984 |
+
arg_node = self.parse_primary()
|
| 985 |
+
arg_node = self.parse_postfix(arg_node)
|
| 986 |
+
args = [arg_node]
|
| 987 |
+
else:
|
| 988 |
+
args = []
|
| 989 |
+
node = nodes.Test(
|
| 990 |
+
node, name, args, kwargs, dyn_args, dyn_kwargs, lineno=token.lineno
|
| 991 |
+
)
|
| 992 |
+
if negated:
|
| 993 |
+
node = nodes.Not(node, lineno=token.lineno)
|
| 994 |
+
return node
|
| 995 |
+
|
| 996 |
+
def subparse(
|
| 997 |
+
self, end_tokens: t.Optional[t.Tuple[str, ...]] = None
|
| 998 |
+
) -> t.List[nodes.Node]:
|
| 999 |
+
body: t.List[nodes.Node] = []
|
| 1000 |
+
data_buffer: t.List[nodes.Node] = []
|
| 1001 |
+
add_data = data_buffer.append
|
| 1002 |
+
|
| 1003 |
+
if end_tokens is not None:
|
| 1004 |
+
self._end_token_stack.append(end_tokens)
|
| 1005 |
+
|
| 1006 |
+
def flush_data() -> None:
|
| 1007 |
+
if data_buffer:
|
| 1008 |
+
lineno = data_buffer[0].lineno
|
| 1009 |
+
body.append(nodes.Output(data_buffer[:], lineno=lineno))
|
| 1010 |
+
del data_buffer[:]
|
| 1011 |
+
|
| 1012 |
+
try:
|
| 1013 |
+
while self.stream:
|
| 1014 |
+
token = self.stream.current
|
| 1015 |
+
if token.type == "data":
|
| 1016 |
+
if token.value:
|
| 1017 |
+
add_data(nodes.TemplateData(token.value, lineno=token.lineno))
|
| 1018 |
+
next(self.stream)
|
| 1019 |
+
elif token.type == "variable_begin":
|
| 1020 |
+
next(self.stream)
|
| 1021 |
+
add_data(self.parse_tuple(with_condexpr=True))
|
| 1022 |
+
self.stream.expect("variable_end")
|
| 1023 |
+
elif token.type == "block_begin":
|
| 1024 |
+
flush_data()
|
| 1025 |
+
next(self.stream)
|
| 1026 |
+
if end_tokens is not None and self.stream.current.test_any(
|
| 1027 |
+
*end_tokens
|
| 1028 |
+
):
|
| 1029 |
+
return body
|
| 1030 |
+
rv = self.parse_statement()
|
| 1031 |
+
if isinstance(rv, list):
|
| 1032 |
+
body.extend(rv)
|
| 1033 |
+
else:
|
| 1034 |
+
body.append(rv)
|
| 1035 |
+
self.stream.expect("block_end")
|
| 1036 |
+
else:
|
| 1037 |
+
raise AssertionError("internal parsing error")
|
| 1038 |
+
|
| 1039 |
+
flush_data()
|
| 1040 |
+
finally:
|
| 1041 |
+
if end_tokens is not None:
|
| 1042 |
+
self._end_token_stack.pop()
|
| 1043 |
+
return body
|
| 1044 |
+
|
| 1045 |
+
def parse(self) -> nodes.Template:
|
| 1046 |
+
"""Parse the whole template into a `Template` node."""
|
| 1047 |
+
result = nodes.Template(self.subparse(), lineno=1)
|
| 1048 |
+
result.set_environment(self.environment)
|
| 1049 |
+
return result
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/py.typed
ADDED
|
File without changes
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/runtime.py
ADDED
|
@@ -0,0 +1,1062 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The runtime functions and state used by compiled templates."""
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import sys
|
| 5 |
+
import typing as t
|
| 6 |
+
from collections import abc
|
| 7 |
+
from itertools import chain
|
| 8 |
+
|
| 9 |
+
from markupsafe import escape # noqa: F401
|
| 10 |
+
from markupsafe import Markup
|
| 11 |
+
from markupsafe import soft_str
|
| 12 |
+
|
| 13 |
+
from .async_utils import auto_aiter
|
| 14 |
+
from .async_utils import auto_await # noqa: F401
|
| 15 |
+
from .exceptions import TemplateNotFound # noqa: F401
|
| 16 |
+
from .exceptions import TemplateRuntimeError # noqa: F401
|
| 17 |
+
from .exceptions import UndefinedError
|
| 18 |
+
from .nodes import EvalContext
|
| 19 |
+
from .utils import _PassArg
|
| 20 |
+
from .utils import concat
|
| 21 |
+
from .utils import internalcode
|
| 22 |
+
from .utils import missing
|
| 23 |
+
from .utils import Namespace # noqa: F401
|
| 24 |
+
from .utils import object_type_repr
|
| 25 |
+
from .utils import pass_eval_context
|
| 26 |
+
|
| 27 |
+
V = t.TypeVar("V")
|
| 28 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 29 |
+
|
| 30 |
+
if t.TYPE_CHECKING:
|
| 31 |
+
import logging
|
| 32 |
+
|
| 33 |
+
import typing_extensions as te
|
| 34 |
+
|
| 35 |
+
from .environment import Environment
|
| 36 |
+
|
| 37 |
+
class LoopRenderFunc(te.Protocol):
|
| 38 |
+
def __call__(
|
| 39 |
+
self,
|
| 40 |
+
reciter: t.Iterable[V],
|
| 41 |
+
loop_render_func: "LoopRenderFunc",
|
| 42 |
+
depth: int = 0,
|
| 43 |
+
) -> str: ...
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
# these variables are exported to the template runtime
|
| 47 |
+
exported = [
|
| 48 |
+
"LoopContext",
|
| 49 |
+
"TemplateReference",
|
| 50 |
+
"Macro",
|
| 51 |
+
"Markup",
|
| 52 |
+
"TemplateRuntimeError",
|
| 53 |
+
"missing",
|
| 54 |
+
"escape",
|
| 55 |
+
"markup_join",
|
| 56 |
+
"str_join",
|
| 57 |
+
"identity",
|
| 58 |
+
"TemplateNotFound",
|
| 59 |
+
"Namespace",
|
| 60 |
+
"Undefined",
|
| 61 |
+
"internalcode",
|
| 62 |
+
]
|
| 63 |
+
async_exported = [
|
| 64 |
+
"AsyncLoopContext",
|
| 65 |
+
"auto_aiter",
|
| 66 |
+
"auto_await",
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def identity(x: V) -> V:
|
| 71 |
+
"""Returns its argument. Useful for certain things in the
|
| 72 |
+
environment.
|
| 73 |
+
"""
|
| 74 |
+
return x
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def markup_join(seq: t.Iterable[t.Any]) -> str:
|
| 78 |
+
"""Concatenation that escapes if necessary and converts to string."""
|
| 79 |
+
buf = []
|
| 80 |
+
iterator = map(soft_str, seq)
|
| 81 |
+
for arg in iterator:
|
| 82 |
+
buf.append(arg)
|
| 83 |
+
if hasattr(arg, "__html__"):
|
| 84 |
+
return Markup("").join(chain(buf, iterator))
|
| 85 |
+
return concat(buf)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def str_join(seq: t.Iterable[t.Any]) -> str:
|
| 89 |
+
"""Simple args to string conversion and concatenation."""
|
| 90 |
+
return concat(map(str, seq))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def new_context(
|
| 94 |
+
environment: "Environment",
|
| 95 |
+
template_name: t.Optional[str],
|
| 96 |
+
blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]],
|
| 97 |
+
vars: t.Optional[t.Dict[str, t.Any]] = None,
|
| 98 |
+
shared: bool = False,
|
| 99 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 100 |
+
locals: t.Optional[t.Mapping[str, t.Any]] = None,
|
| 101 |
+
) -> "Context":
|
| 102 |
+
"""Internal helper for context creation."""
|
| 103 |
+
if vars is None:
|
| 104 |
+
vars = {}
|
| 105 |
+
if shared:
|
| 106 |
+
parent = vars
|
| 107 |
+
else:
|
| 108 |
+
parent = dict(globals or (), **vars)
|
| 109 |
+
if locals:
|
| 110 |
+
# if the parent is shared a copy should be created because
|
| 111 |
+
# we don't want to modify the dict passed
|
| 112 |
+
if shared:
|
| 113 |
+
parent = dict(parent)
|
| 114 |
+
for key, value in locals.items():
|
| 115 |
+
if value is not missing:
|
| 116 |
+
parent[key] = value
|
| 117 |
+
return environment.context_class(
|
| 118 |
+
environment, parent, template_name, blocks, globals=globals
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class TemplateReference:
|
| 123 |
+
"""The `self` in templates."""
|
| 124 |
+
|
| 125 |
+
def __init__(self, context: "Context") -> None:
|
| 126 |
+
self.__context = context
|
| 127 |
+
|
| 128 |
+
def __getitem__(self, name: str) -> t.Any:
|
| 129 |
+
blocks = self.__context.blocks[name]
|
| 130 |
+
return BlockReference(name, self.__context, blocks, 0)
|
| 131 |
+
|
| 132 |
+
def __repr__(self) -> str:
|
| 133 |
+
return f"<{type(self).__name__} {self.__context.name!r}>"
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def _dict_method_all(dict_method: F) -> F:
|
| 137 |
+
@functools.wraps(dict_method)
|
| 138 |
+
def f_all(self: "Context") -> t.Any:
|
| 139 |
+
return dict_method(self.get_all())
|
| 140 |
+
|
| 141 |
+
return t.cast(F, f_all)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
@abc.Mapping.register
|
| 145 |
+
class Context:
|
| 146 |
+
"""The template context holds the variables of a template. It stores the
|
| 147 |
+
values passed to the template and also the names the template exports.
|
| 148 |
+
Creating instances is neither supported nor useful as it's created
|
| 149 |
+
automatically at various stages of the template evaluation and should not
|
| 150 |
+
be created by hand.
|
| 151 |
+
|
| 152 |
+
The context is immutable. Modifications on :attr:`parent` **must not**
|
| 153 |
+
happen and modifications on :attr:`vars` are allowed from generated
|
| 154 |
+
template code only. Template filters and global functions marked as
|
| 155 |
+
:func:`pass_context` get the active context passed as first argument
|
| 156 |
+
and are allowed to access the context read-only.
|
| 157 |
+
|
| 158 |
+
The template context supports read only dict operations (`get`,
|
| 159 |
+
`keys`, `values`, `items`, `iterkeys`, `itervalues`, `iteritems`,
|
| 160 |
+
`__getitem__`, `__contains__`). Additionally there is a :meth:`resolve`
|
| 161 |
+
method that doesn't fail with a `KeyError` but returns an
|
| 162 |
+
:class:`Undefined` object for missing variables.
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
+
def __init__(
|
| 166 |
+
self,
|
| 167 |
+
environment: "Environment",
|
| 168 |
+
parent: t.Dict[str, t.Any],
|
| 169 |
+
name: t.Optional[str],
|
| 170 |
+
blocks: t.Dict[str, t.Callable[["Context"], t.Iterator[str]]],
|
| 171 |
+
globals: t.Optional[t.MutableMapping[str, t.Any]] = None,
|
| 172 |
+
):
|
| 173 |
+
self.parent = parent
|
| 174 |
+
self.vars: t.Dict[str, t.Any] = {}
|
| 175 |
+
self.environment: Environment = environment
|
| 176 |
+
self.eval_ctx = EvalContext(self.environment, name)
|
| 177 |
+
self.exported_vars: t.Set[str] = set()
|
| 178 |
+
self.name = name
|
| 179 |
+
self.globals_keys = set() if globals is None else set(globals)
|
| 180 |
+
|
| 181 |
+
# create the initial mapping of blocks. Whenever template inheritance
|
| 182 |
+
# takes place the runtime will update this mapping with the new blocks
|
| 183 |
+
# from the template.
|
| 184 |
+
self.blocks = {k: [v] for k, v in blocks.items()}
|
| 185 |
+
|
| 186 |
+
def super(
|
| 187 |
+
self, name: str, current: t.Callable[["Context"], t.Iterator[str]]
|
| 188 |
+
) -> t.Union["BlockReference", "Undefined"]:
|
| 189 |
+
"""Render a parent block."""
|
| 190 |
+
try:
|
| 191 |
+
blocks = self.blocks[name]
|
| 192 |
+
index = blocks.index(current) + 1
|
| 193 |
+
blocks[index]
|
| 194 |
+
except LookupError:
|
| 195 |
+
return self.environment.undefined(
|
| 196 |
+
f"there is no parent block called {name!r}.", name="super"
|
| 197 |
+
)
|
| 198 |
+
return BlockReference(name, self, blocks, index)
|
| 199 |
+
|
| 200 |
+
def get(self, key: str, default: t.Any = None) -> t.Any:
|
| 201 |
+
"""Look up a variable by name, or return a default if the key is
|
| 202 |
+
not found.
|
| 203 |
+
|
| 204 |
+
:param key: The variable name to look up.
|
| 205 |
+
:param default: The value to return if the key is not found.
|
| 206 |
+
"""
|
| 207 |
+
try:
|
| 208 |
+
return self[key]
|
| 209 |
+
except KeyError:
|
| 210 |
+
return default
|
| 211 |
+
|
| 212 |
+
def resolve(self, key: str) -> t.Union[t.Any, "Undefined"]:
|
| 213 |
+
"""Look up a variable by name, or return an :class:`Undefined`
|
| 214 |
+
object if the key is not found.
|
| 215 |
+
|
| 216 |
+
If you need to add custom behavior, override
|
| 217 |
+
:meth:`resolve_or_missing`, not this method. The various lookup
|
| 218 |
+
functions use that method, not this one.
|
| 219 |
+
|
| 220 |
+
:param key: The variable name to look up.
|
| 221 |
+
"""
|
| 222 |
+
rv = self.resolve_or_missing(key)
|
| 223 |
+
|
| 224 |
+
if rv is missing:
|
| 225 |
+
return self.environment.undefined(name=key)
|
| 226 |
+
|
| 227 |
+
return rv
|
| 228 |
+
|
| 229 |
+
def resolve_or_missing(self, key: str) -> t.Any:
|
| 230 |
+
"""Look up a variable by name, or return a ``missing`` sentinel
|
| 231 |
+
if the key is not found.
|
| 232 |
+
|
| 233 |
+
Override this method to add custom lookup behavior.
|
| 234 |
+
:meth:`resolve`, :meth:`get`, and :meth:`__getitem__` use this
|
| 235 |
+
method. Don't call this method directly.
|
| 236 |
+
|
| 237 |
+
:param key: The variable name to look up.
|
| 238 |
+
"""
|
| 239 |
+
if key in self.vars:
|
| 240 |
+
return self.vars[key]
|
| 241 |
+
|
| 242 |
+
if key in self.parent:
|
| 243 |
+
return self.parent[key]
|
| 244 |
+
|
| 245 |
+
return missing
|
| 246 |
+
|
| 247 |
+
def get_exported(self) -> t.Dict[str, t.Any]:
|
| 248 |
+
"""Get a new dict with the exported variables."""
|
| 249 |
+
return {k: self.vars[k] for k in self.exported_vars}
|
| 250 |
+
|
| 251 |
+
def get_all(self) -> t.Dict[str, t.Any]:
|
| 252 |
+
"""Return the complete context as dict including the exported
|
| 253 |
+
variables. For optimizations reasons this might not return an
|
| 254 |
+
actual copy so be careful with using it.
|
| 255 |
+
"""
|
| 256 |
+
if not self.vars:
|
| 257 |
+
return self.parent
|
| 258 |
+
if not self.parent:
|
| 259 |
+
return self.vars
|
| 260 |
+
return dict(self.parent, **self.vars)
|
| 261 |
+
|
| 262 |
+
@internalcode
|
| 263 |
+
def call(
|
| 264 |
+
__self,
|
| 265 |
+
__obj: t.Callable[..., t.Any],
|
| 266 |
+
*args: t.Any,
|
| 267 |
+
**kwargs: t.Any, # noqa: B902
|
| 268 |
+
) -> t.Union[t.Any, "Undefined"]:
|
| 269 |
+
"""Call the callable with the arguments and keyword arguments
|
| 270 |
+
provided but inject the active context or environment as first
|
| 271 |
+
argument if the callable has :func:`pass_context` or
|
| 272 |
+
:func:`pass_environment`.
|
| 273 |
+
"""
|
| 274 |
+
if __debug__:
|
| 275 |
+
__traceback_hide__ = True # noqa
|
| 276 |
+
|
| 277 |
+
# Allow callable classes to take a context
|
| 278 |
+
if (
|
| 279 |
+
hasattr(__obj, "__call__") # noqa: B004
|
| 280 |
+
and _PassArg.from_obj(__obj.__call__) is not None
|
| 281 |
+
):
|
| 282 |
+
__obj = __obj.__call__
|
| 283 |
+
|
| 284 |
+
pass_arg = _PassArg.from_obj(__obj)
|
| 285 |
+
|
| 286 |
+
if pass_arg is _PassArg.context:
|
| 287 |
+
# the active context should have access to variables set in
|
| 288 |
+
# loops and blocks without mutating the context itself
|
| 289 |
+
if kwargs.get("_loop_vars"):
|
| 290 |
+
__self = __self.derived(kwargs["_loop_vars"])
|
| 291 |
+
if kwargs.get("_block_vars"):
|
| 292 |
+
__self = __self.derived(kwargs["_block_vars"])
|
| 293 |
+
args = (__self,) + args
|
| 294 |
+
elif pass_arg is _PassArg.eval_context:
|
| 295 |
+
args = (__self.eval_ctx,) + args
|
| 296 |
+
elif pass_arg is _PassArg.environment:
|
| 297 |
+
args = (__self.environment,) + args
|
| 298 |
+
|
| 299 |
+
kwargs.pop("_block_vars", None)
|
| 300 |
+
kwargs.pop("_loop_vars", None)
|
| 301 |
+
|
| 302 |
+
try:
|
| 303 |
+
return __obj(*args, **kwargs)
|
| 304 |
+
except StopIteration:
|
| 305 |
+
return __self.environment.undefined(
|
| 306 |
+
"value was undefined because a callable raised a"
|
| 307 |
+
" StopIteration exception"
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
def derived(self, locals: t.Optional[t.Dict[str, t.Any]] = None) -> "Context":
|
| 311 |
+
"""Internal helper function to create a derived context. This is
|
| 312 |
+
used in situations where the system needs a new context in the same
|
| 313 |
+
template that is independent.
|
| 314 |
+
"""
|
| 315 |
+
context = new_context(
|
| 316 |
+
self.environment, self.name, {}, self.get_all(), True, None, locals
|
| 317 |
+
)
|
| 318 |
+
context.eval_ctx = self.eval_ctx
|
| 319 |
+
context.blocks.update((k, list(v)) for k, v in self.blocks.items())
|
| 320 |
+
return context
|
| 321 |
+
|
| 322 |
+
keys = _dict_method_all(dict.keys)
|
| 323 |
+
values = _dict_method_all(dict.values)
|
| 324 |
+
items = _dict_method_all(dict.items)
|
| 325 |
+
|
| 326 |
+
def __contains__(self, name: str) -> bool:
|
| 327 |
+
return name in self.vars or name in self.parent
|
| 328 |
+
|
| 329 |
+
def __getitem__(self, key: str) -> t.Any:
|
| 330 |
+
"""Look up a variable by name with ``[]`` syntax, or raise a
|
| 331 |
+
``KeyError`` if the key is not found.
|
| 332 |
+
"""
|
| 333 |
+
item = self.resolve_or_missing(key)
|
| 334 |
+
|
| 335 |
+
if item is missing:
|
| 336 |
+
raise KeyError(key)
|
| 337 |
+
|
| 338 |
+
return item
|
| 339 |
+
|
| 340 |
+
def __repr__(self) -> str:
|
| 341 |
+
return f"<{type(self).__name__} {self.get_all()!r} of {self.name!r}>"
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
class BlockReference:
|
| 345 |
+
"""One block on a template reference."""
|
| 346 |
+
|
| 347 |
+
def __init__(
|
| 348 |
+
self,
|
| 349 |
+
name: str,
|
| 350 |
+
context: "Context",
|
| 351 |
+
stack: t.List[t.Callable[["Context"], t.Iterator[str]]],
|
| 352 |
+
depth: int,
|
| 353 |
+
) -> None:
|
| 354 |
+
self.name = name
|
| 355 |
+
self._context = context
|
| 356 |
+
self._stack = stack
|
| 357 |
+
self._depth = depth
|
| 358 |
+
|
| 359 |
+
@property
|
| 360 |
+
def super(self) -> t.Union["BlockReference", "Undefined"]:
|
| 361 |
+
"""Super the block."""
|
| 362 |
+
if self._depth + 1 >= len(self._stack):
|
| 363 |
+
return self._context.environment.undefined(
|
| 364 |
+
f"there is no parent block called {self.name!r}.", name="super"
|
| 365 |
+
)
|
| 366 |
+
return BlockReference(self.name, self._context, self._stack, self._depth + 1)
|
| 367 |
+
|
| 368 |
+
@internalcode
|
| 369 |
+
async def _async_call(self) -> str:
|
| 370 |
+
rv = self._context.environment.concat( # type: ignore
|
| 371 |
+
[x async for x in self._stack[self._depth](self._context)] # type: ignore
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
if self._context.eval_ctx.autoescape:
|
| 375 |
+
return Markup(rv)
|
| 376 |
+
|
| 377 |
+
return rv
|
| 378 |
+
|
| 379 |
+
@internalcode
|
| 380 |
+
def __call__(self) -> str:
|
| 381 |
+
if self._context.environment.is_async:
|
| 382 |
+
return self._async_call() # type: ignore
|
| 383 |
+
|
| 384 |
+
rv = self._context.environment.concat( # type: ignore
|
| 385 |
+
self._stack[self._depth](self._context)
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
if self._context.eval_ctx.autoescape:
|
| 389 |
+
return Markup(rv)
|
| 390 |
+
|
| 391 |
+
return rv
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
class LoopContext:
|
| 395 |
+
"""A wrapper iterable for dynamic ``for`` loops, with information
|
| 396 |
+
about the loop and iteration.
|
| 397 |
+
"""
|
| 398 |
+
|
| 399 |
+
#: Current iteration of the loop, starting at 0.
|
| 400 |
+
index0 = -1
|
| 401 |
+
|
| 402 |
+
_length: t.Optional[int] = None
|
| 403 |
+
_after: t.Any = missing
|
| 404 |
+
_current: t.Any = missing
|
| 405 |
+
_before: t.Any = missing
|
| 406 |
+
_last_changed_value: t.Any = missing
|
| 407 |
+
|
| 408 |
+
def __init__(
|
| 409 |
+
self,
|
| 410 |
+
iterable: t.Iterable[V],
|
| 411 |
+
undefined: t.Type["Undefined"],
|
| 412 |
+
recurse: t.Optional["LoopRenderFunc"] = None,
|
| 413 |
+
depth0: int = 0,
|
| 414 |
+
) -> None:
|
| 415 |
+
"""
|
| 416 |
+
:param iterable: Iterable to wrap.
|
| 417 |
+
:param undefined: :class:`Undefined` class to use for next and
|
| 418 |
+
previous items.
|
| 419 |
+
:param recurse: The function to render the loop body when the
|
| 420 |
+
loop is marked recursive.
|
| 421 |
+
:param depth0: Incremented when looping recursively.
|
| 422 |
+
"""
|
| 423 |
+
self._iterable = iterable
|
| 424 |
+
self._iterator = self._to_iterator(iterable)
|
| 425 |
+
self._undefined = undefined
|
| 426 |
+
self._recurse = recurse
|
| 427 |
+
#: How many levels deep a recursive loop currently is, starting at 0.
|
| 428 |
+
self.depth0 = depth0
|
| 429 |
+
|
| 430 |
+
@staticmethod
|
| 431 |
+
def _to_iterator(iterable: t.Iterable[V]) -> t.Iterator[V]:
|
| 432 |
+
return iter(iterable)
|
| 433 |
+
|
| 434 |
+
@property
|
| 435 |
+
def length(self) -> int:
|
| 436 |
+
"""Length of the iterable.
|
| 437 |
+
|
| 438 |
+
If the iterable is a generator or otherwise does not have a
|
| 439 |
+
size, it is eagerly evaluated to get a size.
|
| 440 |
+
"""
|
| 441 |
+
if self._length is not None:
|
| 442 |
+
return self._length
|
| 443 |
+
|
| 444 |
+
try:
|
| 445 |
+
self._length = len(self._iterable) # type: ignore
|
| 446 |
+
except TypeError:
|
| 447 |
+
iterable = list(self._iterator)
|
| 448 |
+
self._iterator = self._to_iterator(iterable)
|
| 449 |
+
self._length = len(iterable) + self.index + (self._after is not missing)
|
| 450 |
+
|
| 451 |
+
return self._length
|
| 452 |
+
|
| 453 |
+
def __len__(self) -> int:
|
| 454 |
+
return self.length
|
| 455 |
+
|
| 456 |
+
@property
|
| 457 |
+
def depth(self) -> int:
|
| 458 |
+
"""How many levels deep a recursive loop currently is, starting at 1."""
|
| 459 |
+
return self.depth0 + 1
|
| 460 |
+
|
| 461 |
+
@property
|
| 462 |
+
def index(self) -> int:
|
| 463 |
+
"""Current iteration of the loop, starting at 1."""
|
| 464 |
+
return self.index0 + 1
|
| 465 |
+
|
| 466 |
+
@property
|
| 467 |
+
def revindex0(self) -> int:
|
| 468 |
+
"""Number of iterations from the end of the loop, ending at 0.
|
| 469 |
+
|
| 470 |
+
Requires calculating :attr:`length`.
|
| 471 |
+
"""
|
| 472 |
+
return self.length - self.index
|
| 473 |
+
|
| 474 |
+
@property
|
| 475 |
+
def revindex(self) -> int:
|
| 476 |
+
"""Number of iterations from the end of the loop, ending at 1.
|
| 477 |
+
|
| 478 |
+
Requires calculating :attr:`length`.
|
| 479 |
+
"""
|
| 480 |
+
return self.length - self.index0
|
| 481 |
+
|
| 482 |
+
@property
|
| 483 |
+
def first(self) -> bool:
|
| 484 |
+
"""Whether this is the first iteration of the loop."""
|
| 485 |
+
return self.index0 == 0
|
| 486 |
+
|
| 487 |
+
def _peek_next(self) -> t.Any:
|
| 488 |
+
"""Return the next element in the iterable, or :data:`missing`
|
| 489 |
+
if the iterable is exhausted. Only peeks one item ahead, caching
|
| 490 |
+
the result in :attr:`_last` for use in subsequent checks. The
|
| 491 |
+
cache is reset when :meth:`__next__` is called.
|
| 492 |
+
"""
|
| 493 |
+
if self._after is not missing:
|
| 494 |
+
return self._after
|
| 495 |
+
|
| 496 |
+
self._after = next(self._iterator, missing)
|
| 497 |
+
return self._after
|
| 498 |
+
|
| 499 |
+
@property
|
| 500 |
+
def last(self) -> bool:
|
| 501 |
+
"""Whether this is the last iteration of the loop.
|
| 502 |
+
|
| 503 |
+
Causes the iterable to advance early. See
|
| 504 |
+
:func:`itertools.groupby` for issues this can cause.
|
| 505 |
+
The :func:`groupby` filter avoids that issue.
|
| 506 |
+
"""
|
| 507 |
+
return self._peek_next() is missing
|
| 508 |
+
|
| 509 |
+
@property
|
| 510 |
+
def previtem(self) -> t.Union[t.Any, "Undefined"]:
|
| 511 |
+
"""The item in the previous iteration. Undefined during the
|
| 512 |
+
first iteration.
|
| 513 |
+
"""
|
| 514 |
+
if self.first:
|
| 515 |
+
return self._undefined("there is no previous item")
|
| 516 |
+
|
| 517 |
+
return self._before
|
| 518 |
+
|
| 519 |
+
@property
|
| 520 |
+
def nextitem(self) -> t.Union[t.Any, "Undefined"]:
|
| 521 |
+
"""The item in the next iteration. Undefined during the last
|
| 522 |
+
iteration.
|
| 523 |
+
|
| 524 |
+
Causes the iterable to advance early. See
|
| 525 |
+
:func:`itertools.groupby` for issues this can cause.
|
| 526 |
+
The :func:`jinja-filters.groupby` filter avoids that issue.
|
| 527 |
+
"""
|
| 528 |
+
rv = self._peek_next()
|
| 529 |
+
|
| 530 |
+
if rv is missing:
|
| 531 |
+
return self._undefined("there is no next item")
|
| 532 |
+
|
| 533 |
+
return rv
|
| 534 |
+
|
| 535 |
+
def cycle(self, *args: V) -> V:
|
| 536 |
+
"""Return a value from the given args, cycling through based on
|
| 537 |
+
the current :attr:`index0`.
|
| 538 |
+
|
| 539 |
+
:param args: One or more values to cycle through.
|
| 540 |
+
"""
|
| 541 |
+
if not args:
|
| 542 |
+
raise TypeError("no items for cycling given")
|
| 543 |
+
|
| 544 |
+
return args[self.index0 % len(args)]
|
| 545 |
+
|
| 546 |
+
def changed(self, *value: t.Any) -> bool:
|
| 547 |
+
"""Return ``True`` if previously called with a different value
|
| 548 |
+
(including when called for the first time).
|
| 549 |
+
|
| 550 |
+
:param value: One or more values to compare to the last call.
|
| 551 |
+
"""
|
| 552 |
+
if self._last_changed_value != value:
|
| 553 |
+
self._last_changed_value = value
|
| 554 |
+
return True
|
| 555 |
+
|
| 556 |
+
return False
|
| 557 |
+
|
| 558 |
+
def __iter__(self) -> "LoopContext":
|
| 559 |
+
return self
|
| 560 |
+
|
| 561 |
+
def __next__(self) -> t.Tuple[t.Any, "LoopContext"]:
|
| 562 |
+
if self._after is not missing:
|
| 563 |
+
rv = self._after
|
| 564 |
+
self._after = missing
|
| 565 |
+
else:
|
| 566 |
+
rv = next(self._iterator)
|
| 567 |
+
|
| 568 |
+
self.index0 += 1
|
| 569 |
+
self._before = self._current
|
| 570 |
+
self._current = rv
|
| 571 |
+
return rv, self
|
| 572 |
+
|
| 573 |
+
@internalcode
|
| 574 |
+
def __call__(self, iterable: t.Iterable[V]) -> str:
|
| 575 |
+
"""When iterating over nested data, render the body of the loop
|
| 576 |
+
recursively with the given inner iterable data.
|
| 577 |
+
|
| 578 |
+
The loop must have the ``recursive`` marker for this to work.
|
| 579 |
+
"""
|
| 580 |
+
if self._recurse is None:
|
| 581 |
+
raise TypeError(
|
| 582 |
+
"The loop must have the 'recursive' marker to be called recursively."
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
return self._recurse(iterable, self._recurse, depth=self.depth)
|
| 586 |
+
|
| 587 |
+
def __repr__(self) -> str:
|
| 588 |
+
return f"<{type(self).__name__} {self.index}/{self.length}>"
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
class AsyncLoopContext(LoopContext):
|
| 592 |
+
_iterator: t.AsyncIterator[t.Any] # type: ignore
|
| 593 |
+
|
| 594 |
+
@staticmethod
|
| 595 |
+
def _to_iterator( # type: ignore
|
| 596 |
+
iterable: t.Union[t.Iterable[V], t.AsyncIterable[V]],
|
| 597 |
+
) -> t.AsyncIterator[V]:
|
| 598 |
+
return auto_aiter(iterable)
|
| 599 |
+
|
| 600 |
+
@property
|
| 601 |
+
async def length(self) -> int: # type: ignore
|
| 602 |
+
if self._length is not None:
|
| 603 |
+
return self._length
|
| 604 |
+
|
| 605 |
+
try:
|
| 606 |
+
self._length = len(self._iterable) # type: ignore
|
| 607 |
+
except TypeError:
|
| 608 |
+
iterable = [x async for x in self._iterator]
|
| 609 |
+
self._iterator = self._to_iterator(iterable)
|
| 610 |
+
self._length = len(iterable) + self.index + (self._after is not missing)
|
| 611 |
+
|
| 612 |
+
return self._length
|
| 613 |
+
|
| 614 |
+
@property
|
| 615 |
+
async def revindex0(self) -> int: # type: ignore
|
| 616 |
+
return await self.length - self.index
|
| 617 |
+
|
| 618 |
+
@property
|
| 619 |
+
async def revindex(self) -> int: # type: ignore
|
| 620 |
+
return await self.length - self.index0
|
| 621 |
+
|
| 622 |
+
async def _peek_next(self) -> t.Any:
|
| 623 |
+
if self._after is not missing:
|
| 624 |
+
return self._after
|
| 625 |
+
|
| 626 |
+
try:
|
| 627 |
+
self._after = await self._iterator.__anext__()
|
| 628 |
+
except StopAsyncIteration:
|
| 629 |
+
self._after = missing
|
| 630 |
+
|
| 631 |
+
return self._after
|
| 632 |
+
|
| 633 |
+
@property
|
| 634 |
+
async def last(self) -> bool: # type: ignore
|
| 635 |
+
return await self._peek_next() is missing
|
| 636 |
+
|
| 637 |
+
@property
|
| 638 |
+
async def nextitem(self) -> t.Union[t.Any, "Undefined"]:
|
| 639 |
+
rv = await self._peek_next()
|
| 640 |
+
|
| 641 |
+
if rv is missing:
|
| 642 |
+
return self._undefined("there is no next item")
|
| 643 |
+
|
| 644 |
+
return rv
|
| 645 |
+
|
| 646 |
+
def __aiter__(self) -> "AsyncLoopContext":
|
| 647 |
+
return self
|
| 648 |
+
|
| 649 |
+
async def __anext__(self) -> t.Tuple[t.Any, "AsyncLoopContext"]:
|
| 650 |
+
if self._after is not missing:
|
| 651 |
+
rv = self._after
|
| 652 |
+
self._after = missing
|
| 653 |
+
else:
|
| 654 |
+
rv = await self._iterator.__anext__()
|
| 655 |
+
|
| 656 |
+
self.index0 += 1
|
| 657 |
+
self._before = self._current
|
| 658 |
+
self._current = rv
|
| 659 |
+
return rv, self
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
class Macro:
|
| 663 |
+
"""Wraps a macro function."""
|
| 664 |
+
|
| 665 |
+
def __init__(
|
| 666 |
+
self,
|
| 667 |
+
environment: "Environment",
|
| 668 |
+
func: t.Callable[..., str],
|
| 669 |
+
name: str,
|
| 670 |
+
arguments: t.List[str],
|
| 671 |
+
catch_kwargs: bool,
|
| 672 |
+
catch_varargs: bool,
|
| 673 |
+
caller: bool,
|
| 674 |
+
default_autoescape: t.Optional[bool] = None,
|
| 675 |
+
):
|
| 676 |
+
self._environment = environment
|
| 677 |
+
self._func = func
|
| 678 |
+
self._argument_count = len(arguments)
|
| 679 |
+
self.name = name
|
| 680 |
+
self.arguments = arguments
|
| 681 |
+
self.catch_kwargs = catch_kwargs
|
| 682 |
+
self.catch_varargs = catch_varargs
|
| 683 |
+
self.caller = caller
|
| 684 |
+
self.explicit_caller = "caller" in arguments
|
| 685 |
+
|
| 686 |
+
if default_autoescape is None:
|
| 687 |
+
if callable(environment.autoescape):
|
| 688 |
+
default_autoescape = environment.autoescape(None)
|
| 689 |
+
else:
|
| 690 |
+
default_autoescape = environment.autoescape
|
| 691 |
+
|
| 692 |
+
self._default_autoescape = default_autoescape
|
| 693 |
+
|
| 694 |
+
@internalcode
|
| 695 |
+
@pass_eval_context
|
| 696 |
+
def __call__(self, *args: t.Any, **kwargs: t.Any) -> str:
|
| 697 |
+
# This requires a bit of explanation, In the past we used to
|
| 698 |
+
# decide largely based on compile-time information if a macro is
|
| 699 |
+
# safe or unsafe. While there was a volatile mode it was largely
|
| 700 |
+
# unused for deciding on escaping. This turns out to be
|
| 701 |
+
# problematic for macros because whether a macro is safe depends not
|
| 702 |
+
# on the escape mode when it was defined, but rather when it was used.
|
| 703 |
+
#
|
| 704 |
+
# Because however we export macros from the module system and
|
| 705 |
+
# there are historic callers that do not pass an eval context (and
|
| 706 |
+
# will continue to not pass one), we need to perform an instance
|
| 707 |
+
# check here.
|
| 708 |
+
#
|
| 709 |
+
# This is considered safe because an eval context is not a valid
|
| 710 |
+
# argument to callables otherwise anyway. Worst case here is
|
| 711 |
+
# that if no eval context is passed we fall back to the compile
|
| 712 |
+
# time autoescape flag.
|
| 713 |
+
if args and isinstance(args[0], EvalContext):
|
| 714 |
+
autoescape = args[0].autoescape
|
| 715 |
+
args = args[1:]
|
| 716 |
+
else:
|
| 717 |
+
autoescape = self._default_autoescape
|
| 718 |
+
|
| 719 |
+
# try to consume the positional arguments
|
| 720 |
+
arguments = list(args[: self._argument_count])
|
| 721 |
+
off = len(arguments)
|
| 722 |
+
|
| 723 |
+
# For information why this is necessary refer to the handling
|
| 724 |
+
# of caller in the `macro_body` handler in the compiler.
|
| 725 |
+
found_caller = False
|
| 726 |
+
|
| 727 |
+
# if the number of arguments consumed is not the number of
|
| 728 |
+
# arguments expected we start filling in keyword arguments
|
| 729 |
+
# and defaults.
|
| 730 |
+
if off != self._argument_count:
|
| 731 |
+
for name in self.arguments[len(arguments) :]:
|
| 732 |
+
try:
|
| 733 |
+
value = kwargs.pop(name)
|
| 734 |
+
except KeyError:
|
| 735 |
+
value = missing
|
| 736 |
+
if name == "caller":
|
| 737 |
+
found_caller = True
|
| 738 |
+
arguments.append(value)
|
| 739 |
+
else:
|
| 740 |
+
found_caller = self.explicit_caller
|
| 741 |
+
|
| 742 |
+
# it's important that the order of these arguments does not change
|
| 743 |
+
# if not also changed in the compiler's `function_scoping` method.
|
| 744 |
+
# the order is caller, keyword arguments, positional arguments!
|
| 745 |
+
if self.caller and not found_caller:
|
| 746 |
+
caller = kwargs.pop("caller", None)
|
| 747 |
+
if caller is None:
|
| 748 |
+
caller = self._environment.undefined("No caller defined", name="caller")
|
| 749 |
+
arguments.append(caller)
|
| 750 |
+
|
| 751 |
+
if self.catch_kwargs:
|
| 752 |
+
arguments.append(kwargs)
|
| 753 |
+
elif kwargs:
|
| 754 |
+
if "caller" in kwargs:
|
| 755 |
+
raise TypeError(
|
| 756 |
+
f"macro {self.name!r} was invoked with two values for the special"
|
| 757 |
+
" caller argument. This is most likely a bug."
|
| 758 |
+
)
|
| 759 |
+
raise TypeError(
|
| 760 |
+
f"macro {self.name!r} takes no keyword argument {next(iter(kwargs))!r}"
|
| 761 |
+
)
|
| 762 |
+
if self.catch_varargs:
|
| 763 |
+
arguments.append(args[self._argument_count :])
|
| 764 |
+
elif len(args) > self._argument_count:
|
| 765 |
+
raise TypeError(
|
| 766 |
+
f"macro {self.name!r} takes not more than"
|
| 767 |
+
f" {len(self.arguments)} argument(s)"
|
| 768 |
+
)
|
| 769 |
+
|
| 770 |
+
return self._invoke(arguments, autoescape)
|
| 771 |
+
|
| 772 |
+
async def _async_invoke(self, arguments: t.List[t.Any], autoescape: bool) -> str:
|
| 773 |
+
rv = await self._func(*arguments) # type: ignore
|
| 774 |
+
|
| 775 |
+
if autoescape:
|
| 776 |
+
return Markup(rv)
|
| 777 |
+
|
| 778 |
+
return rv # type: ignore
|
| 779 |
+
|
| 780 |
+
def _invoke(self, arguments: t.List[t.Any], autoescape: bool) -> str:
|
| 781 |
+
if self._environment.is_async:
|
| 782 |
+
return self._async_invoke(arguments, autoescape) # type: ignore
|
| 783 |
+
|
| 784 |
+
rv = self._func(*arguments)
|
| 785 |
+
|
| 786 |
+
if autoescape:
|
| 787 |
+
rv = Markup(rv)
|
| 788 |
+
|
| 789 |
+
return rv
|
| 790 |
+
|
| 791 |
+
def __repr__(self) -> str:
|
| 792 |
+
name = "anonymous" if self.name is None else repr(self.name)
|
| 793 |
+
return f"<{type(self).__name__} {name}>"
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
class Undefined:
|
| 797 |
+
"""The default undefined type. This can be printed, iterated, and treated as
|
| 798 |
+
a boolean. Any other operation will raise an :exc:`UndefinedError`.
|
| 799 |
+
|
| 800 |
+
>>> foo = Undefined(name='foo')
|
| 801 |
+
>>> str(foo)
|
| 802 |
+
''
|
| 803 |
+
>>> not foo
|
| 804 |
+
True
|
| 805 |
+
>>> foo + 42
|
| 806 |
+
Traceback (most recent call last):
|
| 807 |
+
...
|
| 808 |
+
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
| 809 |
+
"""
|
| 810 |
+
|
| 811 |
+
__slots__ = (
|
| 812 |
+
"_undefined_hint",
|
| 813 |
+
"_undefined_obj",
|
| 814 |
+
"_undefined_name",
|
| 815 |
+
"_undefined_exception",
|
| 816 |
+
)
|
| 817 |
+
|
| 818 |
+
def __init__(
|
| 819 |
+
self,
|
| 820 |
+
hint: t.Optional[str] = None,
|
| 821 |
+
obj: t.Any = missing,
|
| 822 |
+
name: t.Optional[str] = None,
|
| 823 |
+
exc: t.Type[TemplateRuntimeError] = UndefinedError,
|
| 824 |
+
) -> None:
|
| 825 |
+
self._undefined_hint = hint
|
| 826 |
+
self._undefined_obj = obj
|
| 827 |
+
self._undefined_name = name
|
| 828 |
+
self._undefined_exception = exc
|
| 829 |
+
|
| 830 |
+
@property
|
| 831 |
+
def _undefined_message(self) -> str:
|
| 832 |
+
"""Build a message about the undefined value based on how it was
|
| 833 |
+
accessed.
|
| 834 |
+
"""
|
| 835 |
+
if self._undefined_hint:
|
| 836 |
+
return self._undefined_hint
|
| 837 |
+
|
| 838 |
+
if self._undefined_obj is missing:
|
| 839 |
+
return f"{self._undefined_name!r} is undefined"
|
| 840 |
+
|
| 841 |
+
if not isinstance(self._undefined_name, str):
|
| 842 |
+
return (
|
| 843 |
+
f"{object_type_repr(self._undefined_obj)} has no"
|
| 844 |
+
f" element {self._undefined_name!r}"
|
| 845 |
+
)
|
| 846 |
+
|
| 847 |
+
return (
|
| 848 |
+
f"{object_type_repr(self._undefined_obj)!r} has no"
|
| 849 |
+
f" attribute {self._undefined_name!r}"
|
| 850 |
+
)
|
| 851 |
+
|
| 852 |
+
@internalcode
|
| 853 |
+
def _fail_with_undefined_error(
|
| 854 |
+
self, *args: t.Any, **kwargs: t.Any
|
| 855 |
+
) -> "te.NoReturn":
|
| 856 |
+
"""Raise an :exc:`UndefinedError` when operations are performed
|
| 857 |
+
on the undefined value.
|
| 858 |
+
"""
|
| 859 |
+
raise self._undefined_exception(self._undefined_message)
|
| 860 |
+
|
| 861 |
+
@internalcode
|
| 862 |
+
def __getattr__(self, name: str) -> t.Any:
|
| 863 |
+
# Raise AttributeError on requests for names that appear to be unimplemented
|
| 864 |
+
# dunder methods to keep Python's internal protocol probing behaviors working
|
| 865 |
+
# properly in cases where another exception type could cause unexpected or
|
| 866 |
+
# difficult-to-diagnose failures.
|
| 867 |
+
if name[:2] == "__" and name[-2:] == "__":
|
| 868 |
+
raise AttributeError(name)
|
| 869 |
+
|
| 870 |
+
return self._fail_with_undefined_error()
|
| 871 |
+
|
| 872 |
+
__add__ = __radd__ = __sub__ = __rsub__ = _fail_with_undefined_error
|
| 873 |
+
__mul__ = __rmul__ = __div__ = __rdiv__ = _fail_with_undefined_error
|
| 874 |
+
__truediv__ = __rtruediv__ = _fail_with_undefined_error
|
| 875 |
+
__floordiv__ = __rfloordiv__ = _fail_with_undefined_error
|
| 876 |
+
__mod__ = __rmod__ = _fail_with_undefined_error
|
| 877 |
+
__pos__ = __neg__ = _fail_with_undefined_error
|
| 878 |
+
__call__ = __getitem__ = _fail_with_undefined_error
|
| 879 |
+
__lt__ = __le__ = __gt__ = __ge__ = _fail_with_undefined_error
|
| 880 |
+
__int__ = __float__ = __complex__ = _fail_with_undefined_error
|
| 881 |
+
__pow__ = __rpow__ = _fail_with_undefined_error
|
| 882 |
+
|
| 883 |
+
def __eq__(self, other: t.Any) -> bool:
|
| 884 |
+
return type(self) is type(other)
|
| 885 |
+
|
| 886 |
+
def __ne__(self, other: t.Any) -> bool:
|
| 887 |
+
return not self.__eq__(other)
|
| 888 |
+
|
| 889 |
+
def __hash__(self) -> int:
|
| 890 |
+
return id(type(self))
|
| 891 |
+
|
| 892 |
+
def __str__(self) -> str:
|
| 893 |
+
return ""
|
| 894 |
+
|
| 895 |
+
def __len__(self) -> int:
|
| 896 |
+
return 0
|
| 897 |
+
|
| 898 |
+
def __iter__(self) -> t.Iterator[t.Any]:
|
| 899 |
+
yield from ()
|
| 900 |
+
|
| 901 |
+
async def __aiter__(self) -> t.AsyncIterator[t.Any]:
|
| 902 |
+
for _ in ():
|
| 903 |
+
yield
|
| 904 |
+
|
| 905 |
+
def __bool__(self) -> bool:
|
| 906 |
+
return False
|
| 907 |
+
|
| 908 |
+
def __repr__(self) -> str:
|
| 909 |
+
return "Undefined"
|
| 910 |
+
|
| 911 |
+
|
| 912 |
+
def make_logging_undefined(
|
| 913 |
+
logger: t.Optional["logging.Logger"] = None, base: t.Type[Undefined] = Undefined
|
| 914 |
+
) -> t.Type[Undefined]:
|
| 915 |
+
"""Given a logger object this returns a new undefined class that will
|
| 916 |
+
log certain failures. It will log iterations and printing. If no
|
| 917 |
+
logger is given a default logger is created.
|
| 918 |
+
|
| 919 |
+
Example::
|
| 920 |
+
|
| 921 |
+
logger = logging.getLogger(__name__)
|
| 922 |
+
LoggingUndefined = make_logging_undefined(
|
| 923 |
+
logger=logger,
|
| 924 |
+
base=Undefined
|
| 925 |
+
)
|
| 926 |
+
|
| 927 |
+
.. versionadded:: 2.8
|
| 928 |
+
|
| 929 |
+
:param logger: the logger to use. If not provided, a default logger
|
| 930 |
+
is created.
|
| 931 |
+
:param base: the base class to add logging functionality to. This
|
| 932 |
+
defaults to :class:`Undefined`.
|
| 933 |
+
"""
|
| 934 |
+
if logger is None:
|
| 935 |
+
import logging
|
| 936 |
+
|
| 937 |
+
logger = logging.getLogger(__name__)
|
| 938 |
+
logger.addHandler(logging.StreamHandler(sys.stderr))
|
| 939 |
+
|
| 940 |
+
def _log_message(undef: Undefined) -> None:
|
| 941 |
+
logger.warning("Template variable warning: %s", undef._undefined_message)
|
| 942 |
+
|
| 943 |
+
class LoggingUndefined(base): # type: ignore
|
| 944 |
+
__slots__ = ()
|
| 945 |
+
|
| 946 |
+
def _fail_with_undefined_error( # type: ignore
|
| 947 |
+
self, *args: t.Any, **kwargs: t.Any
|
| 948 |
+
) -> "te.NoReturn":
|
| 949 |
+
try:
|
| 950 |
+
super()._fail_with_undefined_error(*args, **kwargs)
|
| 951 |
+
except self._undefined_exception as e:
|
| 952 |
+
logger.error("Template variable error: %s", e) # type: ignore
|
| 953 |
+
raise e
|
| 954 |
+
|
| 955 |
+
def __str__(self) -> str:
|
| 956 |
+
_log_message(self)
|
| 957 |
+
return super().__str__() # type: ignore
|
| 958 |
+
|
| 959 |
+
def __iter__(self) -> t.Iterator[t.Any]:
|
| 960 |
+
_log_message(self)
|
| 961 |
+
return super().__iter__() # type: ignore
|
| 962 |
+
|
| 963 |
+
def __bool__(self) -> bool:
|
| 964 |
+
_log_message(self)
|
| 965 |
+
return super().__bool__() # type: ignore
|
| 966 |
+
|
| 967 |
+
return LoggingUndefined
|
| 968 |
+
|
| 969 |
+
|
| 970 |
+
class ChainableUndefined(Undefined):
|
| 971 |
+
"""An undefined that is chainable, where both ``__getattr__`` and
|
| 972 |
+
``__getitem__`` return itself rather than raising an
|
| 973 |
+
:exc:`UndefinedError`.
|
| 974 |
+
|
| 975 |
+
>>> foo = ChainableUndefined(name='foo')
|
| 976 |
+
>>> str(foo.bar['baz'])
|
| 977 |
+
''
|
| 978 |
+
>>> foo.bar['baz'] + 42
|
| 979 |
+
Traceback (most recent call last):
|
| 980 |
+
...
|
| 981 |
+
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
| 982 |
+
|
| 983 |
+
.. versionadded:: 2.11.0
|
| 984 |
+
"""
|
| 985 |
+
|
| 986 |
+
__slots__ = ()
|
| 987 |
+
|
| 988 |
+
def __html__(self) -> str:
|
| 989 |
+
return str(self)
|
| 990 |
+
|
| 991 |
+
def __getattr__(self, name: str) -> "ChainableUndefined":
|
| 992 |
+
# Raise AttributeError on requests for names that appear to be unimplemented
|
| 993 |
+
# dunder methods to avoid confusing Python with truthy non-method objects that
|
| 994 |
+
# do not implement the protocol being probed for. e.g., copy.copy(Undefined())
|
| 995 |
+
# fails spectacularly if getattr(Undefined(), '__setstate__') returns an
|
| 996 |
+
# Undefined object instead of raising AttributeError to signal that it does not
|
| 997 |
+
# support that style of object initialization.
|
| 998 |
+
if name[:2] == "__" and name[-2:] == "__":
|
| 999 |
+
raise AttributeError(name)
|
| 1000 |
+
|
| 1001 |
+
return self
|
| 1002 |
+
|
| 1003 |
+
def __getitem__(self, _name: str) -> "ChainableUndefined": # type: ignore[override]
|
| 1004 |
+
return self
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
class DebugUndefined(Undefined):
|
| 1008 |
+
"""An undefined that returns the debug info when printed.
|
| 1009 |
+
|
| 1010 |
+
>>> foo = DebugUndefined(name='foo')
|
| 1011 |
+
>>> str(foo)
|
| 1012 |
+
'{{ foo }}'
|
| 1013 |
+
>>> not foo
|
| 1014 |
+
True
|
| 1015 |
+
>>> foo + 42
|
| 1016 |
+
Traceback (most recent call last):
|
| 1017 |
+
...
|
| 1018 |
+
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
| 1019 |
+
"""
|
| 1020 |
+
|
| 1021 |
+
__slots__ = ()
|
| 1022 |
+
|
| 1023 |
+
def __str__(self) -> str:
|
| 1024 |
+
if self._undefined_hint:
|
| 1025 |
+
message = f"undefined value printed: {self._undefined_hint}"
|
| 1026 |
+
|
| 1027 |
+
elif self._undefined_obj is missing:
|
| 1028 |
+
message = self._undefined_name # type: ignore
|
| 1029 |
+
|
| 1030 |
+
else:
|
| 1031 |
+
message = (
|
| 1032 |
+
f"no such element: {object_type_repr(self._undefined_obj)}"
|
| 1033 |
+
f"[{self._undefined_name!r}]"
|
| 1034 |
+
)
|
| 1035 |
+
|
| 1036 |
+
return f"{{{{ {message} }}}}"
|
| 1037 |
+
|
| 1038 |
+
|
| 1039 |
+
class StrictUndefined(Undefined):
|
| 1040 |
+
"""An undefined that barks on print and iteration as well as boolean
|
| 1041 |
+
tests and all kinds of comparisons. In other words: you can do nothing
|
| 1042 |
+
with it except checking if it's defined using the `defined` test.
|
| 1043 |
+
|
| 1044 |
+
>>> foo = StrictUndefined(name='foo')
|
| 1045 |
+
>>> str(foo)
|
| 1046 |
+
Traceback (most recent call last):
|
| 1047 |
+
...
|
| 1048 |
+
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
| 1049 |
+
>>> not foo
|
| 1050 |
+
Traceback (most recent call last):
|
| 1051 |
+
...
|
| 1052 |
+
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
| 1053 |
+
>>> foo + 42
|
| 1054 |
+
Traceback (most recent call last):
|
| 1055 |
+
...
|
| 1056 |
+
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
| 1057 |
+
"""
|
| 1058 |
+
|
| 1059 |
+
__slots__ = ()
|
| 1060 |
+
__iter__ = __str__ = __len__ = Undefined._fail_with_undefined_error
|
| 1061 |
+
__eq__ = __ne__ = __bool__ = __hash__ = Undefined._fail_with_undefined_error
|
| 1062 |
+
__contains__ = Undefined._fail_with_undefined_error
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/sandbox.py
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A sandbox layer that ensures unsafe operations cannot be performed.
|
| 2 |
+
Useful when the template itself comes from an untrusted source.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import operator
|
| 6 |
+
import types
|
| 7 |
+
import typing as t
|
| 8 |
+
from _string import formatter_field_name_split # type: ignore
|
| 9 |
+
from collections import abc
|
| 10 |
+
from collections import deque
|
| 11 |
+
from functools import update_wrapper
|
| 12 |
+
from string import Formatter
|
| 13 |
+
|
| 14 |
+
from markupsafe import EscapeFormatter
|
| 15 |
+
from markupsafe import Markup
|
| 16 |
+
|
| 17 |
+
from .environment import Environment
|
| 18 |
+
from .exceptions import SecurityError
|
| 19 |
+
from .runtime import Context
|
| 20 |
+
from .runtime import Undefined
|
| 21 |
+
|
| 22 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 23 |
+
|
| 24 |
+
#: maximum number of items a range may produce
|
| 25 |
+
MAX_RANGE = 100000
|
| 26 |
+
|
| 27 |
+
#: Unsafe function attributes.
|
| 28 |
+
UNSAFE_FUNCTION_ATTRIBUTES: t.Set[str] = set()
|
| 29 |
+
|
| 30 |
+
#: Unsafe method attributes. Function attributes are unsafe for methods too.
|
| 31 |
+
UNSAFE_METHOD_ATTRIBUTES: t.Set[str] = set()
|
| 32 |
+
|
| 33 |
+
#: unsafe generator attributes.
|
| 34 |
+
UNSAFE_GENERATOR_ATTRIBUTES = {"gi_frame", "gi_code"}
|
| 35 |
+
|
| 36 |
+
#: unsafe attributes on coroutines
|
| 37 |
+
UNSAFE_COROUTINE_ATTRIBUTES = {"cr_frame", "cr_code"}
|
| 38 |
+
|
| 39 |
+
#: unsafe attributes on async generators
|
| 40 |
+
UNSAFE_ASYNC_GENERATOR_ATTRIBUTES = {"ag_code", "ag_frame"}
|
| 41 |
+
|
| 42 |
+
_mutable_spec: t.Tuple[t.Tuple[t.Type[t.Any], t.FrozenSet[str]], ...] = (
|
| 43 |
+
(
|
| 44 |
+
abc.MutableSet,
|
| 45 |
+
frozenset(
|
| 46 |
+
[
|
| 47 |
+
"add",
|
| 48 |
+
"clear",
|
| 49 |
+
"difference_update",
|
| 50 |
+
"discard",
|
| 51 |
+
"pop",
|
| 52 |
+
"remove",
|
| 53 |
+
"symmetric_difference_update",
|
| 54 |
+
"update",
|
| 55 |
+
]
|
| 56 |
+
),
|
| 57 |
+
),
|
| 58 |
+
(
|
| 59 |
+
abc.MutableMapping,
|
| 60 |
+
frozenset(["clear", "pop", "popitem", "setdefault", "update"]),
|
| 61 |
+
),
|
| 62 |
+
(
|
| 63 |
+
abc.MutableSequence,
|
| 64 |
+
frozenset(
|
| 65 |
+
["append", "clear", "pop", "reverse", "insert", "sort", "extend", "remove"]
|
| 66 |
+
),
|
| 67 |
+
),
|
| 68 |
+
(
|
| 69 |
+
deque,
|
| 70 |
+
frozenset(
|
| 71 |
+
[
|
| 72 |
+
"append",
|
| 73 |
+
"appendleft",
|
| 74 |
+
"clear",
|
| 75 |
+
"extend",
|
| 76 |
+
"extendleft",
|
| 77 |
+
"pop",
|
| 78 |
+
"popleft",
|
| 79 |
+
"remove",
|
| 80 |
+
"rotate",
|
| 81 |
+
]
|
| 82 |
+
),
|
| 83 |
+
),
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def safe_range(*args: int) -> range:
|
| 88 |
+
"""A range that can't generate ranges with a length of more than
|
| 89 |
+
MAX_RANGE items.
|
| 90 |
+
"""
|
| 91 |
+
rng = range(*args)
|
| 92 |
+
|
| 93 |
+
if len(rng) > MAX_RANGE:
|
| 94 |
+
raise OverflowError(
|
| 95 |
+
"Range too big. The sandbox blocks ranges larger than"
|
| 96 |
+
f" MAX_RANGE ({MAX_RANGE})."
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
return rng
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def unsafe(f: F) -> F:
|
| 103 |
+
"""Marks a function or method as unsafe.
|
| 104 |
+
|
| 105 |
+
.. code-block: python
|
| 106 |
+
|
| 107 |
+
@unsafe
|
| 108 |
+
def delete(self):
|
| 109 |
+
pass
|
| 110 |
+
"""
|
| 111 |
+
f.unsafe_callable = True # type: ignore
|
| 112 |
+
return f
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def is_internal_attribute(obj: t.Any, attr: str) -> bool:
|
| 116 |
+
"""Test if the attribute given is an internal python attribute. For
|
| 117 |
+
example this function returns `True` for the `func_code` attribute of
|
| 118 |
+
python objects. This is useful if the environment method
|
| 119 |
+
:meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.
|
| 120 |
+
|
| 121 |
+
>>> from jinja2.sandbox import is_internal_attribute
|
| 122 |
+
>>> is_internal_attribute(str, "mro")
|
| 123 |
+
True
|
| 124 |
+
>>> is_internal_attribute(str, "upper")
|
| 125 |
+
False
|
| 126 |
+
"""
|
| 127 |
+
if isinstance(obj, types.FunctionType):
|
| 128 |
+
if attr in UNSAFE_FUNCTION_ATTRIBUTES:
|
| 129 |
+
return True
|
| 130 |
+
elif isinstance(obj, types.MethodType):
|
| 131 |
+
if attr in UNSAFE_FUNCTION_ATTRIBUTES or attr in UNSAFE_METHOD_ATTRIBUTES:
|
| 132 |
+
return True
|
| 133 |
+
elif isinstance(obj, type):
|
| 134 |
+
if attr == "mro":
|
| 135 |
+
return True
|
| 136 |
+
elif isinstance(obj, (types.CodeType, types.TracebackType, types.FrameType)):
|
| 137 |
+
return True
|
| 138 |
+
elif isinstance(obj, types.GeneratorType):
|
| 139 |
+
if attr in UNSAFE_GENERATOR_ATTRIBUTES:
|
| 140 |
+
return True
|
| 141 |
+
elif hasattr(types, "CoroutineType") and isinstance(obj, types.CoroutineType):
|
| 142 |
+
if attr in UNSAFE_COROUTINE_ATTRIBUTES:
|
| 143 |
+
return True
|
| 144 |
+
elif hasattr(types, "AsyncGeneratorType") and isinstance(
|
| 145 |
+
obj, types.AsyncGeneratorType
|
| 146 |
+
):
|
| 147 |
+
if attr in UNSAFE_ASYNC_GENERATOR_ATTRIBUTES:
|
| 148 |
+
return True
|
| 149 |
+
return attr.startswith("__")
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def modifies_known_mutable(obj: t.Any, attr: str) -> bool:
|
| 153 |
+
"""This function checks if an attribute on a builtin mutable object
|
| 154 |
+
(list, dict, set or deque) or the corresponding ABCs would modify it
|
| 155 |
+
if called.
|
| 156 |
+
|
| 157 |
+
>>> modifies_known_mutable({}, "clear")
|
| 158 |
+
True
|
| 159 |
+
>>> modifies_known_mutable({}, "keys")
|
| 160 |
+
False
|
| 161 |
+
>>> modifies_known_mutable([], "append")
|
| 162 |
+
True
|
| 163 |
+
>>> modifies_known_mutable([], "index")
|
| 164 |
+
False
|
| 165 |
+
|
| 166 |
+
If called with an unsupported object, ``False`` is returned.
|
| 167 |
+
|
| 168 |
+
>>> modifies_known_mutable("foo", "upper")
|
| 169 |
+
False
|
| 170 |
+
"""
|
| 171 |
+
for typespec, unsafe in _mutable_spec:
|
| 172 |
+
if isinstance(obj, typespec):
|
| 173 |
+
return attr in unsafe
|
| 174 |
+
return False
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
class SandboxedEnvironment(Environment):
|
| 178 |
+
"""The sandboxed environment. It works like the regular environment but
|
| 179 |
+
tells the compiler to generate sandboxed code. Additionally subclasses of
|
| 180 |
+
this environment may override the methods that tell the runtime what
|
| 181 |
+
attributes or functions are safe to access.
|
| 182 |
+
|
| 183 |
+
If the template tries to access insecure code a :exc:`SecurityError` is
|
| 184 |
+
raised. However also other exceptions may occur during the rendering so
|
| 185 |
+
the caller has to ensure that all exceptions are caught.
|
| 186 |
+
"""
|
| 187 |
+
|
| 188 |
+
sandboxed = True
|
| 189 |
+
|
| 190 |
+
#: default callback table for the binary operators. A copy of this is
|
| 191 |
+
#: available on each instance of a sandboxed environment as
|
| 192 |
+
#: :attr:`binop_table`
|
| 193 |
+
default_binop_table: t.Dict[str, t.Callable[[t.Any, t.Any], t.Any]] = {
|
| 194 |
+
"+": operator.add,
|
| 195 |
+
"-": operator.sub,
|
| 196 |
+
"*": operator.mul,
|
| 197 |
+
"/": operator.truediv,
|
| 198 |
+
"//": operator.floordiv,
|
| 199 |
+
"**": operator.pow,
|
| 200 |
+
"%": operator.mod,
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
#: default callback table for the unary operators. A copy of this is
|
| 204 |
+
#: available on each instance of a sandboxed environment as
|
| 205 |
+
#: :attr:`unop_table`
|
| 206 |
+
default_unop_table: t.Dict[str, t.Callable[[t.Any], t.Any]] = {
|
| 207 |
+
"+": operator.pos,
|
| 208 |
+
"-": operator.neg,
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
#: a set of binary operators that should be intercepted. Each operator
|
| 212 |
+
#: that is added to this set (empty by default) is delegated to the
|
| 213 |
+
#: :meth:`call_binop` method that will perform the operator. The default
|
| 214 |
+
#: operator callback is specified by :attr:`binop_table`.
|
| 215 |
+
#:
|
| 216 |
+
#: The following binary operators are interceptable:
|
| 217 |
+
#: ``//``, ``%``, ``+``, ``*``, ``-``, ``/``, and ``**``
|
| 218 |
+
#:
|
| 219 |
+
#: The default operation form the operator table corresponds to the
|
| 220 |
+
#: builtin function. Intercepted calls are always slower than the native
|
| 221 |
+
#: operator call, so make sure only to intercept the ones you are
|
| 222 |
+
#: interested in.
|
| 223 |
+
#:
|
| 224 |
+
#: .. versionadded:: 2.6
|
| 225 |
+
intercepted_binops: t.FrozenSet[str] = frozenset()
|
| 226 |
+
|
| 227 |
+
#: a set of unary operators that should be intercepted. Each operator
|
| 228 |
+
#: that is added to this set (empty by default) is delegated to the
|
| 229 |
+
#: :meth:`call_unop` method that will perform the operator. The default
|
| 230 |
+
#: operator callback is specified by :attr:`unop_table`.
|
| 231 |
+
#:
|
| 232 |
+
#: The following unary operators are interceptable: ``+``, ``-``
|
| 233 |
+
#:
|
| 234 |
+
#: The default operation form the operator table corresponds to the
|
| 235 |
+
#: builtin function. Intercepted calls are always slower than the native
|
| 236 |
+
#: operator call, so make sure only to intercept the ones you are
|
| 237 |
+
#: interested in.
|
| 238 |
+
#:
|
| 239 |
+
#: .. versionadded:: 2.6
|
| 240 |
+
intercepted_unops: t.FrozenSet[str] = frozenset()
|
| 241 |
+
|
| 242 |
+
def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
|
| 243 |
+
super().__init__(*args, **kwargs)
|
| 244 |
+
self.globals["range"] = safe_range
|
| 245 |
+
self.binop_table = self.default_binop_table.copy()
|
| 246 |
+
self.unop_table = self.default_unop_table.copy()
|
| 247 |
+
|
| 248 |
+
def is_safe_attribute(self, obj: t.Any, attr: str, value: t.Any) -> bool:
|
| 249 |
+
"""The sandboxed environment will call this method to check if the
|
| 250 |
+
attribute of an object is safe to access. Per default all attributes
|
| 251 |
+
starting with an underscore are considered private as well as the
|
| 252 |
+
special attributes of internal python objects as returned by the
|
| 253 |
+
:func:`is_internal_attribute` function.
|
| 254 |
+
"""
|
| 255 |
+
return not (attr.startswith("_") or is_internal_attribute(obj, attr))
|
| 256 |
+
|
| 257 |
+
def is_safe_callable(self, obj: t.Any) -> bool:
|
| 258 |
+
"""Check if an object is safely callable. By default callables
|
| 259 |
+
are considered safe unless decorated with :func:`unsafe`.
|
| 260 |
+
|
| 261 |
+
This also recognizes the Django convention of setting
|
| 262 |
+
``func.alters_data = True``.
|
| 263 |
+
"""
|
| 264 |
+
return not (
|
| 265 |
+
getattr(obj, "unsafe_callable", False) or getattr(obj, "alters_data", False)
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
def call_binop(
|
| 269 |
+
self, context: Context, operator: str, left: t.Any, right: t.Any
|
| 270 |
+
) -> t.Any:
|
| 271 |
+
"""For intercepted binary operator calls (:meth:`intercepted_binops`)
|
| 272 |
+
this function is executed instead of the builtin operator. This can
|
| 273 |
+
be used to fine tune the behavior of certain operators.
|
| 274 |
+
|
| 275 |
+
.. versionadded:: 2.6
|
| 276 |
+
"""
|
| 277 |
+
return self.binop_table[operator](left, right)
|
| 278 |
+
|
| 279 |
+
def call_unop(self, context: Context, operator: str, arg: t.Any) -> t.Any:
|
| 280 |
+
"""For intercepted unary operator calls (:meth:`intercepted_unops`)
|
| 281 |
+
this function is executed instead of the builtin operator. This can
|
| 282 |
+
be used to fine tune the behavior of certain operators.
|
| 283 |
+
|
| 284 |
+
.. versionadded:: 2.6
|
| 285 |
+
"""
|
| 286 |
+
return self.unop_table[operator](arg)
|
| 287 |
+
|
| 288 |
+
def getitem(
|
| 289 |
+
self, obj: t.Any, argument: t.Union[str, t.Any]
|
| 290 |
+
) -> t.Union[t.Any, Undefined]:
|
| 291 |
+
"""Subscribe an object from sandboxed code."""
|
| 292 |
+
try:
|
| 293 |
+
return obj[argument]
|
| 294 |
+
except (TypeError, LookupError):
|
| 295 |
+
if isinstance(argument, str):
|
| 296 |
+
try:
|
| 297 |
+
attr = str(argument)
|
| 298 |
+
except Exception:
|
| 299 |
+
pass
|
| 300 |
+
else:
|
| 301 |
+
try:
|
| 302 |
+
value = getattr(obj, attr)
|
| 303 |
+
except AttributeError:
|
| 304 |
+
pass
|
| 305 |
+
else:
|
| 306 |
+
fmt = self.wrap_str_format(value)
|
| 307 |
+
if fmt is not None:
|
| 308 |
+
return fmt
|
| 309 |
+
if self.is_safe_attribute(obj, argument, value):
|
| 310 |
+
return value
|
| 311 |
+
return self.unsafe_undefined(obj, argument)
|
| 312 |
+
return self.undefined(obj=obj, name=argument)
|
| 313 |
+
|
| 314 |
+
def getattr(self, obj: t.Any, attribute: str) -> t.Union[t.Any, Undefined]:
|
| 315 |
+
"""Subscribe an object from sandboxed code and prefer the
|
| 316 |
+
attribute. The attribute passed *must* be a bytestring.
|
| 317 |
+
"""
|
| 318 |
+
try:
|
| 319 |
+
value = getattr(obj, attribute)
|
| 320 |
+
except AttributeError:
|
| 321 |
+
try:
|
| 322 |
+
return obj[attribute]
|
| 323 |
+
except (TypeError, LookupError):
|
| 324 |
+
pass
|
| 325 |
+
else:
|
| 326 |
+
fmt = self.wrap_str_format(value)
|
| 327 |
+
if fmt is not None:
|
| 328 |
+
return fmt
|
| 329 |
+
if self.is_safe_attribute(obj, attribute, value):
|
| 330 |
+
return value
|
| 331 |
+
return self.unsafe_undefined(obj, attribute)
|
| 332 |
+
return self.undefined(obj=obj, name=attribute)
|
| 333 |
+
|
| 334 |
+
def unsafe_undefined(self, obj: t.Any, attribute: str) -> Undefined:
|
| 335 |
+
"""Return an undefined object for unsafe attributes."""
|
| 336 |
+
return self.undefined(
|
| 337 |
+
f"access to attribute {attribute!r} of"
|
| 338 |
+
f" {type(obj).__name__!r} object is unsafe.",
|
| 339 |
+
name=attribute,
|
| 340 |
+
obj=obj,
|
| 341 |
+
exc=SecurityError,
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
def wrap_str_format(self, value: t.Any) -> t.Optional[t.Callable[..., str]]:
|
| 345 |
+
"""If the given value is a ``str.format`` or ``str.format_map`` method,
|
| 346 |
+
return a new function than handles sandboxing. This is done at access
|
| 347 |
+
rather than in :meth:`call`, so that calls made without ``call`` are
|
| 348 |
+
also sandboxed.
|
| 349 |
+
"""
|
| 350 |
+
if not isinstance(
|
| 351 |
+
value, (types.MethodType, types.BuiltinMethodType)
|
| 352 |
+
) or value.__name__ not in ("format", "format_map"):
|
| 353 |
+
return None
|
| 354 |
+
|
| 355 |
+
f_self: t.Any = value.__self__
|
| 356 |
+
|
| 357 |
+
if not isinstance(f_self, str):
|
| 358 |
+
return None
|
| 359 |
+
|
| 360 |
+
str_type: t.Type[str] = type(f_self)
|
| 361 |
+
is_format_map = value.__name__ == "format_map"
|
| 362 |
+
formatter: SandboxedFormatter
|
| 363 |
+
|
| 364 |
+
if isinstance(f_self, Markup):
|
| 365 |
+
formatter = SandboxedEscapeFormatter(self, escape=f_self.escape)
|
| 366 |
+
else:
|
| 367 |
+
formatter = SandboxedFormatter(self)
|
| 368 |
+
|
| 369 |
+
vformat = formatter.vformat
|
| 370 |
+
|
| 371 |
+
def wrapper(*args: t.Any, **kwargs: t.Any) -> str:
|
| 372 |
+
if is_format_map:
|
| 373 |
+
if kwargs:
|
| 374 |
+
raise TypeError("format_map() takes no keyword arguments")
|
| 375 |
+
|
| 376 |
+
if len(args) != 1:
|
| 377 |
+
raise TypeError(
|
| 378 |
+
f"format_map() takes exactly one argument ({len(args)} given)"
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
kwargs = args[0]
|
| 382 |
+
args = ()
|
| 383 |
+
|
| 384 |
+
return str_type(vformat(f_self, args, kwargs))
|
| 385 |
+
|
| 386 |
+
return update_wrapper(wrapper, value)
|
| 387 |
+
|
| 388 |
+
def call(
|
| 389 |
+
__self, # noqa: B902
|
| 390 |
+
__context: Context,
|
| 391 |
+
__obj: t.Any,
|
| 392 |
+
*args: t.Any,
|
| 393 |
+
**kwargs: t.Any,
|
| 394 |
+
) -> t.Any:
|
| 395 |
+
"""Call an object from sandboxed code."""
|
| 396 |
+
|
| 397 |
+
# the double prefixes are to avoid double keyword argument
|
| 398 |
+
# errors when proxying the call.
|
| 399 |
+
if not __self.is_safe_callable(__obj):
|
| 400 |
+
raise SecurityError(f"{__obj!r} is not safely callable")
|
| 401 |
+
return __context.call(__obj, *args, **kwargs)
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
class ImmutableSandboxedEnvironment(SandboxedEnvironment):
|
| 405 |
+
"""Works exactly like the regular `SandboxedEnvironment` but does not
|
| 406 |
+
permit modifications on the builtin mutable objects `list`, `set`, and
|
| 407 |
+
`dict` by using the :func:`modifies_known_mutable` function.
|
| 408 |
+
"""
|
| 409 |
+
|
| 410 |
+
def is_safe_attribute(self, obj: t.Any, attr: str, value: t.Any) -> bool:
|
| 411 |
+
if not super().is_safe_attribute(obj, attr, value):
|
| 412 |
+
return False
|
| 413 |
+
|
| 414 |
+
return not modifies_known_mutable(obj, attr)
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
class SandboxedFormatter(Formatter):
|
| 418 |
+
def __init__(self, env: Environment, **kwargs: t.Any) -> None:
|
| 419 |
+
self._env = env
|
| 420 |
+
super().__init__(**kwargs)
|
| 421 |
+
|
| 422 |
+
def get_field(
|
| 423 |
+
self, field_name: str, args: t.Sequence[t.Any], kwargs: t.Mapping[str, t.Any]
|
| 424 |
+
) -> t.Tuple[t.Any, str]:
|
| 425 |
+
first, rest = formatter_field_name_split(field_name)
|
| 426 |
+
obj = self.get_value(first, args, kwargs)
|
| 427 |
+
for is_attr, i in rest:
|
| 428 |
+
if is_attr:
|
| 429 |
+
obj = self._env.getattr(obj, i)
|
| 430 |
+
else:
|
| 431 |
+
obj = self._env.getitem(obj, i)
|
| 432 |
+
return obj, first
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
class SandboxedEscapeFormatter(SandboxedFormatter, EscapeFormatter):
|
| 436 |
+
pass
|
miniconda3/envs/ladir/lib/python3.10/site-packages/jinja2/tests.py
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Built-in template tests used with the ``is`` operator."""
|
| 2 |
+
|
| 3 |
+
import operator
|
| 4 |
+
import typing as t
|
| 5 |
+
from collections import abc
|
| 6 |
+
from numbers import Number
|
| 7 |
+
|
| 8 |
+
from .runtime import Undefined
|
| 9 |
+
from .utils import pass_environment
|
| 10 |
+
|
| 11 |
+
if t.TYPE_CHECKING:
|
| 12 |
+
from .environment import Environment
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_odd(value: int) -> bool:
|
| 16 |
+
"""Return true if the variable is odd."""
|
| 17 |
+
return value % 2 == 1
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_even(value: int) -> bool:
|
| 21 |
+
"""Return true if the variable is even."""
|
| 22 |
+
return value % 2 == 0
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_divisibleby(value: int, num: int) -> bool:
|
| 26 |
+
"""Check if a variable is divisible by a number."""
|
| 27 |
+
return value % num == 0
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_defined(value: t.Any) -> bool:
|
| 31 |
+
"""Return true if the variable is defined:
|
| 32 |
+
|
| 33 |
+
.. sourcecode:: jinja
|
| 34 |
+
|
| 35 |
+
{% if variable is defined %}
|
| 36 |
+
value of variable: {{ variable }}
|
| 37 |
+
{% else %}
|
| 38 |
+
variable is not defined
|
| 39 |
+
{% endif %}
|
| 40 |
+
|
| 41 |
+
See the :func:`default` filter for a simple way to set undefined
|
| 42 |
+
variables.
|
| 43 |
+
"""
|
| 44 |
+
return not isinstance(value, Undefined)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def test_undefined(value: t.Any) -> bool:
|
| 48 |
+
"""Like :func:`defined` but the other way round."""
|
| 49 |
+
return isinstance(value, Undefined)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@pass_environment
|
| 53 |
+
def test_filter(env: "Environment", value: str) -> bool:
|
| 54 |
+
"""Check if a filter exists by name. Useful if a filter may be
|
| 55 |
+
optionally available.
|
| 56 |
+
|
| 57 |
+
.. code-block:: jinja
|
| 58 |
+
|
| 59 |
+
{% if 'markdown' is filter %}
|
| 60 |
+
{{ value | markdown }}
|
| 61 |
+
{% else %}
|
| 62 |
+
{{ value }}
|
| 63 |
+
{% endif %}
|
| 64 |
+
|
| 65 |
+
.. versionadded:: 3.0
|
| 66 |
+
"""
|
| 67 |
+
return value in env.filters
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
@pass_environment
|
| 71 |
+
def test_test(env: "Environment", value: str) -> bool:
|
| 72 |
+
"""Check if a test exists by name. Useful if a test may be
|
| 73 |
+
optionally available.
|
| 74 |
+
|
| 75 |
+
.. code-block:: jinja
|
| 76 |
+
|
| 77 |
+
{% if 'loud' is test %}
|
| 78 |
+
{% if value is loud %}
|
| 79 |
+
{{ value|upper }}
|
| 80 |
+
{% else %}
|
| 81 |
+
{{ value|lower }}
|
| 82 |
+
{% endif %}
|
| 83 |
+
{% else %}
|
| 84 |
+
{{ value }}
|
| 85 |
+
{% endif %}
|
| 86 |
+
|
| 87 |
+
.. versionadded:: 3.0
|
| 88 |
+
"""
|
| 89 |
+
return value in env.tests
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def test_none(value: t.Any) -> bool:
|
| 93 |
+
"""Return true if the variable is none."""
|
| 94 |
+
return value is None
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def test_boolean(value: t.Any) -> bool:
|
| 98 |
+
"""Return true if the object is a boolean value.
|
| 99 |
+
|
| 100 |
+
.. versionadded:: 2.11
|
| 101 |
+
"""
|
| 102 |
+
return value is True or value is False
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def test_false(value: t.Any) -> bool:
|
| 106 |
+
"""Return true if the object is False.
|
| 107 |
+
|
| 108 |
+
.. versionadded:: 2.11
|
| 109 |
+
"""
|
| 110 |
+
return value is False
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_true(value: t.Any) -> bool:
|
| 114 |
+
"""Return true if the object is True.
|
| 115 |
+
|
| 116 |
+
.. versionadded:: 2.11
|
| 117 |
+
"""
|
| 118 |
+
return value is True
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# NOTE: The existing 'number' test matches booleans and floats
|
| 122 |
+
def test_integer(value: t.Any) -> bool:
|
| 123 |
+
"""Return true if the object is an integer.
|
| 124 |
+
|
| 125 |
+
.. versionadded:: 2.11
|
| 126 |
+
"""
|
| 127 |
+
return isinstance(value, int) and value is not True and value is not False
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
# NOTE: The existing 'number' test matches booleans and integers
|
| 131 |
+
def test_float(value: t.Any) -> bool:
|
| 132 |
+
"""Return true if the object is a float.
|
| 133 |
+
|
| 134 |
+
.. versionadded:: 2.11
|
| 135 |
+
"""
|
| 136 |
+
return isinstance(value, float)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def test_lower(value: str) -> bool:
|
| 140 |
+
"""Return true if the variable is lowercased."""
|
| 141 |
+
return str(value).islower()
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def test_upper(value: str) -> bool:
|
| 145 |
+
"""Return true if the variable is uppercased."""
|
| 146 |
+
return str(value).isupper()
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_string(value: t.Any) -> bool:
|
| 150 |
+
"""Return true if the object is a string."""
|
| 151 |
+
return isinstance(value, str)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def test_mapping(value: t.Any) -> bool:
|
| 155 |
+
"""Return true if the object is a mapping (dict etc.).
|
| 156 |
+
|
| 157 |
+
.. versionadded:: 2.6
|
| 158 |
+
"""
|
| 159 |
+
return isinstance(value, abc.Mapping)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def test_number(value: t.Any) -> bool:
|
| 163 |
+
"""Return true if the variable is a number."""
|
| 164 |
+
return isinstance(value, Number)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def test_sequence(value: t.Any) -> bool:
|
| 168 |
+
"""Return true if the variable is a sequence. Sequences are variables
|
| 169 |
+
that are iterable.
|
| 170 |
+
"""
|
| 171 |
+
try:
|
| 172 |
+
len(value)
|
| 173 |
+
value.__getitem__ # noqa B018
|
| 174 |
+
except Exception:
|
| 175 |
+
return False
|
| 176 |
+
|
| 177 |
+
return True
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def test_sameas(value: t.Any, other: t.Any) -> bool:
|
| 181 |
+
"""Check if an object points to the same memory address than another
|
| 182 |
+
object:
|
| 183 |
+
|
| 184 |
+
.. sourcecode:: jinja
|
| 185 |
+
|
| 186 |
+
{% if foo.attribute is sameas false %}
|
| 187 |
+
the foo attribute really is the `False` singleton
|
| 188 |
+
{% endif %}
|
| 189 |
+
"""
|
| 190 |
+
return value is other
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_iterable(value: t.Any) -> bool:
|
| 194 |
+
"""Check if it's possible to iterate over an object."""
|
| 195 |
+
try:
|
| 196 |
+
iter(value)
|
| 197 |
+
except TypeError:
|
| 198 |
+
return False
|
| 199 |
+
|
| 200 |
+
return True
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def test_escaped(value: t.Any) -> bool:
|
| 204 |
+
"""Check if the value is escaped."""
|
| 205 |
+
return hasattr(value, "__html__")
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_in(value: t.Any, seq: t.Container[t.Any]) -> bool:
|
| 209 |
+
"""Check if value is in seq.
|
| 210 |
+
|
| 211 |
+
.. versionadded:: 2.10
|
| 212 |
+
"""
|
| 213 |
+
return value in seq
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
TESTS = {
|
| 217 |
+
"odd": test_odd,
|
| 218 |
+
"even": test_even,
|
| 219 |
+
"divisibleby": test_divisibleby,
|
| 220 |
+
"defined": test_defined,
|
| 221 |
+
"undefined": test_undefined,
|
| 222 |
+
"filter": test_filter,
|
| 223 |
+
"test": test_test,
|
| 224 |
+
"none": test_none,
|
| 225 |
+
"boolean": test_boolean,
|
| 226 |
+
"false": test_false,
|
| 227 |
+
"true": test_true,
|
| 228 |
+
"integer": test_integer,
|
| 229 |
+
"float": test_float,
|
| 230 |
+
"lower": test_lower,
|
| 231 |
+
"upper": test_upper,
|
| 232 |
+
"string": test_string,
|
| 233 |
+
"mapping": test_mapping,
|
| 234 |
+
"number": test_number,
|
| 235 |
+
"sequence": test_sequence,
|
| 236 |
+
"iterable": test_iterable,
|
| 237 |
+
"callable": callable,
|
| 238 |
+
"sameas": test_sameas,
|
| 239 |
+
"escaped": test_escaped,
|
| 240 |
+
"in": test_in,
|
| 241 |
+
"==": operator.eq,
|
| 242 |
+
"eq": operator.eq,
|
| 243 |
+
"equalto": operator.eq,
|
| 244 |
+
"!=": operator.ne,
|
| 245 |
+
"ne": operator.ne,
|
| 246 |
+
">": operator.gt,
|
| 247 |
+
"gt": operator.gt,
|
| 248 |
+
"greaterthan": operator.gt,
|
| 249 |
+
"ge": operator.ge,
|
| 250 |
+
">=": operator.ge,
|
| 251 |
+
"<": operator.lt,
|
| 252 |
+
"lt": operator.lt,
|
| 253 |
+
"lessthan": operator.lt,
|
| 254 |
+
"<=": operator.le,
|
| 255 |
+
"le": operator.le,
|
| 256 |
+
}
|
miniconda3/envs/ladir/lib/python3.10/site-packages/j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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import typing as t
|
| 6 |
+
from collections import abc
|
| 7 |
+
from collections import deque
|
| 8 |
+
from random import choice
|
| 9 |
+
from random import randrange
|
| 10 |
+
from threading import Lock
|
| 11 |
+
from types import CodeType
|
| 12 |
+
from urllib.parse import quote_from_bytes
|
| 13 |
+
|
| 14 |
+
import markupsafe
|
| 15 |
+
|
| 16 |
+
if t.TYPE_CHECKING:
|
| 17 |
+
import typing_extensions as te
|
| 18 |
+
|
| 19 |
+
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class _MissingType:
|
| 23 |
+
def __repr__(self) -> str:
|
| 24 |
+
return "missing"
|
| 25 |
+
|
| 26 |
+
def __reduce__(self) -> str:
|
| 27 |
+
return "missing"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
missing: t.Any = _MissingType()
|
| 31 |
+
"""Special singleton representing missing values for the runtime."""
|
| 32 |
+
|
| 33 |
+
internal_code: t.MutableSet[CodeType] = set()
|
| 34 |
+
|
| 35 |
+
concat = "".join
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def pass_context(f: F) -> F:
|
| 39 |
+
"""Pass the :class:`~jinja2.runtime.Context` as the first argument
|
| 40 |
+
to the decorated function when called while rendering a template.
|
| 41 |
+
|
| 42 |
+
Can be used on functions, filters, and tests.
|
| 43 |
+
|
| 44 |
+
If only ``Context.eval_context`` is needed, use
|
| 45 |
+
:func:`pass_eval_context`. If only ``Context.environment`` is
|
| 46 |
+
needed, use :func:`pass_environment`.
|
| 47 |
+
|
| 48 |
+
.. versionadded:: 3.0.0
|
| 49 |
+
Replaces ``contextfunction`` and ``contextfilter``.
|
| 50 |
+
"""
|
| 51 |
+
f.jinja_pass_arg = _PassArg.context # type: ignore
|
| 52 |
+
return f
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def pass_eval_context(f: F) -> F:
|
| 56 |
+
"""Pass the :class:`~jinja2.nodes.EvalContext` as the first argument
|
| 57 |
+
to the decorated function when called while rendering a template.
|
| 58 |
+
See :ref:`eval-context`.
|
| 59 |
+
|
| 60 |
+
Can be used on functions, filters, and tests.
|
| 61 |
+
|
| 62 |
+
If only ``EvalContext.environment`` is needed, use
|
| 63 |
+
:func:`pass_environment`.
|
| 64 |
+
|
| 65 |
+
.. versionadded:: 3.0.0
|
| 66 |
+
Replaces ``evalcontextfunction`` and ``evalcontextfilter``.
|
| 67 |
+
"""
|
| 68 |
+
f.jinja_pass_arg = _PassArg.eval_context # type: ignore
|
| 69 |
+
return f
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def pass_environment(f: F) -> F:
|
| 73 |
+
"""Pass the :class:`~jinja2.Environment` as the first argument to
|
| 74 |
+
the decorated function when called while rendering a template.
|
| 75 |
+
|
| 76 |
+
Can be used on functions, filters, and tests.
|
| 77 |
+
|
| 78 |
+
.. versionadded:: 3.0.0
|
| 79 |
+
Replaces ``environmentfunction`` and ``environmentfilter``.
|
| 80 |
+
"""
|
| 81 |
+
f.jinja_pass_arg = _PassArg.environment # type: ignore
|
| 82 |
+
return f
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class _PassArg(enum.Enum):
|
| 86 |
+
context = enum.auto()
|
| 87 |
+
eval_context = enum.auto()
|
| 88 |
+
environment = enum.auto()
|
| 89 |
+
|
| 90 |
+
@classmethod
|
| 91 |
+
def from_obj(cls, obj: F) -> t.Optional["_PassArg"]:
|
| 92 |
+
if hasattr(obj, "jinja_pass_arg"):
|
| 93 |
+
return obj.jinja_pass_arg # type: ignore
|
| 94 |
+
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def internalcode(f: F) -> F:
|
| 99 |
+
"""Marks the function as internally used"""
|
| 100 |
+
internal_code.add(f.__code__)
|
| 101 |
+
return f
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def is_undefined(obj: t.Any) -> bool:
|
| 105 |
+
"""Check if the object passed is undefined. This does nothing more than
|
| 106 |
+
performing an instance check against :class:`Undefined` but looks nicer.
|
| 107 |
+
This can be used for custom filters or tests that want to react to
|
| 108 |
+
undefined variables. For example a custom default filter can look like
|
| 109 |
+
this::
|
| 110 |
+
|
| 111 |
+
def default(var, default=''):
|
| 112 |
+
if is_undefined(var):
|
| 113 |
+
return default
|
| 114 |
+
return var
|
| 115 |
+
"""
|
| 116 |
+
from .runtime import Undefined
|
| 117 |
+
|
| 118 |
+
return isinstance(obj, Undefined)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def consume(iterable: t.Iterable[t.Any]) -> None:
|
| 122 |
+
"""Consumes an iterable without doing anything with it."""
|
| 123 |
+
for _ in iterable:
|
| 124 |
+
pass
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def clear_caches() -> None:
|
| 128 |
+
"""Jinja keeps internal caches for environments and lexers. These are
|
| 129 |
+
used so that Jinja doesn't have to recreate environments and lexers all
|
| 130 |
+
the time. Normally you don't have to care about that but if you are
|
| 131 |
+
measuring memory consumption you may want to clean the caches.
|
| 132 |
+
"""
|
| 133 |
+
from .environment import get_spontaneous_environment
|
| 134 |
+
from .lexer import _lexer_cache
|
| 135 |
+
|
| 136 |
+
get_spontaneous_environment.cache_clear()
|
| 137 |
+
_lexer_cache.clear()
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def import_string(import_name: str, silent: bool = False) -> t.Any:
|
| 141 |
+
"""Imports an object based on a string. This is useful if you want to
|
| 142 |
+
use import paths as endpoints or something similar. An import path can
|
| 143 |
+
be specified either in dotted notation (``xml.sax.saxutils.escape``)
|
| 144 |
+
or with a colon as object delimiter (``xml.sax.saxutils:escape``).
|
| 145 |
+
|
| 146 |
+
If the `silent` is True the return value will be `None` if the import
|
| 147 |
+
fails.
|
| 148 |
+
|
| 149 |
+
:return: imported object
|
| 150 |
+
"""
|
| 151 |
+
try:
|
| 152 |
+
if ":" in import_name:
|
| 153 |
+
module, obj = import_name.split(":", 1)
|
| 154 |
+
elif "." in import_name:
|
| 155 |
+
module, _, obj = import_name.rpartition(".")
|
| 156 |
+
else:
|
| 157 |
+
return __import__(import_name)
|
| 158 |
+
return getattr(__import__(module, None, None, [obj]), obj)
|
| 159 |
+
except (ImportError, AttributeError):
|
| 160 |
+
if not silent:
|
| 161 |
+
raise
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def open_if_exists(filename: str, mode: str = "rb") -> t.Optional[t.IO[t.Any]]:
|
| 165 |
+
"""Returns a file descriptor for the filename if that file exists,
|
| 166 |
+
otherwise ``None``.
|
| 167 |
+
"""
|
| 168 |
+
if not os.path.isfile(filename):
|
| 169 |
+
return None
|
| 170 |
+
|
| 171 |
+
return open(filename, mode)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def object_type_repr(obj: t.Any) -> str:
|
| 175 |
+
"""Returns the name of the object's type. For some recognized
|
| 176 |
+
singletons the name of the object is returned instead. (For
|
| 177 |
+
example for `None` and `Ellipsis`).
|
| 178 |
+
"""
|
| 179 |
+
if obj is None:
|
| 180 |
+
return "None"
|
| 181 |
+
elif obj is Ellipsis:
|
| 182 |
+
return "Ellipsis"
|
| 183 |
+
|
| 184 |
+
cls = type(obj)
|
| 185 |
+
|
| 186 |
+
if cls.__module__ == "builtins":
|
| 187 |
+
return f"{cls.__name__} object"
|
| 188 |
+
|
| 189 |
+
return f"{cls.__module__}.{cls.__name__} object"
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def pformat(obj: t.Any) -> str:
|
| 193 |
+
"""Format an object using :func:`pprint.pformat`."""
|
| 194 |
+
from pprint import pformat
|
| 195 |
+
|
| 196 |
+
return pformat(obj)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
_http_re = re.compile(
|
| 200 |
+
r"""
|
| 201 |
+
^
|
| 202 |
+
(
|
| 203 |
+
(https?://|www\.) # scheme or www
|
| 204 |
+
(([\w%-]+\.)+)? # subdomain
|
| 205 |
+
(
|
| 206 |
+
[a-z]{2,63} # basic tld
|
| 207 |
+
|
|
| 208 |
+
xn--[\w%]{2,59} # idna tld
|
| 209 |
+
)
|
| 210 |
+
|
|
| 211 |
+
([\w%-]{2,63}\.)+ # basic domain
|
| 212 |
+
(com|net|int|edu|gov|org|info|mil) # basic tld
|
| 213 |
+
|
|
| 214 |
+
(https?://) # scheme
|
| 215 |
+
(
|
| 216 |
+
(([\d]{1,3})(\.[\d]{1,3}){3}) # IPv4
|
| 217 |
+
|
|
| 218 |
+
(\[([\da-f]{0,4}:){2}([\da-f]{0,4}:?){1,6}]) # IPv6
|
| 219 |
+
)
|
| 220 |
+
)
|
| 221 |
+
(?::[\d]{1,5})? # port
|
| 222 |
+
(?:[/?#]\S*)? # path, query, and fragment
|
| 223 |
+
$
|
| 224 |
+
""",
|
| 225 |
+
re.IGNORECASE | re.VERBOSE,
|
| 226 |
+
)
|
| 227 |
+
_email_re = re.compile(r"^\S+@\w[\w.-]*\.\w+$")
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def urlize(
|
| 231 |
+
text: str,
|
| 232 |
+
trim_url_limit: t.Optional[int] = None,
|
| 233 |
+
rel: t.Optional[str] = None,
|
| 234 |
+
target: t.Optional[str] = None,
|
| 235 |
+
extra_schemes: t.Optional[t.Iterable[str]] = None,
|
| 236 |
+
) -> str:
|
| 237 |
+
"""Convert URLs in text into clickable links.
|
| 238 |
+
|
| 239 |
+
This may not recognize links in some situations. Usually, a more
|
| 240 |
+
comprehensive formatter, such as a Markdown library, is a better
|
| 241 |
+
choice.
|
| 242 |
+
|
| 243 |
+
Works on ``http://``, ``https://``, ``www.``, ``mailto:``, and email
|
| 244 |
+
addresses. Links with trailing punctuation (periods, commas, closing
|
| 245 |
+
parentheses) and leading punctuation (opening parentheses) are
|
| 246 |
+
recognized excluding the punctuation. Email addresses that include
|
| 247 |
+
header fields are not recognized (for example,
|
| 248 |
+
``mailto:address@example.com?cc=copy@example.com``).
|
| 249 |
+
|
| 250 |
+
:param text: Original text containing URLs to link.
|
| 251 |
+
:param trim_url_limit: Shorten displayed URL values to this length.
|
| 252 |
+
:param target: Add the ``target`` attribute to links.
|
| 253 |
+
:param rel: Add the ``rel`` attribute to links.
|
| 254 |
+
:param extra_schemes: Recognize URLs that start with these schemes
|
| 255 |
+
in addition to the default behavior.
|
| 256 |
+
|
| 257 |
+
.. versionchanged:: 3.0
|
| 258 |
+
The ``extra_schemes`` parameter was added.
|
| 259 |
+
|
| 260 |
+
.. versionchanged:: 3.0
|
| 261 |
+
Generate ``https://`` links for URLs without a scheme.
|
| 262 |
+
|
| 263 |
+
.. versionchanged:: 3.0
|
| 264 |
+
The parsing rules were updated. Recognize email addresses with
|
| 265 |
+
or without the ``mailto:`` scheme. Validate IP addresses. Ignore
|
| 266 |
+
parentheses and brackets in more cases.
|
| 267 |
+
"""
|
| 268 |
+
if trim_url_limit is not None:
|
| 269 |
+
|
| 270 |
+
def trim_url(x: str) -> str:
|
| 271 |
+
if len(x) > trim_url_limit:
|
| 272 |
+
return f"{x[:trim_url_limit]}..."
|
| 273 |
+
|
| 274 |
+
return x
|
| 275 |
+
|
| 276 |
+
else:
|
| 277 |
+
|
| 278 |
+
def trim_url(x: str) -> str:
|
| 279 |
+
return x
|
| 280 |
+
|
| 281 |
+
words = re.split(r"(\s+)", str(markupsafe.escape(text)))
|
| 282 |
+
rel_attr = f' rel="{markupsafe.escape(rel)}"' if rel else ""
|
| 283 |
+
target_attr = f' target="{markupsafe.escape(target)}"' if target else ""
|
| 284 |
+
|
| 285 |
+
for i, word in enumerate(words):
|
| 286 |
+
head, middle, tail = "", word, ""
|
| 287 |
+
match = re.match(r"^([(<]|<)+", middle)
|
| 288 |
+
|
| 289 |
+
if match:
|
| 290 |
+
head = match.group()
|
| 291 |
+
middle = middle[match.end() :]
|
| 292 |
+
|
| 293 |
+
# Unlike lead, which is anchored to the start of the string,
|
| 294 |
+
# need to check that the string ends with any of the characters
|
| 295 |
+
# before trying to match all of them, to avoid backtracking.
|
| 296 |
+
if middle.endswith((")", ">", ".", ",", "\n", ">")):
|
| 297 |
+
match = re.search(r"([)>.,\n]|>)+$", middle)
|
| 298 |
+
|
| 299 |
+
if match:
|
| 300 |
+
tail = match.group()
|
| 301 |
+
middle = middle[: match.start()]
|
| 302 |
+
|
| 303 |
+
# Prefer balancing parentheses in URLs instead of ignoring a
|
| 304 |
+
# trailing character.
|
| 305 |
+
for start_char, end_char in ("(", ")"), ("<", ">"), ("<", ">"):
|
| 306 |
+
start_count = middle.count(start_char)
|
| 307 |
+
|
| 308 |
+
if start_count <= middle.count(end_char):
|
| 309 |
+
# Balanced, or lighter on the left
|
| 310 |
+
continue
|
| 311 |
+
|
| 312 |
+
# Move as many as possible from the tail to balance
|
| 313 |
+
for _ in range(min(start_count, tail.count(end_char))):
|
| 314 |
+
end_index = tail.index(end_char) + len(end_char)
|
| 315 |
+
# Move anything in the tail before the end char too
|
| 316 |
+
middle += tail[:end_index]
|
| 317 |
+
tail = tail[end_index:]
|
| 318 |
+
|
| 319 |
+
if _http_re.match(middle):
|
| 320 |
+
if middle.startswith("https://") or middle.startswith("http://"):
|
| 321 |
+
middle = (
|
| 322 |
+
f'<a href="{middle}"{rel_attr}{target_attr}>{trim_url(middle)}</a>'
|
| 323 |
+
)
|
| 324 |
+
else:
|
| 325 |
+
middle = (
|
| 326 |
+
f'<a href="https://{middle}"{rel_attr}{target_attr}>'
|
| 327 |
+
f"{trim_url(middle)}</a>"
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
elif middle.startswith("mailto:") and _email_re.match(middle[7:]):
|
| 331 |
+
middle = f'<a href="{middle}">{middle[7:]}</a>'
|
| 332 |
+
|
| 333 |
+
elif (
|
| 334 |
+
"@" in middle
|
| 335 |
+
and not middle.startswith("www.")
|
| 336 |
+
# ignore values like `@a@b`
|
| 337 |
+
and not middle.startswith("@")
|
| 338 |
+
and ":" not in middle
|
| 339 |
+
and _email_re.match(middle)
|
| 340 |
+
):
|
| 341 |
+
middle = f'<a href="mailto:{middle}">{middle}</a>'
|
| 342 |
+
|
| 343 |
+
elif extra_schemes is not None:
|
| 344 |
+
for scheme in extra_schemes:
|
| 345 |
+
if middle != scheme and middle.startswith(scheme):
|
| 346 |
+
middle = f'<a href="{middle}"{rel_attr}{target_attr}>{middle}</a>'
|
| 347 |
+
|
| 348 |
+
words[i] = f"{head}{middle}{tail}"
|
| 349 |
+
|
| 350 |
+
return "".join(words)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def generate_lorem_ipsum(
|
| 354 |
+
n: int = 5, html: bool = True, min: int = 20, max: int = 100
|
| 355 |
+
) -> str:
|
| 356 |
+
"""Generate some lorem ipsum for the template."""
|
| 357 |
+
from .constants import LOREM_IPSUM_WORDS
|
| 358 |
+
|
| 359 |
+
words = LOREM_IPSUM_WORDS.split()
|
| 360 |
+
result = []
|
| 361 |
+
|
| 362 |
+
for _ in range(n):
|
| 363 |
+
next_capitalized = True
|
| 364 |
+
last_comma = last_fullstop = 0
|
| 365 |
+
word = None
|
| 366 |
+
last = None
|
| 367 |
+
p = []
|
| 368 |
+
|
| 369 |
+
# each paragraph contains out of 20 to 100 words.
|
| 370 |
+
for idx, _ in enumerate(range(randrange(min, max))):
|
| 371 |
+
while True:
|
| 372 |
+
word = choice(words)
|
| 373 |
+
if word != last:
|
| 374 |
+
last = word
|
| 375 |
+
break
|
| 376 |
+
if next_capitalized:
|
| 377 |
+
word = word.capitalize()
|
| 378 |
+
next_capitalized = False
|
| 379 |
+
# add commas
|
| 380 |
+
if idx - randrange(3, 8) > last_comma:
|
| 381 |
+
last_comma = idx
|
| 382 |
+
last_fullstop += 2
|
| 383 |
+
word += ","
|
| 384 |
+
# add end of sentences
|
| 385 |
+
if idx - randrange(10, 20) > last_fullstop:
|
| 386 |
+
last_comma = last_fullstop = idx
|
| 387 |
+
word += "."
|
| 388 |
+
next_capitalized = True
|
| 389 |
+
p.append(word)
|
| 390 |
+
|
| 391 |
+
# ensure that the paragraph ends with a dot.
|
| 392 |
+
p_str = " ".join(p)
|
| 393 |
+
|
| 394 |
+
if p_str.endswith(","):
|
| 395 |
+
p_str = p_str[:-1] + "."
|
| 396 |
+
elif not p_str.endswith("."):
|
| 397 |
+
p_str += "."
|
| 398 |
+
|
| 399 |
+
result.append(p_str)
|
| 400 |
+
|
| 401 |
+
if not html:
|
| 402 |
+
return "\n\n".join(result)
|
| 403 |
+
return markupsafe.Markup(
|
| 404 |
+
"\n".join(f"<p>{markupsafe.escape(x)}</p>" for x in result)
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def url_quote(obj: t.Any, charset: str = "utf-8", for_qs: bool = False) -> str:
|
| 409 |
+
"""Quote a string for use in a URL using the given charset.
|
| 410 |
+
|
| 411 |
+
:param obj: String or bytes to quote. Other types are converted to
|
| 412 |
+
string then encoded to bytes using the given charset.
|
| 413 |
+
:param charset: Encode text to bytes using this charset.
|
| 414 |
+
:param for_qs: Quote "/" and use "+" for spaces.
|
| 415 |
+
"""
|
| 416 |
+
if not isinstance(obj, bytes):
|
| 417 |
+
if not isinstance(obj, str):
|
| 418 |
+
obj = str(obj)
|
| 419 |
+
|
| 420 |
+
obj = obj.encode(charset)
|
| 421 |
+
|
| 422 |
+
safe = b"" if for_qs else b"/"
|
| 423 |
+
rv = quote_from_bytes(obj, safe)
|
| 424 |
+
|
| 425 |
+
if for_qs:
|
| 426 |
+
rv = rv.replace("%20", "+")
|
| 427 |
+
|
| 428 |
+
return rv
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
@abc.MutableMapping.register
|
| 432 |
+
class LRUCache:
|
| 433 |
+
"""A simple LRU Cache implementation."""
|
| 434 |
+
|
| 435 |
+
# this is fast for small capacities (something below 1000) but doesn't
|
| 436 |
+
# scale. But as long as it's only used as storage for templates this
|
| 437 |
+
# won't do any harm.
|
| 438 |
+
|
| 439 |
+
def __init__(self, capacity: int) -> None:
|
| 440 |
+
self.capacity = capacity
|
| 441 |
+
self._mapping: t.Dict[t.Any, t.Any] = {}
|
| 442 |
+
self._queue: te.Deque[t.Any] = deque()
|
| 443 |
+
self._postinit()
|
| 444 |
+
|
| 445 |
+
def _postinit(self) -> None:
|
| 446 |
+
# alias all queue methods for faster lookup
|
| 447 |
+
self._popleft = self._queue.popleft
|
| 448 |
+
self._pop = self._queue.pop
|
| 449 |
+
self._remove = self._queue.remove
|
| 450 |
+
self._wlock = Lock()
|
| 451 |
+
self._append = self._queue.append
|
| 452 |
+
|
| 453 |
+
def __getstate__(self) -> t.Mapping[str, t.Any]:
|
| 454 |
+
return {
|
| 455 |
+
"capacity": self.capacity,
|
| 456 |
+
"_mapping": self._mapping,
|
| 457 |
+
"_queue": self._queue,
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
def __setstate__(self, d: t.Mapping[str, t.Any]) -> None:
|
| 461 |
+
self.__dict__.update(d)
|
| 462 |
+
self._postinit()
|
| 463 |
+
|
| 464 |
+
def __getnewargs__(self) -> t.Tuple[t.Any, ...]:
|
| 465 |
+
return (self.capacity,)
|
| 466 |
+
|
| 467 |
+
def copy(self) -> "te.Self":
|
| 468 |
+
"""Return a shallow copy of the instance."""
|
| 469 |
+
rv = self.__class__(self.capacity)
|
| 470 |
+
rv._mapping.update(self._mapping)
|
| 471 |
+
rv._queue.extend(self._queue)
|
| 472 |
+
return rv
|
| 473 |
+
|
| 474 |
+
def get(self, key: t.Any, default: t.Any = None) -> t.Any:
|
| 475 |
+
"""Return an item from the cache dict or `default`"""
|
| 476 |
+
try:
|
| 477 |
+
return self[key]
|
| 478 |
+
except KeyError:
|
| 479 |
+
return default
|
| 480 |
+
|
| 481 |
+
def setdefault(self, key: t.Any, default: t.Any = None) -> t.Any:
|
| 482 |
+
"""Set `default` if the key is not in the cache otherwise
|
| 483 |
+
leave unchanged. Return the value of this key.
|
| 484 |
+
"""
|
| 485 |
+
try:
|
| 486 |
+
return self[key]
|
| 487 |
+
except KeyError:
|
| 488 |
+
self[key] = default
|
| 489 |
+
return default
|
| 490 |
+
|
| 491 |
+
def clear(self) -> None:
|
| 492 |
+
"""Clear the cache."""
|
| 493 |
+
with self._wlock:
|
| 494 |
+
self._mapping.clear()
|
| 495 |
+
self._queue.clear()
|
| 496 |
+
|
| 497 |
+
def __contains__(self, key: t.Any) -> bool:
|
| 498 |
+
"""Check if a key exists in this cache."""
|
| 499 |
+
return key in self._mapping
|
| 500 |
+
|
| 501 |
+
def __len__(self) -> int:
|
| 502 |
+
"""Return the current size of the cache."""
|
| 503 |
+
return len(self._mapping)
|
| 504 |
+
|
| 505 |
+
def __repr__(self) -> str:
|
| 506 |
+
return f"<{type(self).__name__} {self._mapping!r}>"
|
| 507 |
+
|
| 508 |
+
def __getitem__(self, key: t.Any) -> t.Any:
|
| 509 |
+
"""Get an item from the cache. Moves the item up so that it has the
|
| 510 |
+
highest priority then.
|
| 511 |
+
|
| 512 |
+
Raise a `KeyError` if it does not exist.
|
| 513 |
+
"""
|
| 514 |
+
with self._wlock:
|
| 515 |
+
rv = self._mapping[key]
|
| 516 |
+
|
| 517 |
+
if self._queue[-1] != key:
|
| 518 |
+
try:
|
| 519 |
+
self._remove(key)
|
| 520 |
+
except ValueError:
|
| 521 |
+
# if something removed the key from the container
|
| 522 |
+
# when we read, ignore the ValueError that we would
|
| 523 |
+
# get otherwise.
|
| 524 |
+
pass
|
| 525 |
+
|
| 526 |
+
self._append(key)
|
| 527 |
+
|
| 528 |
+
return rv
|
| 529 |
+
|
| 530 |
+
def __setitem__(self, key: t.Any, value: t.Any) -> None:
|
| 531 |
+
"""Sets the value for an item. Moves the item up so that it
|
| 532 |
+
has the highest priority then.
|
| 533 |
+
"""
|
| 534 |
+
with self._wlock:
|
| 535 |
+
if key in self._mapping:
|
| 536 |
+
self._remove(key)
|
| 537 |
+
elif len(self._mapping) == self.capacity:
|
| 538 |
+
del self._mapping[self._popleft()]
|
| 539 |
+
|
| 540 |
+
self._append(key)
|
| 541 |
+
self._mapping[key] = value
|
| 542 |
+
|
| 543 |
+
def __delitem__(self, key: t.Any) -> None:
|
| 544 |
+
"""Remove an item from the cache dict.
|
| 545 |
+
Raise a `KeyError` if it does not exist.
|
| 546 |
+
"""
|
| 547 |
+
with self._wlock:
|
| 548 |
+
del self._mapping[key]
|
| 549 |
+
|
| 550 |
+
try:
|
| 551 |
+
self._remove(key)
|
| 552 |
+
except ValueError:
|
| 553 |
+
pass
|
| 554 |
+
|
| 555 |
+
def items(self) -> t.Iterable[t.Tuple[t.Any, t.Any]]:
|
| 556 |
+
"""Return a list of items."""
|
| 557 |
+
result = [(key, self._mapping[key]) for key in list(self._queue)]
|
| 558 |
+
result.reverse()
|
| 559 |
+
return result
|
| 560 |
+
|
| 561 |
+
def values(self) -> t.Iterable[t.Any]:
|
| 562 |
+
"""Return a list of all values."""
|
| 563 |
+
return [x[1] for x in self.items()]
|
| 564 |
+
|
| 565 |
+
def keys(self) -> t.Iterable[t.Any]:
|
| 566 |
+
"""Return a list of all keys ordered by most recent usage."""
|
| 567 |
+
return list(self)
|
| 568 |
+
|
| 569 |
+
def __iter__(self) -> t.Iterator[t.Any]:
|
| 570 |
+
return reversed(tuple(self._queue))
|
| 571 |
+
|
| 572 |
+
def __reversed__(self) -> t.Iterator[t.Any]:
|
| 573 |
+
"""Iterate over the keys in the cache dict, oldest items
|
| 574 |
+
coming first.
|
| 575 |
+
"""
|
| 576 |
+
return iter(tuple(self._queue))
|
| 577 |
+
|
| 578 |
+
__copy__ = copy
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
def select_autoescape(
|
| 582 |
+
enabled_extensions: t.Collection[str] = ("html", "htm", "xml"),
|
| 583 |
+
disabled_extensions: t.Collection[str] = (),
|
| 584 |
+
default_for_string: bool = True,
|
| 585 |
+
default: bool = False,
|
| 586 |
+
) -> t.Callable[[t.Optional[str]], bool]:
|
| 587 |
+
"""Intelligently sets the initial value of autoescaping based on the
|
| 588 |
+
filename of the template. This is the recommended way to configure
|
| 589 |
+
autoescaping if you do not want to write a custom function yourself.
|
| 590 |
+
|
| 591 |
+
If you want to enable it for all templates created from strings or
|
| 592 |
+
for all templates with `.html` and `.xml` extensions::
|
| 593 |
+
|
| 594 |
+
from jinja2 import Environment, select_autoescape
|
| 595 |
+
env = Environment(autoescape=select_autoescape(
|
| 596 |
+
enabled_extensions=('html', 'xml'),
|
| 597 |
+
default_for_string=True,
|
| 598 |
+
))
|
| 599 |
+
|
| 600 |
+
Example configuration to turn it on at all times except if the template
|
| 601 |
+
ends with `.txt`::
|
| 602 |
+
|
| 603 |
+
from jinja2 import Environment, select_autoescape
|
| 604 |
+
env = Environment(autoescape=select_autoescape(
|
| 605 |
+
disabled_extensions=('txt',),
|
| 606 |
+
default_for_string=True,
|
| 607 |
+
default=True,
|
| 608 |
+
))
|
| 609 |
+
|
| 610 |
+
The `enabled_extensions` is an iterable of all the extensions that
|
| 611 |
+
autoescaping should be enabled for. Likewise `disabled_extensions` is
|
| 612 |
+
a list of all templates it should be disabled for. If a template is
|
| 613 |
+
loaded from a string then the default from `default_for_string` is used.
|
| 614 |
+
If nothing matches then the initial value of autoescaping is set to the
|
| 615 |
+
value of `default`.
|
| 616 |
+
|
| 617 |
+
For security reasons this function operates case insensitive.
|
| 618 |
+
|
| 619 |
+
.. versionadded:: 2.9
|
| 620 |
+
"""
|
| 621 |
+
enabled_patterns = tuple(f".{x.lstrip('.').lower()}" for x in enabled_extensions)
|
| 622 |
+
disabled_patterns = tuple(f".{x.lstrip('.').lower()}" for x in disabled_extensions)
|
| 623 |
+
|
| 624 |
+
def autoescape(template_name: t.Optional[str]) -> bool:
|
| 625 |
+
if template_name is None:
|
| 626 |
+
return default_for_string
|
| 627 |
+
template_name = template_name.lower()
|
| 628 |
+
if template_name.endswith(enabled_patterns):
|
| 629 |
+
return True
|
| 630 |
+
if template_name.endswith(disabled_patterns):
|
| 631 |
+
return False
|
| 632 |
+
return default
|
| 633 |
+
|
| 634 |
+
return autoescape
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
def htmlsafe_json_dumps(
|
| 638 |
+
obj: t.Any, dumps: t.Optional[t.Callable[..., str]] = None, **kwargs: t.Any
|
| 639 |
+
) -> markupsafe.Markup:
|
| 640 |
+
"""Serialize an object to a string of JSON with :func:`json.dumps`,
|
| 641 |
+
then replace HTML-unsafe characters with Unicode escapes and mark
|
| 642 |
+
the result safe with :class:`~markupsafe.Markup`.
|
| 643 |
+
|
| 644 |
+
This is available in templates as the ``|tojson`` filter.
|
| 645 |
+
|
| 646 |
+
The following characters are escaped: ``<``, ``>``, ``&``, ``'``.
|
| 647 |
+
|
| 648 |
+
The returned string is safe to render in HTML documents and
|
| 649 |
+
``<script>`` tags. The exception is in HTML attributes that are
|
| 650 |
+
double quoted; either use single quotes or the ``|forceescape``
|
| 651 |
+
filter.
|
| 652 |
+
|
| 653 |
+
:param obj: The object to serialize to JSON.
|
| 654 |
+
:param dumps: The ``dumps`` function to use. Defaults to
|
| 655 |
+
``env.policies["json.dumps_function"]``, which defaults to
|
| 656 |
+
:func:`json.dumps`.
|
| 657 |
+
:param kwargs: Extra arguments to pass to ``dumps``. Merged onto
|
| 658 |
+
``env.policies["json.dumps_kwargs"]``.
|
| 659 |
+
|
| 660 |
+
.. versionchanged:: 3.0
|
| 661 |
+
The ``dumper`` parameter is renamed to ``dumps``.
|
| 662 |
+
|
| 663 |
+
.. versionadded:: 2.9
|
| 664 |
+
"""
|
| 665 |
+
if dumps is None:
|
| 666 |
+
dumps = json.dumps
|
| 667 |
+
|
| 668 |
+
return markupsafe.Markup(
|
| 669 |
+
dumps(obj, **kwargs)
|
| 670 |
+
.replace("<", "\\u003c")
|
| 671 |
+
.replace(">", "\\u003e")
|
| 672 |
+
.replace("&", "\\u0026")
|
| 673 |
+
.replace("'", "\\u0027")
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
class Cycler:
|
| 678 |
+
"""Cycle through values by yield them one at a time, then restarting
|
| 679 |
+
once the end is reached. Available as ``cycler`` in templates.
|
| 680 |
+
|
| 681 |
+
Similar to ``loop.cycle``, but can be used outside loops or across
|
| 682 |
+
multiple loops. For example, render a list of folders and files in a
|
| 683 |
+
list, alternating giving them "odd" and "even" classes.
|
| 684 |
+
|
| 685 |
+
.. code-block:: html+jinja
|
| 686 |
+
|
| 687 |
+
{% set row_class = cycler("odd", "even") %}
|
| 688 |
+
<ul class="browser">
|
| 689 |
+
{% for folder in folders %}
|
| 690 |
+
<li class="folder {{ row_class.next() }}">{{ folder }}
|
| 691 |
+
{% endfor %}
|
| 692 |
+
{% for file in files %}
|
| 693 |
+
<li class="file {{ row_class.next() }}">{{ file }}
|
| 694 |
+
{% endfor %}
|
| 695 |
+
</ul>
|
| 696 |
+
|
| 697 |
+
:param items: Each positional argument will be yielded in the order
|
| 698 |
+
given for each cycle.
|
| 699 |
+
|
| 700 |
+
.. versionadded:: 2.1
|
| 701 |
+
"""
|
| 702 |
+
|
| 703 |
+
def __init__(self, *items: t.Any) -> None:
|
| 704 |
+
if not items:
|
| 705 |
+
raise RuntimeError("at least one item has to be provided")
|
| 706 |
+
self.items = items
|
| 707 |
+
self.pos = 0
|
| 708 |
+
|
| 709 |
+
def reset(self) -> None:
|
| 710 |
+
"""Resets the current item to the first item."""
|
| 711 |
+
self.pos = 0
|
| 712 |
+
|
| 713 |
+
@property
|
| 714 |
+
def current(self) -> t.Any:
|
| 715 |
+
"""Return the current item. Equivalent to the item that will be
|
| 716 |
+
returned next time :meth:`next` is called.
|
| 717 |
+
"""
|
| 718 |
+
return self.items[self.pos]
|
| 719 |
+
|
| 720 |
+
def next(self) -> t.Any:
|
| 721 |
+
"""Return the current item, then advance :attr:`current` to the
|
| 722 |
+
next item.
|
| 723 |
+
"""
|
| 724 |
+
rv = self.current
|
| 725 |
+
self.pos = (self.pos + 1) % len(self.items)
|
| 726 |
+
return rv
|
| 727 |
+
|
| 728 |
+
__next__ = next
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
class Joiner:
|
| 732 |
+
"""A joining helper for templates."""
|
| 733 |
+
|
| 734 |
+
def __init__(self, sep: str = ", ") -> None:
|
| 735 |
+
self.sep = sep
|
| 736 |
+
self.used = False
|
| 737 |
+
|
| 738 |
+
def __call__(self) -> str:
|
| 739 |
+
if not self.used:
|
| 740 |
+
self.used = True
|
| 741 |
+
return ""
|
| 742 |
+
return self.sep
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
class Namespace:
|
| 746 |
+
"""A namespace object that can hold arbitrary attributes. It may be
|
| 747 |
+
initialized from a dictionary or with keyword arguments."""
|
| 748 |
+
|
| 749 |
+
def __init__(*args: t.Any, **kwargs: t.Any) -> None: # noqa: B902
|
| 750 |
+
self, args = args[0], args[1:]
|
| 751 |
+
self.__attrs = dict(*args, **kwargs)
|
| 752 |
+
|
| 753 |
+
def __getattribute__(self, name: str) -> t.Any:
|
| 754 |
+
# __class__ is needed for the awaitable check in async mode
|
| 755 |
+
if name in {"_Namespace__attrs", "__class__"}:
|
| 756 |
+
return object.__getattribute__(self, name)
|
| 757 |
+
try:
|
| 758 |
+
return self.__attrs[name]
|
| 759 |
+
except KeyError:
|
| 760 |
+
raise AttributeError(name) from None
|
| 761 |
+
|
| 762 |
+
def __setitem__(self, name: str, value: t.Any) -> None:
|
| 763 |
+
self.__attrs[name] = value
|
| 764 |
+
|
| 765 |
+
def __repr__(self) -> str:
|
| 766 |
+
return f"<Namespace {self.__attrs!r}>"
|