|
2 | 2 |
|
3 | 3 | import copy |
4 | 4 | import re |
5 | | -from collections import OrderedDict |
6 | 5 | from itertools import chain |
7 | | -from typing import Any, Callable, Dict |
| 6 | +from typing import Any, Callable |
8 | 7 |
|
9 | 8 | from django.conf import settings |
10 | 9 | from django.utils.encoding import force_str |
|
52 | 51 | "block-all-mixed-content": None, # Deprecated. |
53 | 52 | } |
54 | 53 |
|
55 | | -DIRECTIVES_T = Dict[str, Any] |
| 54 | +DIRECTIVES_T = dict[str, Any] |
56 | 55 |
|
57 | 56 |
|
58 | 57 | def default_config(csp: DIRECTIVES_T | None) -> DIRECTIVES_T | None: |
@@ -172,15 +171,16 @@ def _async_attr_mapper(attr_name: str, val: str | bool) -> str: |
172 | 171 |
|
173 | 172 |
|
174 | 173 | # Allow per-attribute customization of returned string template |
175 | | -SCRIPT_ATTRS: dict[str, Callable[[str, Any], str]] = OrderedDict() |
176 | | -SCRIPT_ATTRS["nonce"] = _default_attr_mapper |
177 | | -SCRIPT_ATTRS["id"] = _default_attr_mapper |
178 | | -SCRIPT_ATTRS["src"] = _default_attr_mapper |
179 | | -SCRIPT_ATTRS["type"] = _default_attr_mapper |
180 | | -SCRIPT_ATTRS["async"] = _async_attr_mapper |
181 | | -SCRIPT_ATTRS["defer"] = _bool_attr_mapper |
182 | | -SCRIPT_ATTRS["integrity"] = _default_attr_mapper |
183 | | -SCRIPT_ATTRS["nomodule"] = _bool_attr_mapper |
| 174 | +SCRIPT_ATTRS: dict[str, Callable[[str, Any], str]] = { |
| 175 | + "nonce": _default_attr_mapper, |
| 176 | + "id": _default_attr_mapper, |
| 177 | + "src": _default_attr_mapper, |
| 178 | + "type": _default_attr_mapper, |
| 179 | + "async": _async_attr_mapper, |
| 180 | + "defer": _bool_attr_mapper, |
| 181 | + "integrity": _default_attr_mapper, |
| 182 | + "nomodule": _bool_attr_mapper, |
| 183 | +} |
184 | 184 |
|
185 | 185 | # Generates an interpolatable string of valid attrs eg - '{nonce}{id}...' |
186 | 186 | ATTR_FORMAT_STR = "".join([f"{{{a}}}" for a in SCRIPT_ATTRS]) |
|
0 commit comments