Permalink
Browse files

Fixed #18042 -- Advanced deprecation warnings.

Thanks Ramiro for the patch.
  • Loading branch information...
aaugustin committed May 3, 2012
1 parent 227cec6 commit e84f79f05113f546810c1908c7baef99fb1e874a
View
@@ -181,7 +181,7 @@ def compat_patch_logging_config(logging_config):
"handler: adding implicit debug-false-only filter. " "handler: adding implicit debug-false-only filter. "
"See http://docs.djangoproject.com/en/dev/releases/1.4/" "See http://docs.djangoproject.com/en/dev/releases/1.4/"
"#request-exceptions-are-now-always-logged", "#request-exceptions-are-now-always-logged",
PendingDeprecationWarning) DeprecationWarning)
filter_name = "require_debug_false" filter_name = "require_debug_false"
@@ -1,6 +1,6 @@
import warnings import warnings
warnings.warn("django.conf.urls.defaults is deprecated; use django.conf.urls instead", warnings.warn("django.conf.urls.defaults is deprecated; use django.conf.urls instead",
PendingDeprecationWarning) DeprecationWarning)
from django.conf.urls import (handler403, handler404, handler500, from django.conf.urls import (handler403, handler404, handler500,
include, patterns, url) include, patterns, url)
@@ -11,5 +11,5 @@ def admin_media_prefix():
""" """
warnings.warn( warnings.warn(
"The admin_media_prefix template tag is deprecated. " "The admin_media_prefix template tag is deprecated. "
"Use the static template tag instead.", PendingDeprecationWarning) "Use the static template tag instead.", DeprecationWarning)
return PrefixNode.handle_simple("ADMIN_MEDIA_PREFIX") return PrefixNode.handle_simple("ADMIN_MEDIA_PREFIX")
@@ -2,5 +2,4 @@
from django.contrib.databrowse.sites import DatabrowsePlugin, ModelDatabrowse, DatabrowseSite, site from django.contrib.databrowse.sites import DatabrowsePlugin, ModelDatabrowse, DatabrowseSite, site
warnings.warn("The Databrowse contrib app is deprecated", warnings.warn("The Databrowse contrib app is deprecated", DeprecationWarning)
PendingDeprecationWarning)
@@ -7,6 +7,7 @@
from django.contrib.formtools import preview, utils from django.contrib.formtools import preview, utils
from django.contrib.formtools.wizard import FormWizard from django.contrib.formtools.wizard import FormWizard
from django.test import TestCase from django.test import TestCase
from django.test.utils import get_warnings_state, restore_warnings_state
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils import unittest from django.utils import unittest
@@ -40,12 +41,20 @@ class PreviewTests(TestCase):
def setUp(self): def setUp(self):
super(PreviewTests, self).setUp() super(PreviewTests, self).setUp()
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.contrib.formtools.wizard.legacy')
# Create a FormPreview instance to share between tests # Create a FormPreview instance to share between tests
self.preview = preview.FormPreview(TestForm) self.preview = preview.FormPreview(TestForm)
input_template = '<input type="hidden" name="%s" value="%s" />' input_template = '<input type="hidden" name="%s" value="%s" />'
self.input = input_template % (self.preview.unused_name('stage'), "%d") self.input = input_template % (self.preview.unused_name('stage'), "%d")
self.test_data = {'field1':u'foo', 'field1_':u'asdf'} self.test_data = {'field1':u'foo', 'field1_':u'asdf'}
def tearDown(self):
super(PreviewTests, self).tearDown()
self.restore_warnings_state()
def test_unused_name(self): def test_unused_name(self):
""" """
Verifies name mangling to get uniue field name. Verifies name mangling to get uniue field name.
@@ -39,7 +39,7 @@ def __init__(self, form_list, initial=None):
warnings.warn( warnings.warn(
'Old-style form wizards have been deprecated; use the class-based ' 'Old-style form wizards have been deprecated; use the class-based '
'views in django.contrib.formtools.wizard.views instead.', 'views in django.contrib.formtools.wizard.views instead.',
PendingDeprecationWarning) DeprecationWarning)
def __repr__(self): def __repr__(self):
return "step: %d\nform_list: %s\ninitial_data: %s" % (self.step, self.form_list, self.initial) return "step: %d\nform_list: %s\ninitial_data: %s" % (self.step, self.form_list, self.initial)
@@ -10,5 +10,5 @@ class GeoIP(BaseGeoIP):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
warnings.warn('GeoIP class has been moved to `django.contrib.gis.geoip`, and ' warnings.warn('GeoIP class has been moved to `django.contrib.gis.geoip`, and '
'this shortcut will disappear in Django v1.6.', 'this shortcut will disappear in Django v1.6.',
PendingDeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=2)
super(GeoIP, self).__init__(*args, **kwargs) super(GeoIP, self).__init__(*args, **kwargs)
@@ -3,7 +3,7 @@
import warnings import warnings
warnings.warn( warnings.warn(
'The "UK" prefix for United Kingdom has been deprecated in favour of the ' 'The "UK" prefix for United Kingdom has been deprecated in favour of the '
'GB code. Please use the new GB-prefixed names.', PendingDeprecationWarning) 'GB code. Please use the new GB-prefixed names.', DeprecationWarning)
UKPostcodeField = forms.GBPostcodeField UKPostcodeField = forms.GBPostcodeField
UKCountySelect = forms.GBCountySelect UKCountySelect = forms.GBCountySelect
@@ -6,7 +6,7 @@
import warnings import warnings
warnings.warn( warnings.warn(
'The "UK" prefix for United Kingdom has been deprecated in favour of the ' 'The "UK" prefix for United Kingdom has been deprecated in favour of the '
'GB code. Please use the new GB-prefixed names.', PendingDeprecationWarning) 'GB code. Please use the new GB-prefixed names.', DeprecationWarning)
UK_NATIONS_CHOICES = GB_NATIONS_CHOICES UK_NATIONS_CHOICES = GB_NATIONS_CHOICES
UK_REGION_CHOICES = GB_REGION_CHOICES UK_REGION_CHOICES = GB_REGION_CHOICES
@@ -130,7 +130,7 @@ def __init__(self, server, params):
import warnings import warnings
warnings.warn( warnings.warn(
"memcached.CacheClass has been split into memcached.MemcachedCache and memcached.PyLibMCCache. Please update your cache backend setting.", "memcached.CacheClass has been split into memcached.MemcachedCache and memcached.PyLibMCCache. Please update your cache backend setting.",
PendingDeprecationWarning DeprecationWarning
) )
try: try:
import memcache import memcache
@@ -395,7 +395,7 @@ def setup_environ(settings_mod, original_settings_path=None):
"you likely need to update your 'manage.py'; " "you likely need to update your 'manage.py'; "
"please see the Django 1.4 release notes " "please see the Django 1.4 release notes "
"(https://docs.djangoproject.com/en/dev/releases/1.4/).", "(https://docs.djangoproject.com/en/dev/releases/1.4/).",
PendingDeprecationWarning) DeprecationWarning)
# Add this project to sys.path so that it's importable in the conventional # Add this project to sys.path so that it's importable in the conventional
# way. For example, if this file (manage.py) lives in a directory # way. For example, if this file (manage.py) lives in a directory
@@ -451,7 +451,7 @@ def execute_manager(settings_mod, argv=None):
"you likely need to update your 'manage.py'; " "you likely need to update your 'manage.py'; "
"please see the Django 1.4 release notes " "please see the Django 1.4 release notes "
"(https://docs.djangoproject.com/en/dev/releases/1.4/).", "(https://docs.djangoproject.com/en/dev/releases/1.4/).",
PendingDeprecationWarning) DeprecationWarning)
setup_environ(settings_mod) setup_environ(settings_mod)
utility = ManagementUtility(argv) utility = ManagementUtility(argv)
View
@@ -297,7 +297,7 @@ def body(self):
@property @property
def raw_post_data(self): def raw_post_data(self):
warnings.warn('HttpRequest.raw_post_data has been deprecated. Use HttpRequest.body instead.', PendingDeprecationWarning) warnings.warn('HttpRequest.raw_post_data has been deprecated. Use HttpRequest.body instead.', DeprecationWarning)
return self.body return self.body
def _mark_post_parse_error(self): def _mark_post_parse_error(self):
@@ -130,16 +130,14 @@ def _is_ignorable_404(uri):
if getattr(settings, 'IGNORABLE_404_STARTS', ()): if getattr(settings, 'IGNORABLE_404_STARTS', ()):
import warnings import warnings
warnings.warn('The IGNORABLE_404_STARTS setting has been deprecated ' warnings.warn('The IGNORABLE_404_STARTS setting has been deprecated '
'in favor of IGNORABLE_404_URLS.', 'in favor of IGNORABLE_404_URLS.', DeprecationWarning)
PendingDeprecationWarning)
for start in settings.IGNORABLE_404_STARTS: for start in settings.IGNORABLE_404_STARTS:
if uri.startswith(start): if uri.startswith(start):
return True return True
if getattr(settings, 'IGNORABLE_404_ENDS', ()): if getattr(settings, 'IGNORABLE_404_ENDS', ()):
import warnings import warnings
warnings.warn('The IGNORABLE_404_ENDS setting has been deprecated ' warnings.warn('The IGNORABLE_404_ENDS setting has been deprecated '
'in favor of IGNORABLE_404_URLS.', 'in favor of IGNORABLE_404_URLS.', DeprecationWarning)
PendingDeprecationWarning)
for end in settings.IGNORABLE_404_ENDS: for end in settings.IGNORABLE_404_ENDS:
if uri.endswith(end): if uri.endswith(end):
return True return True
@@ -53,7 +53,7 @@ def _dec(*args, **kwargs):
warnings.warn("Setting the %s attribute of a template filter " warnings.warn("Setting the %s attribute of a template filter "
"function is deprecated; use @register.filter(%s=%s) " "function is deprecated; use @register.filter(%s=%s) "
"instead" % (attr, attr, getattr(func, attr)), "instead" % (attr, attr, getattr(func, attr)),
PendingDeprecationWarning) DeprecationWarning)
setattr(_dec, attr, getattr(func, attr)) setattr(_dec, attr, getattr(func, attr))
return wraps(func)(_dec) return wraps(func)(_dec)
@@ -7,7 +7,7 @@
import warnings import warnings
warnings.warn("django.utils.copycompat is deprecated; use the native copy module instead", warnings.warn("django.utils.copycompat is deprecated; use the native copy module instead",
PendingDeprecationWarning) DeprecationWarning)
# Monkeypatch copy's deepcopy registry to handle functions correctly. # Monkeypatch copy's deepcopy registry to handle functions correctly.
if (hasattr(copy, '_deepcopy_dispatch') and types.FunctionType not in copy._deepcopy_dispatch): if (hasattr(copy, '_deepcopy_dispatch') and types.FunctionType not in copy._deepcopy_dispatch):
@@ -6,7 +6,7 @@
import warnings import warnings
warnings.warn("django.utils.hashcompat is deprecated; use hashlib instead", warnings.warn("django.utils.hashcompat is deprecated; use hashlib instead",
PendingDeprecationWarning) DeprecationWarning)
import hashlib import hashlib
md5_constructor = hashlib.md5 md5_constructor = hashlib.md5
@@ -18,18 +18,16 @@ def is_iterable(x):
return True return True
def product(*args, **kwds): def product(*args, **kwds):
# PendingDeprecationWarning in 1.5, remove this comment when the Deprecations
# will have been advanced for 1.5
warnings.warn("django.utils.itercompat.product is deprecated; use the native version instead", warnings.warn("django.utils.itercompat.product is deprecated; use the native version instead",
PendingDeprecationWarning) PendingDeprecationWarning)
return itertools.product(*args, **kwds) return itertools.product(*args, **kwds)
def all(iterable): def all(iterable):
warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead", warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead",
PendingDeprecationWarning) DeprecationWarning)
return __builtin__.all(iterable) return __builtin__.all(iterable)
def any(iterable): def any(iterable):
warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead", warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead",
PendingDeprecationWarning) DeprecationWarning)
return __builtin__.any(iterable) return __builtin__.any(iterable)
View
@@ -206,14 +206,14 @@ def _html_words(self, length, truncate):
def truncate_words(s, num, end_text='...'): def truncate_words(s, num, end_text='...'):
warnings.warn('This function has been deprecated. Use the Truncator class ' warnings.warn('This function has been deprecated. Use the Truncator class '
'in django.utils.text instead.', category=PendingDeprecationWarning) 'in django.utils.text instead.', category=DeprecationWarning)
truncate = end_text and ' %s' % end_text or '' truncate = end_text and ' %s' % end_text or ''
return Truncator(s).words(num, truncate=truncate) return Truncator(s).words(num, truncate=truncate)
truncate_words = allow_lazy(truncate_words, unicode) truncate_words = allow_lazy(truncate_words, unicode)
def truncate_html_words(s, num, end_text='...'): def truncate_html_words(s, num, end_text='...'):
warnings.warn('This function has been deprecated. Use the Truncator class ' warnings.warn('This function has been deprecated. Use the Truncator class '
'in django.utils.text instead.', category=PendingDeprecationWarning) 'in django.utils.text instead.', category=DeprecationWarning)
truncate = end_text and ' %s' % end_text or '' truncate = end_text and ' %s' % end_text or ''
return Truncator(s).words(num, truncate=truncate, html=True) return Truncator(s).words(num, truncate=truncate, html=True)
truncate_html_words = allow_lazy(truncate_html_words, unicode) truncate_html_words = allow_lazy(truncate_html_words, unicode)
@@ -44,8 +44,8 @@ def warn():
warnings.warn('The cache_page decorator must be called like: ' warnings.warn('The cache_page decorator must be called like: '
'cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). ' 'cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). '
'All other ways are deprecated.', 'All other ways are deprecated.',
PendingDeprecationWarning, DeprecationWarning,
stacklevel=3) stacklevel=2)
if len(args) > 1: if len(args) > 1:
assert len(args) == 2, "cache_page accepts at most 2 arguments" assert len(args) == 2, "cache_page accepts at most 2 arguments"
@@ -55,15 +55,15 @@ def csrf_response_exempt(view_func):
""" """
warnings.warn("csrf_response_exempt is deprecated. It no longer performs a " warnings.warn("csrf_response_exempt is deprecated. It no longer performs a "
"function, and calls to it can be removed.", "function, and calls to it can be removed.",
PendingDeprecationWarning) DeprecationWarning)
return view_func return view_func
def csrf_view_exempt(view_func): def csrf_view_exempt(view_func):
""" """
Marks a view function as being exempt from CSRF view protection. Marks a view function as being exempt from CSRF view protection.
""" """
warnings.warn("csrf_view_exempt is deprecated. Use csrf_exempt instead.", warnings.warn("csrf_view_exempt is deprecated. Use csrf_exempt instead.",
PendingDeprecationWarning) DeprecationWarning)
return csrf_exempt(view_func) return csrf_exempt(view_func)
def csrf_exempt(view_func): def csrf_exempt(view_func):
@@ -1442,12 +1442,18 @@ def hello_world_view(request, value):
) )
class CacheMiddlewareTest(TestCase): class CacheMiddlewareTest(TestCase):
# The following tests will need to be modified in Django 1.6 to not use
# deprecated ways of using the cache_page decorator that will be removed in
# such version
def setUp(self): def setUp(self):
self.factory = RequestFactory() self.factory = RequestFactory()
self.default_cache = get_cache('default') self.default_cache = get_cache('default')
self.other_cache = get_cache('other') self.other_cache = get_cache('other')
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.views.decorators.cache')
def tearDown(self): def tearDown(self):
self.restore_warnings_state()
self.default_cache.clear() self.default_cache.clear()
self.other_cache.clear() self.other_cache.clear()
@@ -70,7 +70,7 @@ class DecoratorsTest(TestCase):
def setUp(self): def setUp(self):
self.warning_state = get_warnings_state() self.warning_state = get_warnings_state()
warnings.filterwarnings('ignore', category=PendingDeprecationWarning, warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.views.decorators.cache') module='django.views.decorators.cache')
def tearDown(self): def tearDown(self):
@@ -1,9 +1,10 @@
import copy import copy
import warnings
from django.conf import compat_patch_logging_config from django.conf import compat_patch_logging_config
from django.core import mail from django.core import mail
from django.test import TestCase, RequestFactory from django.test import TestCase, RequestFactory
from django.test.utils import override_settings from django.test.utils import override_settings, get_warnings_state, restore_warnings_state
from django.utils.log import CallbackFilter, RequireDebugFalse, getLogger from django.utils.log import CallbackFilter, RequireDebugFalse, getLogger
@@ -40,7 +41,13 @@ def test_filter_added(self):
""" """
config = copy.deepcopy(OLD_LOGGING) config = copy.deepcopy(OLD_LOGGING)
compat_patch_logging_config(config)
warnings_state = get_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.conf')
try:
compat_patch_logging_config(config)
finally:
restore_warnings_state(warnings_state)
self.assertEqual( self.assertEqual(
config["handlers"]["mail_admins"]["filters"], config["handlers"]["mail_admins"]["filters"],
@@ -420,5 +420,10 @@ def read(self, len=0):
'CONTENT_LENGTH': len(payload), 'CONTENT_LENGTH': len(payload),
'wsgi.input': ExplodingStringIO(payload)}) 'wsgi.input': ExplodingStringIO(payload)})
with self.assertRaises(UnreadablePostError): warnings_state = get_warnings_state()
request.raw_post_data warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.http')
try:
with self.assertRaises(UnreadablePostError):
request.raw_post_data
finally:
restore_warnings_state(warnings_state)
@@ -1,4 +1,5 @@
import os import os
import warnings
from django.conf import settings, global_settings from django.conf import settings, global_settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
@@ -274,10 +275,14 @@ class EnvironmentVariableTest(TestCase):
Ensures proper settings file is used in setup_environ if Ensures proper settings file is used in setup_environ if
DJANGO_SETTINGS_MODULE is set in the environment. DJANGO_SETTINGS_MODULE is set in the environment.
""" """
# Decide what to do with these tests when setup_environ() gets removed in Django 1.6
def setUp(self): def setUp(self):
self.original_value = os.environ.get('DJANGO_SETTINGS_MODULE') self.original_value = os.environ.get('DJANGO_SETTINGS_MODULE')
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.core.management')
def tearDown(self): def tearDown(self):
self.restore_warnings_state()
if self.original_value: if self.original_value:
os.environ['DJANGO_SETTINGS_MODULE'] = self.original_value os.environ['DJANGO_SETTINGS_MODULE'] = self.original_value
elif 'DJANGO_SETTINGS_MODULE' in os.environ: elif 'DJANGO_SETTINGS_MODULE' in os.environ:
@@ -1,9 +1,19 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest import warnings
from django.test import SimpleTestCase
from django.utils import text from django.utils import text
class TestUtilsText(unittest.TestCase): class TestUtilsText(SimpleTestCase):
# In Django 1.6 truncate_words() and truncate_html_words() will be removed
# so these tests will need to be adapted accordingly
def setUp(self):
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.utils.text')
def tearDown(self):
self.restore_warnings_state()
def test_truncate_chars(self): def test_truncate_chars(self):
truncator = text.Truncator( truncator = text.Truncator(
View
@@ -10,7 +10,7 @@
# databrowse is deprecated, but we still want to run its tests # databrowse is deprecated, but we still want to run its tests
warnings.filterwarnings('ignore', "The Databrowse contrib app is deprecated", warnings.filterwarnings('ignore', "The Databrowse contrib app is deprecated",
PendingDeprecationWarning, 'django.contrib.databrowse') DeprecationWarning, 'django.contrib.databrowse')
CONTRIB_DIR_NAME = 'django.contrib' CONTRIB_DIR_NAME = 'django.contrib'
MODEL_TESTS_DIR_NAME = 'modeltests' MODEL_TESTS_DIR_NAME = 'modeltests'

0 comments on commit e84f79f

Please sign in to comment.