Refs #23919 -- Removed a Python 2 code path in force_text().

Reverted the obsolete fix and tests for refs #12302.
This commit is contained in:
Tim Graham 2017-02-03 19:38:33 -05:00 committed by GitHub
parent 26619ad7b0
commit 2d899ce16b
7 changed files with 16 additions and 49 deletions

View File

@ -66,16 +66,7 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
else: else:
s = str(s) s = str(s)
except UnicodeDecodeError as e: except UnicodeDecodeError as e:
if not isinstance(s, Exception): raise DjangoUnicodeDecodeError(s, *e.args)
raise DjangoUnicodeDecodeError(s, *e.args)
else:
# If we get to here, the caller has passed in an Exception
# subclass populated with non-ASCII bytestring data without a
# working __str__() method. Try to handle this without raising a
# further exception by individually forcing the exception args
# to strings.
s = ' '.join(force_text(arg, encoding, strings_only, errors)
for arg in s)
return s return s

View File

@ -1,8 +0,0 @@
class BrokenException(Exception):
pass
except_args = (b'Broken!', # plain exception with ASCII text
'¡Broken!', # non-ASCII unicode data
'¡Broken!'.encode('utf-8'), # non-ASCII, utf-8 encoded bytestring
b'\xa1Broken!', ) # non-ASCII, latin1 bytestring

View File

@ -1,2 +1,2 @@
{% load debugtags %} {% load debugtags %}
{% go_boom arg %} {% go_boom %}

View File

@ -1,10 +1,8 @@
from django import template from django import template
from ..views import BrokenException
register = template.Library() register = template.Library()
@register.simple_tag @register.simple_tag
def go_boom(arg): def go_boom():
raise BrokenException(arg) raise Exception('boom')

View File

@ -21,7 +21,6 @@ from django.views.debug import (
cleanse_setting, technical_500_response, cleanse_setting, technical_500_response,
) )
from .. import BrokenException, except_args
from ..views import ( from ..views import (
custom_exception_reporter_filter_view, index_page, custom_exception_reporter_filter_view, index_page,
multivalue_dict_key_error, non_sensitive_view, paranoid_view, multivalue_dict_key_error, non_sensitive_view, paranoid_view,
@ -127,11 +126,6 @@ class DebugViewTests(LoggingCaptureMixin, SimpleTestCase):
self.assertContains(response, "Raised by:", status_code=404) self.assertContains(response, "Raised by:", status_code=404)
self.assertContains(response, "view_tests.views.Http404View", status_code=404) self.assertContains(response, "view_tests.views.Http404View", status_code=404)
def test_view_exceptions(self):
for n in range(len(except_args)):
with self.assertRaises(BrokenException):
self.client.get(reverse('view_exception', args=(n,)))
def test_non_l10ned_numeric_ids(self): def test_non_l10ned_numeric_ids(self):
""" """
Numeric IDs and fancy traceback context blocks line numbers shouldn't be localized. Numeric IDs and fancy traceback context blocks line numbers shouldn't be localized.
@ -150,16 +144,15 @@ class DebugViewTests(LoggingCaptureMixin, SimpleTestCase):
) )
def test_template_exceptions(self): def test_template_exceptions(self):
for n in range(len(except_args)): try:
try: self.client.get(reverse('template_exception'))
self.client.get(reverse('template_exception', args=(n,))) except Exception:
except Exception: raising_loc = inspect.trace()[-1][-2][0].strip()
raising_loc = inspect.trace()[-1][-2][0].strip() self.assertNotEqual(
self.assertNotEqual( raising_loc.find("raise Exception('boom')"), -1,
raising_loc.find('raise BrokenException'), -1, "Failed to find 'raise Exception' in last frame of "
"Failed to find 'raise BrokenException' in last frame of " "traceback, instead found: %s" % raising_loc
"traceback, instead found: %s" % raising_loc )
)
def test_template_loader_postmortem(self): def test_template_loader_postmortem(self):
"""Tests for not existing file""" """Tests for not existing file"""

View File

@ -96,8 +96,7 @@ urlpatterns += i18n_patterns(
) )
urlpatterns += [ urlpatterns += [
url(r'view_exception/(?P<n>[0-9]+)/$', views.view_exception, name='view_exception'), url(r'template_exception/$', views.template_exception, name='template_exception'),
url(r'template_exception/(?P<n>[0-9]+)/$', views.template_exception, name='template_exception'),
url( url(
r'^raises_template_does_not_exist/(?P<path>.+)$', r'^raises_template_does_not_exist/(?P<path>.+)$',
views.raises_template_does_not_exist, views.raises_template_does_not_exist,

View File

@ -16,8 +16,6 @@ from django.views.decorators.debug import (
sensitive_post_parameters, sensitive_variables, sensitive_post_parameters, sensitive_variables,
) )
from . import BrokenException, except_args
def index_page(request): def index_page(request):
"""Dummy index page""" """Dummy index page"""
@ -70,12 +68,8 @@ class Http404View(View):
raise Http404("Testing class-based technical 404.") raise Http404("Testing class-based technical 404.")
def view_exception(request, n): def template_exception(request):
raise BrokenException(except_args[int(n)]) return render(request, 'debug/template_exception.html')
def template_exception(request, n):
return render(request, 'debug/template_exception.html', {'arg': except_args[int(n)]})
def jsi18n(request): def jsi18n(request):