Skip to content

Commit

Permalink
mozillaGH-36 rename policy_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanYoung committed Mar 9, 2020
1 parent d9f5590 commit f93db2a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions csp/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def _wrapped(*a, **kw):
return decorator


def csp_update(csp_names=('default',), policy_dict=None, **kwargs):
def csp_update(csp_names=('default',), policy_definitions=None, **kwargs):
update = _policies_from_names_and_kwargs(
csp_names,
policy_dict,
policy_definitions,
**kwargs,
)

Expand All @@ -47,10 +47,10 @@ def _wrapped(*a, **kw):
return decorator


def csp_replace(csp_names=('default',), policy_dict=None, **kwargs):
def csp_replace(csp_names=('default',), policy_definitions=None, **kwargs):
replace = _policies_from_names_and_kwargs(
csp_names,
policy_dict,
policy_definitions,
**kwargs,
)

Expand All @@ -64,31 +64,31 @@ def _wrapped(*a, **kw):
return decorator


def csp(policies=(), policy_dict=None, **kwargs):
def csp(policies=(), policy_definitions=None, **kwargs):
policies = iter_policies(tuple(policies))

if kwargs and not isinstance(next(iter(kwargs.values())), dict):
# Single-policy kwargs is the legacy behaviour (deprecate?)
# TODO: single-policy format isn't currently supported for policy_dict

policy_name = next(policy_names)
if policy_dict:
policy_dict[policy_name] = kwargs
if policy_definitions:
policy_definitions[policy_name] = kwargs
else:
policy_dict = [(policy_name, kwargs)]
elif policy_dict:
duplicates = set(kwargs) & set(policy_dict)
policy_definitions = [(policy_name, kwargs)]
elif policy_definitions:
duplicates = set(kwargs) & set(policy_definitions)
if duplicates:
raise TypeError( # TypeError because python does it
"csp decorator got multiple policy definitions "
"for the same name: %s" % ', '.join(duplicates)
)
policy_dict.update(kwargs)
policy_definitions.update(kwargs)
else:
policy_dict = kwargs
policy_definitions = kwargs

config = OrderedDict(chain(
iter_policies(policy_dict),
iter_policies(policy_definitions),
policies,
))
# import pdb; pdb.set_trace()
Expand Down

0 comments on commit f93db2a

Please sign in to comment.