MCPcopy
hub / github.com/adamchainz/django-cors-headers / check_settings

Function check_settings

src/corsheaders/checks.py:16–165  ·  view source on GitHub ↗
(**kwargs: Any)

Source from the content-addressed store, hash-verified

14
15
16def check_settings(**kwargs: Any) -> list[CheckMessage]:
17 errors: list[CheckMessage] = []
18
19 if not is_sequence(conf.CORS_ALLOW_HEADERS, str):
20 errors.append(
21 Error(
22 "CORS_ALLOW_HEADERS should be a sequence of strings.",
23 id="corsheaders.E001",
24 )
25 )
26
27 if not is_sequence(conf.CORS_ALLOW_METHODS, str):
28 errors.append(
29 Error(
30 "CORS_ALLOW_METHODS should be a sequence of strings.",
31 id="corsheaders.E002",
32 )
33 )
34
35 if not isinstance(conf.CORS_ALLOW_CREDENTIALS, bool):
36 errors.append( # type: ignore [unreachable]
37 Error("CORS_ALLOW_CREDENTIALS should be a bool.", id="corsheaders.E003")
38 )
39
40 if not isinstance(conf.CORS_ALLOW_PRIVATE_NETWORK, bool):
41 errors.append( # type: ignore [unreachable]
42 Error(
43 "CORS_ALLOW_PRIVATE_NETWORK should be a bool.",
44 id="corsheaders.E015",
45 )
46 )
47
48 if (
49 not isinstance(conf.CORS_PREFLIGHT_MAX_AGE, int) # type: ignore [redundant-expr]
50 or conf.CORS_PREFLIGHT_MAX_AGE < 0
51 ):
52 errors.append(
53 Error(
54 (
55 "CORS_PREFLIGHT_MAX_AGE should be an integer greater than "
56 + "or equal to zero."
57 ),
58 id="corsheaders.E004",
59 )
60 )
61
62 if not isinstance(conf.CORS_ALLOW_ALL_ORIGINS, bool):
63 if hasattr(settings, "CORS_ALLOW_ALL_ORIGINS"): # type: ignore [unreachable]
64 allow_all_alias = "CORS_ALLOW_ALL_ORIGINS"
65 else:
66 allow_all_alias = "CORS_ORIGIN_ALLOW_ALL"
67 errors.append(
68 Error(
69 f"{allow_all_alias} should be a bool.",
70 id="corsheaders.E005",
71 )
72 )
73

Callers 1

check_error_codesMethod · 0.90

Calls 1

is_sequenceFunction · 0.85

Tested by 1

check_error_codesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…