|
@@ -16,12 +16,18 @@ from pathlib import Path
|
|
|
import django
|
|
|
from django.conf import global_settings
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
-from django.utils.deprecation import RemovedInDjango30Warning
|
|
|
+from django.utils.deprecation import (
|
|
|
+ RemovedInDjango30Warning, RemovedInDjango31Warning,
|
|
|
+)
|
|
|
from django.utils.functional import LazyObject, empty
|
|
|
|
|
|
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
|
|
|
|
|
|
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG = 'The DEFAULT_CONTENT_TYPE setting is deprecated.'
|
|
|
+FILE_CHARSET_DEPRECATED_MSG = (
|
|
|
+ 'The FILE_CHARSET setting is deprecated. Starting with Django 3.1, all '
|
|
|
+ 'files read from disk must be UTF-8 encoded.'
|
|
|
+)
|
|
|
|
|
|
|
|
|
class LazySettings(LazyObject):
|
|
@@ -111,6 +117,20 @@ class LazySettings(LazyObject):
|
|
|
)
|
|
|
return self.__getattr__('DEFAULT_CONTENT_TYPE')
|
|
|
|
|
|
+ @property
|
|
|
+ def FILE_CHARSET(self):
|
|
|
+ stack = traceback.extract_stack()
|
|
|
+ # Show a warning if the setting is used outside of Django.
|
|
|
+ # Stack index: -1 this line, -2 the caller.
|
|
|
+ filename, _line_number, _function_name, _text = stack[-2]
|
|
|
+ if not filename.startswith(os.path.dirname(django.__file__)):
|
|
|
+ warnings.warn(
|
|
|
+ FILE_CHARSET_DEPRECATED_MSG,
|
|
|
+ RemovedInDjango31Warning,
|
|
|
+ stacklevel=2,
|
|
|
+ )
|
|
|
+ return self.__getattr__('FILE_CHARSET')
|
|
|
+
|
|
|
|
|
|
class Settings:
|
|
|
def __init__(self, settings_module):
|
|
@@ -145,6 +165,8 @@ class Settings:
|
|
|
|
|
|
if self.is_overridden('DEFAULT_CONTENT_TYPE'):
|
|
|
warnings.warn(DEFAULT_CONTENT_TYPE_DEPRECATED_MSG, RemovedInDjango30Warning)
|
|
|
+ if self.is_overridden('FILE_CHARSET'):
|
|
|
+ warnings.warn(FILE_CHARSET_DEPRECATED_MSG, RemovedInDjango31Warning)
|
|
|
|
|
|
if hasattr(time, 'tzset') and self.TIME_ZONE:
|
|
|
# When we can, attempt to validate the timezone. If we can't find
|
|
@@ -191,6 +213,8 @@ class UserSettingsHolder:
|
|
|
self._deleted.discard(name)
|
|
|
if name == 'DEFAULT_CONTENT_TYPE':
|
|
|
warnings.warn(DEFAULT_CONTENT_TYPE_DEPRECATED_MSG, RemovedInDjango30Warning)
|
|
|
+ elif name == 'FILE_CHARSET':
|
|
|
+ warnings.warn(FILE_CHARSET_DEPRECATED_MSG, RemovedInDjango31Warning)
|
|
|
super().__setattr__(name, value)
|
|
|
|
|
|
def __delattr__(self, name):
|