Ticket #11461: 11461.diff
File 11461.diff, 5.2 KB (added by , 15 years ago) |
---|
-
django/template/__init__.py
104 104 invalid_var_format_string = None 105 105 106 106 class TemplateSyntaxError(Exception): 107 def __str__(self): 108 try: 109 import cStringIO as StringIO 110 except ImportError: 111 import StringIO 112 output = StringIO.StringIO() 113 output.write(Exception.__str__(self)) 114 # Check if we wrapped an exception and print that too. 115 if hasattr(self, 'exc_info'): 116 import traceback 117 output.write('\n\nOriginal ') 118 e = self.exc_info 119 traceback.print_exception(e[0], e[1], e[2], 500, output) 120 return output.getvalue() 107 pass 121 108 122 109 class TemplateDoesNotExist(Exception): 123 110 pass -
django/template/debug.py
79 79 wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace')) 80 80 wrapped.source = node.source 81 81 wrapped.exc_info = exc_info() 82 raise wrapped 82 raise wrapped, None, wrapped.exc_info[2] 83 83 return result 84 84 85 85 class DebugVariableNode(VariableNode): -
tests/regressiontests/debug/views.py
1 from django.shortcuts import render_to_response 2 1 3 from regressiontests.debug import BrokenException, except_args 2 4 3 5 def view_exception(request, n): … … 3 5 raise BrokenException(except_args[int(n)]) 4 6 7 def template_exception(request, n): 8 return render_to_response('debug/template_exception.html', 9 {'arg': except_args[int(n)]}) -
tests/regressiontests/debug/tests.py
1 import inspect 2 1 3 from django.test import TestCase 2 4 from django.conf import settings 3 5 from django.core.urlresolvers import reverse 6 from django.template import TemplateSyntaxError 4 7 5 8 from regressiontests.debug import BrokenException, except_args 6 9 … … 10 13 def setUp(self): 11 14 self.old_debug = settings.DEBUG 12 15 settings.DEBUG = True 16 self.old_template_debug = settings.TEMPLATE_DEBUG 17 settings.TEMPLATE_DEBUG = True 13 18 14 19 def tearDown(self): 15 20 settings.DEBUG = self.old_debug 21 settings.TEMPLATE_DEBUG = self.old_template_debug 16 22 17 23 def test_view_exceptions(self): 18 24 for n in range(len(except_args)): 19 25 self.assertRaises(BrokenException, self.client.get, 20 26 reverse('view_exception', args=(n,))) 21 27 28 def test_template_exceptions(self): 29 for n in range(len(except_args)): 30 try: 31 self.client.get(reverse('template_exception', args=(n,))) 32 except TemplateSyntaxError, e: 33 raising_loc = inspect.trace()[-1][-2][0].strip() 34 self.failIf(raising_loc.find('raise BrokenException') == -1, 35 "Failed to find 'raise BrokenException' in last frame of traceback, instead found: %s" % raising_loc) 36 -
tests/regressiontests/debug/templatetags/debugtags.py
1 from django import template 2 3 from regressiontests.debug import BrokenException 4 5 register = template.Library() 6 7 @register.simple_tag 8 def go_boom(arg): 9 raise BrokenException(arg) 10 -
tests/regressiontests/debug/urls.py
Property changes on: tests\regressiontests\debug\templatetags\debugtags.py ___________________________________________________________________ Added: svn:eol-style + native
2 2 3 3 urlpatterns = patterns('regressiontests.debug.views', 4 4 url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'), 5 url(r'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'), 5 6 ) -
tests/regressiontests/debug/templates/debug/template_exception.html
1 {% load debugtags %} 2 {% go_boom arg %}