2
2
3
3
4
4
def csp_exempt (REPORT_ONLY = None ):
5
+ if callable (REPORT_ONLY ):
6
+ raise RuntimeError (
7
+ "Incompatible `csp_exempt` decorator usage. This decorator now requires arguments, "
8
+ "even if none are passed. Change bare decorator usage (@csp_exempt) to parameterized "
9
+ "decorator usage (@csp_exempt()). See the django-csp 4.0 migration guide for more "
10
+ "information."
11
+ )
12
+
5
13
def decorator (f ):
6
14
@wraps (f )
7
15
def _wrapped (* a , ** kw ):
@@ -17,7 +25,17 @@ def _wrapped(*a, **kw):
17
25
return decorator
18
26
19
27
20
- def csp_update (config , * , REPORT_ONLY = False ):
28
+ # Error message for deprecated decorator arguments.
29
+ DECORATOR_DEPRECATION_ERROR = (
30
+ "Incompatible `{fname}` decorator arguments. This decorator now takes a single dict argument. "
31
+ "See the django-csp 4.0 migration guide for more information."
32
+ )
33
+
34
+
35
+ def csp_update (config = None , REPORT_ONLY = False , ** kwargs ):
36
+ if config is None and kwargs :
37
+ raise RuntimeError (DECORATOR_DEPRECATION_ERROR .format (fname = "csp_update" ))
38
+
21
39
def decorator (f ):
22
40
@wraps (f )
23
41
def _wrapped (* a , ** kw ):
@@ -33,7 +51,10 @@ def _wrapped(*a, **kw):
33
51
return decorator
34
52
35
53
36
- def csp_replace (config , * , REPORT_ONLY = False ):
54
+ def csp_replace (config = None , REPORT_ONLY = False , ** kwargs ):
55
+ if config is None and kwargs :
56
+ raise RuntimeError (DECORATOR_DEPRECATION_ERROR .format (fname = "csp_replace" ))
57
+
37
58
def decorator (f ):
38
59
@wraps (f )
39
60
def _wrapped (* a , ** kw ):
@@ -49,7 +70,10 @@ def _wrapped(*a, **kw):
49
70
return decorator
50
71
51
72
52
- def csp (config , * , REPORT_ONLY = False ):
73
+ def csp (config = None , REPORT_ONLY = False , ** kwargs ):
74
+ if config is None and kwargs :
75
+ raise RuntimeError (DECORATOR_DEPRECATION_ERROR .format (fname = "csp" ))
76
+
53
77
config = {k : [v ] if isinstance (v , str ) else v for k , v in config .items ()}
54
78
55
79
def decorator (f ):
0 commit comments