in csp/checks.py [0:0]
def migrate_settings() -> tuple[dict[str, Any], bool]:
# This function is used to migrate settings from the old format to the new format.
config: dict[str, Any] = {
"DIRECTIVES": {},
}
REPORT_ONLY = getattr(settings, "CSP_REPORT_ONLY", False)
_EXCLUDE_URL_PREFIXES = getattr(settings, "CSP_EXCLUDE_URL_PREFIXES", None)
if _EXCLUDE_URL_PREFIXES is not None:
config["EXCLUDE_URL_PREFIXES"] = _EXCLUDE_URL_PREFIXES
_REPORT_PERCENTAGE = getattr(settings, "CSP_REPORT_PERCENTAGE", None)
if _REPORT_PERCENTAGE is not None:
config["REPORT_PERCENTAGE"] = _REPORT_PERCENTAGE * 100
include_nonce_in = getattr(settings, "CSP_INCLUDE_NONCE_IN", [])
for setting in OUTDATED_SETTINGS:
if hasattr(settings, setting):
directive = setting[4:].replace("_", "-").lower()
value = getattr(settings, setting)
if value:
config["DIRECTIVES"][directive] = value
if directive in include_nonce_in:
config["DIRECTIVES"][directive].append(NONCE)
return config, REPORT_ONLY