summaryrefslogtreecommitdiff
path: root/django/conf/__init__.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-10-02 20:45:19 -0700
committerTim Graham <timograham@gmail.com>2018-10-15 17:15:41 -0400
commit0cd465b63aa7c03a3d14bd5fd6543628d585f8da (patch)
tree99adcb585573d78d5cc01c9b9466073dbe988449 /django/conf/__init__.py
parent99d4fc18bdb8110147165531d348be53529eece5 (diff)
Fixed #29817 -- Deprecated settings.FILE_CHARSET.
Diffstat (limited to 'django/conf/__init__.py')
-rw-r--r--django/conf/__init__.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index a380806485..73d943d26e 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -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):