From 2d899ce16bdbef1a015275237f0bfef4045fb6b2 Mon Sep 17 00:00:00 2001
From: Tim Graham <timograham@gmail.com>
Date: Fri, 3 Feb 2017 19:38:33 -0500
Subject: [PATCH] Refs #23919 -- Removed a Python 2 code path in force_text().

Reverted the obsolete fix and tests for refs #12302.
---
 django/utils/encoding.py                      | 11 +-------
 tests/view_tests/__init__.py                  |  8 ------
 .../templates/debug/template_exception.html   |  2 +-
 tests/view_tests/templatetags/debugtags.py    |  6 ++---
 tests/view_tests/tests/test_debug.py          | 25 +++++++------------
 tests/view_tests/urls.py                      |  3 +--
 tests/view_tests/views.py                     | 10 ++------
 7 files changed, 16 insertions(+), 49 deletions(-)

diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 65bc1ad728..a050586cba 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -66,16 +66,7 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
         else:
             s = str(s)
     except UnicodeDecodeError as e:
-        if not isinstance(s, Exception):
-            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)
+        raise DjangoUnicodeDecodeError(s, *e.args)
     return s
 
 
diff --git a/tests/view_tests/__init__.py b/tests/view_tests/__init__.py
index f48b197507..e69de29bb2 100644
--- a/tests/view_tests/__init__.py
+++ b/tests/view_tests/__init__.py
@@ -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
diff --git a/tests/view_tests/templates/debug/template_exception.html b/tests/view_tests/templates/debug/template_exception.html
index c6b34a8388..31c25418fe 100644
--- a/tests/view_tests/templates/debug/template_exception.html
+++ b/tests/view_tests/templates/debug/template_exception.html
@@ -1,2 +1,2 @@
 {% load debugtags %}
-{% go_boom arg %}
+{% go_boom %}
diff --git a/tests/view_tests/templatetags/debugtags.py b/tests/view_tests/templatetags/debugtags.py
index 443a89f32c..d08b3c079e 100644
--- a/tests/view_tests/templatetags/debugtags.py
+++ b/tests/view_tests/templatetags/debugtags.py
@@ -1,10 +1,8 @@
 from django import template
 
-from ..views import BrokenException
-
 register = template.Library()
 
 
 @register.simple_tag
-def go_boom(arg):
-    raise BrokenException(arg)
+def go_boom():
+    raise Exception('boom')
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index dcec795f68..8d8d5a57a4 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -21,7 +21,6 @@ from django.views.debug import (
     cleanse_setting, technical_500_response,
 )
 
-from .. import BrokenException, except_args
 from ..views import (
     custom_exception_reporter_filter_view, index_page,
     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, "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):
         """
         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):
-        for n in range(len(except_args)):
-            try:
-                self.client.get(reverse('template_exception', args=(n,)))
-            except Exception:
-                raising_loc = inspect.trace()[-1][-2][0].strip()
-                self.assertNotEqual(
-                    raising_loc.find('raise BrokenException'), -1,
-                    "Failed to find 'raise BrokenException' in last frame of "
-                    "traceback, instead found: %s" % raising_loc
-                )
+        try:
+            self.client.get(reverse('template_exception'))
+        except Exception:
+            raising_loc = inspect.trace()[-1][-2][0].strip()
+            self.assertNotEqual(
+                raising_loc.find("raise Exception('boom')"), -1,
+                "Failed to find 'raise Exception' in last frame of "
+                "traceback, instead found: %s" % raising_loc
+            )
 
     def test_template_loader_postmortem(self):
         """Tests for not existing file"""
diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py
index 26130f37bb..a942662845 100644
--- a/tests/view_tests/urls.py
+++ b/tests/view_tests/urls.py
@@ -96,8 +96,7 @@ urlpatterns += i18n_patterns(
 )
 
 urlpatterns += [
-    url(r'view_exception/(?P<n>[0-9]+)/$', views.view_exception, name='view_exception'),
-    url(r'template_exception/(?P<n>[0-9]+)/$', views.template_exception, name='template_exception'),
+    url(r'template_exception/$', views.template_exception, name='template_exception'),
     url(
         r'^raises_template_does_not_exist/(?P<path>.+)$',
         views.raises_template_does_not_exist,
diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py
index 2e47037470..cdc3f533ef 100644
--- a/tests/view_tests/views.py
+++ b/tests/view_tests/views.py
@@ -16,8 +16,6 @@ from django.views.decorators.debug import (
     sensitive_post_parameters, sensitive_variables,
 )
 
-from . import BrokenException, except_args
-
 
 def index_page(request):
     """Dummy index page"""
@@ -70,12 +68,8 @@ class Http404View(View):
         raise Http404("Testing class-based technical 404.")
 
 
-def view_exception(request, n):
-    raise BrokenException(except_args[int(n)])
-
-
-def template_exception(request, n):
-    return render(request, 'debug/template_exception.html', {'arg': except_args[int(n)]})
+def template_exception(request):
+    return render(request, 'debug/template_exception.html')
 
 
 def jsi18n(request):