Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_static_url(self, name):
try:
return decode_if_byte_string(staticfiles_storage.url(name))
except ValueError:
return None
self.use_finders = settings.DEBUG
self.static_prefix = urlparse(settings.STATIC_URL or '').path
if settings.DEBUG:
self.max_age = 0
# Allow settings to override default attributes
for attr in self.config_attrs:
settings_key = 'WHITENOISE_{0}'.format(attr.upper())
try:
value = getattr(settings, settings_key)
except AttributeError:
pass
else:
value = decode_if_byte_string(value)
setattr(self, attr, value)
self.static_prefix = ensure_leading_trailing_slash(self.static_prefix)
self.static_root = decode_if_byte_string(settings.STATIC_ROOT)
# Default configuration
self.charset = settings.FILE_CHARSET
self.autorefresh = settings.DEBUG
self.use_finders = settings.DEBUG
self.static_prefix = urlparse(settings.STATIC_URL or '').path
if settings.DEBUG:
self.max_age = 0
# Allow settings to override default attributes
for attr in self.config_attrs:
settings_key = 'WHITENOISE_{0}'.format(attr.upper())
try:
value = getattr(settings, settings_key)
except AttributeError:
pass
else:
value = decode_if_byte_string(value)
setattr(self, attr, value)
self.static_prefix = ensure_leading_trailing_slash(self.static_prefix)
self.static_root = decode_if_byte_string(settings.STATIC_ROOT)
def add_files(self, root, prefix=None):
root = decode_if_byte_string(root, force_text=True)
root = os.path.abspath(root)
root = root.rstrip(os.path.sep) + os.path.sep
prefix = decode_if_byte_string(prefix)
prefix = ensure_leading_trailing_slash(prefix)
if self.autorefresh:
# Later calls to `add_files` overwrite earlier ones, hence we need
# to store the list of directories in reverse order so later ones
# match first when they're checked in "autorefresh" mode
self.directories.insert(0, (root, prefix))
else:
if os.path.isdir(root):
self.update_files_dictionary(root, prefix)
else:
warnings.warn(u"No directory at: {}".format(root))
def get_static_url(self, name):
try:
return decode_if_byte_string(staticfiles_storage.url(name))
except ValueError:
return None
if self.static_prefix.startswith(script_name):
self.static_prefix = self.static_prefix[len(script_name) :]
if settings.DEBUG:
self.max_age = 0
# Allow settings to override default attributes
for attr in self.config_attrs:
settings_key = "WHITENOISE_{0}".format(attr.upper())
try:
value = getattr(settings, settings_key)
except AttributeError:
pass
else:
value = decode_if_byte_string(value)
setattr(self, attr, value)
self.static_prefix = ensure_leading_trailing_slash(self.static_prefix)
self.static_root = decode_if_byte_string(settings.STATIC_ROOT)