mirror of
https://github.com/quantum5/django-csp-advanced.git
synced 2025-04-24 11:22:00 -04:00
Remove dependency on six
This commit is contained in:
parent
6363ff8b6f
commit
c5869c11ee
|
@ -1,7 +1,5 @@
|
|||
from itertools import chain
|
||||
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class InvalidCSPError(ValueError):
|
||||
pass
|
||||
|
@ -76,7 +74,7 @@ class CSPCompiler(object):
|
|||
|
||||
def compile(self):
|
||||
pieces = []
|
||||
for name, value in six.iteritems(self.csp):
|
||||
for name, value in self.csp.items():
|
||||
if name in self.CSP_LISTS:
|
||||
if value:
|
||||
pieces.append(self.compile_list(name, value))
|
||||
|
@ -128,5 +126,5 @@ class CSPCompiler(object):
|
|||
|
||||
@staticmethod
|
||||
def ensure_str(name, value):
|
||||
if not isinstance(value, six.string_types):
|
||||
if not isinstance(value, str):
|
||||
raise InvalidCSPError('Values for %s must be a string type, not %s', (name, type(value)))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import MiddlewareNotUsed
|
||||
from django.utils import six
|
||||
|
||||
from csp_advanced.csp import CSPCompiler, InvalidCSPError
|
||||
from csp_advanced.utils import is_callable_csp_dict, call_csp_dict, merge_csp_dict
|
||||
|
@ -13,11 +12,11 @@ class AdvancedCSPMiddleware(object):
|
|||
def __init__(self, get_response=None):
|
||||
self.get_response = get_response
|
||||
self.enforced_csp = getattr(settings, 'ADVANCED_CSP', None) or {}
|
||||
self.enforced_csp_is_str = isinstance(self.enforced_csp, six.string_types)
|
||||
self.enforced_csp_is_str = isinstance(self.enforced_csp, str)
|
||||
self.enforced_csp_callable = is_callable_csp_dict(self.enforced_csp)
|
||||
self.report_csp = getattr(settings, 'ADVANCED_CSP_REPORT_ONLY', None) or {}
|
||||
self.report_csp_callable = is_callable_csp_dict(self.report_csp)
|
||||
self.report_csp_is_str = isinstance(self.enforced_csp, six.string_types)
|
||||
self.report_csp_is_str = isinstance(self.enforced_csp, str)
|
||||
self.report_only_csp = not self.enforced_csp
|
||||
|
||||
if not self.enforced_csp and not self.report_csp:
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
from django.utils import six
|
||||
|
||||
|
||||
def is_callable_csp_dict(data):
|
||||
if callable(data):
|
||||
return True
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
return any(callable(value) for value in six.itervalues(data))
|
||||
return any(callable(value) for value in data.values())
|
||||
|
||||
|
||||
def call_csp_dict(data, request, response):
|
||||
|
@ -14,7 +11,7 @@ def call_csp_dict(data, request, response):
|
|||
return data(request, response)
|
||||
|
||||
result = {}
|
||||
for key, value in six.iteritems(data):
|
||||
for key, value in data.items():
|
||||
if callable(value):
|
||||
result[key] = value(request, response)
|
||||
else:
|
||||
|
@ -24,7 +21,7 @@ def call_csp_dict(data, request, response):
|
|||
|
||||
def merge_csp_dict(template, override):
|
||||
result = template.copy()
|
||||
for key, value in six.iteritems(override):
|
||||
for key, value in override.items():
|
||||
if key not in result:
|
||||
result[key] = value
|
||||
continue
|
||||
|
|
Loading…
Reference in a new issue