web/lib/django/template/debug.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
     1 from django.template import Lexer, Parser, tag_re, NodeList, VariableNode, TemplateSyntaxError
     1 from django.template import Lexer, Parser, tag_re, NodeList, VariableNode, TemplateSyntaxError
     2 from django.utils.encoding import force_unicode
     2 from django.utils.encoding import force_unicode
     3 from django.utils.html import escape
     3 from django.utils.html import escape
     4 from django.utils.safestring import SafeData, EscapeData
     4 from django.utils.safestring import SafeData, EscapeData
       
     5 from django.utils.formats import localize
     5 
     6 
     6 class DebugLexer(Lexer):
     7 class DebugLexer(Lexer):
     7     def __init__(self, template_string, origin):
     8     def __init__(self, template_string, origin):
     8         super(DebugLexer, self).__init__(template_string, origin)
     9         super(DebugLexer, self).__init__(template_string, origin)
     9 
    10 
    73             if not hasattr(e, 'source'):
    74             if not hasattr(e, 'source'):
    74                 e.source = node.source
    75                 e.source = node.source
    75             raise
    76             raise
    76         except Exception, e:
    77         except Exception, e:
    77             from sys import exc_info
    78             from sys import exc_info
    78             wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace'))
    79             wrapped = TemplateSyntaxError(u'Caught %s while rendering: %s' %
       
    80                 (e.__class__.__name__, force_unicode(e, errors='replace')))
    79             wrapped.source = node.source
    81             wrapped.source = node.source
    80             wrapped.exc_info = exc_info()
    82             wrapped.exc_info = exc_info()
    81             raise wrapped
    83             raise wrapped, None, wrapped.exc_info[2]
    82         return result
    84         return result
    83 
    85 
    84 class DebugVariableNode(VariableNode):
    86 class DebugVariableNode(VariableNode):
    85     def render(self, context):
    87     def render(self, context):
    86         try:
    88         try:
    87             output = force_unicode(self.filter_expression.resolve(context))
    89             output = self.filter_expression.resolve(context)
       
    90             output = localize(output)
       
    91             output = force_unicode(output)
    88         except TemplateSyntaxError, e:
    92         except TemplateSyntaxError, e:
    89             if not hasattr(e, 'source'):
    93             if not hasattr(e, 'source'):
    90                 e.source = self.source
    94                 e.source = self.source
    91             raise
    95             raise
    92         except UnicodeDecodeError:
    96         except UnicodeDecodeError: